Skip to content

Commit

Permalink
Remove DogStatsD mode (#2)
Browse files Browse the repository at this point in the history
* Remove DogStatsD mode

* go mod tidy

* Remove mentions to DogStatSD
  • Loading branch information
mx-psi authored Sep 23, 2020
1 parent 0ce7520 commit fcc9b77
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 501 deletions.
7 changes: 1 addition & 6 deletions exporter/datadogexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@ This exporter sends metric data to [Datadog](https://datadoghq.com).

## Configuration

The metrics exporter has two modes:
- If sending metrics through DogStatsD (the default mode), there are no required settings.
- If sending metrics without an Agent the mode must be set explicitly and
you must provide a [Datadog API key](https://app.datadoghq.com/account/settings#api).
The only required setting is a [Datadog API key](https://app.datadoghq.com/account/settings#api).
```yaml
datadog:
api:
key: "<API key>"
# site: datadoghq.eu for sending data to the Datadog EU site
metrics:
mode: agentless
```

The hostname, environment, service and version can be set in the configuration for unified service tagging.
Expand Down
61 changes: 11 additions & 50 deletions exporter/datadogexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ var (
errUnsetAPIKey = errors.New("the Datadog API key is unset")
)

const (
NoneMode = "none"
AgentlessMode = "agentless"
DogStatsDMode = "dogstatsd"
)

// APIConfig defines the API configuration options
type APIConfig struct {
// Key is the Datadog API key to associate your Agent's data with your organization.
Expand All @@ -50,26 +44,7 @@ func (api *APIConfig) GetCensoredKey() string {
if len(api.Key) <= 5 {
return api.Key
}
return strings.Repeat("*", len(api.Key)-5) + api.Key[:len(api.Key)-5]
}

// DogStatsDConfig defines the DogStatsd related configuration
type DogStatsDConfig struct {
// FIXME Use confignet.NetAddr
// Endpoint is the DogStatsD address.
// The default value is 127.0.0.1:8125
// A Unix address is supported
Endpoint string `mapstructure:"endpoint"`

// Telemetry states whether to send internal telemetry metrics from the statsd client
Telemetry bool `mapstructure:"telemetry"`
}

// AgentlessConfig defines the Agentless related configuration
type AgentlessConfig struct {
// Endpoint is the host of the Datadog intake server to send metrics to.
// If unset, the value is obtained from the Site.
confignet.TCPAddr `mapstructure:",squash"`
return strings.Repeat("*", len(api.Key)-5) + api.Key[len(api.Key)-5:]
}

// MetricsConfig defines the metrics exporter specific configuration options
Expand All @@ -78,21 +53,16 @@ type MetricsConfig struct {
// By default metrics are not namespaced
Namespace string `mapstructure:"namespace"`

// Mode is the metrics sending mode: either 'dogstatsd' or 'agentless'
Mode string `mapstructure:"mode"`

// Percentiles states whether to report percentiles for summary metrics,
// including the minimum and maximum
Percentiles bool `mapstructure:"report_percentiles"`

// Buckets states whether to report buckets from distribution metrics
Buckets bool `mapstructure:"report_buckets"`

// DogStatsD defines the DogStatsD configuration options.
DogStatsD DogStatsDConfig `mapstructure:"dogstatsd"`

// Agentless defines the Agentless configuration options.
Agentless AgentlessConfig `mapstructure:"agentless"`
// TCPAddr.Endpoint is the host of the Datadog intake server to send metrics to.
// If unset, the value is obtained from the Site.
confignet.TCPAddr `mapstructure:",squash"`
}

// TagsConfig defines the tag-related configuration
Expand Down Expand Up @@ -180,33 +150,24 @@ type Config struct {

// Sanitize tries to sanitize a given configuration
func (c *Config) Sanitize() error {

if c.Metrics.Mode != AgentlessMode && c.Metrics.Mode != DogStatsDMode {
return fmt.Errorf("metrics mode '%s' is not recognized", c.Metrics.Mode)
}

// Get info from environment variables
// if unset
c.TagsConfig.UpdateWithEnv()

// Add '.' at the end of namespace
// to have the same behavior on DogStatsD and the API
if c.Metrics.Namespace != "" && !strings.HasSuffix(c.Metrics.Namespace, ".") {
c.Metrics.Namespace = c.Metrics.Namespace + "."
}

// Exactly one configuration for metrics must be set
if c.Metrics.Mode == AgentlessMode {
if c.API.Key == "" {
return errUnsetAPIKey
}
if c.API.Key == "" {
return errUnsetAPIKey
}

c.API.Key = strings.TrimSpace(c.API.Key)
c.API.Key = strings.TrimSpace(c.API.Key)

// Set the endpoint based on the Site
if c.Metrics.Agentless.Endpoint == "" {
c.Metrics.Agentless.Endpoint = fmt.Sprintf("https://api.%s", c.API.Site)
}
// Set the endpoint based on the Site
if c.Metrics.TCPAddr.Endpoint == "" {
c.Metrics.TCPAddr.Endpoint = fmt.Sprintf("https://api.%s", c.API.Site)
}

return nil
Expand Down
49 changes: 7 additions & 42 deletions exporter/datadogexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,51 +62,15 @@ func TestLoadConfig(t *testing.T) {
},

Metrics: MetricsConfig{
Mode: AgentlessMode,
Namespace: "opentelemetry.",
Percentiles: false,

DogStatsD: DogStatsDConfig{
Endpoint: "127.0.0.1:8125",
Telemetry: true,
},

Agentless: AgentlessConfig{
confignet.TCPAddr{
Endpoint: "https://api.datadoghq.eu",
},
TCPAddr: confignet.TCPAddr{
Endpoint: "https://api.datadoghq.eu",
},
},
}, apiConfig)

dogstatsdConfig := cfg.Exporters["datadog/dogstatsd"].(*Config)
err = dogstatsdConfig.Sanitize()

require.NoError(t, err)
assert.Equal(t, &Config{
ExporterSettings: configmodels.ExporterSettings{
NameVal: "datadog/dogstatsd",
TypeVal: typeStr,
},

TagsConfig: TagsConfig{},
API: APIConfig{Site: "datadoghq.com"},

Metrics: MetricsConfig{
Mode: DogStatsDMode,
Percentiles: true,
DogStatsD: DogStatsDConfig{
Endpoint: "127.0.0.1:8125",
Telemetry: true,
},
},
}, dogstatsdConfig)

invalidConfig := cfg.Exporters["datadog/invalid"].(*Config)
err = invalidConfig.Sanitize()
require.Error(t, err)

invalidConfig2 := cfg.Exporters["datadog/agentless/invalid"].(*Config)
invalidConfig2 := cfg.Exporters["datadog/invalid"].(*Config)
err = invalidConfig2.Sanitize()
require.Error(t, err)

Expand Down Expand Up @@ -143,12 +107,13 @@ func TestOverrideMetricsURL(t *testing.T) {
cfg := Config{
API: APIConfig{Key: "notnull", Site: DefaultSite},
Metrics: MetricsConfig{
Mode: AgentlessMode,
Agentless: AgentlessConfig{confignet.TCPAddr{Endpoint: DebugEndpoint}},
TCPAddr: confignet.TCPAddr{
Endpoint: DebugEndpoint,
},
},
}

err := cfg.Sanitize()
require.NoError(t, err)
assert.Equal(t, cfg.Metrics.Agentless.Endpoint, DebugEndpoint)
assert.Equal(t, cfg.Metrics.Endpoint, DebugEndpoint)
}
69 changes: 0 additions & 69 deletions exporter/datadogexporter/dogstatd_test.go

This file was deleted.

98 changes: 0 additions & 98 deletions exporter/datadogexporter/dogstatsd.go

This file was deleted.

Loading

0 comments on commit fcc9b77

Please sign in to comment.