Observability

This plugin supports injecting an AWS MetricPublisher into the underlying DynamoDB SDK client. This injection is accomplished by defining a class extendingimplementing AWSClientMetricsProviderAWSClientMetricsProvider.

Your implementation must expose a single constructor with one argument: an akka.actor.ClassicActorSystemProvider. Its metricPublisherFor method will take the config path to the client section of this instance of the plugin configuration.

The AWS SDK provides an implementation of MetricPublisher which publishes to Amazon CloudWatch. An AWSClientMetricsProvider providing this MetricPublisher with defaults would look like:

Scala
sourceimport akka.actor.ClassicActorSystemProvider
import akka.persistence.dynamodb.util.AWSClientMetricsProvider
import software.amazon.awssdk.metrics.MetricPublisher
import software.amazon.awssdk.metrics.publishers.cloudwatch.CloudWatchMetricPublisher

class CloudWatchWithDefaultConfigurationMetricsProvider(system: ClassicActorSystemProvider)
    extends AWSClientMetricsProvider {
  def metricPublisherFor(configLocation: String): MetricPublisher = {
    // These are just the defaults... a more elaborate configuration using its builder is possible
    CloudWatchMetricPublisher.create()
  }
}
Java
sourceimport akka.actor.ClassicActorSystemProvider;
import akka.persistence.dynamodb.util.AWSClientMetricsProvider;
import software.amazon.awssdk.metrics.MetricPublisher;
import software.amazon.awssdk.metrics.publishers.cloudwatch.CloudWatchMetricPublisher;

public class CloudWatchWithDefaultConfigurationMetricsProvider implements AWSClientMetricsProvider {
  public CloudWatchWithDefaultConfigurationMetricsProvider(ClassicActorSystemProvider system) {
  }

  @Override
  public MetricPublisher metricPublisherFor(String configLocation) {
    // These are just the defaults... a more elaborate configuration using its builder is possible
    return CloudWatchMetricPublisher.create();
  }
}

To register your provider implementation with the plugin, add its fully-qualified class name to the configuration path akka.persistence.dynamodb.client.metrics-providers (e.g. in application.conf):

akka.persistence.dynamodb.client.metrics-providers += domain.package.CloudWatchWithDefaultConfigurationMetricsProvider

In a test case, it may be useful to set the entire list of metrics-providers explicitly:

akka.persistence.dynamodb.client.metrics-providers = [ "domain.package.CloudWatchWithDefaultConfigurationMetricsProvider" ]

If multiple providers are specified, they will automatically be combined into a “meta-provider” which provides a publisher which will publish using all of the specified providers’ respective publishers.

If implementing your own MetricPublisher, Amazon recommends that care be taken to not block the thread calling the methods of the MetricPublisher: all I/O and “heavy” computation should be performed asynchronously and control immediately returned to the caller.

Found an error in this documentation? The source code for this page can be found here. Please feel free to edit and contribute a pull request.