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

Go DI: Encode correct JSON format for eventually uploading to Datadog backend

Open grantseltzer opened this issue 5 months ago • 3 comments

What does this PR do?

Encodes the correct envelope format for turning events from bpf into messages for upload.

Also updates integration test and testdata. Service name is currently being injected, and artificially so in integration test.

Notably program counters are not yet symbolicated.

Motivation

Uploading events to the datadog backend

Describe how you validated your changes

Integration test

Possible Drawbacks / Trade-offs

Example:

{
    "service": "sample",
    "ddsource": "dd_debugger",
    "ddtags": "",
    "logger": {
        "name": "",
        "method": ""
    },
    "debugger": {
        "snapshot": {
            "id": "f0750577-5127-11f0-a476-001c421ddea2",
            "timestamp": 1750789242826,
            "language": "go",
            "stack": [
                674592,
                672252,
                672252,
                298500,
                517188
            ],
            "probe": {
                "id": "testUintPointer",
                "location": {
                    "method": "main.testUintPointer"
                }
            },
            "captures": {
                "entry": {
                    "arguments": {
                        "x": {
                            "type": "*uint",
                            "value": {
                                "Address": "0x400010fd38",
                                "Value": 1
                            }
                        }
                    }
                }
            }
        }
    }
}

grantseltzer avatar Jun 25 '25 17:06 grantseltzer

Regression Detector

Regression Detector Results

Metrics dashboard
Target profiles
Run ID: 4c5b1fd1-e1ea-4e53-a37a-cd14988054bc

Baseline: 65e5bb120202b3907f9253b0cefcdebfb3a38bda Comparison: 761ce3574c363812cb344cf4b3e4d759fae2896c Diff

Optimization Goals: ✅ Improvement(s) detected

perf experiment goal Δ mean % Δ mean % CI trials links
quality_gate_logs % cpu utilization -5.95 [-8.64, -3.25] 1 Logs bounds checks dashboard

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI trials links
uds_dogstatsd_to_api_cpu % cpu utilization +3.16 [+2.30, +4.03] 1 Logs
docker_containers_memory memory utilization +0.78 [+0.70, +0.86] 1 Logs
otlp_ingest_logs memory utilization +0.71 [+0.58, +0.84] 1 Logs
ddot_metrics memory utilization +0.35 [+0.24, +0.47] 1 Logs
quality_gate_idle_all_features memory utilization +0.25 [+0.17, +0.32] 1 Logs bounds checks dashboard
tcp_syslog_to_blackhole ingress throughput +0.19 [+0.12, +0.25] 1 Logs
quality_gate_idle memory utilization +0.18 [+0.11, +0.25] 1 Logs bounds checks dashboard
ddot_logs memory utilization +0.17 [+0.08, +0.26] 1 Logs
otlp_ingest_metrics memory utilization +0.10 [-0.04, +0.25] 1 Logs
file_to_blackhole_0ms_latency_http1 egress throughput +0.04 [-0.51, +0.58] 1 Logs
file_to_blackhole_0ms_latency_http2 egress throughput +0.02 [-0.56, +0.59] 1 Logs
tcp_dd_logs_filter_exclude ingress throughput -0.01 [-0.03, +0.02] 1 Logs
uds_dogstatsd_to_api ingress throughput -0.01 [-0.28, +0.27] 1 Logs
file_to_blackhole_500ms_latency egress throughput -0.01 [-0.64, +0.62] 1 Logs
file_to_blackhole_1000ms_latency_linear_load egress throughput -0.08 [-0.31, +0.16] 1 Logs
file_to_blackhole_1000ms_latency egress throughput -0.08 [-0.63, +0.47] 1 Logs
file_to_blackhole_300ms_latency egress throughput -0.08 [-0.69, +0.54] 1 Logs
file_to_blackhole_0ms_latency egress throughput -0.08 [-0.69, +0.53] 1 Logs
file_to_blackhole_100ms_latency egress throughput -0.08 [-0.65, +0.48] 1 Logs
uds_dogstatsd_20mb_12k_contexts_20_senders memory utilization -0.16 [-0.23, -0.10] 1 Logs
file_tree memory utilization -0.82 [-0.95, -0.70] 1 Logs
docker_containers_cpu % cpu utilization -1.20 [-4.34, +1.95] 1 Logs
quality_gate_logs % cpu utilization -5.95 [-8.64, -3.25] 1 Logs bounds checks dashboard

Bounds Checks: ✅ Passed

perf experiment bounds_check_name replicates_passed links
docker_containers_cpu simple_check_run 10/10
docker_containers_memory memory_usage 10/10
docker_containers_memory simple_check_run 10/10
file_to_blackhole_0ms_latency lost_bytes 10/10
file_to_blackhole_0ms_latency memory_usage 10/10
file_to_blackhole_0ms_latency_http1 lost_bytes 10/10
file_to_blackhole_0ms_latency_http1 memory_usage 10/10
file_to_blackhole_0ms_latency_http2 lost_bytes 10/10
file_to_blackhole_0ms_latency_http2 memory_usage 10/10
file_to_blackhole_1000ms_latency memory_usage 10/10
file_to_blackhole_1000ms_latency_linear_load 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 lost_bytes 10/10
file_to_blackhole_300ms_latency memory_usage 10/10
file_to_blackhole_500ms_latency lost_bytes 10/10
file_to_blackhole_500ms_latency memory_usage 10/10
quality_gate_idle intake_connections 10/10 bounds checks dashboard
quality_gate_idle memory_usage 10/10 bounds checks dashboard
quality_gate_idle_all_features intake_connections 10/10 bounds checks dashboard
quality_gate_idle_all_features memory_usage 10/10 bounds checks dashboard
quality_gate_logs intake_connections 10/10 bounds checks dashboard
quality_gate_logs lost_bytes 10/10 bounds checks dashboard
quality_gate_logs 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".

CI Pass/Fail Decision

Passed. All Quality Gates passed.

  • quality_gate_logs, bounds check lost_bytes: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_idle_all_features, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_idle_all_features, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_idle, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_idle, bounds check intake_connections: 10/10 replicas passed. Gate passed.

cit-pr-commenter[bot] avatar Jun 25 '25 18:06 cit-pr-commenter[bot]

Static quality checks

✅ Please find below the results from static quality gates Comparison made with ancestor 65e5bb120202b3907f9253b0cefcdebfb3a38bda

Successful checks

Info

Quality gate Delta On disk size (MiB) Delta On wire size (MiB)
agent_deb_amd64 $${0}$$ $${698.99}$$ < $${700.55}$$ $${-0.05}$$ $${176.69}$$ < $${177.62}$$
agent_deb_amd64_fips $${0}$$ $${697.24}$$ < $${699.75}$$ $${+0.02}$$ $${176.09}$$ < $${177.04}$$
agent_heroku_amd64 $${0}$$ $${351.98}$$ < $${362.84}$$ $${+0}$$ $${95.2}$$ < $${98.91}$$
agent_msi $${0}$$ $${971.07}$$ < $${974.5}$$ $${-0.01}$$ $${147.22}$$ < $${148.11}$$
agent_rpm_amd64 $${0}$$ $${698.98}$$ < $${700.53}$$ $${+0}$$ $${178.36}$$ < $${179.2}$$
agent_rpm_amd64_fips $${0}$$ $${697.23}$$ < $${699.74}$$ $${-0.02}$$ $${177.98}$$ < $${178.75}$$
agent_rpm_arm64 $${0}$$ $${688.88}$$ < $${690.5}$$ $${-0.03}$$ $${161.79}$$ < $${162.56}$$
agent_rpm_arm64_fips $${0}$$ $${687.18}$$ < $${689.8}$$ $${-0.05}$$ $${160.79}$$ < $${161.61}$$
agent_suse_amd64 $${0}$$ $${698.98}$$ < $${700.54}$$ $${+0}$$ $${178.36}$$ < $${179.2}$$
agent_suse_amd64_fips $${0}$$ $${697.23}$$ < $${699.74}$$ $${-0.02}$$ $${177.98}$$ < $${178.93}$$
agent_suse_arm64 $${0}$$ $${688.88}$$ < $${690.43}$$ $${-0.03}$$ $${161.79}$$ < $${162.57}$$
agent_suse_arm64_fips $${0}$$ $${687.18}$$ < $${689.78}$$ $${-0.05}$$ $${160.79}$$ < $${161.61}$$
docker_agent_amd64 $${+0}$$ $${782.78}$$ < $${784.33}$$ $${+0}$$ $${269.74}$$ < $${270.56}$$
docker_agent_arm64 $${-0}$$ $${796.13}$$ < $${797.68}$$ $${+0}$$ $${257.07}$$ < $${257.84}$$
docker_agent_jmx_amd64 $${-0}$$ $${973.98}$$ < $${975.52}$$ $${-0}$$ $${338.7}$$ < $${339.53}$$
docker_agent_jmx_arm64 $${0}$$ $${975.92}$$ < $${977.47}$$ $${+0}$$ $${322.03}$$ < $${322.81}$$
docker_agent_windows1809 $${-2.23}$$ $${1181.8}$$ < $${1190.0}$$ $${-0.99}$$ $${416.18}$$ < $${422.66}$$
docker_agent_windows1809_core $${-0}$$ $${5913.92}$$ < $${5919.41}$$ $${0}$$ $${2048.0}$$ < $${2049.0}$$
docker_agent_windows1809_core_jmx $${-0}$$ $${6035.5}$$ < $${6063.56}$$ $${0}$$ $${2048.0}$$ < $${2049.0}$$
docker_agent_windows1809_jmx $${-0}$$ $${1305.59}$$ < $${1311.1}$$ $${+0.01}$$ $${459.77}$$ < $${464.35}$$
docker_agent_windows2022 $${-0.2}$$ $${1203.06}$$ < $${1208.75}$$ $${-0.01}$$ $${430.24}$$ < $${434.91}$$
docker_agent_windows2022_core $${-0.06}$$ $${5886.99}$$ < $${5892.66}$$ $${0}$$ $${2048.0}$$ < $${2049.0}$$
docker_agent_windows2022_core_jmx $${-0.18}$$ $${6008.63}$$ < $${6014.08}$$ $${0}$$ $${2048.0}$$ < $${2049.0}$$
docker_agent_windows2022_jmx $${-0}$$ $${1324.66}$$ < $${1330.39}$$ $${-0}$$ $${472.52}$$ < $${477.17}$$
docker_cluster_agent_amd64 $${0}$$ $${213.63}$$ < $${214.5}$$ $${+0}$$ $${72.63}$$ < $${73.51}$$
docker_cluster_agent_arm64 $${-0}$$ $${229.42}$$ < $${230.33}$$ $${-0}$$ $${68.89}$$ < $${69.77}$$
docker_cws_instrumentation_amd64 $${0}$$ $${7.07}$$ < $${7.12}$$ $${-0}$$ $${2.95}$$ < $${3.29}$$
docker_cws_instrumentation_arm64 $${0}$$ $${6.69}$$ < $${6.92}$$ $${0}$$ $${2.7}$$ < $${3.07}$$
docker_dogstatsd_amd64 $${0}$$ $${39.21}$$ < $${39.57}$$ $${+0}$$ $${15.12}$$ < $${15.76}$$
docker_dogstatsd_arm64 $${0}$$ $${37.88}$$ < $${38.2}$$ $${-0}$$ $${14.54}$$ < $${14.83}$$
dogstatsd_deb_amd64 $${0}$$ $${30.42}$$ < $${31.4}$$ $${-0}$$ $${8.0}$$ < $${8.95}$$
dogstatsd_deb_arm64 $${0}$$ $${28.99}$$ < $${29.97}$$ $${-0}$$ $${6.94}$$ < $${7.89}$$
dogstatsd_rpm_amd64 $${0}$$ $${30.42}$$ < $${31.4}$$ $${-0}$$ $${8.01}$$ < $${8.96}$$
dogstatsd_suse_amd64 $${0}$$ $${30.42}$$ < $${31.4}$$ $${-0}$$ $${8.01}$$ < $${8.96}$$
iot_agent_deb_amd64 $${0}$$ $${53.76}$$ < $${54.55}$$ $${+0}$$ $${13.55}$$ < $${14.45}$$
iot_agent_deb_arm64 $${0}$$ $${51.1}$$ < $${51.9}$$ $${+0}$$ $${11.73}$$ < $${12.63}$$
iot_agent_deb_armhf $${0}$$ $${50.61}$$ < $${51.42}$$ $${-0.01}$$ $${11.82}$$ < $${12.74}$$
iot_agent_rpm_amd64 $${0}$$ $${53.76}$$ < $${54.55}$$ $${+0}$$ $${13.57}$$ < $${14.47}$$
iot_agent_rpm_arm64 $${0}$$ $${51.1}$$ < $${51.91}$$ $${-0}$$ $${11.74}$$ < $${12.65}$$
iot_agent_suse_amd64 $${0}$$ $${53.76}$$ < $${54.55}$$ $${+0}$$ $${13.57}$$ < $${14.47}$$

I think we're doing ourselves a disservice with regards to readability and adaptability by writing all these tokens like this. It makes sense in the dynamic parse as you had before, but for this outer envelope I think it's a lot more harm than good.

Consider:

type snapshotMessage struct {
    Service string `json:"service"`
    DDSource string `json:"ddsource"`
    // ...

}

For the parts of the message that are dynamic, you wrap up the relevant state and shove it into the relevant field and implement https://pkg.go.dev/github.com/go-json-experiment/json#MarshalerTo

All of this can hang off the decoder, so you don't need to allocate anything new per call. You set the relevant fields and then just call json.Marshal and good efficient things can happen where we want them to and we can eliminate all this toil.

I've pushed a change that I believe does what you describe. In addition to looking for code organization and allocation efficiency, I want to clarify from our irl conversation earlier (please tell me if the following is true or not)

  1. An ir.Program should not be assumed to be for a single service. For example, you may instrument the same functions in a bunch of different binaries (i.e. probing library functions).

  2. A decoder is not specifically for a single service, but the service/process information can be injected by the ProcessInfoResolver that we added to this branch. So it shouldn't be assumed to be specific to anything as such.

  3. I still need to figure out exactly what goes into, and/or what is the purpose of, ddsource, logger, and message.

grantseltzer avatar Jun 26 '25 17:06 grantseltzer

I think generally we've gotten the format wrong when it comes to encodeValue. You need to have the envelopes recursively. Like at every level there needs to be an object with {"type": <type_name>, "value": [, "isNull": true][,"notCapturedReason":<...>}. We've been dragging this on for a while, but also it feels like a pretty minor and small change. If you can't fit it into this one, we need it ASAP because as it stands compound structures break the UI. Let's get some more tests with some more complex pointer graphs in play ASAP too.

Thanks for pointing this out. I've fixed this. Another nuance to it is that structs expect a "fields" key instead of value, slices/arrays expect "elements". Everything else is "value".

grantseltzer avatar Jul 02 '25 16:07 grantseltzer

CLA assistant check
All committers have signed the CLA.

bits-bot avatar Jul 02 '25 20:07 bits-bot

/merge

grantseltzer avatar Jul 03 '25 19:07 grantseltzer

View all feedbacks in Devflow UI.

2025-07-03 19:46:07 UTC :information_source: Start processing command /merge


2025-07-03 19:46:16 UTC :information_source: MergeQueue: waiting for PR to be ready

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.


2025-07-03 21:35:11 UTC :information_source: MergeQueue: merge request added to the queue

The expected merge time in main is approximately 46m (p90).


2025-07-03 22:19:57 UTC :information_source: MergeQueue: This merge request was merged

dd-devflow[bot] avatar Jul 03 '25 19:07 dd-devflow[bot]