-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[extension/solarwindsapmsettingsextension] Overall structure of the n…
…ew component (#30153) **Description:** - Adding the overall structure of the new component `extension/solarwindsapmsettingsextension` for the first PR **Link to tracking Issue:** [27668](#27668) **Testing:** - Added config test - Added basic factory test and extension test **Documentation:** - Updated the README.md --------- Co-authored-by: Antoine Toulme <antoine@toulme.name>
- Loading branch information
1 parent
f07bcda
commit c89b81a
Showing
23 changed files
with
1,029 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: new_component | ||
|
||
# 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 configuration and readme | ||
|
||
# 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: [user] |
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include ../../Makefile.Common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Solarwinds APM Settings extension | ||
|
||
<!-- status autogenerated section --> | ||
| Status | | | ||
| ------------- |-----------| | ||
| Stability | [development] | | ||
| Distributions | [] | | ||
| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Aextension%2Fsolarwindsapmsettings%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Aextension%2Fsolarwindsapmsettings) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Aextension%2Fsolarwindsapmsettings%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Aextension%2Fsolarwindsapmsettings) | | ||
| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@jerrytfleung](https://www.github.com/jerrytfleung), [@cheempz](https://www.github.com/cheempz) | | ||
|
||
[development]: https://github.com/open-telemetry/opentelemetry-collector#development | ||
<!-- 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. | ||
|
||
## Configuration | ||
|
||
Example: | ||
|
||
```yaml | ||
extensions: | ||
solarwindsapmsettings: | ||
endpoint: "<endpoint>" | ||
key: "<token>:<name>" | ||
interval: 1m | ||
``` | ||
### endpoint (Required) | ||
The APM collector endpoint which this extension calls `getSettings`. See [here](https://documentation.solarwinds.com/en/success_center/observability/content/system_requirements/endpoints.htm) for our APM collector endpoints. | ||
|
||
### key (Required) | ||
The service key in format `<token>:<name>` for `getSettings` from Solarwinds APM collector. See [here](https://documentation.solarwinds.com/en/success_center/observability/content/configure/configure-services.htm) for configuring a service key. | ||
|
||
### interval (Optional) | ||
Periodic interval to get Solarwinds APM specific settings from Solarwinds APM collector. | ||
|
||
Default: `1m` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package solarwindsapmsettingsextension // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/solarwindsapmsettingsextension" | ||
|
||
import ( | ||
"errors" | ||
"strconv" | ||
"strings" | ||
"time" | ||
) | ||
|
||
type Config struct { | ||
Endpoint string `mapstructure:"endpoint"` | ||
Key string `mapstructure:"key"` | ||
Interval string `mapstructure:"interval"` | ||
} | ||
|
||
func (cfg *Config) Validate() error { | ||
if len(cfg.Endpoint) == 0 { | ||
return errors.New("endpoint must not be empty") | ||
} | ||
endpointArr := strings.Split(cfg.Endpoint, ":") | ||
if len(endpointArr) != 2 { | ||
return errors.New("endpoint should be in \"<host>:<port>\" format") | ||
} | ||
if _, err := strconv.Atoi(endpointArr[1]); err != nil { | ||
return errors.New("the <port> portion of endpoint has to be an integer") | ||
} | ||
if len(cfg.Key) == 0 { | ||
return errors.New("key must not be empty") | ||
} | ||
keyArr := strings.Split(cfg.Key, ":") | ||
if len(keyArr) != 2 { | ||
return errors.New("key should be in \"<token>:<service_name>\" format") | ||
} | ||
if _, err := time.ParseDuration(cfg.Interval); err != nil { | ||
return errors.New("interval has to be a duration string. Valid time units are \"ns\", \"us\" (or \"µs\"), \"ms\", \"s\", \"m\", \"h\"") | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package solarwindsapmsettingsextension | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestValidate(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
cfg *Config | ||
err error | ||
}{ | ||
{ | ||
name: "nothing", | ||
cfg: &Config{}, | ||
err: errors.New("endpoint must not be empty"), | ||
}, | ||
{ | ||
name: "empty key", | ||
cfg: &Config{ | ||
Endpoint: "host:12345", | ||
}, | ||
err: errors.New("key must not be empty"), | ||
}, | ||
{ | ||
name: "invalid endpoint", | ||
cfg: &Config{ | ||
Endpoint: "invalid", | ||
Key: "token:name", | ||
}, | ||
err: errors.New("endpoint should be in \"<host>:<port>\" format"), | ||
}, | ||
{ | ||
name: "invalid endpoint format but port is not an integer", | ||
cfg: &Config{ | ||
Endpoint: "host:abc", | ||
Key: "token:name", | ||
}, | ||
err: errors.New("the <port> portion of endpoint has to be an integer"), | ||
}, | ||
{ | ||
name: "invalid key", | ||
cfg: &Config{ | ||
Endpoint: "host:12345", | ||
Key: "invalid", | ||
}, | ||
err: errors.New("key should be in \"<token>:<service_name>\" format"), | ||
}, | ||
} | ||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
err := tc.cfg.Validate() | ||
if tc.err != nil { | ||
require.EqualError(t, err, tc.err.Error()) | ||
} else { | ||
require.NoError(t, err) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//go:generate mdatagen metadata.yaml | ||
|
||
// Package solarwindsapmsettingsextension | ||
package solarwindsapmsettingsextension // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/solarwindsapmsettingsextension" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package solarwindsapmsettingsextension // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/solarwindsapmsettingsextension" | ||
|
||
import ( | ||
"context" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/extension" | ||
"go.uber.org/zap" | ||
) | ||
|
||
type solarwindsapmSettingsExtension struct { | ||
logger *zap.Logger | ||
config *Config | ||
cancel context.CancelFunc | ||
} | ||
|
||
func newSolarwindsApmSettingsExtension(extensionCfg *Config, logger *zap.Logger) (extension.Extension, error) { | ||
settingsExtension := &solarwindsapmSettingsExtension{ | ||
config: extensionCfg, | ||
logger: logger, | ||
} | ||
return settingsExtension, nil | ||
} | ||
|
||
func (extension *solarwindsapmSettingsExtension) Start(_ context.Context, _ component.Host) error { | ||
extension.logger.Debug("Starting up solarwinds apm settings extension") | ||
_, extension.cancel = context.WithCancel(context.Background()) | ||
return nil | ||
} | ||
|
||
func (extension *solarwindsapmSettingsExtension) Shutdown(_ context.Context) error { | ||
extension.logger.Debug("Shutting down solarwinds apm settings extension") | ||
return nil | ||
} |
53 changes: 53 additions & 0 deletions
53
extension/solarwindsapmsettingsextension/extension_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package solarwindsapmsettingsextension | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/extension" | ||
"go.uber.org/zap" | ||
) | ||
|
||
func TestCreateExtension(t *testing.T) { | ||
conf := &Config{ | ||
Endpoint: "apm-testcollector.click:443", | ||
Key: "valid:unittest", | ||
Interval: "1s", | ||
} | ||
ex := createAnExtension(conf, t) | ||
require.NoError(t, ex.Shutdown(context.TODO())) | ||
} | ||
|
||
func TestCreateExtensionWrongEndpoint(t *testing.T) { | ||
conf := &Config{ | ||
Endpoint: "apm-testcollector.nothing:443", | ||
Key: "valid:unittest", | ||
Interval: "1s", | ||
} | ||
ex := createAnExtension(conf, t) | ||
require.NoError(t, ex.Shutdown(context.TODO())) | ||
} | ||
|
||
func TestCreateExtensionWrongKey(t *testing.T) { | ||
conf := &Config{ | ||
Endpoint: "apm-testcollector.click:443", | ||
Key: "invalid", | ||
Interval: "1s", | ||
} | ||
ex := createAnExtension(conf, t) | ||
require.NoError(t, ex.Shutdown(context.TODO())) | ||
} | ||
|
||
// create extension | ||
func createAnExtension(c *Config, t *testing.T) extension.Extension { | ||
logger, err := zap.NewProduction() | ||
require.NoError(t, err) | ||
ex, err := newSolarwindsApmSettingsExtension(c, logger) | ||
require.NoError(t, err) | ||
require.NoError(t, ex.Start(context.TODO(), nil)) | ||
return ex | ||
} |
Oops, something went wrong.