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

[Serverless] Reset both inferred spans on each invocation. #30881

Merged
merged 1 commit into from
Nov 8, 2024

Conversation

purple4reina
Copy link
Contributor

@purple4reina purple4reina commented Nov 7, 2024

What does this PR do?

When a new invocation starts, the resourceHandler is reset. In addition to resetting the first inferred span, also reset the second by setting it to nil.

Motivation

A single lambda can have multiple event types that invoke it. When some of the invocations would create 2 inferred spans, and some of the invocations would create 1 inferred span, we must ensure that both inferred spans are reset.

This was leading to some really weird behavior when I tried to add sns->sqs trace propagation to the Trace Propagation Functional Tests. I was seeing weird stuff like this, where an sqs.sendMessage, calls aws.sns inferred span, calls aws.lambda.url inferred span, calls aws.lambda span.

Screenshot 2024-11-07 at 3 19 16 PM

Describe how to test/QA your changes

I built an extension layer with this change as arn:aws:lambda:us-east-1:425362996713:layer:Datadog-Extension-REY:8 and ran the Trace Propagation Functional Tests and finally saw them all passing.

Possible Drawbacks / Trade-offs

Additional Notes

datadoghq.atlassian.net/browse/SVLS-5732

@purple4reina purple4reina requested review from a team as code owners November 7, 2024 23:23
@github-actions github-actions bot added the short review PR is simple enough to be reviewed quickly label Nov 7, 2024
@purple4reina purple4reina added changelog/no-changelog team/serverless qa/done QA done before merge and regressions are covered by tests labels Nov 7, 2024
@purple4reina purple4reina added this to the Triage milestone Nov 7, 2024
Copy link
Contributor

github-actions bot commented Nov 7, 2024

Serverless Benchmark Results

BenchmarkStartEndInvocation comparison between 361d38b and 1bc1147.

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                           89.93µ ± 10%   82.23µ ± 5%   -8.57% (p=0.000 n=10)
api-gateway-kong-appsec.json                      71.71µ ±  6%   66.07µ ± 3%   -7.86% (p=0.000 n=10)
api-gateway-kong.json                             69.91µ ±  9%   64.77µ ± 2%   -7.35% (p=0.018 n=10)
api-gateway-non-proxy-async.json                  108.9µ ±  4%   104.2µ ± 3%   -4.35% (p=0.004 n=10)
api-gateway-non-proxy.json                        109.5µ ±  2%   102.8µ ± 2%   -6.12% (p=0.000 n=10)
api-gateway-websocket-connect.json                71.89µ ±  2%   69.55µ ± 3%   -3.26% (p=0.001 n=10)
api-gateway-websocket-default.json                65.46µ ±  4%   62.07µ ± 1%   -5.17% (p=0.000 n=10)
api-gateway-websocket-disconnect.json             65.00µ ±  3%   62.17µ ± 1%   -4.35% (p=0.000 n=10)
api-gateway.json                                  120.2µ ±  1%   112.1µ ± 1%   -6.75% (p=0.000 n=10)
application-load-balancer.json                    67.57µ ±  3%   63.00µ ± 2%   -6.78% (p=0.000 n=10)
cloudfront.json                                   52.44µ ±  1%   47.30µ ± 2%   -9.80% (p=0.000 n=10)
cloudwatch-events.json                            43.64µ ±  3%   38.53µ ± 3%  -11.71% (p=0.000 n=10)
cloudwatch-logs.json                              70.78µ ±  4%   66.92µ ± 1%   -5.46% (p=0.000 n=10)
custom.json                                       34.48µ ±  4%   31.26µ ± 1%   -9.35% (p=0.000 n=10)
dynamodb.json                                     98.01µ ±  4%   92.05µ ± 3%   -6.08% (p=0.000 n=10)
empty.json                                        32.03µ ±  1%   29.28µ ± 3%   -8.58% (p=0.000 n=10)
eventbridge-custom.json                           51.31µ ±  2%   47.13µ ± 3%   -8.13% (p=0.000 n=10)
eventbridge-no-bus.json                           50.11µ ±  2%   46.36µ ± 1%   -7.49% (p=0.000 n=10)
eventbridge-no-timestamp.json                     50.15µ ±  3%   46.81µ ± 1%   -6.66% (p=0.000 n=10)
eventbridgesns.json                               67.69µ ±  2%   62.96µ ± 0%   -7.00% (p=0.000 n=10)
eventbridgesqs.json                               77.08µ ±  1%   70.22µ ± 1%   -8.89% (p=0.000 n=10)
http-api.json                                     77.38µ ±  3%   73.08µ ± 1%   -5.56% (p=0.000 n=10)
kinesis-batch.json                                75.48µ ±  1%   70.39µ ± 2%   -6.74% (p=0.000 n=10)
kinesis.json                                      58.24µ ±  2%   54.04µ ± 2%   -7.21% (p=0.000 n=10)
s3.json                                           63.43µ ±  2%   60.20µ ± 3%   -5.09% (p=0.000 n=10)
sns-batch.json                                    96.89µ ±  2%   90.97µ ± 2%   -6.11% (p=0.000 n=10)
sns.json                                          73.06µ ±  4%   67.90µ ± 2%   -7.06% (p=0.000 n=10)
snssqs.json                                       128.7µ ±  4%   116.3µ ± 1%   -9.69% (p=0.001 n=10)
snssqs_no_dd_context.json                         117.0µ ±  2%   105.1µ ± 2%  -10.16% (p=0.000 n=10)
sqs-aws-header.json                               60.63µ ±  3%   58.58µ ± 2%   -3.38% (p=0.000 n=10)
sqs-batch.json                                    98.12µ ±  5%   94.32µ ± 1%   -3.87% (p=0.000 n=10)
sqs.json                                          73.81µ ±  2%   72.10µ ± 4%        ~ (p=0.280 n=10)
sqs_no_dd_context.json                            69.86µ ±  2%   67.69µ ± 4%   -3.10% (p=0.007 n=10)
stepfunction.json                                 50.49µ ±  4%   46.01µ ± 4%   -8.86% (p=0.000 n=10)
geomean                                           70.07µ         65.34µ        -6.76%

                                      │ baseline/benchmark.log │        current/benchmark.log        │
                                      │          B/op          │     B/op      vs base               │
api-gateway-appsec.json                           37.35Ki ± 0%   37.35Ki ± 0%       ~ (p=0.424 n=10)
api-gateway-kong-appsec.json                      26.95Ki ± 0%   26.95Ki ± 0%       ~ (p=0.403 n=10)
api-gateway-kong.json                             24.45Ki ± 0%   24.45Ki ± 0%       ~ (p=0.342 n=10)
api-gateway-non-proxy-async.json                  48.14Ki ± 0%   48.13Ki ± 0%       ~ (p=0.210 n=10)
api-gateway-non-proxy.json                        47.36Ki ± 0%   47.35Ki ± 0%       ~ (p=0.066 n=10)
api-gateway-websocket-connect.json                25.53Ki ± 0%   25.53Ki ± 0%       ~ (p=0.447 n=10)
api-gateway-websocket-default.json                21.44Ki ± 0%   21.44Ki ± 0%       ~ (p=0.725 n=10)
api-gateway-websocket-disconnect.json             21.22Ki ± 0%   21.22Ki ± 0%       ~ (p=0.753 n=10)
api-gateway.json                                  49.60Ki ± 0%   49.59Ki ± 0%       ~ (p=0.324 n=10)
application-load-balancer.json                    23.32Ki ± 0%   23.31Ki ± 0%       ~ (p=0.424 n=10)
cloudfront.json                                   17.68Ki ± 0%   17.69Ki ± 0%       ~ (p=0.210 n=10)
cloudwatch-events.json                            11.76Ki ± 0%   11.75Ki ± 0%       ~ (p=0.060 n=10)
cloudwatch-logs.json                              53.39Ki ± 0%   53.40Ki ± 0%       ~ (p=0.424 n=10)
custom.json                                       9.769Ki ± 0%   9.762Ki ± 0%       ~ (p=0.239 n=10)
dynamodb.json                                     40.80Ki ± 0%   40.81Ki ± 0%       ~ (p=0.183 n=10)
empty.json                                        9.322Ki ± 0%   9.326Ki ± 0%       ~ (p=0.617 n=10)
eventbridge-custom.json                           15.04Ki ± 0%   15.02Ki ± 0%       ~ (p=0.425 n=10)
eventbridge-no-bus.json                           13.99Ki ± 0%   14.00Ki ± 0%       ~ (p=0.984 n=10)
eventbridge-no-timestamp.json                     14.02Ki ± 1%   14.04Ki ± 0%       ~ (p=0.183 n=10)
eventbridgesns.json                               20.96Ki ± 0%   20.95Ki ± 0%       ~ (p=0.796 n=10)
eventbridgesqs.json                               25.19Ki ± 0%   25.16Ki ± 0%       ~ (p=0.119 n=10)
http-api.json                                     23.94Ki ± 0%   23.94Ki ± 0%       ~ (p=0.699 n=10)
kinesis-batch.json                                27.19Ki ± 0%   27.12Ki ± 0%  -0.25% (p=0.000 n=10)
kinesis.json                                      17.93Ki ± 1%   17.92Ki ± 0%       ~ (p=0.494 n=10)
s3.json                                           20.47Ki ± 1%   20.46Ki ± 0%       ~ (p=0.796 n=10)
sns-batch.json                                    39.93Ki ± 0%   39.91Ki ± 0%       ~ (p=0.565 n=10)
sns.json                                          25.24Ki ± 0%   25.21Ki ± 0%       ~ (p=0.218 n=10)
snssqs.json                                       53.94Ki ± 1%   53.85Ki ± 0%       ~ (p=0.393 n=10)
snssqs_no_dd_context.json                         47.63Ki ± 0%   47.52Ki ± 0%       ~ (p=0.075 n=10)
sqs-aws-header.json                               19.45Ki ± 1%   19.45Ki ± 1%       ~ (p=0.840 n=10)
sqs-batch.json                                    42.27Ki ± 0%   42.28Ki ± 1%       ~ (p=0.796 n=10)
sqs.json                                          26.24Ki ± 1%   26.27Ki ± 0%       ~ (p=0.592 n=10)
sqs_no_dd_context.json                            21.87Ki ± 1%   21.93Ki ± 0%       ~ (p=0.280 n=10)
stepfunction.json                                 14.25Ki ± 1%   14.28Ki ± 1%       ~ (p=0.481 n=10)
geomean                                           24.62Ki        24.62Ki       -0.01%

                                      │ baseline/benchmark.log │        current/benchmark.log        │
                                      │       allocs/op        │ allocs/op   vs base                 │
api-gateway-appsec.json                             630.5 ± 0%   630.0 ± 0%       ~ (p=1.000 n=10)
api-gateway-kong-appsec.json                        489.0 ± 0%   489.0 ± 0%       ~ (p=1.000 n=10) ¹
api-gateway-kong.json                               467.0 ± 0%   467.0 ± 0%       ~ (p=1.000 n=10) ¹
api-gateway-non-proxy-async.json                    726.0 ± 0%   725.0 ± 0%       ~ (p=0.370 n=10)
api-gateway-non-proxy.json                          716.0 ± 0%   716.0 ± 0%       ~ (p=1.000 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               370.0 ± 0%   370.0 ± 0%       ~ (p=1.000 n=10)
api-gateway.json                                    791.0 ± 0%   791.0 ± 0%       ~ (p=1.000 n=10)
application-load-balancer.json                      353.0 ± 0%   353.0 ± 0%       ~ (p=1.000 n=10)
cloudfront.json                                     285.0 ± 0%   285.0 ± 0%       ~ (p=1.000 n=10)
cloudwatch-events.json                              221.0 ± 0%   221.0 ± 0%       ~ (p=0.087 n=10)
cloudwatch-logs.json                                216.0 ± 0%   216.5 ± 0%       ~ (p=0.650 n=10)
custom.json                                         169.0 ± 1%   169.0 ± 0%       ~ (p=1.000 n=10)
dynamodb.json                                       589.5 ± 0%   590.0 ± 0%       ~ (p=0.141 n=10)
empty.json                                          161.0 ± 1%   161.0 ± 1%       ~ (p=1.000 n=10)
eventbridge-custom.json                             267.0 ± 0%   266.5 ± 0%       ~ (p=1.000 n=10)
eventbridge-no-bus.json                             257.5 ± 1%   257.0 ± 0%       ~ (p=0.514 n=10)
eventbridge-no-timestamp.json                       258.0 ± 0%   258.0 ± 0%       ~ (p=0.721 n=10)
eventbridgesns.json                                 326.0 ± 0%   326.0 ± 0%       ~ (p=0.721 n=10)
eventbridgesqs.json                                 367.0 ± 0%   367.0 ± 0%       ~ (p=0.734 n=10)
http-api.json                                       434.0 ± 0%   434.0 ± 0%       ~ (p=1.000 n=10)
kinesis-batch.json                                  393.0 ± 0%   392.0 ± 0%  -0.25% (p=0.001 n=10)
kinesis.json                                        287.5 ± 1%   287.0 ± 0%       ~ (p=0.422 n=10)
s3.json                                             360.0 ± 1%   359.5 ± 0%       ~ (p=0.861 n=10)
sns-batch.json                                      478.5 ± 1%   478.0 ± 1%       ~ (p=0.836 n=10)
sns.json                                            347.5 ± 0%   347.5 ± 0%       ~ (p=0.689 n=10)
snssqs.json                                         479.0 ± 1%   478.0 ± 0%       ~ (p=0.328 n=10)
snssqs_no_dd_context.json                           438.0 ± 0%   436.0 ± 1%       ~ (p=0.051 n=10)
sqs-aws-header.json                                 286.5 ± 1%   286.5 ± 1%       ~ (p=0.804 n=10)
sqs-batch.json                                      516.0 ± 0%   516.0 ± 1%       ~ (p=0.811 n=10)
sqs.json                                            364.0 ± 1%   364.5 ± 1%       ~ (p=0.785 n=10)
sqs_no_dd_context.json                              349.5 ± 1%   351.0 ± 1%       ~ (p=0.297 n=10)
stepfunction.json                                   237.0 ± 1%   237.0 ± 0%       ~ (p=0.935 n=10)
geomean                                             367.7        367.6       -0.03%
¹ all samples are equal

@agent-platform-auto-pr
Copy link
Contributor

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=48518985 --os-family=ubuntu

Note: This applies to commit aa1420c

Copy link

Regression Detector

Regression Detector Results

Metrics dashboard
Target profiles
Run ID: a610b34b-2b13-4061-bd8d-68e064b3de7e

Baseline: 2a4706d
Comparison: aa1420c
Diff

Optimization Goals: ❌ Significant changes detected

perf experiment goal Δ mean % Δ mean % CI trials links
pycheck_lots_of_tags % cpu utilization -5.20 [-8.42, -1.99] 1 Logs

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI trials links
basic_py_check % cpu utilization +2.80 [-0.98, +6.58] 1 Logs
uds_dogstatsd_to_api_cpu % cpu utilization +1.83 [+1.11, +2.55] 1 Logs
quality_gate_idle_all_features memory utilization +0.77 [+0.66, +0.88] 1 Logs bounds checks dashboard
file_to_blackhole_500ms_latency egress throughput +0.13 [-0.11, +0.36] 1 Logs
file_to_blackhole_100ms_latency egress throughput +0.02 [-0.24, +0.29] 1 Logs
file_to_blackhole_1000ms_latency egress throughput +0.02 [-0.47, +0.50] 1 Logs
tcp_dd_logs_filter_exclude ingress throughput -0.00 [-0.01, +0.01] 1 Logs
file_to_blackhole_0ms_latency egress throughput -0.00 [-0.38, +0.38] 1 Logs
uds_dogstatsd_to_api ingress throughput -0.01 [-0.11, +0.10] 1 Logs
file_to_blackhole_300ms_latency egress throughput -0.04 [-0.23, +0.15] 1 Logs
idle memory utilization -0.10 [-0.15, -0.05] 1 Logs bounds checks dashboard
tcp_syslog_to_blackhole ingress throughput -0.28 [-0.34, -0.22] 1 Logs
file_tree memory utilization -0.30 [-0.43, -0.17] 1 Logs
idle_all_features memory utilization -0.33 [-0.43, -0.23] 1 Logs bounds checks dashboard
quality_gate_idle memory utilization -0.71 [-0.75, -0.66] 1 Logs bounds checks dashboard
pycheck_lots_of_tags % cpu utilization -5.20 [-8.42, -1.99] 1 Logs

Bounds Checks: ❌ Failed

perf experiment bounds_check_name replicates_passed links
idle memory_usage 8/10 bounds checks dashboard
quality_gate_idle memory_usage 8/10 bounds checks dashboard
quality_gate_idle_all_features memory_usage 9/10 bounds checks dashboard
file_to_blackhole_0ms_latency lost_bytes 10/10
file_to_blackhole_0ms_latency memory_usage 10/10
file_to_blackhole_1000ms_latency memory_usage 10/10
file_to_blackhole_100ms_latency lost_bytes 10/10
file_to_blackhole_100ms_latency memory_usage 10/10
file_to_blackhole_300ms_latency memory_usage 10/10
file_to_blackhole_500ms_latency memory_usage 10/10
idle_all_features memory_usage 10/10 bounds checks dashboard

Explanation

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

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

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

@nhulston nhulston left a comment

Choose a reason for hiding this comment

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

Looks good to me, nice job testing both cases

@purple4reina
Copy link
Contributor Author

/merge

@dd-devflow
Copy link

dd-devflow bot commented Nov 8, 2024

Devflow running: /merge

View all feedbacks in Devflow UI.


2024-11-08 20:00:37 UTC ℹ️ MergeQueue: pull request added to the queue

The median merge time in main is 24m.

@dd-mergequeue dd-mergequeue bot merged commit 9b6d767 into main Nov 8, 2024
251 of 254 checks passed
@dd-mergequeue dd-mergequeue bot deleted the rey.abolofia/inf-span-fix branch November 8, 2024 20:23
@github-actions github-actions bot modified the milestones: Triage, 7.61.0 Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog/no-changelog qa/done QA done before merge and regressions are covered by tests short review PR is simple enough to be reviewed quickly team/serverless
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants