-
Notifications
You must be signed in to change notification settings - Fork 154
Bug: Prevent a single metric have more than 100 data points #1529
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
Hi @leandrodamascena thanks for reporting this. I have added a (failing) test that looks like this: test("it should publish metrics when the array of values reaches the maximum size", () => {
// Prepare
const metrics: Metrics = new Metrics({ namespace: TEST_NAMESPACE });
const consoleSpy = jest.spyOn(console, "log");
const metricName = "test-metric";
// Act
for (let i = 0; i <= MAX_METRICS_SIZE; i++) {
metrics.addMetric(`${metricName}`, MetricUnits.Count, i);
}
metrics.publishStoredMetrics();
// Assess
// 2 calls to console.log: 1 for the first batch of metrics, 1 for the second batch (explicit call)
expect(consoleSpy).toHaveBeenCalledTimes(2);
const firstMetricsJson = JSON.parse(consoleSpy.mock.calls[0][0]) as EmfOutput;
const secondMetricsJson = JSON.parse(consoleSpy.mock.calls[1][0]) as EmfOutput;
expect(firstMetricsJson[metricName]).toHaveLength(MAX_METRICS_SIZE);
expect(secondMetricsJson[metricName]).toHaveLength(1);
}); Based on my understanding of this section of the EMF Specification, the values array should not exceed length 100:
As a result, Metrics should flush the stored metrics and handle the next ones transparently - which is not the case at the moment. We'll work on a fix and include it in the next release. |
|
This is now released under version 1.10.0! |
Expected Behaviour
Flush metric set when data point is reached to prevent potential data loss, where 100+ data points are added thus being ignored silently by CloudWatch EMF when processed in the background.
https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format_Specification.html#CloudWatch_Embedded_Metric_Format_Specification_structure_target
Current Behaviour
More than 100 metric data points can be added.
Code snippet
Steps to Reproduce
Run the code added in code snippet
Possible Solution
Serialize and flush metric data set when a single metric reaches 100 data points. Dimensions etc should be kept intact.
Powertools for AWS Lambda (TypeScript) version
latest
AWS Lambda function runtime
18.x
Packaging format used
Lambda Layers, npm
Execution logs
No response
The text was updated successfully, but these errors were encountered: