-
Notifications
You must be signed in to change notification settings - Fork 37
putDimension with same key is adding always new elements #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I see that How can we add a new dimension while keeping existing ones, without adding new empty elements in each request to that Dimensions List? I can create a new object in each metric flush, as it would happen in a Lambda/serverless context, but that seems poor usage of memory for EC2 context for what are similar metric flush, using same setup for a given service. |
Any feedback on this? |
This is a bug and we will be working on a fix. We do not have an ETA yet. |
@arielapostoli Thank you for the update. I have a very small PR for simplifying the test docker image , and I have another one prepared with some refactor simplifications, could you, or someone in the team take a look at that PR? |
you can try
Then use it in following way:
because after flush, the existing dimension will be copied and kept aws-embedded-metrics-java/src/main/java/software/amazon/cloudwatchlogs/emf/logger/MetricsLogger.java Line 66 in da5a3b1
Note that we use The dimensions you use `["LogGroup", "ServiceName", "ServiceType","Api" ] seems won't change once set so this makes me ^ should be enough |
Uh oh!
There was an error while loading. Please reload this page.
Hello,
I'm using the lib for a Java service on EC2, not serverless, so I create a single instance of the
MetricsLogger
that is created as@Bean
in a Spring context, and then I have have it in the class that log metrics as:Then I use this helper as such
However, when checking the logGroup, as the logged metrics increase, I see an ever increasing list of "Dimensions", even if the value for the metric is just 1, the event includes a huge Dimensions list
A sample record:
Digging a bit in code, whenever calling putDimension, indeed a new element is added to a java
List<DimensionSet>
.Code is here in MetricDirective.
Should this really be a list? if adding a new dimension that is already used, we could just update the value, this feels like it could be a Map and not a List to avoid this growing record size.
Or, is this the right usage? maybe when doing flush, this list should be cleaned? From the README.md I feel like the usage is correct, and user should not be worried about dimension internal structure (growing, or deleting/removing elements).
So maybe use a map would solve it, or integrate a clean in the flush
The text was updated successfully, but these errors were encountered: