EmfMetricLoggingPublisher: Support multiple dimensionsets for metrics
- Dominant language
- Java
- Stars
- 2.6k
- Forks
- 1k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 51
Description
### Describe the feature
The existing [EmfMetricLoggingPublisher](https://docs.aws.amazon.com/java/api/latest/software/amazon/awssdk/metrics/publishers/emf/EmfMetricLoggingPublisher.Builder.html) currently supports a single set of dimensions for metrics. The EMF format supports an array of [DimensionSet](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format_Specification.html#CloudWatch_Embedded_Metric_Format_Specification_structure_dimensionset) for each metric to allow metrics to be rolled up at different granularity.
### Use Case
I'd like to be able to report client metrics rolled up for the entire service and also report them rolled up per api operation in that service.
e.g. for `FooService` with operations `foo` and `bar`, I'd like to have metrics reporting the DynamoDB query latency with the DimensionSets below
- `[Service=FooService, Client=DDB, ClientOperation=Query]`
- Service level
- `[Service=FooService, Operation=[foo|bar], Client=DDB, ClientOperation=Query]`
- Service+Operation level
Note: In order to provide the Context to the `EmfMetricLoggingPublisher` as to which Service Operation is running, that is possible today with a client interceptor that adds a custom SDK metric to the call which is capable of propagating whatever context is needed to produce these dimensions. That is functionally how I plan to bridge service level context information into the MetricCollection that the publisher has access to.
### Proposed Solution
Add an additional field on the builder to support a DimensionSetsFactory which follows the same pattern as the [PropertiesFactory](https://docs.aws.amazon.com/java/api/latest/software/amazon/awssdk/metrics/publishers/emf/EmfMetricLoggingPublisher.Builder.html#propertiesFactory(software.amazon.awssdk.metrics.publishers.emf.PropertiesFactory)). The existing dimensions options would continue to work as they do today with them producing DimensionSetsFactory internally allowing the publisher to consistently adopt the DimensionSetsFactory internally for producing metric dimensions.
Alternatively one could update the builder to accept a Collection of DimenionSets rather than just a single DimensionSet but the factory may prove more flexible for consumers.
### Other Information
_No response_
### Acknowledgements
- [x] I may be able to implement this feature request
- [ ] This feature might incur a breaking change
### AWS Java SDK version used
2
### JDK version used
21
### Operating System and version
linux
Contributor guide
Research direction
Start with EmfMetricLoggingPublisher and its Builder, then read the existing dimensions options and the PropertiesFactory pattern in the linked API documentation. Define how a DimensionSetsFactory is supplied and how existing dimension settings continue to work. Done means metrics can emit multiple EMF DimensionSets while preserving current single-dimension behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, java
- Domain
- observability-sre
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 56/100