Skip to content

Commit 271a0e3

Browse files
support process tags in apm stats - first pass
1 parent 10b43a6 commit 271a0e3

File tree

14 files changed

+327
-120
lines changed

14 files changed

+327
-120
lines changed

pkg/proto/datadog/trace/stats.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ message ClientStatsPayload {
4949
string git_commit_sha = 13;
5050
// The image tag is obtained from a container's set of tags.
5151
string image_tag = 14;
52+
// The process tags hash is used as a key for agent stats agregation.
53+
uint64 process_tags_hash = 15;
54+
// The process tags contains a list of tags that are specific to the process.
55+
string process_tags = 16;
5256
}
5357

5458
// ClientStatsBucket is a time bucket containing aggregated stats.

pkg/proto/pbgo/trace/stats.pb.go

Lines changed: 84 additions & 61 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/proto/pbgo/trace/stats_gen.go

Lines changed: 58 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/proto/pbgo/trace/stats_vtproto.pb.go

Lines changed: 72 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/trace/agent/agent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ func (a *Agent) Process(p *api.Payload) {
313313
defer a.Timing.Since("datadog.trace_agent.internal.process_payload_ms", now)
314314
ts := p.Source
315315
sampledChunks := new(writer.SampledChunks)
316-
statsInput := stats.NewStatsInput(len(p.TracerPayload.Chunks), p.TracerPayload.ContainerID, p.ClientComputedStats)
316+
statsInput := stats.NewStatsInput(len(p.TracerPayload.Chunks), p.TracerPayload.ContainerID, p.ClientComputedStats, p.ProcessTags)
317317

318318
p.TracerPayload.Env = traceutil.NormalizeTagValue(p.TracerPayload.Env)
319319

pkg/trace/api/api.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ const (
440440
// tagContainersTags specifies the name of the tag which holds key/value
441441
// pairs representing information about the container (Docker, EC2, etc).
442442
tagContainersTags = "_dd.tags.container"
443+
tagProcessTags = "_dd.tags.process"
443444
)
444445

445446
// TagStats returns the stats and tags coinciding with the information found in header.
@@ -657,13 +658,21 @@ func (r *HTTPReceiver) handleTraces(v Version, w http.ResponseWriter, req *http.
657658
}
658659
tp.Tags[tagContainersTags] = ctags
659660
}
661+
ptags := getProcessTagsFromHeader(req.Header, ts)
662+
if ptags != "" {
663+
if tp.Tags == nil {
664+
tp.Tags = make(map[string]string)
665+
}
666+
tp.Tags[tagProcessTags] = ptags
667+
}
660668

661669
payload := &Payload{
662670
Source: ts,
663671
TracerPayload: tp,
664672
ClientComputedTopLevel: isHeaderTrue(header.ComputedTopLevel, req.Header.Get(header.ComputedTopLevel)),
665673
ClientComputedStats: isHeaderTrue(header.ComputedStats, req.Header.Get(header.ComputedStats)),
666674
ClientDroppedP0s: droppedTracesFromHeader(req.Header, ts),
675+
ProcessTags: ptags,
667676
}
668677
r.out <- payload
669678
}
@@ -700,6 +709,10 @@ func droppedTracesFromHeader(h http.Header, ts *info.TagStats) int64 {
700709
return dropped
701710
}
702711

712+
func getProcessTagsFromHeader(h http.Header, ts *info.TagStats) string {
713+
return h.Get(header.ProcessTags)
714+
}
715+
703716
// handleServices handle a request with a list of several services
704717
func (r *HTTPReceiver) handleServices(_ Version, w http.ResponseWriter, _ *http.Request) {
705718
httpOK(w)

pkg/trace/api/internal/header/headers.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ const (
1111
// with the number of traces contained in the payload.
1212
TraceCount = "X-Datadog-Trace-Count"
1313

14+
// ProcessTags is a list that contains process tags split by a ','.
15+
ProcessTags = "X-Datadog-Process-Tags"
16+
1417
// ContainerID specifies the name of the header which contains the ID of the
1518
// container where the request originated.
1619
// Deprecated in favor of Datadog-Entity-ID.

pkg/trace/api/payload.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ type Payload struct {
2929

3030
// ClientDroppedP0s specifies the number of P0 traces chunks dropped by the client.
3131
ClientDroppedP0s int64
32+
33+
// ProcessTags is a list of tags describing an instrumented process.
34+
ProcessTags string
3235
}
3336

3437
// Chunks returns chunks in TracerPayload

pkg/trace/stats/aggregation.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@ type BucketsAggregationKey struct {
4646

4747
// PayloadAggregationKey specifies the key by which a payload is aggregated.
4848
type PayloadAggregationKey struct {
49-
Env string
50-
Hostname string
51-
Version string
52-
ContainerID string
53-
GitCommitSha string
54-
ImageTag string
49+
Env string
50+
Hostname string
51+
Version string
52+
ContainerID string
53+
GitCommitSha string
54+
ImageTag string
55+
ProcessTagsHash uint64
5556
}
5657

5758
func getStatusCode(meta map[string]string, metrics map[string]float64) uint32 {
@@ -99,6 +100,10 @@ func NewAggregationFromSpan(s *StatSpan, origin string, aggKey PayloadAggregatio
99100
return agg
100101
}
101102

103+
func processTagsHash(processTags string) uint64 {
104+
return peerTagsHash(strings.Split(processTags, ","))
105+
}
106+
102107
func peerTagsHash(tags []string) uint64 {
103108
if len(tags) == 0 {
104109
return 0

0 commit comments

Comments
 (0)