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/Datadogexporter] Use Agent modules for validating hostname #34030

Merged
Show file tree
Hide file tree
Changes from all commits
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
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"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this? Can you add a tracking issue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crobert-1 Could you help us with the best way to deal with this? (e.g. is there a template for tracking issues?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a need to track it.

We aim to have no leaks at all in the Collector, this should be tracked and eventually fixed in the Agent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created internal jira to track this work in Agent.

Copy link
Member

@crobert-1 crobert-1 Jul 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add frequency and information to this issue: cihub/seelog#182

Also, please add a reference in this file to that issue so that we have future context for why this ignore is necessary.

Since this goroutine is started during a dependency's init(), there's nothing we can do if we need to import the package that depends on it. It's okay to ignore for now.

)
}

This file was deleted.

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

This file was deleted.

This file was deleted.