software.amazon.kinesis.metrics.MetricsConfig Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of amazon-kinesis-client Show documentation
Show all versions of amazon-kinesis-client Show documentation
The Amazon Kinesis Client Library for Java enables Java developers to easily consume and process data
from Amazon Kinesis.
/*
* Copyright 2019 Amazon.com, Inc. or its affiliates.
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License 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.kinesis.metrics;
import java.util.HashSet;
import java.util.Set;
import com.google.common.collect.ImmutableSet;
import lombok.Data;
import lombok.experimental.Accessors;
import software.amazon.awssdk.services.cloudwatch.CloudWatchAsyncClient;
/**
* Used by KCL to configure the metrics reported by the application.
*/
@Data
@Accessors(fluent = true)
public class MetricsConfig {
/**
* Metrics dimensions that always will be enabled regardless of the config provided by user.
*/
public static final Set METRICS_ALWAYS_ENABLED_DIMENSIONS = ImmutableSet
.of(MetricsUtil.OPERATION_DIMENSION_NAME);
/**
* Allowed dimensions for CloudWatch metrics. By default, worker ID dimension will be disabled.
*/
public static final Set METRICS_ALWAYS_ENABLED_DIMENSIONS_WITH_SHARD_ID = ImmutableSet. builder()
.addAll(METRICS_ALWAYS_ENABLED_DIMENSIONS).add(MetricsUtil.SHARD_ID_DIMENSION_NAME).build();
/**
* Metrics dimensions that signify all possible dimensions.
*/
public static final Set METRICS_DIMENSIONS_ALL = ImmutableSet.of(MetricsScope.METRICS_DIMENSIONS_ALL);
/**
* Client used by the KCL to access the CloudWatch service for reporting metrics.
*
* @return {@link CloudWatchAsyncClient}
*/
private final CloudWatchAsyncClient cloudWatchClient;
/**
* Namespace for KCL metrics.
*
* @return String
*/
private final String namespace;
/**
* Buffer metrics for at most this long before publishing to CloudWatch.
*
*
* Default value: 10000L
*
*/
private long metricsBufferTimeMillis = 10000L;
/**
* Buffer at most this many metrics before publishing to CloudWatch.
*
*
* Default value: 10000
*
*/
private int metricsMaxQueueSize = 10000;
/**
* Metrics level for which to enable CloudWatch metrics.
*
*
* Default value: {@link MetricsLevel#DETAILED}
*
*/
private MetricsLevel metricsLevel = MetricsLevel.DETAILED;
/**
* Allowed dimensions for CloudWatchMetrics.
*
*
* Default value: {@link MetricsConfig#METRICS_DIMENSIONS_ALL}
*
*/
private HashSet metricsEnabledDimensions = new HashSet(METRICS_DIMENSIONS_ALL);
/**
* Buffer size for MetricDatums before publishing.
*
*
* Default value: 200
*
*/
private int publisherFlushBuffer = 200;
private MetricsFactory metricsFactory;
public MetricsFactory metricsFactory() {
if (metricsFactory == null) {
metricsFactory = new CloudWatchMetricsFactory(cloudWatchClient(), namespace(), metricsBufferTimeMillis(),
metricsMaxQueueSize(), metricsLevel(), metricsEnabledDimensions(), publisherFlushBuffer());
}
return metricsFactory;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy