Skip to content

Commit

Permalink
Added min and max supported interval
Browse files Browse the repository at this point in the history
  • Loading branch information
jerrytfleung committed Jan 18, 2024
1 parent d3193cb commit 70d5559
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 6 deletions.
6 changes: 6 additions & 0 deletions extension/solarwindsapmsettingsextension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@ The service key in format `<token>:<name>` for `getSettings` from Solarwinds APM
### interval (Optional)
Periodic interval to get Solarwinds APM specific settings from Solarwinds APM collector.

Minimum value: `5s`

Maximum value: `60s`

Value that is outside the boundary will be bounded to either the minimum or maximum value.

Default: `10s`
9 changes: 9 additions & 0 deletions extension/solarwindsapmsettingsextension/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ func TestValidate(t *testing.T) {
},
err: errors.New("key should be in \"<token>:<service_name>\" format"),
},
{
name: "valid",
cfg: &Config{
Endpoint: "host:12345",
Key: "token:name",
Interval: "1s",
},
err: nil,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
Expand Down
19 changes: 16 additions & 3 deletions extension/solarwindsapmsettingsextension/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import (
)

const (
RawOutputFile = "/tmp/solarwinds-apm-settings-raw"
JSONOutputFile = "/tmp/solarwinds-apm-settings.json"
RawOutputFile = "/tmp/solarwinds-apm-settings-raw"
JSONOutputFile = "/tmp/solarwinds-apm-settings.json"
MinimumInterval = "5s"
MaximumInterval = "60s"
)

type solarwindsapmSettingsExtension struct {
Expand Down Expand Up @@ -195,7 +197,18 @@ func (extension *solarwindsapmSettingsExtension) Start(ctx context.Context, _ co

// setup lightweight thread to refresh
var interval time.Duration
interval, err = time.ParseDuration(extension.config.Interval)
interval, _ = time.ParseDuration(extension.config.Interval)
minimum, _ := time.ParseDuration(MinimumInterval)
maximum, _ := time.ParseDuration(MaximumInterval)
if interval.Seconds() < minimum.Seconds() {
interval = minimum
extension.logger.Warn("Interval " + extension.config.Interval + " is bounded to the minimum interval " + MinimumInterval)
}
if interval.Seconds() > maximum.Seconds() {
interval = maximum
extension.logger.Warn("Interval " + extension.config.Interval + " is bounded to the maximum interval " + MaximumInterval)
}

go func() {
ticker := time.NewTicker(interval)
defer ticker.Stop()
Expand Down
26 changes: 23 additions & 3 deletions extension/solarwindsapmsettingsextension/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestCreateExtension(t *testing.T) {
conf := &Config{
Endpoint: "apm-testcollector.click:443",
Key: "valid:unittest",
Interval: "1s",
Interval: "10s",
}
ex := createAnExtension(conf, t)
ex.Shutdown(context.TODO())
Expand All @@ -22,7 +22,7 @@ func TestCreateExtensionWrongEndpoint(t *testing.T) {
conf := &Config{
Endpoint: "apm-testcollector.nothing:443",
Key: "valid:unittest",
Interval: "1s",
Interval: "5s",
}
ex := createAnExtension(conf, t)
ex.Shutdown(context.TODO())
Expand All @@ -32,7 +32,27 @@ func TestCreateExtensionWrongKey(t *testing.T) {
conf := &Config{
Endpoint: "apm-testcollector.click:443",
Key: "invalid",
Interval: "1s",
Interval: "60s",
}
ex := createAnExtension(conf, t)
ex.Shutdown(context.TODO())
}

func TestCreateExtensionIntervalLessThanMinimum(t *testing.T) {
conf := &Config{
Endpoint: "apm-testcollector.click:443",
Key: "valid:unittest",
Interval: "4s",
}
ex := createAnExtension(conf, t)
ex.Shutdown(context.TODO())
}

func TestCreateExtensionIntervalGreaterThanMaximum(t *testing.T) {
conf := &Config{
Endpoint: "apm-testcollector.click:443",
Key: "valid:unittest",
Interval: "61s",
}
ex := createAnExtension(conf, t)
ex.Shutdown(context.TODO())
Expand Down

0 comments on commit 70d5559

Please sign in to comment.