Skip to content
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

EmfMetricPublisher class added #5752

Merged
merged 31 commits into from
Jan 3, 2025

Conversation

Fred1155
Copy link
Contributor

@Fred1155 Fred1155 commented Dec 13, 2024

Motivation and Context

The existing CloudWatchMetricPublisher has limitations when used with AWS Lambda functions. When current implementation be applied to lambda functions, it can results in metrics being lost when the lambda function terminates before the scheduled batch upload. EMF allows metrics to be published through CloudWatch Logs using a structured JSON format, which CloudWatch automatically processes to extract and publish metrics. The proposed EMFMetricPublisher will convert SDK metric collections into EMF-formatted log entries, leveraging Lambda's as well as other execution environment that has built-in integration with cloudwatch logs such as ECS.

Modifications

Add a new metric publisher that transforms an metricCollection to a list of emf format Strings and publish it to CouldWatch using cloudwatch agents

Testing

  1. Unit test covering different cases of metricCollection in convertMetricCollectionToEMF method
  2. End to End test (In process)

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • I confirm that this pull request can be released under the Apache 2 license

@Fred1155 Fred1155 requested a review from a team as a code owner December 13, 2024 23:01
Copy link
Contributor

@zoewangg zoewangg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some high level comments, still reviewing the implementation

}

@Test
void testConvertMetricCollectionToEMF_EmptyCollection(){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using parameterized tests if we are just testing with different input

metric-publishers/emf-metric-publisher/pom.xml Outdated Show resolved Hide resolved
// Write CloudWatchMetrics array
jsonWriter.writeFieldName("CloudWatchMetrics");
jsonWriter.writeStartArray();
jsonWriter.writeStartObject();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct? It seems this CloudWatchMetrics only has one object

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so. In the example https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format_Specification.html, CloudWatchMetrics should have one object, because we only have one namespace and one set of dimensions

<version>2.29.35-SNAPSHOT</version>
</parent>

<artifactId>emf-metric-publisher</artifactId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have to change it now, but we should discuss it in API surface area review. Should we rename it to emf-metric-logger, since technically it's not publishing metrics?

import software.amazon.awssdk.testutils.LogCaptor;


public class EmfMetricPublisherTest extends LogCaptor.LogCaptorTestBase{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test case where metricCollector throws an exception?

Copy link
Contributor

@zoewangg zoewangg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably easier if you see the code, so I pushed suggested changes for MetricEmfConverter here :) Feel free to change as needed. bole/EMFMetricPublisher...zoewang/reviewPR5752

Comment on lines 224 to 228


ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(emfLogs.get(0));
Set<ValidationMessage> errors = schema.validate(jsonNode);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting is a bit weird

metric-publishers/emf-metric-publisher/pom.xml Outdated Show resolved Hide resolved
metric-publishers/emf-metric-publisher/pom.xml Outdated Show resolved Hide resolved
Copy link
Contributor

@zoewangg zoewangg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!

@Fred1155 Fred1155 merged commit e8b9bbd into feature/master/emf-metric-publisher Jan 3, 2025
17 checks passed
@Fred1155 Fred1155 deleted the bole/EMFMetricPublisher branch January 6, 2025 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants