Skip to content

Commit

Permalink
Implements file reading for peer tags to synchronize cross repo usage (
Browse files Browse the repository at this point in the history
  • Loading branch information
zarirhamza authored May 30, 2024
1 parent 9f16962 commit 49deb26
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 31 deletions.
1 change: 1 addition & 0 deletions cmd/serverless/dependencies_linux_amd64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,7 @@ gopkg.in/DataDog/dd-trace-go.v1/internal/samplernames
gopkg.in/DataDog/dd-trace-go.v1/internal/telemetry
gopkg.in/DataDog/dd-trace-go.v1/internal/traceprof
gopkg.in/DataDog/dd-trace-go.v1/internal/version
gopkg.in/ini.v1
gopkg.in/yaml.v2
gopkg.in/yaml.v3
hash
Expand Down
1 change: 1 addition & 0 deletions cmd/serverless/dependencies_linux_arm64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,7 @@ gopkg.in/DataDog/dd-trace-go.v1/internal/samplernames
gopkg.in/DataDog/dd-trace-go.v1/internal/telemetry
gopkg.in/DataDog/dd-trace-go.v1/internal/traceprof
gopkg.in/DataDog/dd-trace-go.v1/internal/version
gopkg.in/ini.v1
gopkg.in/yaml.v2
gopkg.in/yaml.v3
hash
Expand Down
1 change: 1 addition & 0 deletions comp/otelcol/otlp/components/statsprocessor/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
2 changes: 2 additions & 0 deletions comp/otelcol/otlp/components/statsprocessor/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/trace/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ require (
golang.org/x/time v0.5.0
google.golang.org/grpc v1.63.2
google.golang.org/protobuf v1.34.0
gopkg.in/ini.v1 v1.67.0
k8s.io/apimachinery v0.25.5
)

Expand Down
2 changes: 2 additions & 0 deletions pkg/trace/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 25 additions & 31 deletions pkg/trace/stats/concentrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
package stats

import (
_ "embed"
"sort"
"strings"
"sync"
"time"

"gopkg.in/ini.v1"

pb "github.com/DataDog/datadog-agent/pkg/proto/pbgo/trace"
"github.com/DataDog/datadog-agent/pkg/trace/config"
"github.com/DataDog/datadog-agent/pkg/trace/log"
Expand Down Expand Up @@ -55,37 +58,28 @@ type Concentrator struct {
statsd statsd.ClientInterface
}

var defaultPeerTags = []string{
"_dd.base_service",
"amqp.destination",
"amqp.exchange",
"amqp.queue",
"aws.queue.name",
"bucketname",
"cassandra.cluster",
"db.cassandra.contact.points",
"db.couchbase.seed.nodes",
"db.hostname",
"db.instance",
"db.name",
"db.system",
"hazelcast.instance",
"messaging.kafka.bootstrap.servers",
"mongodb.db",
"msmq.queue.path",
"net.peer.name",
"network.destination.name",
"peer.hostname",
"peer.service",
"queuename",
"rpc.service",
"rulename",
"server.address",
"statemachinename",
"streamname",
"tablename",
"topicname",
}
//go:embed peer_tags.ini
var peerTagFile []byte

var defaultPeerTags = func() []string {
var tags []string = []string{"_dd.base_service"}

cfg, err := ini.Load(peerTagFile)
if err != nil {
log.Error("Error loading file for peer tags: ", err)
return tags
}
keys := cfg.Section("dd.apm.peer.tags").Keys()

for _, key := range keys {
value := strings.Split(key.Value(), ",")
tags = append(tags, value...)
}

sort.Strings(tags)

return tags
}()

func preparePeerTags(tags ...string) []string {
if len(tags) == 0 {
Expand Down
49 changes: 49 additions & 0 deletions pkg/trace/stats/concentrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1062,3 +1062,52 @@ func TestPreparePeerTags(t *testing.T) {
assert.Equal(t, tc.output, preparePeerTags(tc.input...))
}
}

func TestDefaultPeerTags(t *testing.T) {
expectedListOfPeerTags := []string{
"_dd.base_service",
"amqp.destination",
"amqp.exchange",
"amqp.queue",
"aws.queue.name",
"aws.s3.bucket",
"bucketname",
"cassandra.keyspace",
"db.cassandra.contact.points",
"db.couchbase.seed.nodes",
"db.hostname",
"db.instance",
"db.name",
"db.namespace",
"db.system",
"grpc.host",
"hostname",
"http.host",
"http.server_name",
"messaging.destination",
"messaging.destination.name",
"messaging.kafka.bootstrap.servers",
"messaging.rabbitmq.exchange",
"messaging.system",
"mongodb.db",
"msmq.queue.path",
"net.peer.name",
"network.destination.name",
"peer.hostname",
"peer.service",
"queuename",
"rpc.service",
"rpc.system",
"server.address",
"streamname",
"tablename",
"topicname",
}
actualListOfPeerTags := defaultPeerTags

// Sort both arrays for comparison
sort.Strings(actualListOfPeerTags)
sort.Strings(expectedListOfPeerTags)

assert.Equal(t, expectedListOfPeerTags, actualListOfPeerTags)
}
1 change: 1 addition & 0 deletions pkg/trace/stats/oteltest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ require (
golang.org/x/tools v0.16.1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/grpc v1.63.2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Expand Down
2 changes: 2 additions & 0 deletions pkg/trace/stats/oteltest/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions pkg/trace/stats/peer_tags.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# if a peer entity tag is expected to be set at the tracer, and we want to keep it, then it must be included
# in the list. I.e., since we have at least one tracer which actually sets `peer.hostname` directly, we need
# to set `peer.hostname = "peer.hostname" else it will get stripped out
# the order of the precursors matters, as it is "first one wins". so if we expect some spans to have more than one
# precursor, and the precursors may not always have the exact same meaning, then put the higher priority one at the front
[dd.apm.peer.tags]
peer.aws.dynamodb.table = "tablename"
peer.aws.kinesis.stream = "streamname"
peer.aws.s3.bucket = "bucketname,aws.s3.bucket"
peer.aws.sqs.queue = "queuename"
peer.cassandra.contact.points = "db.cassandra.contact.points"
peer.couchbase.seed.nodes = "db.couchbase.seed.nodes"
peer.db.name = "db.name,mongodb.db,db.instance,cassandra.keyspace,db.namespace"
peer.db.system = "db.system"
peer.hostname = "peer.hostname,hostname,net.peer.name,db.hostname,network.destination.name,grpc.host,http.host,server.address,http.server_name"
peer.kafka.bootstrap.servers = "messaging.kafka.bootstrap.servers"
peer.messaging.destination = "topicname,messaging.destination,messaging.destination.name,messaging.rabbitmq.exchange,amqp.destination,amqp.queue,amqp.exchange,msmq.queue.path,aws.queue.name"
peer.messaging.system = "messaging.system"
peer.rpc.service = "rpc.service"
peer.rpc.system = "rpc.system"
peer.service = "peer.service"

0 comments on commit 49deb26

Please sign in to comment.