-
Notifications
You must be signed in to change notification settings - Fork 1.5k
test(errortracking): add FakeIntake support for agent telemetry logs #52487
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
Merged
gh-worker-dd-mergequeue-cf854d
merged 5 commits into
main
from
pducolin/coat-errortracking/stack-3-wiring
Jun 29, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
024f180
feat(errortracking): add FakeIntake aggregator and client support for…
pducolin 2492097
ci(errortracking): add new-e2e-agent-telemetry GitLab job and change …
pducolin d174f47
disable agent telemetry e2e test
pducolin 4926b0f
Merge branch 'main' into pducolin/coat-errortracking/stack-3-wiring
pducolin a16e455
ci: retrigger pipeline (incident-56883 e2e infra flakes)
pducolin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| // Unless explicitly stated otherwise all files in this repository are licensed | ||
| // under the Apache License Version 2.0. | ||
| // This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
| // Copyright 2016-present Datadog, Inc. | ||
|
|
||
| package aggregator | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "encoding/json" | ||
| "time" | ||
|
|
||
| "github.com/DataDog/datadog-agent/test/fakeintake/api" | ||
| ) | ||
|
|
||
| // AgentTelemetryLog represents a single log record from the agent's internal | ||
| // telemetry pipeline. It mirrors comp/core/agenttelemetry/impl/logs_payload.go::Log | ||
| // and is populated only for payloads whose request_type is "agent-logs". | ||
| type AgentTelemetryLog struct { | ||
| Level string `json:"level"` | ||
| StackTrace string `json:"stack_trace"` | ||
| TracerTime int64 `json:"tracer_time"` | ||
| Count int `json:"count"` | ||
| IsCrash bool `json:"is_crash"` | ||
| Message string `json:"message"` | ||
| ErrorKind string `json:"error_kind"` | ||
| Tags string `json:"tags"` | ||
| collectedTime time.Time | ||
| } | ||
|
|
||
| // name returns the grouping key used by the aggregator. All agent-logs records | ||
| // share one key; per-hostname grouping is not needed for single-agent test VMs. | ||
| func (l *AgentTelemetryLog) name() string { return "agent-errortracking" } | ||
|
|
||
| // GetTags returns no tags — agent telemetry logs carry none on the wire. | ||
| func (l *AgentTelemetryLog) GetTags() []string { return []string{} } | ||
|
|
||
| // GetCollectedTime returns when the fakeintake server received this payload. | ||
| func (l *AgentTelemetryLog) GetCollectedTime() time.Time { return l.collectedTime } | ||
|
|
||
| // apmTelemetryEnvelope is the outer POST body sent to /api/v2/apmtelemetry. | ||
| // The same endpoint receives metrics, heartbeats, and other request types; | ||
| // request_type discriminates agent-logs records from the rest. | ||
| type apmTelemetryEnvelope struct { | ||
| RequestType string `json:"request_type"` | ||
| Payload struct { | ||
| Logs []*AgentTelemetryLog `json:"logs"` | ||
| } `json:"payload"` | ||
| } | ||
|
|
||
| // ParseAgentTelemetryLogs parses one api.Payload into zero-or-more | ||
| // AgentTelemetryLog items. Payloads whose request_type is not "agent-logs" | ||
| // are silently skipped — the /api/v2/apmtelemetry endpoint is shared with | ||
| // agent metrics, heartbeats, and other telemetry types. | ||
| func ParseAgentTelemetryLogs(payload api.Payload) ([]*AgentTelemetryLog, error) { | ||
| if bytes.Equal(payload.Data, []byte("{}")) { | ||
| return []*AgentTelemetryLog{}, nil | ||
| } | ||
|
|
||
| inflated, err := inflate(payload.Data, payload.Encoding) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| // The /api/v2/apmtelemetry endpoint is shared: agent metrics, heartbeats, | ||
| // and other payload types arrive here too, some encoded as protobuf. If | ||
| // JSON unmarshal fails, skip silently — this payload is not agent-logs. | ||
| var env apmTelemetryEnvelope | ||
| if err := json.Unmarshal(inflated, &env); err != nil { | ||
| return []*AgentTelemetryLog{}, nil | ||
| } | ||
|
|
||
| if env.RequestType != "agent-logs" { | ||
| return []*AgentTelemetryLog{}, nil | ||
| } | ||
|
|
||
| for _, l := range env.Payload.Logs { | ||
| l.collectedTime = payload.Timestamp | ||
| } | ||
| return env.Payload.Logs, nil | ||
| } | ||
|
|
||
| // AgentTelemetryLogAggregator aggregates AgentTelemetryLog payloads received | ||
| // on the /api/v2/apmtelemetry endpoint. | ||
| type AgentTelemetryLogAggregator struct { | ||
| Aggregator[*AgentTelemetryLog] | ||
| } | ||
|
|
||
| // NewAgentTelemetryLogAggregator returns a new AgentTelemetryLogAggregator. | ||
| func NewAgentTelemetryLogAggregator() AgentTelemetryLogAggregator { | ||
| return AgentTelemetryLogAggregator{ | ||
| Aggregator: newAggregator(ParseAgentTelemetryLogs), | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| // Unless explicitly stated otherwise all files in this repository are licensed | ||
| // under the Apache License Version 2.0. | ||
| // This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
| // Copyright 2016-present Datadog, Inc. | ||
|
|
||
| package aggregator | ||
|
|
||
| import ( | ||
| _ "embed" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/DataDog/datadog-agent/test/fakeintake/api" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| //go:embed fixtures/apm_telemetry_bytes | ||
| var apmTelemetryData []byte | ||
|
|
||
| func TestParseAgentTelemetryLogs(t *testing.T) { | ||
| t.Run("empty JSON object is silently skipped", func(t *testing.T) { | ||
| logs, err := ParseAgentTelemetryLogs(api.Payload{ | ||
| Data: []byte("{}"), | ||
| Encoding: encodingJSON, | ||
| }) | ||
| require.NoError(t, err) | ||
| assert.Empty(t, logs) | ||
| }) | ||
|
|
||
| t.Run("non-agent-logs request_type is silently skipped", func(t *testing.T) { | ||
| logs, err := ParseAgentTelemetryLogs(api.Payload{ | ||
| Data: []byte(`{"request_type":"agent-metrics","payload":{}}`), | ||
| Encoding: encodingJSON, | ||
| }) | ||
| require.NoError(t, err) | ||
| assert.Empty(t, logs) | ||
| }) | ||
|
|
||
| t.Run("non-JSON payload (e.g. protobuf) is silently skipped", func(t *testing.T) { | ||
| logs, err := ParseAgentTelemetryLogs(api.Payload{ | ||
| Data: []byte("not valid json"), | ||
| Encoding: encodingJSON, | ||
| }) | ||
| require.NoError(t, err) | ||
| assert.Empty(t, logs) | ||
| }) | ||
|
|
||
| t.Run("valid agent-logs payload parses all fields and stamps collected time", func(t *testing.T) { | ||
| ts := time.Date(2025, 6, 1, 12, 0, 0, 0, time.UTC) | ||
| logs, err := ParseAgentTelemetryLogs(api.Payload{ | ||
| Data: apmTelemetryData, | ||
| Encoding: encodingJSON, | ||
| Timestamp: ts, | ||
| }) | ||
| require.NoError(t, err) | ||
| require.Len(t, logs, 1) | ||
|
|
||
| l := logs[0] | ||
| assert.Equal(t, "ERROR", l.Level) | ||
| assert.Contains(t, l.StackTrace, "main.main()") | ||
| assert.Equal(t, int64(1234567890), l.TracerTime) | ||
| assert.Equal(t, 3, l.Count) | ||
| assert.False(t, l.IsCrash) | ||
| assert.Empty(t, l.Message) | ||
| assert.Equal(t, ts, l.GetCollectedTime()) | ||
| }) | ||
|
|
||
| t.Run("multiple logs in one payload are all returned", func(t *testing.T) { | ||
| data := []byte(`{"request_type":"agent-logs","payload":{"logs":[` + | ||
| `{"level":"ERROR","stack_trace":"foo","tracer_time":1,"count":1,"is_crash":false},` + | ||
| `{"level":"ERROR","stack_trace":"bar","tracer_time":2,"count":2,"is_crash":true}` + | ||
| `]}}`) | ||
| logs, err := ParseAgentTelemetryLogs(api.Payload{ | ||
| Data: data, | ||
| Encoding: encodingJSON, | ||
| }) | ||
| require.NoError(t, err) | ||
| require.Len(t, logs, 2) | ||
| assert.Equal(t, int64(1), logs[0].TracerTime) | ||
| assert.Equal(t, int64(2), logs[1].TracerTime) | ||
| assert.True(t, logs[1].IsCrash) | ||
| }) | ||
|
|
||
| t.Run("GetTags returns empty slice", func(t *testing.T) { | ||
| l := &AgentTelemetryLog{} | ||
| assert.Empty(t, l.GetTags()) | ||
| }) | ||
|
|
||
| t.Run("name returns agent-errortracking", func(t *testing.T) { | ||
| l := &AgentTelemetryLog{} | ||
| assert.Equal(t, "agent-errortracking", l.name()) | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"request_type":"agent-logs","payload":{"logs":[{"level":"ERROR","stack_trace":"goroutine 1 [running]:\nmain.main()\n\t/app/main.go:10 +0x58","tracer_time":1234567890,"count":3,"is_crash":false,"message":""}]}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.