Skip to content

Commit

Permalink
[exporter/datadog] Deprecate TagsConfig.GetHostTags method (#8975)
Browse files Browse the repository at this point in the history
* [exporter/datadog] Deprecate GetHostTags method

* Also add `nolint` to silence all the linters

* Add CHANGELOG entry
  • Loading branch information
mx-psi authored Mar 31, 2022
1 parent e52d6be commit 32f6541
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

- `datadogexporter`: Deprecate `service` setting in favor of `service.name` semantic convention (#8784)
- `datadogexporter`: Deprecate `version` setting in favor of `service.version` semantic convention (#8784)
- `datadogexporter`: Deprecate `GetHostTags` method from `TagsConfig` struct (#8975)

### 🚀 New components 🚀

Expand Down
1 change: 1 addition & 0 deletions exporter/datadogexporter/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ type TagsConfig struct {
}

// GetHostTags gets the host tags extracted from the configuration
// Deprecated: [v0.49.0] Access fields explicitly instead.
func (t *TagsConfig) GetHostTags() []string {
tags := t.Tags

Expand Down
20 changes: 19 additions & 1 deletion exporter/datadogexporter/hostmetadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,33 @@
package datadogexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter"

import (
"fmt"
"strings"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/config"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/metadata"
)

// getHostTags gets the host tags extracted from the configuration.
func getHostTags(t *config.TagsConfig) []string {
tags := t.Tags

if len(tags) == 0 {
//lint:ignore SA1019 Will be removed when environment variable detection is removed
tags = strings.Split(t.EnvVarTags, " ") //nolint
}

if t.Env != "none" {
tags = append(tags, fmt.Sprintf("env:%s", t.Env))
}
return tags
}

// newMetadataConfigfromConfig creates a new metadata pusher config from the main config.
func newMetadataConfigfromConfig(cfg *config.Config) metadata.PusherConfig {
return metadata.PusherConfig{
ConfigHostname: cfg.Hostname,
ConfigTags: cfg.GetHostTags(),
ConfigTags: getHostTags(&cfg.TagsConfig),
MetricsEndpoint: cfg.Metrics.Endpoint,
APIKey: cfg.API.Key,
UseResourceMetadata: cfg.UseResourceMetadata,
Expand Down
80 changes: 80 additions & 0 deletions exporter/datadogexporter/hostmetadata_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package datadogexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter"

import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/config"
)

func TestHostTags(t *testing.T) {
tc := config.TagsConfig{
Hostname: "customhost",
Env: "customenv",
// Service and version should be only used for traces
Service: "customservice",
Version: "customversion",
Tags: []string{"key1:val1", "key2:val2"},
}

assert.ElementsMatch(t,
[]string{
"env:customenv",
"key1:val1",
"key2:val2",
},
getHostTags(&tc),
)

tc = config.TagsConfig{
Hostname: "customhost",
Env: "customenv",
// Service and version should be only used for traces
Service: "customservice",
Version: "customversion",
Tags: []string{"key1:val1", "key2:val2"},
EnvVarTags: "key3:val3 key4:val4",
}

assert.ElementsMatch(t,
[]string{
"env:customenv",
"key1:val1",
"key2:val2",
},
getHostTags(&tc),
)

tc = config.TagsConfig{
Hostname: "customhost",
Env: "customenv",
// Service and version should be only used for traces
Service: "customservice",
Version: "customversion",
EnvVarTags: "key3:val3 key4:val4",
}

assert.ElementsMatch(t,
[]string{
"env:customenv",
"key3:val3",
"key4:val4",
},
getHostTags(&tc),
)
}

0 comments on commit 32f6541

Please sign in to comment.