All Downloads are FREE. Search and download functionalities are using the official Maven repository.

software.amazon.awssdk.services.cloudwatchlogs.model.MetricTransformation Maven / Gradle / Ivy

Go to download

The AWS Java SDK for Amazon CloudWatch Logs module holds the client classes that are used for communicating with Amazon CloudWatch Logs Service

There is a newer version: 2.30.1
Show newest version
/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
 * the License. A copy of the License is located at
 * 
 * http://aws.amazon.com/apache2.0
 * 
 * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
 * and limitations under the License.
 */

package software.amazon.awssdk.services.cloudwatchlogs.model;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Function;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.core.SdkField;
import software.amazon.awssdk.core.SdkPojo;
import software.amazon.awssdk.core.protocol.MarshallLocation;
import software.amazon.awssdk.core.protocol.MarshallingType;
import software.amazon.awssdk.core.traits.LocationTrait;
import software.amazon.awssdk.core.traits.MapTrait;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructMap;
import software.amazon.awssdk.core.util.SdkAutoConstructMap;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;

/**
 * 

* Indicates how to transform ingested log events to metric data in a CloudWatch metric. *

*/ @Generated("software.amazon.awssdk:codegen") public final class MetricTransformation implements SdkPojo, Serializable, ToCopyableBuilder { private static final SdkField METRIC_NAME_FIELD = SdkField. builder(MarshallingType.STRING) .memberName("metricName").getter(getter(MetricTransformation::metricName)).setter(setter(Builder::metricName)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("metricName").build()).build(); private static final SdkField METRIC_NAMESPACE_FIELD = SdkField. builder(MarshallingType.STRING) .memberName("metricNamespace").getter(getter(MetricTransformation::metricNamespace)) .setter(setter(Builder::metricNamespace)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("metricNamespace").build()).build(); private static final SdkField METRIC_VALUE_FIELD = SdkField. builder(MarshallingType.STRING) .memberName("metricValue").getter(getter(MetricTransformation::metricValue)).setter(setter(Builder::metricValue)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("metricValue").build()).build(); private static final SdkField DEFAULT_VALUE_FIELD = SdkField. builder(MarshallingType.DOUBLE) .memberName("defaultValue").getter(getter(MetricTransformation::defaultValue)).setter(setter(Builder::defaultValue)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("defaultValue").build()).build(); private static final SdkField> DIMENSIONS_FIELD = SdkField .> builder(MarshallingType.MAP) .memberName("dimensions") .getter(getter(MetricTransformation::dimensions)) .setter(setter(Builder::dimensions)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("dimensions").build(), MapTrait.builder() .keyLocationName("key") .valueLocationName("value") .valueFieldInfo( SdkField. builder(MarshallingType.STRING) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD) .locationName("value").build()).build()).build()).build(); private static final SdkField UNIT_FIELD = SdkField. builder(MarshallingType.STRING).memberName("unit") .getter(getter(MetricTransformation::unitAsString)).setter(setter(Builder::unit)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("unit").build()).build(); private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(METRIC_NAME_FIELD, METRIC_NAMESPACE_FIELD, METRIC_VALUE_FIELD, DEFAULT_VALUE_FIELD, DIMENSIONS_FIELD, UNIT_FIELD)); private static final long serialVersionUID = 1L; private final String metricName; private final String metricNamespace; private final String metricValue; private final Double defaultValue; private final Map dimensions; private final String unit; private MetricTransformation(BuilderImpl builder) { this.metricName = builder.metricName; this.metricNamespace = builder.metricNamespace; this.metricValue = builder.metricValue; this.defaultValue = builder.defaultValue; this.dimensions = builder.dimensions; this.unit = builder.unit; } /** *

* The name of the CloudWatch metric. *

* * @return The name of the CloudWatch metric. */ public final String metricName() { return metricName; } /** *

* A custom namespace to contain your metric in CloudWatch. Use namespaces to group together metrics that are * similar. For more information, see Namespaces. *

* * @return A custom namespace to contain your metric in CloudWatch. Use namespaces to group together metrics that * are similar. For more information, see Namespaces. */ public final String metricNamespace() { return metricNamespace; } /** *

* The value to publish to the CloudWatch metric when a filter pattern matches a log event. *

* * @return The value to publish to the CloudWatch metric when a filter pattern matches a log event. */ public final String metricValue() { return metricValue; } /** *

* (Optional) The value to emit when a filter pattern does not match a log event. This value can be null. *

* * @return (Optional) The value to emit when a filter pattern does not match a log event. This value can be null. */ public final Double defaultValue() { return defaultValue; } /** * For responses, this returns true if the service returned a value for the Dimensions property. This DOES NOT check * that the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is * useful because the SDK will never return a null collection or map, but you may need to differentiate between the * service returning nothing (or null) and the service returning an empty collection or map. For requests, this * returns true if a value for the property was specified in the request builder, and false if a value was not * specified. */ public final boolean hasDimensions() { return dimensions != null && !(dimensions instanceof SdkAutoConstructMap); } /** *

* The fields to use as dimensions for the metric. One metric filter can include as many as three dimensions. *

* *

* Metrics extracted from log events are charged as custom metrics. To prevent unexpected high charges, do not * specify high-cardinality fields such as IPAddress or requestID as dimensions. Each * different value found for a dimension is treated as a separate metric and accrues charges as a separate custom * metric. *

*

* CloudWatch Logs disables a metric filter if it generates 1000 different name/value pairs for your specified * dimensions within a certain amount of time. This helps to prevent accidental high charges. *

*

* You can also set up a billing alarm to alert you if your charges are higher than expected. For more information, * see * Creating a Billing Alarm to Monitor Your Estimated Amazon Web Services Charges. *

*
*

* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException. *

*

* This method will never return null. If you would like to know whether the service returned this field (so that * you can differentiate between null and empty), you can use the {@link #hasDimensions} method. *

* * @return The fields to use as dimensions for the metric. One metric filter can include as many as three * dimensions.

*

* Metrics extracted from log events are charged as custom metrics. To prevent unexpected high charges, do * not specify high-cardinality fields such as IPAddress or requestID as * dimensions. Each different value found for a dimension is treated as a separate metric and accrues * charges as a separate custom metric. *

*

* CloudWatch Logs disables a metric filter if it generates 1000 different name/value pairs for your * specified dimensions within a certain amount of time. This helps to prevent accidental high charges. *

*

* You can also set up a billing alarm to alert you if your charges are higher than expected. For more * information, see Creating a Billing Alarm to Monitor Your Estimated Amazon Web Services Charges. *

*/ public final Map dimensions() { return dimensions; } /** *

* The unit to assign to the metric. If you omit this, the unit is set as None. *

*

* If the service returns an enum value that is not available in the current SDK version, {@link #unit} will return * {@link StandardUnit#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available from * {@link #unitAsString}. *

* * @return The unit to assign to the metric. If you omit this, the unit is set as None. * @see StandardUnit */ public final StandardUnit unit() { return StandardUnit.fromValue(unit); } /** *

* The unit to assign to the metric. If you omit this, the unit is set as None. *

*

* If the service returns an enum value that is not available in the current SDK version, {@link #unit} will return * {@link StandardUnit#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available from * {@link #unitAsString}. *

* * @return The unit to assign to the metric. If you omit this, the unit is set as None. * @see StandardUnit */ public final String unitAsString() { return unit; } @Override public Builder toBuilder() { return new BuilderImpl(this); } public static Builder builder() { return new BuilderImpl(); } public static Class serializableBuilderClass() { return BuilderImpl.class; } @Override public final int hashCode() { int hashCode = 1; hashCode = 31 * hashCode + Objects.hashCode(metricName()); hashCode = 31 * hashCode + Objects.hashCode(metricNamespace()); hashCode = 31 * hashCode + Objects.hashCode(metricValue()); hashCode = 31 * hashCode + Objects.hashCode(defaultValue()); hashCode = 31 * hashCode + Objects.hashCode(hasDimensions() ? dimensions() : null); hashCode = 31 * hashCode + Objects.hashCode(unitAsString()); return hashCode; } @Override public final boolean equals(Object obj) { return equalsBySdkFields(obj); } @Override public final boolean equalsBySdkFields(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof MetricTransformation)) { return false; } MetricTransformation other = (MetricTransformation) obj; return Objects.equals(metricName(), other.metricName()) && Objects.equals(metricNamespace(), other.metricNamespace()) && Objects.equals(metricValue(), other.metricValue()) && Objects.equals(defaultValue(), other.defaultValue()) && hasDimensions() == other.hasDimensions() && Objects.equals(dimensions(), other.dimensions()) && Objects.equals(unitAsString(), other.unitAsString()); } /** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. */ @Override public final String toString() { return ToString.builder("MetricTransformation").add("MetricName", metricName()).add("MetricNamespace", metricNamespace()) .add("MetricValue", metricValue()).add("DefaultValue", defaultValue()) .add("Dimensions", hasDimensions() ? dimensions() : null).add("Unit", unitAsString()).build(); } public final Optional getValueForField(String fieldName, Class clazz) { switch (fieldName) { case "metricName": return Optional.ofNullable(clazz.cast(metricName())); case "metricNamespace": return Optional.ofNullable(clazz.cast(metricNamespace())); case "metricValue": return Optional.ofNullable(clazz.cast(metricValue())); case "defaultValue": return Optional.ofNullable(clazz.cast(defaultValue())); case "dimensions": return Optional.ofNullable(clazz.cast(dimensions())); case "unit": return Optional.ofNullable(clazz.cast(unitAsString())); default: return Optional.empty(); } } @Override public final List> sdkFields() { return SDK_FIELDS; } private static Function getter(Function g) { return obj -> g.apply((MetricTransformation) obj); } private static BiConsumer setter(BiConsumer s) { return (obj, val) -> s.accept((Builder) obj, val); } public interface Builder extends SdkPojo, CopyableBuilder { /** *

* The name of the CloudWatch metric. *

* * @param metricName * The name of the CloudWatch metric. * @return Returns a reference to this object so that method calls can be chained together. */ Builder metricName(String metricName); /** *

* A custom namespace to contain your metric in CloudWatch. Use namespaces to group together metrics that are * similar. For more information, see Namespaces. *

* * @param metricNamespace * A custom namespace to contain your metric in CloudWatch. Use namespaces to group together metrics that * are similar. For more information, see Namespaces. * @return Returns a reference to this object so that method calls can be chained together. */ Builder metricNamespace(String metricNamespace); /** *

* The value to publish to the CloudWatch metric when a filter pattern matches a log event. *

* * @param metricValue * The value to publish to the CloudWatch metric when a filter pattern matches a log event. * @return Returns a reference to this object so that method calls can be chained together. */ Builder metricValue(String metricValue); /** *

* (Optional) The value to emit when a filter pattern does not match a log event. This value can be null. *

* * @param defaultValue * (Optional) The value to emit when a filter pattern does not match a log event. This value can be null. * @return Returns a reference to this object so that method calls can be chained together. */ Builder defaultValue(Double defaultValue); /** *

* The fields to use as dimensions for the metric. One metric filter can include as many as three dimensions. *

* *

* Metrics extracted from log events are charged as custom metrics. To prevent unexpected high charges, do not * specify high-cardinality fields such as IPAddress or requestID as dimensions. Each * different value found for a dimension is treated as a separate metric and accrues charges as a separate * custom metric. *

*

* CloudWatch Logs disables a metric filter if it generates 1000 different name/value pairs for your specified * dimensions within a certain amount of time. This helps to prevent accidental high charges. *

*

* You can also set up a billing alarm to alert you if your charges are higher than expected. For more * information, see Creating a Billing Alarm to Monitor Your Estimated Amazon Web Services Charges. *

*
* * @param dimensions * The fields to use as dimensions for the metric. One metric filter can include as many as three * dimensions.

*

* Metrics extracted from log events are charged as custom metrics. To prevent unexpected high charges, * do not specify high-cardinality fields such as IPAddress or requestID as * dimensions. Each different value found for a dimension is treated as a separate metric and accrues * charges as a separate custom metric. *

*

* CloudWatch Logs disables a metric filter if it generates 1000 different name/value pairs for your * specified dimensions within a certain amount of time. This helps to prevent accidental high charges. *

*

* You can also set up a billing alarm to alert you if your charges are higher than expected. For more * information, see Creating a Billing Alarm to Monitor Your Estimated Amazon Web Services Charges. *

* @return Returns a reference to this object so that method calls can be chained together. */ Builder dimensions(Map dimensions); /** *

* The unit to assign to the metric. If you omit this, the unit is set as None. *

* * @param unit * The unit to assign to the metric. If you omit this, the unit is set as None. * @see StandardUnit * @return Returns a reference to this object so that method calls can be chained together. * @see StandardUnit */ Builder unit(String unit); /** *

* The unit to assign to the metric. If you omit this, the unit is set as None. *

* * @param unit * The unit to assign to the metric. If you omit this, the unit is set as None. * @see StandardUnit * @return Returns a reference to this object so that method calls can be chained together. * @see StandardUnit */ Builder unit(StandardUnit unit); } static final class BuilderImpl implements Builder { private String metricName; private String metricNamespace; private String metricValue; private Double defaultValue; private Map dimensions = DefaultSdkAutoConstructMap.getInstance(); private String unit; private BuilderImpl() { } private BuilderImpl(MetricTransformation model) { metricName(model.metricName); metricNamespace(model.metricNamespace); metricValue(model.metricValue); defaultValue(model.defaultValue); dimensions(model.dimensions); unit(model.unit); } public final String getMetricName() { return metricName; } public final void setMetricName(String metricName) { this.metricName = metricName; } @Override public final Builder metricName(String metricName) { this.metricName = metricName; return this; } public final String getMetricNamespace() { return metricNamespace; } public final void setMetricNamespace(String metricNamespace) { this.metricNamespace = metricNamespace; } @Override public final Builder metricNamespace(String metricNamespace) { this.metricNamespace = metricNamespace; return this; } public final String getMetricValue() { return metricValue; } public final void setMetricValue(String metricValue) { this.metricValue = metricValue; } @Override public final Builder metricValue(String metricValue) { this.metricValue = metricValue; return this; } public final Double getDefaultValue() { return defaultValue; } public final void setDefaultValue(Double defaultValue) { this.defaultValue = defaultValue; } @Override public final Builder defaultValue(Double defaultValue) { this.defaultValue = defaultValue; return this; } public final Map getDimensions() { if (dimensions instanceof SdkAutoConstructMap) { return null; } return dimensions; } public final void setDimensions(Map dimensions) { this.dimensions = DimensionsCopier.copy(dimensions); } @Override public final Builder dimensions(Map dimensions) { this.dimensions = DimensionsCopier.copy(dimensions); return this; } public final String getUnit() { return unit; } public final void setUnit(String unit) { this.unit = unit; } @Override public final Builder unit(String unit) { this.unit = unit; return this; } @Override public final Builder unit(StandardUnit unit) { this.unit(unit == null ? null : unit.toString()); return this; } @Override public MetricTransformation build() { return new MetricTransformation(this); } @Override public List> sdkFields() { return SDK_FIELDS; } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy