Skip to content

Commit d46f03c

Browse files
committed
add reporter_period configuration value for metadata payloads
1 parent 0d4f359 commit d46f03c

File tree

9 files changed

+48
-15
lines changed

9 files changed

+48
-15
lines changed

extension/datadogfleetautomationextension/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ This is the POC for the Datadog Fleet Automation Extension.
33
You can configure this extension in service, using the following configuration values:
44
`api::key`: a Datadog API Key, required
55
`api::site`: your Datadog site value (e.g. us5.datadoghq.com), defaults to "datadoghq.com"
6-
`hostname`: custom hostname; if you do not specify one, the extension will try to infer one. Note: this must match any hostname value set in the `host_metadata` section of Datadog Exporter, if enabled in your collector.
6+
`hostname`: custom hostname; if you do not specify one, the extension will try to infer one. Note: this must match any hostname value set in the `host_metadata` section of Datadog Exporter, if enabled in your collector.
7+
`reporter_period`: A value (given in time notation, e.g. "20m") of time between sending fleet automation data to Datadog backend. Must be 5 minutes or greater.

extension/datadogfleetautomationextension/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
package datadogfleetautomationextension
77

88
import (
9+
"errors"
910
"fmt"
1011
"strings"
12+
"time"
1113

1214
"go.opentelemetry.io/collector/component"
1315
"go.opentelemetry.io/collector/config/confighttp"
@@ -33,6 +35,8 @@ const (
3335
DefaultSite = datadogconfig.DefaultSite
3436
// NonHexChars is a regex of characters that are always invalid in a Datadog API key.
3537
NonHexChars = datadogconfig.NonHexChars
38+
// DefaultReporterPeriod is the default amount of time between sending fleet automation payloads to Datadog.
39+
DefaultReporterPeriod = 20 * time.Minute
3640
)
3741

3842
// Config contains the information necessary for enabling the Datadog Fleet
@@ -42,6 +46,8 @@ type Config struct {
4246
API APIConfig `mapstructure:"api"`
4347
// If Hostname is empty extension will use available system APIs and cloud provider endpoints.
4448
Hostname string `mapstructure:"hostname"`
49+
// ReporterPeriod sets the amount of time between sending fleet automation payloads to Datadog.
50+
ReporterPeriod time.Duration `mapstructure:"reporter_period"`
4551
}
4652

4753
// APIConfig contains the information necessary for configuring the Datadog API.
@@ -59,5 +65,8 @@ func (c *Config) Validate() error {
5965
if len(invalidAPIKeyChars) > 0 {
6066
return fmt.Errorf("%w: invalid characters: %s", ErrAPIKeyFormat, strings.Join(invalidAPIKeyChars, ", "))
6167
}
68+
if c.ReporterPeriod < 5*time.Minute {
69+
return errors.New("reporter_period must be 5 minutes or higher")
70+
}
6271
return nil
6372
}

extension/datadogfleetautomationextension/config_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package datadogfleetautomationextension
88
import (
99
"fmt"
1010
"testing"
11+
"time"
1112

1213
"github.com/stretchr/testify/assert"
1314
)
@@ -25,6 +26,7 @@ func TestConfig_Validate(t *testing.T) {
2526
Site: DefaultSite,
2627
Key: "1234567890abcdef1234567890abcdef",
2728
},
29+
ReporterPeriod: DefaultReporterPeriod,
2830
},
2931
wantErr: nil,
3032
},
@@ -35,6 +37,7 @@ func TestConfig_Validate(t *testing.T) {
3537
Site: "",
3638
Key: "1234567890abcdef1234567890abcdef",
3739
},
40+
ReporterPeriod: DefaultReporterPeriod,
3841
},
3942
wantErr: ErrEmptyEndpoint,
4043
},
@@ -45,6 +48,7 @@ func TestConfig_Validate(t *testing.T) {
4548
Site: DefaultSite,
4649
Key: "",
4750
},
51+
ReporterPeriod: DefaultReporterPeriod,
4852
},
4953
wantErr: ErrUnsetAPIKey,
5054
},
@@ -55,9 +59,21 @@ func TestConfig_Validate(t *testing.T) {
5559
Site: DefaultSite,
5660
Key: "1234567890abcdef1234567890abcdeg",
5761
},
62+
ReporterPeriod: DefaultReporterPeriod,
5863
},
5964
wantErr: fmt.Errorf("%w: invalid characters: %s", ErrAPIKeyFormat, "g"),
6065
},
66+
{
67+
name: "too small reporter period",
68+
config: Config{
69+
API: APIConfig{
70+
Site: DefaultSite,
71+
Key: "1234567890abcdef1234567890abcdef",
72+
},
73+
ReporterPeriod: 2 * time.Minute,
74+
},
75+
wantErr: fmt.Errorf("reporter_period must be 5 minutes or higher"),
76+
},
6177
}
6278

6379
for _, tt := range tests {

extension/datadogfleetautomationextension/factory.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func createDefaultConfig() component.Config {
2828
API: APIConfig{
2929
Site: DefaultSite,
3030
},
31+
ReporterPeriod: DefaultReporterPeriod,
3132
}
3233
}
3334

extension/datadogfleetautomationextension/factory_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func TestFactory_CreateDefaultConfig(t *testing.T) {
2424
API: APIConfig{
2525
Site: DefaultSite,
2626
},
27+
ReporterPeriod: DefaultReporterPeriod,
2728
}
2829
cfg := createDefaultConfig()
2930
assert.Equal(t, expectedConfig, cfg)
@@ -53,6 +54,7 @@ func TestFactory_NewFactory(t *testing.T) {
5354
API: APIConfig{
5455
Site: DefaultSite,
5556
},
57+
ReporterPeriod: DefaultReporterPeriod,
5658
}
5759
assert.Equal(t, expectedConfig, defaultConfig)
5860

extension/datadogfleetautomationextension/fleetautomationextension.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ func newExtension(
327327
serializer: serializer,
328328
buildInfo: settings.BuildInfo,
329329
version: version,
330-
ticker: time.NewTicker(20 * time.Minute),
330+
ticker: time.NewTicker(config.ReporterPeriod),
331331
done: make(chan bool),
332332
hostnameProvider: sp,
333333
hostnameSource: hostnameSource,

extension/datadogfleetautomationextension/fleetautomationextension_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func Test_NotifyConfig(t *testing.T) {
152152
tt.apikey = api.ValidateAPIKey
153153
}
154154

155-
faExt, err := newExtension(ctx, &Config{}, set, clientutil.ValidateAPIKey, tt.provider, tt.forwarder)
155+
faExt, err := newExtension(ctx, &Config{ReporterPeriod: DefaultReporterPeriod}, set, clientutil.ValidateAPIKey, tt.provider, tt.forwarder)
156156
assert.NoError(t, err)
157157
mcc := &mockComponentChecker{
158158
ccFunc: faExt.isComponentConfigured,
@@ -258,7 +258,8 @@ func TestNewExtension(t *testing.T) {
258258
Site: "datadoghq.com",
259259
Key: "valid-api-key",
260260
},
261-
Hostname: "test-hostname",
261+
Hostname: "test-hostname",
262+
ReporterPeriod: DefaultReporterPeriod,
262263
},
263264
apiKeyValidator: &mockAPIKeyValidator{
264265
err: nil,
@@ -295,7 +296,8 @@ func TestNewExtension(t *testing.T) {
295296
Site: "datadoghq.com",
296297
Key: "valid-api-key",
297298
},
298-
Hostname: "",
299+
Hostname: "",
300+
ReporterPeriod: DefaultReporterPeriod,
299301
},
300302
apiKeyValidator: &mockAPIKeyValidator{
301303
err: nil,
@@ -313,7 +315,8 @@ func TestNewExtension(t *testing.T) {
313315
Site: "datadoghq.com",
314316
Key: "valid-api-key",
315317
},
316-
Hostname: "test-hostname",
318+
Hostname: "test-hostname",
319+
ReporterPeriod: DefaultReporterPeriod,
317320
},
318321
apiKeyValidator: &mockAPIKeyValidator{
319322
err: nil,

extension/datadogfleetautomationextension/http_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestStartLocalConfigServer(t *testing.T) {
5050
telemetry: component.TelemetrySettings{
5151
Logger: logger,
5252
},
53-
ticker: time.NewTicker(20 * time.Minute),
53+
ticker: time.NewTicker(DefaultReporterPeriod),
5454
done: make(chan bool),
5555
httpServer: &http.Server{
5656
Addr: server.Listener.Addr().String(),
@@ -266,7 +266,7 @@ func TestPrepareAndSendFleetAutomationPayloads(t *testing.T) {
266266
},
267267
},
268268
hostname: "test-hostname",
269-
ticker: time.NewTicker(20 * time.Minute),
269+
ticker: time.NewTicker(DefaultReporterPeriod),
270270
done: make(chan bool),
271271
}, logs
272272
},
@@ -306,7 +306,7 @@ func TestPrepareAndSendFleetAutomationPayloads(t *testing.T) {
306306
},
307307
},
308308
hostname: "test-hostname",
309-
ticker: time.NewTicker(20 * time.Minute),
309+
ticker: time.NewTicker(DefaultReporterPeriod),
310310
done: make(chan bool),
311311
}, logs
312312
},
@@ -340,7 +340,7 @@ func TestPrepareAndSendFleetAutomationPayloads(t *testing.T) {
340340
},
341341
},
342342
hostname: "test-hostname",
343-
ticker: time.NewTicker(20 * time.Minute),
343+
ticker: time.NewTicker(DefaultReporterPeriod),
344344
done: make(chan bool),
345345
}, logs
346346
},
@@ -372,7 +372,7 @@ func TestPrepareAndSendFleetAutomationPayloads(t *testing.T) {
372372
},
373373
},
374374
hostname: "test-hostname",
375-
ticker: time.NewTicker(20 * time.Minute),
375+
ticker: time.NewTicker(DefaultReporterPeriod),
376376
done: make(chan bool),
377377
}, logs
378378
},
@@ -397,7 +397,7 @@ func TestPrepareAndSendFleetAutomationPayloads(t *testing.T) {
397397
},
398398
serializer: &mockSerializer{},
399399
hostname: "test-hostname",
400-
ticker: time.NewTicker(20 * time.Minute),
400+
ticker: time.NewTicker(DefaultReporterPeriod),
401401
done: make(chan bool),
402402
}, logs
403403
},
@@ -539,7 +539,7 @@ func TestHandleMetadata(t *testing.T) {
539539
return nil
540540
},
541541
},
542-
ticker: time.NewTicker(20 * time.Minute),
542+
ticker: time.NewTicker(DefaultReporterPeriod),
543543
done: make(chan bool),
544544
}, logs
545545
},
@@ -558,7 +558,7 @@ func TestHandleMetadata(t *testing.T) {
558558
Logger: logger,
559559
},
560560
hostnameSource: "unset",
561-
ticker: time.NewTicker(20 * time.Minute),
561+
ticker: time.NewTicker(DefaultReporterPeriod),
562562
done: make(chan bool),
563563
}, logs
564564
},
@@ -582,7 +582,7 @@ func TestHandleMetadata(t *testing.T) {
582582
return errors.New("failed to send payload")
583583
},
584584
},
585-
ticker: time.NewTicker(20 * time.Minute),
585+
ticker: time.NewTicker(DefaultReporterPeriod),
586586
done: make(chan bool),
587587
}, logs
588588
},

extension/datadogfleetautomationextension/testdata/collector-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ extensions:
1919
key: ${env:DD_API_KEY}
2020
site: datadoghq.com
2121
hostname: "datadogfleetautomation-confighostname"
22+
reporter_period: 20m
2223
healthcheckv2:
2324
use_v2: true
2425
component_health:

0 commit comments

Comments
 (0)