Skip to content

Commit

Permalink
[extension/solarwindsapmsettingsextension] Added remaining implementa…
Browse files Browse the repository at this point in the history
…tion of solarwindsapmsettingsextension (open-telemetry#33315)

**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
- Added logic for `refresh` function

**Link to tracking Issue:** <Issue number if applicable>

[27668](open-telemetry#27668)

**Testing:** <Describe what testing was performed and which tests were
added.>
Manually tested against test server
```
extensions:
  solarwindsapmsettings:
    endpoint: "apm-testcollector.click:443"
    key: "any:any"

service:
  extensions: [solarwindsapmsettings]
```

**Documentation:** <Describe the documentation added.>
- Updated README to remove the support of
`/tmp/solarwinds-apm-settings-raw` file

---------

Co-authored-by: Antoine Toulme <antoine@toulme.name>
  • Loading branch information
2 people authored and f7o committed Sep 12, 2024
1 parent ce740be commit 6bdfbf1
Show file tree
Hide file tree
Showing 11 changed files with 751 additions and 54 deletions.
27 changes: 27 additions & 0 deletions .chloggen/feature_solarwindsapmsettingsetension-impl-2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: solarwindsapmsettingsextension

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Added logic for refresh function

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [27668]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
2 changes: 1 addition & 1 deletion extension/solarwindsapmsettingsextension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<!-- end autogenerated section -->

## Overview
The Solarwinds APM Settings extension gets Solarwinds APM specific settings from Solarwinds APM collector and `/tmp/solarwinds-apm-settings.json` & `/tmp/solarwinds-apm-settings-raw` periodically.
The Solarwinds APM Settings extension gets Solarwinds APM specific settings from Solarwinds APM collector and `/tmp/solarwinds-apm-settings.json` periodically.

## Configuration

Expand Down
15 changes: 9 additions & 6 deletions extension/solarwindsapmsettingsextension/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import (
"time"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configgrpc"
)

type Config struct {
Endpoint string `mapstructure:"endpoint"`
Key string `mapstructure:"key"`
Interval time.Duration `mapstructure:"interval"`
ClientConfig configgrpc.ClientConfig `mapstructure:",squash"`
Key string `mapstructure:"key"`
Interval time.Duration `mapstructure:"interval"`
}

const (
Expand All @@ -27,17 +28,19 @@ const (

func createDefaultConfig() component.Config {
return &Config{
Endpoint: DefaultEndpoint,
ClientConfig: configgrpc.ClientConfig{
Endpoint: DefaultEndpoint,
},
Interval: DefaultInterval,
}
}

func (cfg *Config) Validate() error {
// Endpoint
matched, _ := regexp.MatchString(`apm.collector.[a-z]{2,3}-[0-9]{2}.[a-z\-]*.solarwinds.com:443`, cfg.Endpoint)
matched, _ := regexp.MatchString(`apm.collector.[a-z]{2,3}-[0-9]{2}.[a-z\-]*.solarwinds.com:443`, cfg.ClientConfig.Endpoint)
if !matched {
// Replaced by the default
cfg.Endpoint = DefaultEndpoint
cfg.ClientConfig.Endpoint = DefaultEndpoint
}
// Key
keyArr := strings.Split(cfg.Key, ":")
Expand Down
219 changes: 213 additions & 6 deletions extension/solarwindsapmsettingsextension/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configgrpc"
"go.opentelemetry.io/collector/confmap/confmaptest"

"github.com/open-telemetry/opentelemetry-collector-contrib/extension/solarwindsapmsettingsextension/internal/metadata"
Expand All @@ -31,25 +32,231 @@ func TestLoadConfig(t *testing.T) {
{
id: component.NewIDWithName(metadata.Type, "1"),
expected: &Config{
Endpoint: "apm.collector.apj-01.cloud.solarwinds.com:443",
ClientConfig: configgrpc.ClientConfig{
Endpoint: "apm.collector.na-01.cloud.solarwinds.com:443",
},
Key: "something:name",
Interval: time.Duration(10) * time.Second,
},
},
{
id: component.NewIDWithName(metadata.Type, "2"),
expected: &Config{
Endpoint: "apm.collector.na-01.cloud.solarwinds.com:443",
Key: "something",
Interval: time.Duration(5) * time.Second,
ClientConfig: configgrpc.ClientConfig{
Endpoint: "apm.collector.na-02.cloud.solarwinds.com:443",
},
Key: "something:name",
Interval: time.Duration(10) * time.Second,
},
},
{
id: component.NewIDWithName(metadata.Type, "3"),
expected: &Config{
Endpoint: "apm.collector.na-01.cloud.solarwinds.com:443",
ClientConfig: configgrpc.ClientConfig{
Endpoint: "apm.collector.eu-01.cloud.solarwinds.com:443",
},
Key: "something:name",
Interval: time.Duration(10) * time.Second,
},
},
{
id: component.NewIDWithName(metadata.Type, "4"),
expected: &Config{
ClientConfig: configgrpc.ClientConfig{
Endpoint: "apm.collector.apj-01.cloud.solarwinds.com:443",
},
Key: "something:name",
Interval: time.Duration(10) * time.Second,
},
},
{
id: component.NewIDWithName(metadata.Type, "5"),
expected: &Config{
ClientConfig: configgrpc.ClientConfig{
Endpoint: "apm.collector.na-01.st-ssp.solarwinds.com:443",
},
Key: "something:name",
Interval: time.Duration(10) * time.Second,
},
},
{
id: component.NewIDWithName(metadata.Type, "6"),
expected: &Config{
ClientConfig: configgrpc.ClientConfig{
Endpoint: "apm.collector.na-01.dev-ssp.solarwinds.com:443",
},
Key: "something:name",
Interval: time.Duration(10) * time.Second,
},
},
{
id: component.NewIDWithName(metadata.Type, "7"),
expected: &Config{
ClientConfig: configgrpc.ClientConfig{
Endpoint: DefaultEndpoint,
},
Key: "something:name",
Interval: time.Duration(10) * time.Second,
},
},
{
id: component.NewIDWithName(metadata.Type, "8"),
expected: &Config{
ClientConfig: configgrpc.ClientConfig{
Endpoint: DefaultEndpoint,
},
Key: "something:name",
Interval: time.Duration(10) * time.Second,
},
},
{
id: component.NewIDWithName(metadata.Type, "9"),
expected: &Config{
ClientConfig: configgrpc.ClientConfig{
Endpoint: DefaultEndpoint,
},
Key: "something:name",
Interval: time.Duration(10) * time.Second,
},
},
{
id: component.NewIDWithName(metadata.Type, "10"),
expected: &Config{
ClientConfig: configgrpc.ClientConfig{
Endpoint: DefaultEndpoint,
},
Key: "something:name",
Interval: time.Duration(10) * time.Second,
},
},
{
id: component.NewIDWithName(metadata.Type, "11"),
expected: &Config{
ClientConfig: configgrpc.ClientConfig{
Endpoint: DefaultEndpoint,
},
Key: "something:name",
Interval: time.Duration(10) * time.Second,
},
},
{
id: component.NewIDWithName(metadata.Type, "12"),
expected: &Config{
ClientConfig: configgrpc.ClientConfig{
Endpoint: DefaultEndpoint,
},
Key: "something:name",
Interval: time.Duration(60) * time.Second,
Interval: time.Duration(10) * time.Second,
},
},
{
id: component.NewIDWithName(metadata.Type, "13"),
expected: &Config{
ClientConfig: configgrpc.ClientConfig{
Endpoint: DefaultEndpoint,
},
Key: "something:name",
Interval: time.Duration(10) * time.Second,
},
},
{
id: component.NewIDWithName(metadata.Type, "14"),
expected: &Config{
ClientConfig: configgrpc.ClientConfig{
Endpoint: DefaultEndpoint,
},
Key: "something:name",
Interval: time.Duration(10) * time.Second,
},
},
{
id: component.NewIDWithName(metadata.Type, "15"),
expected: &Config{
ClientConfig: configgrpc.ClientConfig{
Endpoint: DefaultEndpoint,
},
Key: "something:name",
Interval: time.Duration(10) * time.Second,
},
},
{
id: component.NewIDWithName(metadata.Type, "16"),
expected: &Config{
ClientConfig: configgrpc.ClientConfig{
Endpoint: DefaultEndpoint,
},
Key: "",
Interval: time.Duration(10) * time.Second,
},
},
{
id: component.NewIDWithName(metadata.Type, "17"),
expected: &Config{
ClientConfig: configgrpc.ClientConfig{
Endpoint: DefaultEndpoint,
},
Key: ":",
Interval: time.Duration(10) * time.Second,
},
},
{
id: component.NewIDWithName(metadata.Type, "18"),
expected: &Config{
ClientConfig: configgrpc.ClientConfig{
Endpoint: DefaultEndpoint,
},
Key: "::",
Interval: time.Duration(10) * time.Second,
},
},
{
id: component.NewIDWithName(metadata.Type, "19"),
expected: &Config{
ClientConfig: configgrpc.ClientConfig{
Endpoint: DefaultEndpoint,
},
Key: ":name",
Interval: time.Duration(10) * time.Second,
},
},
{
id: component.NewIDWithName(metadata.Type, "20"),
expected: &Config{
ClientConfig: configgrpc.ClientConfig{
Endpoint: DefaultEndpoint,
},
Key: "token:",
Interval: time.Duration(10) * time.Second,
},
},
{
id: component.NewIDWithName(metadata.Type, "21"),
expected: &Config{
ClientConfig: configgrpc.ClientConfig{
Endpoint: DefaultEndpoint,
},
Key: "token:name",
Interval: MinimumInterval,
},
},
{
id: component.NewIDWithName(metadata.Type, "22"),
expected: &Config{
ClientConfig: configgrpc.ClientConfig{
Endpoint: DefaultEndpoint,
},
Key: "token:name",
Interval: MaximumInterval,
},
},
{
id: component.NewIDWithName(metadata.Type, "23"),
expected: &Config{
ClientConfig: configgrpc.ClientConfig{
Endpoint: DefaultEndpoint,
},
Key: "token:name",
Interval: MinimumInterval,
},
},
}
Expand Down
Loading

0 comments on commit 6bdfbf1

Please sign in to comment.