Skip to content

Commit 95a4c5c

Browse files
committed
Have the same behavior as the Datadog Agent with tags
Only env should be added to host tags if set.
1 parent 5a715dc commit 95a4c5c

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed

exporter/datadogexporter/config.go

+3-11
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,10 @@ type TagsConfig struct {
9999

100100
// GetTags gets the default tags extracted from the configuration
101101
func (t *TagsConfig) GetTags() []string {
102-
tags := make([]string, 0, 4)
102+
tags := make([]string, 0, len(t.Tags)+1)
103103

104-
vars := map[string]string{
105-
"env": t.Env,
106-
"service": t.Service,
107-
"version": t.Version,
108-
}
109-
110-
for name, val := range vars {
111-
if val != "" {
112-
tags = append(tags, fmt.Sprintf("%s:%s", name, val))
113-
}
104+
if t.Env != "none" {
105+
tags = append(tags, fmt.Sprintf("env:%s", t.Env))
114106
}
115107

116108
tags = append(tags, t.Tags...)

exporter/datadogexporter/config_test.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ func TestLoadConfig(t *testing.T) {
8484

8585
func TestTags(t *testing.T) {
8686
tc := TagsConfig{
87-
Env: "customenv",
87+
// environment should be picked up if it is not 'none'
88+
Env: "customenv",
89+
90+
// these should be ignored;
91+
// they are used only on trace translation
8892
Service: "customservice",
8993
Version: "customversion",
9094
Tags: []string{"key1:val1", "key2:val2"},
@@ -93,13 +97,14 @@ func TestTags(t *testing.T) {
9397
assert.ElementsMatch(t,
9498
[]string{
9599
"env:customenv",
96-
"service:customservice",
97-
"version:customversion",
98100
"key1:val1",
99101
"key2:val2",
100102
},
101-
tc.GetTags(), // get host
103+
tc.GetTags(),
102104
)
105+
106+
tc.Env = "none"
107+
assert.ElementsMatch(t, tc.GetTags(), tc.Tags)
103108
}
104109

105110
// TestOverrideMetricsURL tests that the metrics URL is overridden

exporter/datadogexporter/host.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ type hostTags struct {
6868
// meta includes metadata about the host aliases
6969
type meta struct {
7070
// InstanceID is the EC2 instance id the Collector is running on, if available
71-
InstanceID string `json:"instance-id,omitemtpy"`
71+
InstanceID string `json:"instance-id,omitempty"`
7272

7373
// EC2Hostname is the hostname from the EC2 metadata API
7474
EC2Hostname string `json:"ec2-hostname,omitempty"`

exporter/datadogexporter/metrics_exporter.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,13 @@ func (exp *metricsExporter) pushHostMetadata(metadata hostMetadata) error {
5050

5151
client := &http.Client{Timeout: 10 * time.Second}
5252
resp, err := client.Do(req)
53-
defer resp.Body.Close()
5453

5554
if err != nil {
5655
return err
5756
}
5857

58+
defer resp.Body.Close()
59+
5960
if resp.StatusCode/100 >= 4 {
6061
return fmt.Errorf(
6162
"'%d - %s' error when sending metadata payload to %s",

0 commit comments

Comments
 (0)