Skip to content

Commit 72da8fd

Browse files
authored
feat(lambda): fix calculation on function cost (#647)
Fixes #645 Implement what was described in the issue. ![image](https://github.com/user-attachments/assets/5fa11ccf-87fb-4793-b9b5-6fabae7d3151) --- _By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license_
1 parent 84e9527 commit 72da8fd

File tree

3 files changed

+53
-14
lines changed

3 files changed

+53
-14
lines changed

API.md

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/monitoring/aws-lambda/LambdaFunctionEnhancedMetricFactory.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,19 @@ export class LambdaFunctionEnhancedMetricFactory extends BaseMetricFactory<Lambd
9898
);
9999
}
100100

101-
enhancedMetricFunctionCost() {
102-
return this.metricFactory.createMetricMath(
103-
"memory_utilization * duration",
104-
{
105-
memory_utilization: this.enhancedMetricMaxMemoryUtilization(),
106-
duration: this.enhancedMetricFunctionDuration(),
107-
},
108-
"Function Cost (avg: ${AVG}, max: ${MAX})",
101+
enhancedMetricInitDuration() {
102+
return this.enhancedMetric(
103+
"init_duration",
104+
MetricStatistic.SUM,
105+
"InitDuration.Sum",
106+
);
107+
}
108+
109+
enhancedMetricMaxTotalMemory() {
110+
return this.enhancedMetric(
111+
"total_memory",
112+
MetricStatistic.MAX,
113+
"TotalMemory",
109114
);
110115
}
111116

@@ -119,6 +124,18 @@ export class LambdaFunctionEnhancedMetricFactory extends BaseMetricFactory<Lambd
119124
);
120125
}
121126

127+
enhancedMetricFunctionCost() {
128+
return this.metricFactory.createMetricMath(
129+
"(total_memory * duration) + (total_memory * init_duration)",
130+
{
131+
total_memory: this.enhancedMetricMaxTotalMemory(),
132+
duration: this.enhancedMetricFunctionDuration(),
133+
init_duration: this.enhancedMetricInitDuration(),
134+
},
135+
"Function Cost (avg: ${AVG}, max: ${MAX})",
136+
);
137+
}
138+
122139
private enhancedMetric(
123140
metricName: string,
124141
statistic: MetricStatistic,

test/monitoring/aws-lambda/__snapshots__/LambdaFunctionMonitoring.test.ts.snap

Lines changed: 14 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)