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

sumologicexporter: use Sumo Logic Extension for authentication and to obtain endpoint #32383

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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/drosiek-exporter-extension.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: sumologicexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: use Sumo Logic Extension for authentication and to obtain endpoint

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

# (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]
4 changes: 4 additions & 0 deletions cmd/configschema/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ require (
github.com/mistifyio/go-zfs v2.1.2-0.20190413222219-f784269be439+incompatible // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-ps v1.0.0 // indirect
github.com/mitchellh/hashstructure v1.1.0 // indirect
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
github.com/mitchellh/mapstructure v1.5.1-0.20231216201459-8508981c8b6c // indirect
Expand Down Expand Up @@ -495,6 +496,7 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/extension/sigv4authextension v0.98.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/extension/storage/dbstorage v0.98.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/extension/storage/filestorage v0.98.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/extension/sumologicextension v0.98.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/cwlogs v0.98.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/metrics v0.98.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/proxy v0.98.0 // indirect
Expand Down Expand Up @@ -1149,3 +1151,5 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/extension/enco
replace github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding => ../../extension/encoding

replace github.com/open-telemetry/opentelemetry-collector-contrib/connector/grafanacloudconnector => ../../connector/grafanacloudconnector

replace github.com/open-telemetry/opentelemetry-collector-contrib/extension/sumologicextension => ../../extension/sumologicextension
2 changes: 2 additions & 0 deletions cmd/configschema/go.sum

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

24 changes: 19 additions & 5 deletions exporter/sumologicexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ package sumologicexporter // import "github.com/open-telemetry/opentelemetry-col
import (
"errors"
"fmt"
"net/url"
"time"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configauth"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/configretry"
"go.opentelemetry.io/collector/exporter/exporterhelper"

"github.com/open-telemetry/opentelemetry-collector-contrib/extension/sumologicextension"
)

// Config defines configuration for Sumo Logic exporter.
Expand Down Expand Up @@ -62,9 +67,12 @@ type Config struct {

// createDefaultClientConfig returns default http client settings
func createDefaultClientConfig() confighttp.ClientConfig {
config := confighttp.NewDefaultClientConfig()
config.Timeout = defaultTimeout
return config
return confighttp.ClientConfig{
Timeout: defaultTimeout,
Auth: &configauth.Authentication{
AuthenticatorID: component.NewID(sumologicextension.NewFactory().Type()),
},
}
}

// LogFormatType represents log_format
Expand Down Expand Up @@ -148,8 +156,14 @@ func (cfg *Config) Validate() error {
return fmt.Errorf("unexpected compression encoding: %s", cfg.CompressEncoding)
}

if len(cfg.ClientConfig.Endpoint) == 0 {
return errors.New("endpoint is not set")
if len(cfg.ClientConfig.Endpoint) == 0 && cfg.ClientConfig.Auth == nil {
return errors.New("no endpoint and no auth extension specified")
}

if _, err := url.Parse(cfg.ClientConfig.Endpoint); err != nil {
return fmt.Errorf("failed parsing endpoint URL: %s; err: %w",
cfg.ClientConfig.Endpoint, err,
)
}

if err := cfg.QueueSettings.Validate(); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions exporter/sumologicexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ func TestConfigValidation(t *testing.T) {
expectedErr: "unexpected compression encoding: test_format",
},
{
name: "invalid endpoint",
name: "no endpoint and no auth extension specified",
expectedErr: "no endpoint and no auth extension specified",
cfg: &Config{
LogFormat: "json",
MetricFormat: "carbon2",
Expand All @@ -67,7 +68,6 @@ func TestConfigValidation(t *testing.T) {
Timeout: defaultTimeout,
},
},
expectedErr: "endpoint is not set",
},
{
name: "invalid log format",
Expand Down
Loading