Skip to content

Commit

Permalink
[exporter/Datadogexporter] Use Agent modules for validating hostname (#…
Browse files Browse the repository at this point in the history
…34030)

**Description:** <Describe what has changed.>
Use Agent modules for validating hostname

**Link to tracking Issue:** <Issue number if applicable>

**Testing:** <Describe what testing was performed and which tests were
added.>

**Documentation:** <Describe the documentation added.>
  • Loading branch information
dineshg13 committed Jul 12, 2024
1 parent e1c9148 commit 6a5b9e6
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 106 deletions.
5 changes: 2 additions & 3 deletions exporter/datadogexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"regexp"
"strings"

"github.com/DataDog/datadog-agent/pkg/util/hostname/validate"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/confignet"
Expand All @@ -18,8 +19,6 @@ import (
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/hostmetadata/valid"
)

var (
Expand Down Expand Up @@ -469,7 +468,7 @@ func (c *Config) Validate() error {
return errNoMetadata
}

if err := valid.Hostname(c.Hostname); c.Hostname != "" && err != nil {
if err := validate.ValidHostname(c.Hostname); c.Hostname != "" && err != nil {
return fmt.Errorf("hostname field is invalid: %w", err)
}

Expand Down
2 changes: 1 addition & 1 deletion exporter/datadogexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestValidate(t *testing.T) {
API: APIConfig{Key: "notnull"},
TagsConfig: TagsConfig{Hostname: "invalid_host"},
},
err: "hostname field is invalid: 'invalid_host' is not RFC1123 compliant",
err: "hostname field is invalid: invalid_host is not RFC1123 compliant",
},
{
name: "no metadata",
Expand Down
5 changes: 2 additions & 3 deletions exporter/datadogexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/DataDog/datadog-agent/comp/otelcol/logsagentpipeline/logsagentpipelineimpl v0.56.0-rc.1
github.com/DataDog/datadog-agent/comp/otelcol/otlp/components/exporter/logsagentexporter v0.56.0-rc.1
github.com/DataDog/datadog-agent/comp/otelcol/otlp/components/metricsclient v0.56.0-rc.1
github.com/DataDog/datadog-agent/comp/trace/compression/impl-gzip v0.56.0-rc.1
github.com/DataDog/datadog-agent/pkg/config/model v0.56.0-rc.1
github.com/DataDog/datadog-agent/pkg/config/setup v0.56.0-rc.1
github.com/DataDog/datadog-agent/pkg/logs/auditor v0.56.0-rc.1 // indirect
Expand All @@ -23,6 +24,7 @@ require (
github.com/DataDog/datadog-agent/pkg/proto v0.56.0-rc.1
github.com/DataDog/datadog-agent/pkg/status/health v0.56.0-rc.1 // indirect
github.com/DataDog/datadog-agent/pkg/trace v0.56.0-rc.1.0.20240711082232-dc70454ece9f
github.com/DataDog/datadog-agent/pkg/util/hostname/validate v0.56.0-rc.1
github.com/DataDog/datadog-agent/pkg/util/startstop v0.56.0-rc.1 // indirect
github.com/DataDog/datadog-api-client-go/v2 v2.27.0
github.com/DataDog/datadog-go/v5 v5.5.0
Expand Down Expand Up @@ -86,8 +88,6 @@ require (
k8s.io/client-go v0.29.3
)

require github.com/DataDog/datadog-agent/comp/trace/compression/impl-gzip v0.56.0-rc.1

require (
cloud.google.com/go/auth v0.5.1 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect
Expand Down Expand Up @@ -123,7 +123,6 @@ require (
github.com/DataDog/datadog-agent/pkg/util/executable v0.56.0-rc.1 // indirect
github.com/DataDog/datadog-agent/pkg/util/filesystem v0.56.0-rc.1 // indirect
github.com/DataDog/datadog-agent/pkg/util/fxutil v0.56.0-rc.1 // indirect
github.com/DataDog/datadog-agent/pkg/util/hostname/validate v0.56.0-rc.1 // indirect
github.com/DataDog/datadog-agent/pkg/util/http v0.56.0-rc.1 // indirect
github.com/DataDog/datadog-agent/pkg/util/log v0.56.0-rc.1 // indirect
github.com/DataDog/datadog-agent/pkg/util/optional v0.56.0-rc.1 // indirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import (
"os"
"sync"

"github.com/DataDog/datadog-agent/pkg/util/hostname/validate"
"github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes/source"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/hostmetadata/valid"
)

type HostInfo struct {
Expand Down Expand Up @@ -44,7 +43,7 @@ func (hi *HostInfo) GetHostname(logger *zap.Logger) string {
if hi.FQDN == "" {
// Don't report failure since FQDN was just not available
return hi.OS
} else if err := valid.Hostname(hi.FQDN); err != nil {
} else if err := validate.ValidHostname(hi.FQDN); err != nil {
logger.Info("FQDN is not valid", zap.Error(err))
return hi.OS
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@ import (
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
// We have to ignore seelog because of upstream issue
// https://github.com/cihub/seelog/issues/182
goleak.VerifyTestMain(m,
goleak.IgnoreAnyFunction("github.com/cihub/seelog.(*asyncLoopLogger).processQueue"),
)
}

This file was deleted.

53 changes: 0 additions & 53 deletions exporter/datadogexporter/internal/hostmetadata/valid/valid.go

This file was deleted.

28 changes: 0 additions & 28 deletions exporter/datadogexporter/internal/hostmetadata/valid/valid_test.go

This file was deleted.

0 comments on commit 6a5b9e6

Please sign in to comment.