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

fix(metrics): store service name in defaultDimensions to avoid clearing it #1146

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/metrics/src/Metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ class Metrics extends Utility implements MetricsInterface {
if (!this.isColdStart()) return;
const singleMetric = this.singleMetric();

if (this.dimensions.service) {
singleMetric.addDimension('service', this.dimensions.service);
if (this.defaultDimensions.service) {
singleMetric.setDefaultDimensions({ service: this.defaultDimensions.service });
}
if (this.functionName != null) {
singleMetric.addDimension('function_name', this.functionName);
Expand Down Expand Up @@ -455,7 +455,7 @@ class Metrics extends Utility implements MetricsInterface {
this.getCustomConfigService()?.getServiceName() ||
this.getEnvVarsService().getServiceName()) as string;
if (targetService.length > 0) {
this.addDimension('service', targetService);
this.setDefaultDimensions({ service: targetService });
}
}

Expand Down
8 changes: 4 additions & 4 deletions packages/metrics/tests/unit/middleware/middy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,14 @@ describe('Middy middleware', () => {
CloudWatchMetrics: [
{
Namespace: 'serverlessAirline',
Dimensions: [[ 'environment', 'aws_region', 'service', 'function_name' ]],
Dimensions: [[ 'service', 'environment', 'aws_region', 'function_name' ]],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change (& the one a few lines below) is needed because we are comparing the JSON.stringif-ied version of these strings, so order counts.

I could have converted to object comparison but wanted to keep the diff small.

Metrics: [{ Name: 'ColdStart', Unit: 'Count' }],
},
],
},
service: 'orders',
environment: 'prod',
aws_region: 'eu-west-1',
service: 'orders',
function_name: 'foo-bar-function',
ColdStart: 1,
})
Expand All @@ -267,14 +267,14 @@ describe('Middy middleware', () => {
CloudWatchMetrics: [
{
Namespace: 'serverlessAirline',
Dimensions: [[ 'environment', 'aws_region', 'service' ]],
Dimensions: [[ 'service', 'environment', 'aws_region' ]],
Metrics: [{ Name: 'successfulBooking', Unit: 'Count' }],
},
],
},
service: 'orders',
environment: 'prod',
aws_region: 'eu-west-1',
service: 'orders',
successfulBooking: 1,
})
);
Expand Down