Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[extension/solarwindsapmsettingsextension] Overall structure of the new component #30153

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3811585
Added solarwindsapmsettingextension
jerrytfleung Oct 25, 2023
440d0a3
Renamed module
jerrytfleung Oct 25, 2023
35ea679
Added CODEOWNERS
jerrytfleung Nov 3, 2023
d68daa1
Changed module name
jerrytfleung Nov 3, 2023
ddd3881
Enabled extension test and delete SignatureKey from arguments
jerrytfleung Nov 29, 2023
6088191
Use Error instead of Fatal
jerrytfleung Nov 29, 2023
f96f440
Updated test cases
jerrytfleung Nov 29, 2023
590fe63
Updated go module name
jerrytfleung Nov 29, 2023
b644d37
Removed the hardcode DefaultEndpoint
jerrytfleung Dec 13, 2023
7f66b29
Updated README.md
jerrytfleung Dec 13, 2023
2bb218a
Meet the repo linting expectations
jerrytfleung Dec 20, 2023
6185f53
Meeting the requirement of 1st PR
jerrytfleung Dec 21, 2023
c9dfc87
Fulfill the linting requirements and remove concrete implementation f…
jerrytfleung Dec 21, 2023
e34cd3e
nits
jerrytfleung Dec 21, 2023
058dce4
Used errors.New instead of fmt.Errorf
jerrytfleung Dec 21, 2023
0ec104b
After gotidy
jerrytfleung Dec 21, 2023
bea14c8
Updated generated file
jerrytfleung Dec 21, 2023
b410429
Added contrib distributions
jerrytfleung Dec 21, 2023
0aa4cfc
nits
jerrytfleung Dec 21, 2023
8b0ff48
Updated
jerrytfleung Dec 21, 2023
c75ddb1
Removed yaml for chloggen in the first PR and updated otelcontribcol …
jerrytfleung Dec 21, 2023
59fa70c
Reverted allowlist.txt
jerrytfleung Dec 21, 2023
c77476b
Updated otelcontribcol
jerrytfleung Dec 21, 2023
9398765
Too early to update otelcontribcol, reverted
jerrytfleung Dec 21, 2023
3407e6c
commit contrib.yaml after make gendistributions
jerrytfleung Dec 21, 2023
47f289d
Updated go.mod & go.sum
jerrytfleung Dec 21, 2023
a963595
Update extension/solarwindsapmsettingsextension/metadata.yaml
jerrytfleung Jan 3, 2024
a0e4ab1
Regenerated the README.md & added add-solarwindsapmsettingsextension.…
jerrytfleung Jan 3, 2024
25624b0
Rerun make gendistributions to revert contrib.yaml
jerrytfleung Jan 3, 2024
b0bc88d
Rebased
jerrytfleung Jan 13, 2024
1358ce3
Updated collector version
jerrytfleung Jan 13, 2024
31e160f
Updated collector component version in go.mod
jerrytfleung Jan 13, 2024
df5e4d1
Updated dependencies
jerrytfleung Jan 13, 2024
a676bcb
Included this extension in otelcontribcol extensions test
jerrytfleung Jan 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -446,5 +447,6 @@ 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
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 @@ -79,6 +79,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 @@ -1185,6 +1186,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
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