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
(@aws-cdk/aws-lambda): Version.metric() function uses wrong metric options when the version is associated with an alias #14248
Comments
Hey @huyphan, sorry for the long response time. As you can see in the implementation, the comment says that @nija-at what are your thoughts on this? |
I'm not super familiar with function metrics, so let me know if I say anything incorrect here. It seems to me that we need to split this issue into two.
@huyphan - does that sound correct? @peterwoodworth - could you apply these changes? |
Thanks @nija-at and @peterwoodworth! What @nija-at described is correct. Let me know if you want me to create a separate feature request for |
@huyphan I can't promise I can get to actually fixing these any time in the next month. If you'd like to see the bug fixed, you could implement it yourself and I'd be happy to take a look at the PR. Also, go ahead with creating the feature request for executed version. It would be good to separate those from each other. |
Has anybody had time to look at this issue? In theory I think it might be a simple change, but I'm struggling to get CDK built locally so I can verify the change: diff --git a/packages/@aws-cdk/aws-lambda/lib/lambda-version.ts b/packages/@aws-cdk/aws-lambda/lib/lambda-version.ts
index 1249c48746..a2fdf25c60 100644
--- a/packages/@aws-cdk/aws-lambda/lib/lambda-version.ts
+++ b/packages/@aws-cdk/aws-lambda/lib/lambda-version.ts
@@ -229,15 +229,25 @@ export class Version extends QualifiedFunctionBase implements IVersion {
}
public metric(metricName: string, props: cloudwatch.MetricOptions = {}): cloudwatch.Metric {
- // Metrics on Aliases need the "bare" function name, and the alias' ARN, this differs from the base behavior.
- return super.metric(metricName, {
- dimensions: {
+ let dimensions;
+ if (this.lambda instanceof Alias) {
+ // Metrics on Aliases need the "bare" function name, and the alias' ARN, this differs from the base behavior.
+ dimensions = {
+ FunctionName: this.lambda.functionName,
+ Resource: `${this.lambda.functionArn}:${this.lambda.aliasName}`,
+ ExecutedVersion: this.version,
+ };
+ } else {
+ dimensions = {
FunctionName: this.lambda.functionName,
// construct the ARN from the underlying lambda so that alarms on an alias
// don't cause a circular dependency with CodeDeploy
// see: https://github.com/aws/aws-cdk/issues/2231
Resource: `${this.lambda.functionArn}:${this.version}`,
- },
+ };
+ }
+ return super.metric(metricName, {
+ dimensions: dimensions,
...props,
});
} |
The Issue
When the Lambda function version is associated with an alias, its
metric()
function (or other metric helper functions such asmetricErrors()
ormetricInvocations()
) uses the wrong values ofdimensions
property for the metrics. Consider the snippet below where we have a Lambda function and an alias:That code will return a metric with a
dimensions
property like this:(42 is the function version)
In reality, the correct dimensions for function version's metrics should be like this:
(live is the name of the function alias)
You can probably verify that by running using
ListMetrics
API of CloudWatch againstAWS/Lambda
namespace:References:
metric()
functionExecutedVersion
dimension: https://docs.aws.amazon.com/lambda/latest/dg/monitoring-metrics.htmlThe proposal
Users should be able to:
Version.metric*()
functionsAlias.metric*()
functionsEither case, the functions would return metrics with the same dimensions described above.
Environment
1.98.0 (build 79f4512)
1.98
v10.0.0
Other information
The text was updated successfully, but these errors were encountered: