Skip to content

Commit 35c9fa8

Browse files
committed
Keep only DogStatsD parts
The API exporter will be added on a future PR
1 parent c366603 commit 35c9fa8

File tree

8 files changed

+31
-242
lines changed

8 files changed

+31
-242
lines changed

exporter/datadogexporter/README.md

+3-15
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
# Datadog Exporter
22

3-
This exporter sends metric data to [Datadog](https://datadoghq.com).
3+
This exporter sends metric data to [Datadog](https://datadoghq.com) using DogStatsD.
44

55
## Configuration
66

7-
The metrics exporter has two modes:
8-
- If sending metrics through DogStatsD (the default mode), there are no required settings.
9-
- If sending metrics without an Agent the mode must be set explicitly and
10-
you must provide a [Datadog API key](https://app.datadoghq.com/account/settings#api).
11-
```yaml
12-
datadog:
13-
api:
14-
key: "<API key>"
15-
# site: datadoghq.eu for sending data to the Datadog EU site
16-
metrics:
17-
mode: agentless
18-
```
19-
7+
There are no required settings.
208
The hostname, environment, service and version can be set in the configuration for unified service tagging.
219

22-
See the sample configuration file under the `example` folder for other available options.
10+
See the sample configuration file under the `example` folder for all available options.

exporter/datadogexporter/config.go

+1-58
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,11 @@
1515
package datadogexporter
1616

1717
import (
18-
"errors"
1918
"fmt"
20-
"strings"
2119

2220
"go.opentelemetry.io/collector/config/configmodels"
2321
)
2422

25-
var (
26-
errUnsetAPIKey = errors.New("the Datadog API key is unset")
27-
)
28-
29-
const (
30-
NoneMode = "none"
31-
AgentlessMode = "agentless"
32-
DogStatsDMode = "dogstatsd"
33-
)
34-
35-
// APIConfig defines the API configuration options
36-
type APIConfig struct {
37-
// Key is the Datadog API key to associate your Agent's data with your organization.
38-
// Create a new API key here: https://app.datadoghq.com/account/settings
39-
Key string `mapstructure:"key"`
40-
41-
// Site is the site of the Datadog intake to send data to.
42-
// The default value is "datadoghq.com".
43-
Site string `mapstructure:"site"`
44-
}
45-
4623
// DogStatsDConfig defines the DogStatsd related configuration
4724
type DogStatsDConfig struct {
4825
// Endpoint is the DogStatsD address.
@@ -54,22 +31,12 @@ type DogStatsDConfig struct {
5431
Telemetry bool `mapstructure:"telemetry"`
5532
}
5633

57-
// AgentlessConfig defines the Agentless related configuration
58-
type AgentlessConfig struct {
59-
// Endpoint is the host of the Datadog intake server to send metrics to.
60-
// If unset, the value is obtained from the Site.
61-
Endpoint string `mapstructure:"endpoint"`
62-
}
63-
6434
// MetricsConfig defines the metrics exporter specific configuration options
6535
type MetricsConfig struct {
6636
// Namespace is the namespace under which the metrics are sent
6737
// By default metrics are not namespaced
6838
Namespace string `mapstructure:"namespace"`
6939

70-
// Mode is the metrics sending mode: either 'dogstatsd' or 'agentless'
71-
Mode string `mapstructure:"mode"`
72-
7340
// Percentiles states whether to report percentiles for summary metrics,
7441
// including the minimum and maximum
7542
Percentiles bool `mapstructure:"report_percentiles"`
@@ -79,9 +46,6 @@ type MetricsConfig struct {
7946

8047
// DogStatsD defines the DogStatsD configuration options.
8148
DogStatsD DogStatsDConfig `mapstructure:"dogstatsd"`
82-
83-
// Agentless defines the Agentless configuration options.
84-
Agentless AgentlessConfig `mapstructure:"agentless"`
8549
}
8650

8751
// TagsConfig defines the tag-related configuration
@@ -142,33 +106,12 @@ type Config struct {
142106

143107
TagsConfig `mapstructure:",squash"`
144108

145-
// API defines the Datadog API configuration.
146-
API APIConfig `mapstructure:"api"`
147-
148109
// Metrics defines the Metrics exporter specific configuration
149110
Metrics MetricsConfig `mapstructure:"metrics"`
150111
}
151112

152113
// Sanitize tries to sanitize a given configuration
153114
func (c *Config) Sanitize() error {
154-
155-
if c.Metrics.Mode != AgentlessMode && c.Metrics.Mode != DogStatsDMode {
156-
return fmt.Errorf("Metrics mode '%s' is not recognized", c.Metrics.Mode)
157-
}
158-
159-
// Exactly one configuration for metrics must be set
160-
if c.Metrics.Mode == AgentlessMode {
161-
if c.API.Key == "" {
162-
return errUnsetAPIKey
163-
}
164-
165-
c.API.Key = strings.TrimSpace(c.API.Key)
166-
167-
// Set the endpoint based on the Site
168-
if c.Metrics.Agentless.Endpoint == "" {
169-
c.Metrics.Agentless.Endpoint = fmt.Sprintf("https://api.%s", c.API.Site)
170-
}
171-
}
172-
115+
// This will be useful on a future PR
173116
return nil
174117
}

exporter/datadogexporter/config_test.go

+17-59
Original file line numberDiff line numberDiff line change
@@ -37,95 +37,53 @@ func TestLoadConfig(t *testing.T) {
3737
require.NoError(t, err)
3838
require.NotNil(t, cfg)
3939

40-
apiConfig := cfg.Exporters["datadog/api"].(*Config)
40+
apiConfig := cfg.Exporters["datadog/dogstatsd"].(*Config)
4141
err = apiConfig.Sanitize()
4242

4343
require.NoError(t, err)
4444
assert.Equal(t, apiConfig, &Config{
4545
ExporterSettings: configmodels.ExporterSettings{
46-
NameVal: "datadog/api",
46+
NameVal: "datadog/dogstatsd",
4747
TypeVal: "datadog",
4848
},
4949

50-
TagsConfig: TagsConfig{
51-
Hostname: "customhostname",
52-
Env: "prod",
53-
Service: "myservice",
54-
Version: "myversion",
55-
Tags: []string{"example:tag"},
56-
},
57-
58-
API: APIConfig{
59-
Key: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
60-
Site: "datadoghq.eu",
61-
},
62-
6350
Metrics: MetricsConfig{
64-
Mode: AgentlessMode,
65-
Namespace: "opentelemetry",
66-
Percentiles: false,
51+
Percentiles: true,
6752

6853
DogStatsD: DogStatsDConfig{
6954
Endpoint: "127.0.0.1:8125",
7055
Telemetry: true,
7156
},
72-
73-
Agentless: AgentlessConfig{
74-
Endpoint: "https://api.datadoghq.eu",
75-
},
7657
},
7758
})
7859

79-
dogstatsdConfig := cfg.Exporters["datadog/dogstatsd"].(*Config)
60+
dogstatsdConfig := cfg.Exporters["datadog/dogstatsd/config"].(*Config)
8061
err = dogstatsdConfig.Sanitize()
8162

8263
require.NoError(t, err)
8364
assert.Equal(t, dogstatsdConfig, &Config{
8465
ExporterSettings: configmodels.ExporterSettings{
85-
NameVal: "datadog/dogstatsd",
66+
NameVal: "datadog/dogstatsd/config",
8667
TypeVal: "datadog",
8768
},
8869

89-
TagsConfig: TagsConfig{},
90-
API: APIConfig{Site: "datadoghq.com"},
70+
TagsConfig: TagsConfig{
71+
Hostname: "customhostname",
72+
Env: "prod",
73+
Service: "myservice",
74+
Version: "myversion",
75+
Tags: []string{"example:tag"},
76+
},
9177

9278
Metrics: MetricsConfig{
93-
Mode: DogStatsDMode,
94-
Percentiles: true,
79+
Namespace: "opentelemetry",
80+
Percentiles: false,
81+
Buckets: true,
9582
DogStatsD: DogStatsDConfig{
96-
Endpoint: "127.0.0.1:8125",
97-
Telemetry: true,
83+
Endpoint: "localhost:5000",
84+
Telemetry: false,
9885
},
99-
100-
Agentless: AgentlessConfig{},
10186
},
10287
})
10388

104-
invalidConfig := cfg.Exporters["datadog/invalid"].(*Config)
105-
err = invalidConfig.Sanitize()
106-
require.Error(t, err)
107-
108-
invalidConfig2 := cfg.Exporters["datadog/agentless/invalid"].(*Config)
109-
err = invalidConfig2.Sanitize()
110-
require.Error(t, err)
111-
112-
}
113-
114-
// TestOverrideMetricsURL tests that the metrics URL is overridden
115-
// correctly when set manually.
116-
func TestOverrideMetricsURL(t *testing.T) {
117-
118-
const DebugEndpoint string = "http://localhost:8080"
119-
120-
cfg := Config{
121-
API: APIConfig{Key: "notnull", Site: DefaultSite},
122-
Metrics: MetricsConfig{
123-
Mode: AgentlessMode,
124-
Agentless: AgentlessConfig{Endpoint: DebugEndpoint},
125-
},
126-
}
127-
128-
err := cfg.Sanitize()
129-
require.NoError(t, err)
130-
assert.Equal(t, cfg.Metrics.Agentless.Endpoint, DebugEndpoint)
13189
}

exporter/datadogexporter/example/config.yaml

-39
Original file line numberDiff line numberDiff line change
@@ -35,39 +35,10 @@ exporters:
3535
#
3636
# tags: []
3737

38-
## @param api - custom object - optional.
39-
## Specific API configuration for the agentless exporters.
40-
#
41-
# api:
42-
## @ param key - string - optional
43-
## The Datadog API key to associate your Agent's data with your organization.
44-
## Create a new API key here: https://app.datadoghq.com/account/settings
45-
##
46-
## This is required if using any agentless exporter.
47-
#
48-
# key: <YOUR API KEY>
49-
50-
## @param site - string - optional - default: datadoghq.com
51-
## The site of the Datadog intake to send Agent data to.
52-
## Set to 'datadoghq.eu' to send data to the EU site.
53-
#
54-
# site: datadoghq.com
55-
5638
## @param metrics - custom object - optional
5739
## Metric exporter specific configuration.
5840
#
5941
# metrics:
60-
## @param mode - string - optional - default: dogstatsd
61-
## The mode with which to send metrics.
62-
## It can be one of
63-
## - 'none' (to explicitly disable it)
64-
## - 'dogstatsd' (to send metrics to a DogStatsD endpoint)
65-
## - 'agentless' (to send metrics directly through the API)
66-
##
67-
## If the mode is 'agentless' the API key must be set.
68-
#
69-
# mode: dogstatsd
70-
7142
## @param namespace - string - optional
7243
## The namespace with which to prefix all metrics.
7344
## By default metrics are not namespaced.
@@ -100,16 +71,6 @@ exporters:
10071
## Whether to send telemetry metrics about the number of custom metrics sent.
10172
#
10273
# telemetry: true
103-
104-
## @param agentless - custom object - optional
105-
## Agentless metrics exporter specific configuration
106-
#
107-
# agentless:
108-
## @param endpoint - string - optional
109-
## The host of the Datadog intake server to send metrics to.
110-
## If unset the value is obtained through the `site` parameter in the `api` section.
111-
#
112-
# endpoint: https://api.datadoghq.com
11374
service:
11475
pipelines:
11576
traces:

exporter/datadogexporter/factory.go

-10
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,13 @@ func NewFactory() component.ExporterFactory {
5353
// createDefaultConfig creates the default exporter configuration
5454
func createDefaultConfig() configmodels.Exporter {
5555
return &Config{
56-
API: APIConfig{
57-
Key: "", // must be set if using API
58-
Site: "datadoghq.com",
59-
},
60-
6156
Metrics: MetricsConfig{
62-
Mode: DogStatsDMode,
6357
Percentiles: true,
6458

6559
DogStatsD: DogStatsDConfig{
6660
Endpoint: "127.0.0.1:8125",
6761
Telemetry: true,
6862
},
69-
70-
Agentless: AgentlessConfig{
71-
Endpoint: "", // set during config sanitization
72-
},
7363
},
7464
}
7565
}

exporter/datadogexporter/factory_test.go

+2-29
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ func TestCreateDefaultConfig(t *testing.T) {
3434
cfg := factory.CreateDefaultConfig()
3535

3636
assert.Equal(t, cfg, &Config{
37-
API: APIConfig{Site: "datadoghq.com"},
3837
Metrics: MetricsConfig{
39-
Mode: DogStatsDMode,
4038
Percentiles: true,
4139
DogStatsD: DogStatsDConfig{
4240
Endpoint: "127.0.0.1:8125",
@@ -71,32 +69,7 @@ func TestCreateAgentMetricsExporter(t *testing.T) {
7169
assert.NotNil(t, exp)
7270
}
7371

74-
func TestCreateAPIMetricsExporter(t *testing.T) {
75-
logger := zap.NewNop()
76-
77-
factories, err := componenttest.ExampleComponents()
78-
assert.NoError(t, err)
79-
80-
factory := NewFactory()
81-
factories.Exporters[configmodels.Type(typeStr)] = factory
82-
cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories)
83-
84-
require.NoError(t, err)
85-
require.NotNil(t, cfg)
86-
87-
ctx := context.Background()
88-
exp, err := factory.CreateMetricsExporter(
89-
ctx,
90-
component.ExporterCreateParams{Logger: logger},
91-
cfg.Exporters["datadog/api"],
92-
)
93-
94-
// Not implemented
95-
assert.NotNil(t, err)
96-
assert.Nil(t, exp)
97-
}
98-
99-
func TestCreateAPITraceExporter(t *testing.T) {
72+
func TestCreateTraceExporter(t *testing.T) {
10073
logger := zap.NewNop()
10174

10275
factories, err := componenttest.ExampleComponents()
@@ -113,7 +86,7 @@ func TestCreateAPITraceExporter(t *testing.T) {
11386
exp, err := factory.CreateTraceExporter(
11487
ctx,
11588
component.ExporterCreateParams{Logger: logger},
116-
cfg.Exporters["datadog/api"],
89+
cfg.Exporters["datadog/dogstatsd"],
11790
)
11891

11992
// Not implemented

exporter/datadogexporter/metrics.go

+3-8
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,9 @@ type MetricsExporter interface {
3535
}
3636

3737
func newMetricsExporter(logger *zap.Logger, cfg *Config) (MetricsExporter, error) {
38-
switch cfg.Metrics.Mode {
39-
case DogStatsDMode:
40-
return newDogStatsDExporter(logger, cfg)
41-
case NoneMode:
42-
return nil, fmt.Errorf("Metrics exporter disabled for Datadog exporter")
43-
}
44-
45-
return nil, fmt.Errorf("Unsupported mode: '%s'", cfg.Metrics.Mode)
38+
// A different exporter will be added depending on configuration
39+
// in the future
40+
return newDogStatsDExporter(logger, cfg)
4641
}
4742

4843
type MetricType int

0 commit comments

Comments
 (0)