Skip to content

Commit

Permalink
[extension/solarwindsapmsettingsextension] Overall structure of the n…
Browse files Browse the repository at this point in the history
…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
jerrytfleung and atoulme authored Jan 23, 2024
1 parent f07bcda commit c89b81a
Show file tree
Hide file tree
Showing 23 changed files with 1,029 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .chloggen/add-solarwindsapmsettingsextension.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: 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]
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ extension/opampextension/ @open-telemetry/collect
extension/pprofextension/ @open-telemetry/collector-contrib-approvers @MovieStoreGuy
extension/remotetapextension/ @open-telemetry/collector-contrib-approvers @atoulme
extension/sigv4authextension/ @open-telemetry/collector-contrib-approvers @Aneurysm9 @erichsueh3
extension/solarwindsapmsettingsextension/ @open-telemetry/collector-contrib-approvers @jerrytfleung @cheempz
extension/storage/ @open-telemetry/collector-contrib-approvers @dmitryax @atoulme @djaglowski
extension/storage/dbstorage/ @open-telemetry/collector-contrib-approvers @dmitryax @atoulme
extension/storage/filestorage/ @open-telemetry/collector-contrib-approvers @djaglowski
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ body:
- extension/pprof
- extension/remotetap
- extension/sigv4auth
- extension/solarwindsapmsettings
- extension/storage
- extension/storage/dbstorage
- extension/storage/filestorage
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ body:
- extension/pprof
- extension/remotetap
- extension/sigv4auth
- extension/solarwindsapmsettings
- extension/storage
- extension/storage/dbstorage
- extension/storage/filestorage
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/other.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ body:
- extension/pprof
- extension/remotetap
- extension/sigv4auth
- extension/solarwindsapmsettings
- extension/storage
- extension/storage/dbstorage
- extension/storage/filestorage
Expand Down
2 changes: 2 additions & 0 deletions cmd/otelcontribcol/builder-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ extensions:
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/pprofextension v0.92.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/remotetapextension v0.92.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/sigv4authextension v0.92.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/solarwindsapmsettingsextension v0.92.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/storage v0.92.0
import: github.com/open-telemetry/opentelemetry-collector-contrib/extension/storage/filestorage
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/storage v0.92.0
Expand Down Expand Up @@ -449,6 +450,7 @@ replaces:
- github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/jaegerencodingextension => ../../extension/encoding/jaegerencodingextension
- github.com/open-telemetry/opentelemetry-collector-contrib/extension/remotetapextension => ../../extension/remotetapextension
- github.com/open-telemetry/opentelemetry-collector-contrib/extension/opampextension => ../../extension/opampextension
- github.com/open-telemetry/opentelemetry-collector-contrib/extension/solarwindsapmsettingsextension => ../../extension/solarwindsapmsettingsextension
- github.com/open-telemetry/opentelemetry-collector-contrib/testbed/mockdatasenders/mockdatadogagentexporter => ../../testbed/mockdatasenders/mockdatadogagentexporter
- github.com/open-telemetry/opentelemetry-collector-contrib/testbed => ../../testbed
- github.com/open-telemetry/opentelemetry-collector-contrib/receiver/namedpipereceiver => ../../receiver/namedpipereceiver
2 changes: 2 additions & 0 deletions cmd/otelcontribcol/components.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions cmd/otelcontribcol/extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ func TestDefaultExtensions(t *testing.T) {
return cfg
},
},
{
extension: "solarwindsapmsettings",
skipLifecycle: true, // Requires Solarwinds APM endpoint and token
},
}

extensionCount := 0
Expand Down
3 changes: 3 additions & 0 deletions cmd/otelcontribcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/extension/pprofextension v0.92.0
github.com/open-telemetry/opentelemetry-collector-contrib/extension/remotetapextension v0.92.0
github.com/open-telemetry/opentelemetry-collector-contrib/extension/sigv4authextension v0.92.0
github.com/open-telemetry/opentelemetry-collector-contrib/extension/solarwindsapmsettingsextension v0.92.0
github.com/open-telemetry/opentelemetry-collector-contrib/extension/storage v0.92.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.92.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.92.0
Expand Down Expand Up @@ -1186,6 +1187,8 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/extension/remo

replace github.com/open-telemetry/opentelemetry-collector-contrib/extension/opampextension => ../../extension/opampextension

replace github.com/open-telemetry/opentelemetry-collector-contrib/extension/solarwindsapmsettingsextension => ../../extension/solarwindsapmsettingsextension

replace github.com/open-telemetry/opentelemetry-collector-contrib/testbed/mockdatasenders/mockdatadogagentexporter => ../../testbed/mockdatasenders/mockdatadogagentexporter

replace github.com/open-telemetry/opentelemetry-collector-contrib/testbed => ../../testbed
Expand Down
1 change: 1 addition & 0 deletions extension/solarwindsapmsettingsextension/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
38 changes: 38 additions & 0 deletions extension/solarwindsapmsettingsextension/README.md
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`
41 changes: 41 additions & 0 deletions extension/solarwindsapmsettingsextension/config.go
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
}
66 changes: 66 additions & 0 deletions extension/solarwindsapmsettingsextension/config_test.go
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)
}
})
}
}
7 changes: 7 additions & 0 deletions extension/solarwindsapmsettingsextension/doc.go
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"
37 changes: 37 additions & 0 deletions extension/solarwindsapmsettingsextension/extension.go
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 extension/solarwindsapmsettingsextension/extension_test.go
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
}
Loading

0 comments on commit c89b81a

Please sign in to comment.