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

Use "${DOCKER_HOST}" when available instead of a hard-coded "/var/run" path for the Docker UNIX socket #34404

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion receiver/dockerstatsreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ var _ component.Config = (*Config)(nil)

type Config struct {
scraperhelper.ControllerConfig `mapstructure:",squash"`
// The URL of the docker server. Default is "unix:///var/run/docker.sock"
// The URL of the docker server. Default is derived from
// the environment variable ${DOCKER_HOST}, with a fallback
// to "unix:///var/run/docker.sock" if no ${DOCKER_HOST}.
Endpoint string `mapstructure:"endpoint"`

// A mapping of container label names to MetricDescriptor label keys.
Expand Down
11 changes: 10 additions & 1 deletion receiver/dockerstatsreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package dockerstatsreceiver // import "github.com/open-telemetry/opentelemetry-c

import (
"context"
"os"
"time"

"go.opentelemetry.io/collector/component"
Expand All @@ -22,13 +23,21 @@ func NewFactory() receiver.Factory {
receiver.WithMetrics(createMetricsReceiver, metadata.MetricsStability))
}

func defaultDockerEndpoint() string {
endpoint := os.Getenv("DOCKER_HOST")
if endpoint != "" {
return endpoint
}
return "unix:///var/run/docker.sock"
}

func createDefaultConfig() component.Config {
scs := scraperhelper.NewDefaultControllerConfig()
scs.CollectionInterval = 10 * time.Second
scs.Timeout = 5 * time.Second
return &Config{
ControllerConfig: scs,
Endpoint: "unix:///var/run/docker.sock",
Endpoint: defaultDockerEndpoint(),
DockerAPIVersion: defaultDockerAPIVersion,
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
}
Expand Down