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

[SVLS-3697] Fix missing post runtime duration metrics and log values after a shutdown #25473

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

DylanLovesCoffee
Copy link
Contributor

What does this PR do?

Fixes a 0 value for aws.lambda.enhanced.post_runtime_duration metric and a 0 value for the Runtime Duration and Post Runtime Duration in the Extension's REPORT log.

BEFORE:
before

AFTER:
after

Motivation

https://datadoghq.atlassian.net/browse/SVLS-3697
Related to #18933

After some investigation, I found that during a SHUTDOWN event caused by a timeout, we would save the invocation's execution context to disk before we processed the platform.runtimeDone log from which we get the runtime's endTime. Then we process the platform.report log where we generate aws.lambda.enhanced.post_runtime_duration and the REPORT log, but we fail to calculate the durations due to a zero value for the endTime.

Rough visual timeline of the issue:

[Invocation 1]
- invocation starts
-- platform.start log is received and processed. The invocation start time is collected and stored in the execution context
---- we enter a SHUTDOWN phase and the Extension immediately saves the execution context to disk 
------ platform.runtimeDone log is received and processed. The invocation end time is stored in the execution ctx but not saved to disk
-------- invocation ends
[Invocation 2]
- invocation starts
-- execution context is restored from disk, where only the start time was saved
---- platform.report log from Invocation 1 is received and processed, but the end time does not exist so runtime duration values can't be calculated
------ rest of invocation things happen ~

Additional Notes

Possible Drawbacks / Trade-offs

Describe how to test/QA your changes

Updated unit tests and rolled out to self-monitoring apps

@DylanLovesCoffee DylanLovesCoffee added kind/bug team/serverless qa/done Skip QA week as QA was done before merge and regressions are covered by tests labels May 8, 2024
@DylanLovesCoffee DylanLovesCoffee added this to the Triage milestone May 8, 2024
@DylanLovesCoffee DylanLovesCoffee requested a review from a team as a code owner May 8, 2024 19:45
@pr-commenter
Copy link

pr-commenter bot commented May 8, 2024

Regression Detector

Regression Detector Results

Run ID: ec8749ad-5fa8-40dc-a4ba-29adca51b1b1
Baseline: 71b3fd4
Comparison: 318db70

Performance changes are noted in the perf column of each table:

  • ✅ = significantly better comparison variant performance
  • ❌ = significantly worse comparison variant performance
  • ➖ = no significant change in performance

No significant changes in experiment optimization goals

Confidence level: 90.00%
Effect size tolerance: |Δ mean %| ≥ 5.00%

There were no significant changes in experiment optimization goals at this confidence level and effect size tolerance.

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI
tcp_syslog_to_blackhole ingress throughput +13.19 [-9.50, +35.88]
pycheck_1000_100byte_tags % cpu utilization +0.48 [-4.35, +5.30]
uds_dogstatsd_to_api_cpu % cpu utilization +0.24 [-2.66, +3.14]
otel_to_otel_logs ingress throughput +0.17 [-0.19, +0.54]
basic_py_check % cpu utilization +0.10 [-2.57, +2.76]
uds_dogstatsd_to_api ingress throughput +0.03 [-0.17, +0.23]
trace_agent_json ingress throughput -0.00 [-0.01, +0.01]
trace_agent_msgpack ingress throughput -0.00 [-0.00, +0.00]
tcp_dd_logs_filter_exclude ingress throughput -0.04 [-0.09, +0.00]
file_tree memory utilization -0.19 [-0.31, -0.08]
idle memory utilization -0.38 [-0.42, -0.35]

Explanation

A regression test is an A/B test of target performance in a repeatable rig, where "performance" is measured as "comparison variant minus baseline variant" for an optimization goal (e.g., ingress throughput). Due to intrinsic variability in measuring that goal, we can only estimate its mean value for each experiment; we report uncertainty in that value as a 90.00% confidence interval denoted "Δ mean % CI".

For each experiment, we decide whether a change in performance is a "regression" -- a change worth investigating further -- if all of the following criteria are true:

  1. Its estimated |Δ mean %| ≥ 5.00%, indicating the change is big enough to merit a closer look.

  2. Its 90.00% confidence interval "Δ mean % CI" does not contain zero, indicating that if our statistical model is accurate, there is at least a 90.00% chance there is a difference in performance between baseline and comparison variants.

  3. Its configuration does not mark it "erratic".

Copy link
Contributor

@jcstorms1 jcstorms1 left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@@ -310,6 +310,15 @@ func (lc *LambdaLogsCollector) processMessage(
})
lc.invocationEndTime = message.time
lc.executionContext.UpdateEndTime(message.time)

// The state is saved when a shutdown event is received. A shutdown event can occur before the
// runtimeDone log message is received so we save the state again to properly store the end time
Copy link
Contributor

Choose a reason for hiding this comment

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

Just want to confirm there can't be a race condition here, where we save the context of the next invocation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, shouldn't be the case here since we reset the isStateSaved bool to false at the start of the next invocation. So worse case we won't attempt to save the context

@pr-commenter
Copy link

pr-commenter bot commented May 9, 2024

Test changes on VM

Use this command from test-infra-definitions to manually test this PR changes on a VM:

inv create-vm --pipeline-id=34843387 --os-family=ubuntu

@@ -1304,6 +1304,101 @@ func TestRuntimeMetricsMatchLogsProactiveInit(t *testing.T) {
assert.Len(t, timedMetrics, 0)
}

func TestRuntimeMetricsOnTimeout(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

test is flaky -> fix in-progress

Copy link
Contributor

Serverless Benchmark Results

BenchmarkStartEndInvocation comparison between 71b3fd4 and 596fdf1.

tl;dr

Use these benchmarks as an insight tool during development.

  1. Skim down the vs base column in each chart. If there is a ~, then there was no statistically significant change to the benchmark. Otherwise, ensure the estimated percent change is either negative or very small.

  2. The last row of each chart is the geomean. Ensure this percentage is either negative or very small.

What is this benchmarking?

The BenchmarkStartEndInvocation compares the amount of time it takes to call the start-invocation and end-invocation endpoints. For universal instrumentation languages (Dotnet, Golang, Java, Ruby), this represents the majority of the duration overhead added by our tracing layer.

The benchmark is run using a large variety of lambda request payloads. In the charts below, there is one row for each event payload type.

How do I interpret these charts?

The charts below comes from benchstat. They represent the statistical change in duration (sec/op), memory overhead (B/op), and allocations (allocs/op).

The benchstat docs explain how to interpret these charts.

Before the comparison table, we see common file-level configuration. If there are benchmarks with different configuration (for example, from different packages), benchstat will print separate tables for each configuration.

The table then compares the two input files for each benchmark. It shows the median and 95% confidence interval summaries for each benchmark before and after the change, and an A/B comparison under "vs base". ... The p-value measures how likely it is that any differences were due to random chance (i.e., noise). The "~" means benchstat did not detect a statistically significant difference between the two inputs. ...

Note that "statistically significant" is not the same as "large": with enough low-noise data, even very small changes can be distinguished from noise and considered statistically significant. It is, of course, generally easier to distinguish large changes from noise.

Finally, the last row of the table shows the geometric mean of each column, giving an overall picture of how the benchmarks changed. Proportional changes in the geomean reflect proportional changes in the benchmarks. For example, given n benchmarks, if sec/op for one of them increases by a factor of 2, then the sec/op geomean will increase by a factor of ⁿ√2.

I need more help

First off, do not worry if the benchmarks are failing. They are not tests. The intention is for them to be a tool for you to use during development.

If you would like a hand interpreting the results come chat with us in #serverless-agent in the internal DataDog slack or in #serverless in the public DataDog slack. We're happy to help!

Benchmark stats
goos: linux
goarch: amd64
pkg: github.com/DataDog/datadog-agent/pkg/serverless/daemon
cpu: AMD EPYC 7763 64-Core Processor                
                                      │ baseline/benchmark.log │        current/benchmark.log        │
                                      │         sec/op         │    sec/op     vs base               │
api-gateway-appsec.json                            83.44µ ± 8%    90.44µ ± 4%  +8.39% (p=0.001 n=10)
api-gateway-kong-appsec.json                       70.05µ ± 2%    71.98µ ± 1%  +2.76% (p=0.005 n=10)
api-gateway-kong.json                              68.22µ ± 2%    69.27µ ± 2%  +1.53% (p=0.000 n=10)
api-gateway-non-proxy-async.json                   107.9µ ± 3%    109.0µ ± 2%       ~ (p=0.353 n=10)
api-gateway-non-proxy.json                         105.1µ ± 1%    109.2µ ± 3%  +3.90% (p=0.000 n=10)
api-gateway-websocket-connect.json                 68.55µ ± 2%    72.82µ ± 2%  +6.23% (p=0.000 n=10)
api-gateway-websocket-default.json                 63.19µ ± 1%    64.43µ ± 2%  +1.96% (p=0.002 n=10)
api-gateway-websocket-disconnect.json              61.52µ ± 1%    64.77µ ± 3%  +5.27% (p=0.000 n=10)
api-gateway.json                                   112.7µ ± 2%    121.8µ ± 1%  +8.04% (p=0.000 n=10)
application-load-balancer.json                     62.52µ ± 1%    65.23µ ± 1%  +4.34% (p=0.000 n=10)
cloudfront.json                                    48.17µ ± 2%    49.63µ ± 2%  +3.03% (p=0.002 n=10)
cloudwatch-events.json                             38.43µ ± 2%    39.40µ ± 2%  +2.51% (p=0.001 n=10)
cloudwatch-logs.json                               65.39µ ± 1%    70.63µ ± 3%  +8.01% (p=0.000 n=10)
custom.json                                        30.46µ ± 3%    31.52µ ± 3%  +3.49% (p=0.001 n=10)
dynamodb.json                                      93.00µ ± 1%    96.96µ ± 2%  +4.26% (p=0.000 n=10)
empty.json                                         28.93µ ± 2%    29.67µ ± 4%  +2.56% (p=0.000 n=10)
eventbridge-custom.json                            42.09µ ± 1%    43.73µ ± 3%  +3.90% (p=0.001 n=10)
http-api.json                                      71.69µ ± 1%    75.49µ ± 1%  +5.30% (p=0.000 n=10)
kinesis-batch.json                                 70.25µ ± 1%    74.47µ ± 3%  +6.01% (p=0.000 n=10)
kinesis.json                                       53.24µ ± 1%    56.21µ ± 2%  +5.58% (p=0.000 n=10)
s3.json                                            58.15µ ± 1%    62.59µ ± 3%  +7.63% (p=0.000 n=10)
sns-batch.json                                     88.34µ ± 1%    95.19µ ± 2%  +7.75% (p=0.000 n=10)
sns.json                                           63.79µ ± 4%    67.35µ ± 1%  +5.57% (p=0.000 n=10)
snssqs.json                                        109.6µ ± 1%    118.5µ ± 2%  +8.12% (p=0.000 n=10)
snssqs_no_dd_context.json                          98.88µ ± 3%   103.93µ ± 4%  +5.10% (p=0.000 n=10)
sqs-aws-header.json                                55.34µ ± 1%    59.64µ ± 1%  +7.77% (p=0.000 n=10)
sqs-batch.json                                     95.35µ ± 1%   101.61µ ± 4%  +6.56% (p=0.000 n=10)
sqs.json                                           69.67µ ± 1%    71.32µ ± 2%  +2.36% (p=0.004 n=10)
sqs_no_dd_context.json                             61.82µ ± 2%    65.69µ ± 3%  +6.26% (p=0.000 n=10)
geomean                                            66.62µ         69.95µ       +4.99%

                                      │ baseline/benchmark.log │        current/benchmark.log        │
                                      │          B/op          │     B/op      vs base               │
api-gateway-appsec.json                           37.13Ki ± 0%   37.13Ki ± 0%       ~ (p=0.447 n=10)
api-gateway-kong-appsec.json                      26.80Ki ± 0%   26.80Ki ± 0%       ~ (p=0.956 n=10)
api-gateway-kong.json                             24.28Ki ± 0%   24.29Ki ± 0%       ~ (p=0.591 n=10)
api-gateway-non-proxy-async.json                  47.94Ki ± 0%   47.94Ki ± 0%       ~ (p=0.868 n=10)
api-gateway-non-proxy.json                        47.14Ki ± 0%   47.15Ki ± 0%       ~ (p=0.591 n=10)
api-gateway-websocket-connect.json                25.37Ki ± 0%   25.38Ki ± 0%       ~ (p=0.195 n=10)
api-gateway-websocket-default.json                21.27Ki ± 0%   21.28Ki ± 0%       ~ (p=0.670 n=10)
api-gateway-websocket-disconnect.json             21.05Ki ± 0%   21.06Ki ± 0%  +0.04% (p=0.017 n=10)
api-gateway.json                                  49.45Ki ± 0%   49.47Ki ± 0%  +0.06% (p=0.012 n=10)
application-load-balancer.json                    22.24Ki ± 0%   22.24Ki ± 0%       ~ (p=0.183 n=10)
cloudfront.json                                   17.57Ki ± 0%   17.58Ki ± 0%       ~ (p=0.160 n=10)
cloudwatch-events.json                            11.61Ki ± 0%   11.62Ki ± 0%       ~ (p=0.271 n=10)
cloudwatch-logs.json                              53.27Ki ± 0%   53.30Ki ± 0%  +0.05% (p=0.001 n=10)
custom.json                                       9.649Ki ± 0%   9.646Ki ± 0%       ~ (p=0.541 n=10)
dynamodb.json                                     40.58Ki ± 0%   40.60Ki ± 0%  +0.07% (p=0.030 n=10)
empty.json                                        9.190Ki ± 0%   9.199Ki ± 0%       ~ (p=0.172 n=10)
eventbridge-custom.json                           13.34Ki ± 0%   13.34Ki ± 0%       ~ (p=0.868 n=10)
http-api.json                                     23.62Ki ± 0%   23.64Ki ± 0%       ~ (p=0.288 n=10)
kinesis-batch.json                                26.94Ki ± 0%   26.96Ki ± 0%       ~ (p=0.138 n=10)
kinesis.json                                      17.72Ki ± 0%   17.73Ki ± 0%       ~ (p=0.362 n=10)
s3.json                                           20.25Ki ± 1%   20.23Ki ± 1%       ~ (p=0.985 n=10)
sns-batch.json                                    38.54Ki ± 0%   38.60Ki ± 0%  +0.14% (p=0.007 n=10)
sns.json                                          23.90Ki ± 0%   23.93Ki ± 0%       ~ (p=0.362 n=10)
snssqs.json                                       50.49Ki ± 0%   50.58Ki ± 0%  +0.18% (p=0.041 n=10)
snssqs_no_dd_context.json                         44.73Ki ± 0%   44.76Ki ± 0%       ~ (p=0.404 n=10)
sqs-aws-header.json                               18.76Ki ± 0%   18.82Ki ± 0%  +0.30% (p=0.005 n=10)
sqs-batch.json                                    41.45Ki ± 0%   41.61Ki ± 0%  +0.39% (p=0.001 n=10)
sqs.json                                          25.51Ki ± 1%   25.52Ki ± 0%       ~ (p=0.494 n=10)
sqs_no_dd_context.json                            20.61Ki ± 0%   20.64Ki ± 0%       ~ (p=0.315 n=10)
geomean                                           25.60Ki        25.62Ki       +0.07%

                                      │ baseline/benchmark.log │        current/benchmark.log        │
                                      │       allocs/op        │ allocs/op   vs base                 │
api-gateway-appsec.json                             629.0 ± 0%   630.0 ± 0%       ~ (p=0.370 n=10)
api-gateway-kong-appsec.json                        488.0 ± 0%   488.0 ± 0%       ~ (p=1.000 n=10) ¹
api-gateway-kong.json                               466.0 ± 0%   466.0 ± 0%       ~ (p=1.000 n=10) ¹
api-gateway-non-proxy-async.json                    725.0 ± 0%   725.5 ± 0%       ~ (p=0.141 n=10)
api-gateway-non-proxy.json                          716.0 ± 0%   716.0 ± 0%       ~ (p=0.211 n=10)
api-gateway-websocket-connect.json                  453.0 ± 0%   453.0 ± 0%       ~ (p=1.000 n=10)
api-gateway-websocket-default.json                  379.0 ± 0%   379.0 ± 0%       ~ (p=1.000 n=10)
api-gateway-websocket-disconnect.json               369.0 ± 0%   369.0 ± 0%       ~ (p=0.087 n=10)
api-gateway.json                                    790.0 ± 0%   791.0 ± 0%       ~ (p=0.070 n=10)
application-load-balancer.json                      352.0 ± 0%   352.0 ± 0%       ~ (p=1.000 n=10)
cloudfront.json                                     283.5 ± 0%   284.0 ± 0%       ~ (p=0.141 n=10)
cloudwatch-events.json                              220.0 ± 0%   220.0 ± 0%       ~ (p=1.000 n=10) ¹
cloudwatch-logs.json                                215.0 ± 0%   215.5 ± 0%  +0.23% (p=0.033 n=10)
custom.json                                         168.0 ± 0%   168.0 ± 0%       ~ (p=1.000 n=10)
dynamodb.json                                       588.0 ± 0%   589.0 ± 0%       ~ (p=0.170 n=10)
empty.json                                          159.0 ± 0%   159.0 ± 1%       ~ (p=0.087 n=10)
eventbridge-custom.json                             254.0 ± 0%   254.0 ± 0%       ~ (p=1.000 n=10)
http-api.json                                       432.0 ± 0%   432.0 ± 0%       ~ (p=0.582 n=10)
kinesis-batch.json                                  390.0 ± 0%   391.0 ± 0%       ~ (p=0.157 n=10)
kinesis.json                                        285.0 ± 0%   285.0 ± 0%       ~ (p=1.000 n=10)
s3.json                                             357.0 ± 0%   357.0 ± 1%       ~ (p=0.947 n=10)
sns-batch.json                                      454.0 ± 0%   455.0 ± 0%  +0.22% (p=0.035 n=10)
sns.json                                            323.0 ± 1%   323.0 ± 0%       ~ (p=0.518 n=10)
snssqs.json                                         445.0 ± 0%   446.0 ± 0%  +0.22% (p=0.020 n=10)
snssqs_no_dd_context.json                           399.0 ± 0%   400.0 ± 1%       ~ (p=0.330 n=10)
sqs-aws-header.json                                 273.0 ± 0%   274.0 ± 0%  +0.37% (p=0.003 n=10)
sqs-batch.json                                      501.5 ± 0%   504.0 ± 0%  +0.50% (p=0.003 n=10)
sqs.json                                            351.5 ± 1%   351.5 ± 0%       ~ (p=0.332 n=10)
sqs_no_dd_context.json                              324.5 ± 0%   325.0 ± 1%       ~ (p=0.193 n=10)
geomean                                             376.2        376.6       +0.10%
¹ all samples are equal

Copy link

codecov bot commented May 22, 2024

Codecov Report

Attention: Patch coverage is 61.11111% with 7 lines in your changes are missing coverage. Please review.

Project coverage is 73.15%. Comparing base (71b3fd4) to head (318db70).
Report is 25 commits behind head on main.

Files Patch % Lines
...kg/serverless/executioncontext/executioncontext.go 60.00% 4 Missing ⚠️
pkg/serverless/logs/logs_collector.go 62.50% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main   #25473       +/-   ##
===========================================
+ Coverage   45.00%   73.15%   +28.15%     
===========================================
  Files        2314       58     -2256     
  Lines      266463     5298   -261165     
===========================================
- Hits       119919     3876   -116043     
+ Misses     136986     1251   -135735     
+ Partials     9558      171     -9387     
Flag Coverage Δ
amzn_aarch64 72.86% <61.11%> (+27.06%) ⬆️
centos_x86_64 72.88% <61.11%> (+27.17%) ⬆️
ubuntu_aarch64 72.88% <61.11%> (+27.08%) ⬆️
ubuntu_x86_64 72.94% <61.11%> (+27.15%) ⬆️
windows_amd64 71.15% <62.50%> (+19.94%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog/no-changelog kind/bug qa/done Skip QA week as QA was done before merge and regressions are covered by tests team/serverless
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants