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

ASCII-808: Linter ensures fxutil.Run is tested using TestRun #21461

Merged
merged 3 commits into from
Dec 13, 2023

Conversation

dustmop
Copy link
Contributor

@dustmop dustmop commented Dec 11, 2023

What does this PR do?

Improve the existing linter check to ensure that users of fx.Run and fx.OneShot have corresponding unit tests. These unit tests should verify that the fx dependencies are correctly fulfilled by using fx. This is done by checking for calls to fxutil.TestOneShot, fxutil.TestOneShotSubcommand, and fxutil.Run.

Motivation

Ensure that fx.dependencies are fulfilled, preventing future breakages.

Additional Notes

Possible Drawbacks / Trade-offs

Describe how to test/QA your changes

Reviewer's Checklist

  • If known, an appropriate milestone has been selected; otherwise the Triage milestone is set.
  • Use the major_change label if your change either has a major impact on the code base, is impacting multiple teams or is changing important well-established internals of the Agent. This label will be use during QA to make sure each team pay extra attention to the changed behavior. For any customer facing change use a releasenote.
  • A release note has been added or the changelog/no-changelog label has been applied.
  • Changed code has automated tests for its functionality.
  • Adequate QA/testing plan information is provided if the qa/skip-qa label is not applied.
  • At least one team/.. label has been applied, indicating the team(s) that should QA this change.
  • If applicable, docs team has been notified or an issue has been opened on the documentation repo.
  • If applicable, the need-change/operator and need-change/helm labels have been applied.
  • If applicable, the k8s/<min-version> label, indicating the lowest Kubernetes version compatible with this feature.
  • If applicable, the config template has been updated.

@pr-commenter
Copy link

pr-commenter bot commented Dec 11, 2023

Bloop Bleep... Dogbot Here

Regression Detector Results

Run ID: 2dfe1955-0e05-44fe-9f79-9b959287416a
Baseline: c61bbc2
Comparison: 527e6f4
Total CPUs: 7

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

  • ✅ denotes better comparison variant performance
  • ❌ denotes worse comparison variant performance

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".

No interesting changes in experiment optimization goals with confidence ≥ 90.00% and |Δ mean %| ≥ 5.00%.

Declared stable experiments that are now erratic

An experiment is erratic (i.e., not stable) if its coefficient of variation is at least 0.10.

perf experiment goal Δ mean % Δ mean % CI confidence
otel_to_otel_logs ingress throughput +1.99 [+1.28, +2.71] 100.00%

Experiments with missing or malformed data

  • idle

Usually, this warning means that there is no usable optimization goal data for that experiment, which could be a result of misconfiguration.

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI confidence
otel_to_otel_logs ingress throughput +1.99 [+1.28, +2.71] 100.00%
file_to_blackhole egress throughput +0.05 [-6.12, +6.21] 1.03%
dogstatsd_string_interner_8MiB_100k ingress throughput +0.00 [-0.01, +0.02] 5.14%
trace_agent_msgpack ingress throughput +0.00 [-0.00, +0.00] 0.95%
trace_agent_json ingress throughput +0.00 [-0.01, +0.01] 0.00%
dogstatsd_string_interner_64MiB_1k ingress throughput +0.00 [-0.00, +0.00] 0.00%
dogstatsd_string_interner_8MiB_100 ingress throughput +0.00 [-0.00, +0.00] 0.00%
dogstatsd_string_interner_8MiB_10k ingress throughput +0.00 [-0.00, +0.00] 0.00%
dogstatsd_string_interner_8MiB_50k ingress throughput +0.00 [-0.00, +0.00] 0.00%
dogstatsd_string_interner_64MiB_100 ingress throughput +0.00 [-0.00, +0.00] 0.00%
dogstatsd_string_interner_128MiB_1k ingress throughput +0.00 [-0.00, +0.00] 0.00%
tcp_dd_logs_filter_exclude ingress throughput +0.00 [-0.00, +0.00] 0.00%
dogstatsd_string_interner_8MiB_1k ingress throughput +0.00 [-0.00, +0.00] 0.00%
dogstatsd_string_interner_128MiB_100 ingress throughput +0.00 [-0.00, +0.00] 0.00%
uds_dogstatsd_to_api ingress throughput +0.00 [-0.00, +0.00] 0.00%
file_tree egress throughput -0.21 [-2.00, +1.58] 15.43%
tcp_syslog_to_blackhole ingress throughput -0.69 [-0.76, -0.62] 100.00%

Copy link
Member

@GustavoCaso GustavoCaso left a comment

Choose a reason for hiding this comment

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

I left a few nit comments. Outside of that LGTM

Copy link
Contributor

@ogaca-dd ogaca-dd left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -379,24 +379,32 @@ def lint_fxutil_oneshot_test(_):
if str(file).endswith("_test.go") or str(file).endswith("main.go") or str(file).endswith("main_windows.go"):
Copy link
Contributor

Choose a reason for hiding this comment

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

Can str(file).endswith("main.go") or str(file).endswith("main_windows.go") be removed by using fxutil.TestRun?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, indeed, that increases coverage for a couple of additional files.

cmd/systray/command/command_test.go Show resolved Hide resolved
@dustmop dustmop force-pushed the dustin.long/lint-fx-run branch from 20616b9 to 527e6f4 Compare December 11, 2023 20:13
@dustmop dustmop requested review from a team as code owners December 11, 2023 20:13
@dustmop dustmop requested a review from gbbr December 11, 2023 20:13
@@ -43,3 +44,7 @@ func TestTagsSetup(t *testing.T) {
assert.Subset(t, metricAgent.GetExtraTags(), allTags)
assert.Subset(t, logs.GetLogsTags(), allTags)
}

func TestFxApp(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

What about TestMain ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These I think make sense staying this way because they are specifically testing the usage of fx dependencies.

"github.com/stretchr/testify/require"
)

func TestFxRun(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

What about TestRun?

"github.com/DataDog/datadog-agent/pkg/util/fxutil"
)

func TestFxRun(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

What about TestRun?

Copy link
Contributor

@ogaca-dd ogaca-dd left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -377,7 +377,8 @@ def lint_fxutil_oneshot_test(_):
for folder in folders:
folder_path = pathlib.Path(folder)
for file in folder_path.rglob("*.go"):
if str(file).endswith("_test.go") or str(file).endswith("main.go") or str(file).endswith("main_windows.go"):
# Don't lint test files
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@dustmop dustmop force-pushed the dustin.long/lint-fx-run branch from 527e6f4 to 73f9fa9 Compare December 12, 2023 15:03
Copy link
Contributor

Serverless Benchmark Results

BenchmarkStartEndInvocation comparison between 45c3a4a and 1a457a1.

tl;dr
  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.

Benchmark stats
goos: linux
goarch: amd64
pkg: github.com/DataDog/datadog-agent/pkg/serverless/daemon
cpu: AMD EPYC 7763 64-Core Processor                
                                      │   previous    │               current                │
                                      │    sec/op     │    sec/op     vs base                │
api-gateway-appsec.json                  161.9µ ±  2%   164.2µ ±  3%        ~ (p=0.436 n=10)
api-gateway-kong-appsec.json             108.4µ ±  2%   107.8µ ±  2%        ~ (p=0.436 n=10)
api-gateway-kong.json                    106.2µ ±  4%   106.9µ ±  4%        ~ (p=0.353 n=10)
api-gateway-non-proxy-async.json         162.9µ ±  2%   161.6µ ±  4%        ~ (p=0.353 n=10)
api-gateway-non-proxy.json               163.1µ ±  3%   161.6µ ±  2%        ~ (p=0.579 n=10)
api-gateway-websocket-connect.json       105.6µ ±  3%   105.0µ ±  3%        ~ (p=0.631 n=10)
api-gateway-websocket-default.json       89.15µ ±  2%   87.70µ ±  5%   -1.63% (p=0.029 n=10)
api-gateway-websocket-disconnect.json    87.92µ ±  4%   89.60µ ±  3%        ~ (p=0.089 n=10)
api-gateway.json                         186.5µ ±  2%   184.4µ ±  2%        ~ (p=0.529 n=10)
application-load-balancer.json           81.84µ ±  5%   82.28µ ±  3%        ~ (p=0.631 n=10)
cloudfront.json                          67.18µ ±  6%   68.09µ ±  5%        ~ (p=0.247 n=10)
cloudwatch-events.json                   52.25µ ±  4%   52.74µ ±  3%        ~ (p=0.436 n=10)
cloudwatch-logs.json                     69.53µ ±  2%   69.65µ ±  5%        ~ (p=0.529 n=10)
custom.json                              34.04µ ±  9%   34.52µ ±  7%        ~ (p=0.436 n=10)
dynamodb.json                            190.5µ ±  5%   179.9µ ±  4%   -5.58% (p=0.019 n=10)
empty.json                               35.67µ ± 11%   34.17µ ±  8%        ~ (p=0.529 n=10)
eventbridge-custom.json                  60.97µ ±  8%   56.86µ ±  6%   -6.75% (p=0.015 n=10)
http-api.json                            99.00µ ± 10%   91.59µ ±  3%   -7.48% (p=0.015 n=10)
kinesis-batch.json                       116.3µ ± 12%   110.2µ ±  7%   -5.31% (p=0.009 n=10)
kinesis.json                             92.33µ ±  8%   77.06µ ±  2%  -16.53% (p=0.000 n=10)
s3.json                                 101.99µ ± 11%   95.77µ ±  3%   -6.10% (p=0.000 n=10)
sns-batch.json                           170.8µ ± 11%   155.9µ ±  4%   -8.77% (p=0.001 n=10)
sns.json                                109.15µ ± 13%   99.44µ ±  5%        ~ (p=0.075 n=10)
snssqs.json                              159.9µ ± 15%   155.9µ ±  5%        ~ (p=0.218 n=10)
snssqs_no_dd_context.json                156.2µ ± 13%   146.1µ ±  4%        ~ (p=0.393 n=10)
sqs-aws-header.json                      97.03µ ± 11%   90.94µ ±  6%        ~ (p=0.218 n=10)
sqs-batch.json                           159.9µ ± 10%   169.6µ ± 11%        ~ (p=0.481 n=10)
sqs.json                                 123.1µ ± 10%   108.9µ ± 13%  -11.58% (p=0.015 n=10)
sqs_no_dd_context.json                   125.0µ ± 17%   112.0µ ± 10%  -10.39% (p=0.005 n=10)
geomean                                  103.3µ         99.72µ         -3.50%

                                      │   previous    │               current                │
                                      │     B/op      │     B/op       vs base               │
api-gateway-appsec.json                 47.15Ki ±  2%   47.15Ki ±  2%       ~ (p=0.929 n=10)
api-gateway-kong-appsec.json            30.99Ki ± 11%   30.99Ki ±  9%       ~ (p=0.669 n=10)
api-gateway-kong.json                   28.31Ki ±  0%   28.31Ki ± 17%       ~ (p=0.515 n=10)
api-gateway-non-proxy-async.json        54.96Ki ±  0%   54.97Ki ±  0%       ~ (p=0.404 n=10)
api-gateway-non-proxy.json              53.53Ki ±  0%   53.53Ki ±  0%       ~ (p=0.196 n=10)
api-gateway-websocket-connect.json      31.15Ki ±  0%   31.15Ki ±  0%       ~ (p=0.643 n=10)
api-gateway-websocket-default.json      25.05Ki ±  0%   25.05Ki ±  0%       ~ (p=0.224 n=10)
api-gateway-websocket-disconnect.json   24.60Ki ±  0%   24.59Ki ±  0%       ~ (p=0.896 n=10)
api-gateway.json                        59.24Ki ±  0%   59.24Ki ±  0%       ~ (p=0.643 n=10)
application-load-balancer.json          24.78Ki ±  0%   24.79Ki ±  0%       ~ (p=0.197 n=10)
cloudfront.json                         18.60Ki ±  0%   18.59Ki ±  0%       ~ (p=0.670 n=10)
cloudwatch-events.json                  12.61Ki ±  0%   12.60Ki ±  0%       ~ (p=0.615 n=10)
cloudwatch-logs.json                    54.57Ki ±  0%   54.57Ki ±  0%       ~ (p=0.660 n=10)
custom.json                             9.709Ki ±  0%   9.709Ki ±  0%       ~ (p=1.000 n=10)
dynamodb.json                           52.31Ki ±  0%   52.31Ki ±  0%       ~ (p=0.781 n=10)
empty.json                              9.163Ki ±  0%   9.164Ki ±  0%       ~ (p=0.955 n=10)
eventbridge-custom.json                 13.78Ki ±  0%   13.78Ki ±  0%       ~ (p=0.468 n=10)
http-api.json                           24.93Ki ±  0%   24.92Ki ±  0%       ~ (p=0.359 n=10)
kinesis-batch.json                      28.72Ki ±  0%   28.71Ki ±  0%       ~ (p=0.148 n=10)
kinesis.json                            18.70Ki ±  0%   18.69Ki ±  0%       ~ (p=0.170 n=10)
s3.json                                 21.89Ki ±  0%   21.89Ki ±  0%       ~ (p=0.283 n=10)
sns-batch.json                          42.64Ki ±  0%   42.63Ki ±  0%       ~ (p=0.109 n=10)
sns.json                                25.70Ki ±  0%   25.70Ki ±  0%       ~ (p=0.867 n=10)
snssqs.json                             44.90Ki ±  0%   44.90Ki ±  0%       ~ (p=0.725 n=10)
snssqs_no_dd_context.json               38.07Ki ±  0%   38.07Ki ±  0%       ~ (p=0.100 n=10)
sqs-aws-header.json                     19.63Ki ±  0%   19.64Ki ±  0%       ~ (p=0.423 n=10)
sqs-batch.json                          43.71Ki ±  0%   43.71Ki ±  0%       ~ (p=0.446 n=10)
sqs.json                                26.70Ki ±  0%   26.70Ki ±  0%       ~ (p=0.341 n=10)
sqs_no_dd_context.json                  21.01Ki ±  0%   21.00Ki ±  0%       ~ (p=0.448 n=10)
geomean                                 27.79Ki         27.79Ki        -0.00%

                                      │  previous  │               current               │
                                      │ allocs/op  │ allocs/op   vs base                 │
api-gateway-appsec.json                 597.0 ± 0%   597.0 ± 0%       ~ (p=0.582 n=10)
api-gateway-kong-appsec.json            495.5 ± 0%   496.0 ± 0%       ~ (p=0.650 n=10)
api-gateway-kong.json                   473.0 ± 0%   473.0 ± 0%       ~ (p=1.000 n=10)
api-gateway-non-proxy-async.json        679.0 ± 0%   680.0 ± 0%       ~ (p=0.170 n=10)
api-gateway-non-proxy.json              670.0 ± 0%   670.0 ± 0%       ~ (p=0.582 n=10)
api-gateway-websocket-connect.json      436.0 ± 0%   436.0 ± 0%       ~ (p=1.000 n=10) ¹
api-gateway-websocket-default.json      348.0 ± 0%   347.0 ± 0%       ~ (p=0.057 n=10)
api-gateway-websocket-disconnect.json   338.0 ± 0%   338.0 ± 0%       ~ (p=1.000 n=10)
api-gateway.json                        772.0 ± 0%   772.5 ± 0%       ~ (p=0.650 n=10)
application-load-balancer.json          337.0 ± 0%   337.0 ± 0%       ~ (p=1.000 n=10) ¹
cloudfront.json                         246.0 ± 0%   246.0 ± 0%       ~ (p=1.000 n=10) ¹
cloudwatch-events.json                  227.0 ± 0%   227.0 ± 0%       ~ (p=1.000 n=10) ¹
cloudwatch-logs.json                    225.0 ± 0%   225.0 ± 0%       ~ (p=1.000 n=10) ¹
custom.json                             172.0 ± 0%   172.0 ± 0%       ~ (p=1.000 n=10) ¹
dynamodb.json                           597.0 ± 0%   597.0 ± 0%       ~ (p=1.000 n=10) ¹
empty.json                              161.0 ± 0%   161.0 ± 0%       ~ (p=1.000 n=10) ¹
eventbridge-custom.json                 242.0 ± 0%   242.0 ± 0%       ~ (p=1.000 n=10) ¹
http-api.json                           385.0 ± 0%   385.0 ± 0%       ~ (p=0.628 n=10)
kinesis-batch.json                      309.0 ± 0%   309.0 ± 0%       ~ (p=1.000 n=10)
kinesis.json                            250.0 ± 0%   250.0 ± 0%       ~ (p=1.000 n=10) ¹
s3.json                                 306.0 ± 0%   306.0 ± 0%       ~ (p=1.000 n=10) ¹
sns-batch.json                          363.0 ± 0%   363.0 ± 0%       ~ (p=1.000 n=10) ¹
sns.json                                282.0 ± 0%   282.0 ± 0%       ~ (p=1.000 n=10)
snssqs.json                             338.0 ± 0%   338.0 ± 0%       ~ (p=1.000 n=10)
snssqs_no_dd_context.json               298.0 ± 0%   298.0 ± 0%       ~ (p=1.000 n=10)
sqs-aws-header.json                     244.0 ± 0%   244.0 ± 0%       ~ (p=1.000 n=10) ¹
sqs-batch.json                          405.5 ± 0%   405.0 ± 0%       ~ (p=1.000 n=10)
sqs.json                                305.0 ± 0%   305.0 ± 0%       ~ (p=1.000 n=10) ¹
sqs_no_dd_context.json                  281.0 ± 0%   281.0 ± 0%       ~ (p=1.000 n=10) ¹
geomean                                 343.2        343.2       -0.00%
¹ all samples are equal

@dustmop dustmop merged commit 996e1bf into main Dec 13, 2023
158 of 160 checks passed
@dustmop dustmop deleted the dustin.long/lint-fx-run branch December 13, 2023 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants