Skip to content

Rksrcl/string grpc#34220

Merged
dd-mergequeue[bot] merged 31 commits into
mainfrom
rksrcl/string-grpc
Feb 27, 2025
Merged

Rksrcl/string grpc#34220
dd-mergequeue[bot] merged 31 commits into
mainfrom
rksrcl/string-grpc

Conversation

@rksrcl

@rksrcl rksrcl commented Feb 19, 2025

Copy link
Copy Markdown
Contributor

What does this PR do?

The agent will send grpc status codes to the stats backend

Motivation

We want grpc status codes to appear in trace metrics

Describe how you validated your changes

Added tests:

  • pkg/trace/stats/aggregation_test.go
  • pkg/trace/stats/client_stats_aggregator_test.go

Ran system tests to check changes with all the tracer libraries: https://github.com/DataDog/system-tests-dashboard/actions/runs/13530539811

Possible Drawbacks / Trade-offs

Additional Notes

@rksrcl rksrcl requested review from a team as code owners February 19, 2025 17:52
@rksrcl rksrcl marked this pull request as draft February 19, 2025 17:52
@github-actions github-actions Bot added medium review PR review might take time team/agent-apm trace-agent labels Feb 19, 2025
@cit-pr-commenter

cit-pr-commenter Bot commented Feb 19, 2025

Copy link
Copy Markdown

Go Package Import Differences

Baseline: 45d43d5
Comparison: 2b40790

binaryosarchchange
agentdarwinamd64
+1, -0
+google.golang.org/genproto/googleapis/rpc/code
agentdarwinarm64
+1, -0
+google.golang.org/genproto/googleapis/rpc/code
iot-agentlinuxamd64
+1, -0
+google.golang.org/genproto/googleapis/rpc/code
iot-agentlinuxarm64
+1, -0
+google.golang.org/genproto/googleapis/rpc/code
heroku-agentlinuxamd64
+1, -0
+google.golang.org/genproto/googleapis/rpc/code
cluster-agentlinuxamd64
+1, -0
+google.golang.org/genproto/googleapis/rpc/code
cluster-agentlinuxarm64
+1, -0
+google.golang.org/genproto/googleapis/rpc/code
serverlesslinuxamd64
+1, -0
+google.golang.org/genproto/googleapis/rpc/code
serverlesslinuxarm64
+1, -0
+google.golang.org/genproto/googleapis/rpc/code
trace-agentlinuxamd64
+1, -0
+google.golang.org/genproto/googleapis/rpc/code
trace-agentlinuxarm64
+1, -0
+google.golang.org/genproto/googleapis/rpc/code
trace-agentwindowsamd64
+1, -0
+google.golang.org/genproto/googleapis/rpc/code
trace-agentdarwinamd64
+1, -0
+google.golang.org/genproto/googleapis/rpc/code
trace-agentdarwinarm64
+1, -0
+google.golang.org/genproto/googleapis/rpc/code
heroku-trace-agentlinuxamd64
+1, -0
+google.golang.org/genproto/googleapis/rpc/code

@cit-pr-commenter

cit-pr-commenter Bot commented Feb 19, 2025

Copy link
Copy Markdown

Regression Detector

Regression Detector Results

Metrics dashboard
Target profiles
Run ID: cf7fc08b-1e13-4929-8b70-1de69b54c989

Baseline: 45d43d5
Comparison: 2b40790
Diff

Optimization Goals: ✅ No significant changes detected

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI trials links
quality_gate_logs % cpu utilization +2.67 [-0.36, +5.70] 1 Logs
quality_gate_idle_all_features memory utilization +0.75 [+0.69, +0.80] 1 Logs bounds checks dashboard
file_to_blackhole_500ms_latency egress throughput +0.50 [-0.27, +1.27] 1 Logs
file_tree memory utilization +0.23 [+0.17, +0.30] 1 Logs
file_to_blackhole_1000ms_latency_linear_load egress throughput +0.21 [-0.26, +0.67] 1 Logs
uds_dogstatsd_to_api_cpu % cpu utilization +0.18 [-0.80, +1.16] 1 Logs
quality_gate_idle memory utilization +0.15 [+0.10, +0.20] 1 Logs bounds checks dashboard
file_to_blackhole_100ms_latency egress throughput +0.03 [-0.66, +0.72] 1 Logs
file_to_blackhole_300ms_latency egress throughput +0.02 [-0.61, +0.64] 1 Logs
file_to_blackhole_0ms_latency_http1 egress throughput +0.01 [-0.80, +0.82] 1 Logs
uds_dogstatsd_to_api ingress throughput +0.01 [-0.30, +0.32] 1 Logs
file_to_blackhole_0ms_latency egress throughput -0.00 [-0.84, +0.83] 1 Logs
tcp_dd_logs_filter_exclude ingress throughput -0.00 [-0.03, +0.02] 1 Logs
file_to_blackhole_0ms_latency_http2 egress throughput -0.01 [-0.82, +0.79] 1 Logs
file_to_blackhole_1000ms_latency egress throughput -0.04 [-0.81, +0.73] 1 Logs
tcp_syslog_to_blackhole ingress throughput -1.05 [-1.10, -0.99] 1 Logs

Bounds Checks: ✅ Passed

perf experiment bounds_check_name replicates_passed links
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
quality_gate_logs lost_bytes 10/10
quality_gate_logs memory_usage 10/10

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_idle, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_idle, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check lost_bytes: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_idle_all_features, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_idle_all_features, bounds check intake_connections: 10/10 replicas passed. Gate passed.

@rksrcl rksrcl marked this pull request as ready for review February 19, 2025 21:21
@rksrcl rksrcl requested a review from a team as a code owner February 19, 2025 21:23
@github-actions github-actions Bot removed the medium review PR review might take time label Feb 19, 2025
Comment thread pkg/trace/stats/aggregation.go Outdated
@rksrcl rksrcl requested a review from dineshg13 February 20, 2025 20:22
Comment thread pkg/trace/stats/aggregation.go Outdated
@rksrcl rksrcl requested a review from dineshg13 February 20, 2025 21:13
return strconv.FormatUint(c, 10)
}
strCUpper := strings.ToUpper(strC)
if strCUpper == "CANCELED" || strCUpper == "CANCELLED" { // the rpc code google api checks for "CANCELLED" but we receive "Canceled" from upstream

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we add a unit test in aggregation_test.go to make sure that the "canceled" status code is being properly set.

Comment thread pkg/trace/stats/aggregation.go Outdated
}
}

return "" // invalid gRPC code

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can take this comment out
It's not always invalid if we reach this point. Only grpc traces have grpc_status_codes. All other traces will not have the tag in the span, in which case there is nothing to return.

// E.g., `grpc.target` to describe the name of a gRPC peer, or `db.hostname` to describe the name of peer DB
repeated string peer_tags = 16;
Trilean is_trace_root = 17; // this field's value is equal to span's ParentID == 0.
string GRPC_status_code = 18;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: can this be a number rather than a string as IIRC we're displaying these as the raw number rather than the string associated with the code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If it's an integer the default if it's not set is 0, so this screws up the end to end tests for dd-go because a gRPC status code tag with 0 will be appended when not intentionally set and 0 is a valid gRPC status code that should get sent downstream.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Integers have a default of 0 but 0 is also a valid status code. We've switched to a string since a string allows us to handle nil status codes better. Sources like USM won't be submitting grpc status codes.

Though it could be argued that we could keep the string format representation of the grpc code while the variable is of type string until we create the metric tag

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You can regain "presence" checking in protobuf by marking the field optional (check the proto3 section not the proto2 section)
https://protobuf.dev/programming-guides/field_presence/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Our proto files in dd-go are currently generated with protoc-gen-gogo which doesn't support the optional field. Regenerating them using the normal protoc-gen-go changed the structs' formats. We've scoped updating our protobuf files out of this project and onto a separate M&R jira ticket.

Synthetics bool
PeerTagsHash uint64
IsTraceRoot pb.Trilean
GRPCStatusCode string

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: same question as above r.e can this be an int


func getGRPCStatusCode(meta map[string]string, metrics map[string]float64) string {
// List of possible keys to check in order
metaKeys := []string{"rpc.grpc.status_code", "grpc.code", "rpc.grpc.status.code", "grpc.status.code"}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Where did this list come from? If possible let's make this configurable and have these tags be the default values

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These are the various ways the tracer libraries will send the tag from upstream depending on the tracer library: https://docs.google.com/spreadsheets/d/1tbn04E-wLv8ozTtDO02PCqkruCNbJ-aK-1G8Ytp7H5o/edit?gid=0#gid=0. The getGRPCStatusCode function just tries to return a value of the integer gRPC code regardless of how it was sent by the tracers.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think we'll want this to be configurable so we can easily adapt to changes and new traces, but this is a good default list for sure

Comment thread pkg/trace/stats/aggregation.go Outdated
return strconv.FormatUint(uint64(codes.Code(codeNum)), 10)
}

log.Debugf("Invalid status code %s. Using empty string", strC)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: we can probably get rid of this log, we can recover it from looking at the input data as needed

@@ -0,0 +1,4 @@
upgrade:
- |
APM: Adds grpc status codes to trace metrics

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: it might be more accurate to say something like "aggregate apm stats payloads by grpc code" since this change alone doesn't put them on trace metrics

Comment thread pkg/trace/stats/statsraw_test.go Outdated
"testing"
"time"

"github.com/DataDog/datadog-agent/pkg/trace/traceutil"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: my formatter does this too but since we didn't change anything else here let's undo this change to keep the diff smaller

@agent-platform-auto-pr

Copy link
Copy Markdown
Contributor

Static quality checks ❌

Please find below the results from static quality gates

Error

Result Quality gate On disk size On disk size limit On wire size On wire size limit
static_quality_gate_agent_rpm_arm64 DataNotFound 836.66MiB DataNotFound 194.24MiB
Gate failure full details
Quality gate Error type Error message
static_quality_gate_agent_rpm_arm64 StackTrace Traceback (most recent call last):
File "/go/src/github.com/DataDog/datadog-agent/tasks/quality_gates.py", line 121, in parse_and_trigger_gates
gate_mod.entrypoint(**gate_inputs)
File "/go/src/github.com/DataDog/datadog-agent/tasks/static_quality_gates/static_quality_gate_agent_rpm_arm64.py", line 5, in entrypoint
generic_package_agent_quality_gate(
File "/go/src/github.com/DataDog/datadog-agent/tasks/static_quality_gates/lib/package_agent_lib.py", line 69, in generic_package_agent_quality_gate
package_on_wire_size, package_on_disk_size = calculate_package_size(
^^^^^^^^^^^^^^^^^^^^^^^
File "/go/src/github.com/DataDog/datadog-agent/tasks/static_quality_gates/lib/package_agent_lib.py", line 10, in calculate_package_size
extract_package(ctx=ctx, package_os=package_os, package_path=package_path, extract_dir=extract_dir)
File "/go/src/github.com/DataDog/datadog-agent/tasks/libs/package/size.py", line 72, in extract_package
return extract_rpm_package(ctx, package_path, extract_dir)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/go/src/github.com/DataDog/datadog-agent/tasks/libs/package/size.py", line 65, in extract_rpm_package
ctx.run(f"rpm2cpio {package_path}
Successful checks

Info

Result Quality gate On disk size On disk size limit On wire size On wire size limit
static_quality_gate_agent_deb_amd64 831.59MiB 847.49MiB 181.72MiB 212.33MiB
static_quality_gate_agent_deb_arm64 821.41MiB 836.66MiB 167.35MiB 192.5MiB
static_quality_gate_agent_rpm_amd64 831.65MiB 847.82MiB 184.14MiB 215.76MiB
static_quality_gate_agent_suse_amd64 831.58MiB 847.82MiB 184.14MiB 215.76MiB
static_quality_gate_agent_suse_arm64 821.43MiB 836.66MiB 166.49MiB 194.24MiB
static_quality_gate_dogstatsd_deb_amd64 39.57MiB 49.7MiB 10.41MiB 20.6MiB
static_quality_gate_dogstatsd_deb_arm64 37.91MiB 48.1MiB 8.98MiB 19.1MiB
static_quality_gate_dogstatsd_rpm_amd64 39.57MiB 49.7MiB 10.42MiB 20.6MiB
static_quality_gate_dogstatsd_suse_amd64 39.57MiB 49.7MiB 10.42MiB 20.6MiB
static_quality_gate_iot_agent_deb_amd64 59.24MiB 69.0MiB 14.59MiB 24.8MiB
static_quality_gate_iot_agent_deb_arm64 56.61MiB 66.4MiB 12.58MiB 22.8MiB
static_quality_gate_iot_agent_rpm_amd64 59.24MiB 69.0MiB 14.61MiB 24.8MiB
static_quality_gate_iot_agent_rpm_arm64 56.61MiB 66.4MiB 12.6MiB 22.8MiB
static_quality_gate_iot_agent_suse_amd64 59.24MiB 69.0MiB 14.61MiB 24.8MiB
static_quality_gate_docker_agent_amd64 915.91MiB 931.7MiB 307.44MiB 318.67MiB
static_quality_gate_docker_agent_arm64 928.98MiB 944.08MiB 292.44MiB 303.0MiB
static_quality_gate_docker_agent_jmx_amd64 1.09GiB 1.1GiB 382.55MiB 393.75MiB
static_quality_gate_docker_agent_jmx_arm64 1.09GiB 1.1GiB 363.52MiB 373.71MiB
static_quality_gate_docker_dogstatsd_amd64 47.71MiB 57.88MiB 18.26MiB 28.29MiB
static_quality_gate_docker_dogstatsd_arm64 46.09MiB 56.27MiB 17.02MiB 27.06MiB
static_quality_gate_docker_cluster_agent_amd64 264.96MiB 274.78MiB 106.36MiB 116.28MiB
static_quality_gate_docker_cluster_agent_arm64 280.92MiB 290.82MiB 101.17MiB 111.12MiB

@ichinaski ichinaski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Leaving the PR approved not to block it on the response value casing, but I think the spec and possible values from tracers should be clearer and defined somewhere, so we don't have to account for multiple variants.

@rksrcl

rksrcl commented Feb 27, 2025

Copy link
Copy Markdown
Contributor Author

/merge

@dd-devflow

dd-devflow Bot commented Feb 27, 2025

Copy link
Copy Markdown

View all feedbacks in Devflow UI.
2025-02-27 14:56:58 UTC ℹ️ Start processing command /merge


2025-02-27 14:57:06 UTC ℹ️ MergeQueue: pull request added to the queue

The median merge time in main is 29m.


2025-02-27 15:33:19 UTC ℹ️ MergeQueue: This merge request was merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

long review PR is complex, plan time to review it qa/done QA done before merge and regressions are covered by tests team/agent-apm trace-agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants