datadog-agent icon indicating copy to clipboard operation
datadog-agent copied to clipboard

[CONTINT-3759] Add a retry mechanism in the SBOM scanner for container images

Open AliDatadog opened this issue 1 year ago • 8 comments

What does this PR do?

This PR adds a retry mechanism in the SBOM scanner only for container images. It also does a bit of refactoring to make the code more readable.

Motivation

A container image scan can fail and succeed later. It also fixes an issue where an image could be enqueued in the scan queue multiple times.

Additional Notes

N/A

Possible Drawbacks / Trade-offs

None, it should even reduce the resource usage as we should avoid scanning multiple times the same image.

Describe how to test/QA your changes

  1. Container-image retries Deploy the agent on kind with sbom collection enabled. You'll need to install it with helm and this setting. Set sbom.scan_queue.base_backoff and sbom.scan_queue.max_backoff to low values for testing.

Some built-in kind images can't be scanned unless pulled on your worker node. Make sure that we retry scans with an exponential backoff policy. Example: Capture d’écran 2024-03-01 à 12 19 39

Log line example:

2024-03-01 11:18:59 UTC | CORE | INFO | (pkg/sbom/collectors/containerd/containerd.go:104 in Scan) | containerd scan request [sha256:d022557af8b6306cc24be6f095d77b7892f28b34b765c4337774e5e4cbb39132]: scanning image sha256:d022557af8b6306cc24be6f095d77b7892f28b34b765c4337774e5e4cbb39132

Now pull the image again:

docker exec container-id ctr -n k8s.io image pull <image>

Make sure that the next retry will populate the image in workloadmeta and no more retry log occurs after then.

Moreover, also make sure that we stop retrying when every reference of a container image is deleted. Similarly, you can use docker exec <containerid> ctr -n k8s.io image rm <ref>

  1. Host scans Make sure host scans still work and are not retried.

AliDatadog avatar Mar 01 '24 11:03 AliDatadog

Go Package Import Differences

Baseline: cbb39b7eeb80f5377e54a574a23eb13e56f8db77 Comparison: 6ee64f0a3bfd785fe14ee501ec2348930768d1b4

binaryosarchchange
trace-agentwindows386
+11, -0
+container/heap
+k8s.io/apimachinery/pkg/util/runtime
+k8s.io/client-go/util/workqueue
+k8s.io/klog/v2
+k8s.io/klog/v2/internal/buffer
+k8s.io/klog/v2/internal/clock
+k8s.io/klog/v2/internal/dbg
+k8s.io/klog/v2/internal/serialize
+k8s.io/klog/v2/internal/severity
+k8s.io/klog/v2/internal/sloghandler
+k8s.io/utils/clock
heroku-trace-agentlinuxamd64
+11, -0
+container/heap
+k8s.io/apimachinery/pkg/util/runtime
+k8s.io/client-go/util/workqueue
+k8s.io/klog/v2
+k8s.io/klog/v2/internal/buffer
+k8s.io/klog/v2/internal/clock
+k8s.io/klog/v2/internal/dbg
+k8s.io/klog/v2/internal/serialize
+k8s.io/klog/v2/internal/severity
+k8s.io/klog/v2/internal/sloghandler
+k8s.io/utils/clock

cit-pr-commenter[bot] avatar Mar 01 '24 11:03 cit-pr-commenter[bot]

Bloop Bleep... Dogbot Here

Regression Detector Results

Run ID: 91c49ea2-5b01-4ac7-a925-d670f1d35aa3 Baseline: cbb39b7eeb80f5377e54a574a23eb13e56f8db77 Comparison: 6ee64f0a3bfd785fe14ee501ec2348930768d1b4

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

Experiments with missing or malformed data

  • basic_py_check

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

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.

Experiments ignored for regressions

Regressions in experiments with settings containing erratic: true are ignored.

perf experiment goal Δ mean % Δ mean % CI
file_to_blackhole % cpu utilization +0.76 [-5.82, +7.34]

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI
uds_dogstatsd_to_api_cpu % cpu utilization +1.13 [-0.32, +2.58]
tcp_syslog_to_blackhole ingress throughput +0.80 [+0.75, +0.85]
file_to_blackhole % cpu utilization +0.76 [-5.82, +7.34]
process_agent_standard_check memory utilization +0.62 [+0.59, +0.65]
idle memory utilization +0.44 [+0.40, +0.47]
uds_dogstatsd_to_api ingress throughput -0.00 [-0.00, +0.00]
tcp_dd_logs_filter_exclude ingress throughput -0.00 [-0.00, +0.00]
trace_agent_json ingress throughput -0.02 [-0.05, +0.00]
trace_agent_msgpack ingress throughput -0.02 [-0.04, -0.01]
process_agent_standard_check_with_stats memory utilization -0.04 [-0.07, -0.01]
process_agent_real_time_mode memory utilization -0.08 [-0.11, -0.04]
otel_to_otel_logs ingress throughput -0.43 [-1.06, +0.19]
file_tree memory utilization -0.54 [-0.60, -0.47]

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

pr-commenter[bot] avatar Mar 01 '24 12:03 pr-commenter[bot]

/merge

AliDatadog avatar Mar 05 '24 10:03 AliDatadog

:steam_locomotive: MergeQueue

This merge request is not mergeable yet, because of pending checks/missing approvals. It will be added to the queue as soon as checks pass and/or get approvals. Note: if you pushed new commits since the last approval, you may need additional approval. You can remove it from the waiting list with /remove command.

Use /merge -c to cancel this operation!

dd-devflow[bot] avatar Mar 05 '24 10:03 dd-devflow[bot]

:warning: MergeQueue

This merge request was unqueued

If you need support, contact us on Slack #ci-interfaces!

dd-devflow[bot] avatar Mar 05 '24 14:03 dd-devflow[bot]

/merge

AliDatadog avatar Mar 05 '24 15:03 AliDatadog

:steam_locomotive: MergeQueue

This merge request is not mergeable yet, because of pending checks/missing approvals. It will be added to the queue as soon as checks pass and/or get approvals. Note: if you pushed new commits since the last approval, you may need additional approval. You can remove it from the waiting list with /remove command.

Use /merge -c to cancel this operation!

dd-devflow[bot] avatar Mar 05 '24 15:03 dd-devflow[bot]

:warning: MergeQueue

This merge request was unqueued

If you need support, contact us on Slack #ci-interfaces!

dd-devflow[bot] avatar Mar 05 '24 19:03 dd-devflow[bot]

/merge

AliDatadog avatar Mar 06 '24 10:03 AliDatadog

:steam_locomotive: MergeQueue

This merge request is not mergeable yet, because of pending checks/missing approvals. It will be added to the queue as soon as checks pass and/or get approvals. Note: if you pushed new commits since the last approval, you may need additional approval. You can remove it from the waiting list with /remove command.

Use /merge -c to cancel this operation!

dd-devflow[bot] avatar Mar 06 '24 10:03 dd-devflow[bot]

:steam_locomotive: MergeQueue

Added to the queue.

This build is going to start soon! (estimated merge in less than 26m)

Use /merge -c to cancel this operation!

dd-devflow[bot] avatar Mar 06 '24 11:03 dd-devflow[bot]