Skip to content

Conversation

Miqueasher
Copy link
Contributor

This PR adds custom metrics to the existing sample app to verify public documentation is correct and functionality continues to work as changes happen in the future (Regression testing). Specifically for OpenTelemetry metrics using the CloudWatch Agent.

The changes made in this PR are:

  • 2 New imports to views.py (sample app's frontend service for the 'main' instance)
  • Global meter, and histogram/counter added to views.py from OTEL SDK Metrics page
  • Update to environment variables in main.tf
  • Update to jobs & env sections in python-ec2-default-test
  • Update from aws region us-west-2 to us-east-1
  • Update to Cloudwatch agent config to include otlp ports
  • Update to variables.tf to include custom metrics enabled
  • For loop expansion for easier Debugging logs (used in testing & for future)
  • New Validator file to call updated predefined template file
  • Update to PredefinedExpectedTemplate to include new mustache file
  • New mustache file for validation of custom metrics

IMPORTANT
Updates to views.py effect 'python-sample-app.zip which exists in S3 bucket. Proper Zip protocol must be followed for it properly deploy and run. If not it will fail.

Rollback procedure:
A git revert to the most recent SHA (4ca5d60) will be easy to revert back to if necessary.

Passing test runs:
Test 1
Test 2

References:
https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AppSignals-CustomMetrics.html#AppSignals-CustomMetrics-OpenTelemetry
https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-OpenTelemetry-metrics.html
https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#exporter-selection
https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/#otel_exporter_otlp_metrics_endpoint
https://opentelemetry.io/docs/specs/otel/metrics/sdk/

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.


env:
E2E_TEST_AWS_REGION: 'us-west-2'
E2E_TEST_AWS_REGION: 'us-east-1'
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't change stuff for unrelated files

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will be updated in the next push


env:
E2E_TEST_AWS_REGION: us-west-2
E2E_TEST_AWS_REGION: us-east-1
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will be updated in the next push


env:
E2E_TEST_AWS_REGION: 'us-west-2' # Test uses us-west-2 in the us-east-1 accoun
E2E_TEST_AWS_REGION: 'us-east-1' # Test uses us-east-1 in the us-east-1 account
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will be updated in the next push


env:
E2E_TEST_AWS_REGION: 'us-west-2'
E2E_TEST_AWS_REGION: 'us-east-1'
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will be updated in the next push


env:
E2E_TEST_AWS_REGION: 'us-west-2'
E2E_TEST_AWS_REGION: 'us-east-1'
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will be updated in the next push

# Copy in CW Agent configuration
agent_config='${replace(replace(file("./amazon-cloudwatch-agent.json"), "/\\s+/", ""), "$REGION", var.aws_region)}'
echo $agent_config > amazon-cloudwatch-agent.json
echo "$agent_config" > amazon-cloudwatch-agent.json
Copy link
Contributor

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agent_config goes through the replace function and the quotes are just to prevent word splitting from breaking it.

Comment on lines +213 to +214
/** Python EC2 Default Custom Metrics Test Case Validations */
PYTHON_EC2_DEFAULT_AWS_OTEL_CUSTOM_METRIC("/expected-data-template/python/ec2/default/aws-otel-custom-metrics.mustache"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/** Python EC2 Default Custom Metrics Test Case Validations */
PYTHON_EC2_DEFAULT_AWS_OTEL_CUSTOM_METRIC("/expected-data-template/python/ec2/default/aws-otel-custom-metrics.mustache"),
/** Python EC2 Default Custom Metrics Test Case Validations */
PYTHON_EC2_DEFAULT_AWS_OTEL_CUSTOM_METRIC("/expected-data-template/python/ec2/default/aws-otel-custom-metrics.mustache"),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will be updated in the next push

Copy link
Contributor

Choose a reason for hiding this comment

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

This file should be moved to .../python/ec2/custom-metrics since it's a unique test case, even though it's using the same workflow file. Same with the other file added under .../resources

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will be updated in the next push

value: {{serviceName}}
-
name: cloud.account.id
value: ANY_VALUE
Copy link
Contributor

Choose a reason for hiding this comment

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

We know the values in some cases, so we should put it in. In this case, we know the account ID so we should be able to validate it fully.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will be updated in the next push

value: opentelemetry
-
name: telemetry.sdk.version
value: 1.33.1
Copy link
Contributor

Choose a reason for hiding this comment

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

This value can change in the future, don't hardcode it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will be updated in the next push

@majanjua-amzn majanjua-amzn changed the title Custom metrics test [Python] Custom Metrics E2E Test Oct 16, 2025
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