Skip to content
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

[exporter/datadog] Decouple Config structs from internal components #8375

Merged
merged 4 commits into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[exporter/datadog] Remove reference to Config on GetHost
  • Loading branch information
mx-psi committed Mar 10, 2022
commit 695fdff448ea9398c470d946df94fce5181e4a6a
7 changes: 3 additions & 4 deletions exporter/datadogexporter/internal/metadata/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package metadata // import "github.com/open-telemetry/opentelemetry-collector-co
import (
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/config"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/metadata/ec2"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/metadata/system"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/metadata/valid"
Expand All @@ -30,9 +29,9 @@ import (
// 2. Cache
// 3. EC2 instance metadata
// 4. System
func GetHost(logger *zap.Logger, cfg *config.Config) string {
if cfg.Hostname != "" {
return cfg.Hostname
func GetHost(logger *zap.Logger, configHostname string) string {
if configHostname != "" {
return configHostname
}

if cacheVal, ok := cache.Cache.Get(cache.CanonicalHostnameKey); ok {
Expand Down
11 changes: 3 additions & 8 deletions exporter/datadogexporter/internal/metadata/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/stretchr/testify/require"
"go.uber.org/zap"

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

Expand All @@ -34,15 +33,11 @@ func TestHost(t *testing.T) {
// if the cache key is already set.
cache.Cache.Delete(cache.CanonicalHostnameKey)

host := GetHost(logger, &config.Config{
TagsConfig: config.TagsConfig{Hostname: "test-host"},
})
host := GetHost(logger, "test-host")
assert.Equal(t, host, "test-host")

// config.Config.Hostname does not get stored in the cache
host = GetHost(logger, &config.Config{
TagsConfig: config.TagsConfig{Hostname: "test-host-2"},
})
host = GetHost(logger, "test-host-2")
assert.Equal(t, host, "test-host-2")

// Disable EC2 Metadata service to prevent fetching hostname from there,
Expand All @@ -53,7 +48,7 @@ func TestHost(t *testing.T) {
require.NoError(t, err)
defer os.Setenv(awsEc2MetadataDisabled, curr)

host = GetHost(logger, &config.Config{})
host = GetHost(logger, "")
osHostname, err := os.Hostname()
require.NoError(t, err)
// TODO: Investigate why the returned host contains more data on github actions.
Expand Down
2 changes: 1 addition & 1 deletion exporter/datadogexporter/internal/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func metadataFromAttributes(attrs pdata.AttributeMap) *HostMetadata {
func fillHostMetadata(params component.ExporterCreateSettings, cfg *config.Config, hm *HostMetadata) {
// Could not get hostname from attributes
if hm.InternalHostname == "" {
hostname := GetHost(params.Logger, cfg)
hostname := GetHost(params.Logger, cfg.Hostname)
hm.InternalHostname = hostname
hm.Meta.Hostname = hostname
}
Expand Down
2 changes: 1 addition & 1 deletion exporter/datadogexporter/metrics_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type hostProvider struct {
}

func (p *hostProvider) Hostname(context.Context) (string, error) {
return metadata.GetHost(p.logger, p.cfg), nil
return metadata.GetHost(p.logger, p.cfg.Hostname), nil
}

// translatorFromConfig creates a new metrics translator from the exporter config.
Expand Down
2 changes: 1 addition & 1 deletion exporter/datadogexporter/traces_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (exp *traceExporter) pushTraceData(
// convert traces to datadog traces and group trace payloads by env
// we largely apply the same logic as the serverless implementation, simplified a bit
// https://github.com/DataDog/datadog-serverless-functions/blob/f5c3aedfec5ba223b11b76a4239fcbf35ec7d045/aws/logs_monitoring/trace_forwarder/cmd/trace/main.go#L61-L83
fallbackHost := metadata.GetHost(exp.params.Logger, exp.cfg)
fallbackHost := metadata.GetHost(exp.params.Logger, exp.cfg.Hostname)
ddTraces, ms := convertToDatadogTd(td, fallbackHost, exp.cfg, exp.denylister, exp.params.BuildInfo)

// group the traces by env to reduce the number of flushes
Expand Down