Skip to content

Commit

Permalink
[exporter/sumologic]: remove deprecated configuration options (#33012)
Browse files Browse the repository at this point in the history
**Description:**

remove deprecated configuration options and remove unused code

Depends on #33011

**Link to tracking Issue:**

#32315

**Testing:**

* Unit tests

**Documentation:**

* Update Readme

---------

Signed-off-by: Dominik Rosiek <drosiek@sumologic.com>
  • Loading branch information
sumo-drosiek authored May 14, 2024
1 parent fe8d190 commit b9ea5c1
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 573 deletions.
29 changes: 29 additions & 0 deletions .chloggen/drosiek-refactor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Use this changelog template to create an entry for release notes.

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

# 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: remove deprecated configuration options

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

# (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: |-
migration has been described in the following document
https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/v0.100.0/exporter/sumologicexporter#migration-to-new-architecture
# 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]
45 changes: 0 additions & 45 deletions exporter/sumologicexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,6 @@ exporters:
# default = 1_048_576 (1MB)
max_request_body_size: <max_request_body_size>
# List of regexes for attributes which should be send as metadata
# default = []
#
# This option is unsupported:
# https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/sumologicexporter#migration-to-new-architecture
metadata_attributes: [<regex>]
# format to use when sending logs to Sumo Logic, default = otlp,
log_format: {otlp, json, text}
Expand All @@ -105,44 +98,6 @@ exporters:
# default = false
decompose_otlp_histograms: {true, false}

# Template for Graphite format.
# this option affects graphite format only
# By default this is "%{_metric_}".
#
# Please regfer to Source temmplates for formatting explanation:
# https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/sumologicexporter#source-templates
#
# This option is unsupported:
# https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/sumologicexporter#migration-to-new-architecture
graphite_template: <template>

# Desired source category. Useful if you want to override the source category configured for the source.
#
# Please regfer to Source temmplates for formatting explanation:
# https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/sumologicexporter#source-templates
#
# This option is unsupported:
# https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/sumologicexporter#migration-to-new-architecture
source_category: <template>

# Desired source name. Useful if you want to override the source name configured for the source.
#
# Please regfer to Source temmplates for formatting explanation:
# https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/sumologicexporter#source-templates
#
# This option is unsupported:
# https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/sumologicexporter#migration-to-new-architecture
source_name: <template>

# Desired source host. Useful if you want to override the source hosy configured for the source.
#
# Please regfer to Source temmplates for formatting explanation:
# https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/sumologicexporter#source-templates
#
# This option is unsupported:
# https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/sumologicexporter#migration-to-new-architecture
source_host: <template>

# timeout is the timeout for every attempt to send data to the backend,
# maximum connection timeout is 55s, default = 5s
timeout: <timeout>
Expand Down
110 changes: 47 additions & 63 deletions exporter/sumologicexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,6 @@ type Config struct {
// Decompose OTLP Histograms into individual metrics, similar to how they're represented in Prometheus format
DecomposeOtlpHistograms bool `mapstructure:"decompose_otlp_histograms"`

// List of regexes for attributes which should be send as metadata
MetadataAttributes []string `mapstructure:"metadata_attributes"`

// Sumo specific options
// Desired source category.
// Useful if you want to override the source category configured for the source.
// Placeholders `%{attr_name}` will be replaced with attribute value for attr_name.
SourceCategory string `mapstructure:"source_category"`
// Desired source name.
// Useful if you want to override the source name configured for the source.
// Placeholders `%{attr_name}` will be replaced with attribute value for attr_name.
SourceName string `mapstructure:"source_name"`
// Desired host name.
// Useful if you want to override the source host configured for the source.
// Placeholders `%{attr_name}` will be replaced with attribute value for attr_name.
SourceHost string `mapstructure:"source_host"`
// Name of the client
Client string `mapstructure:"client"`

Expand All @@ -81,6 +65,53 @@ func createDefaultClientConfig() confighttp.ClientConfig {
}
}

func (cfg *Config) Validate() error {
switch cfg.LogFormat {
case OTLPLogFormat:
case JSONFormat:
case TextFormat:
default:
return fmt.Errorf("unexpected log format: %s", cfg.LogFormat)
}

switch cfg.MetricFormat {
case RemovedGraphiteFormat:
return fmt.Errorf("support for the graphite metric format was removed, please use prometheus or otlp instead")
case RemovedCarbon2Format:
return fmt.Errorf("support for the carbon2 metric format was removed, please use prometheus or otlp instead")
case PrometheusFormat:
case OTLPMetricFormat:
default:
return fmt.Errorf("unexpected metric format: %s", cfg.MetricFormat)
}

switch cfg.ClientConfig.Compression {
case configcompression.TypeGzip:
case configcompression.TypeDeflate:
case configcompression.TypeZstd:
case NoCompression:

default:
return fmt.Errorf("invalid compression encoding type: %v", cfg.ClientConfig.Compression)
}

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 {
return fmt.Errorf("queue settings has invalid configuration: %w", err)
}

return nil
}

// LogFormatType represents log_format
type LogFormatType string

Expand Down Expand Up @@ -141,50 +172,3 @@ const (
// DefaultStickySessionEnabled defines default StickySessionEnabled value
DefaultStickySessionEnabled bool = false
)

func (cfg *Config) Validate() error {
switch cfg.LogFormat {
case OTLPLogFormat:
case JSONFormat:
case TextFormat:
default:
return fmt.Errorf("unexpected log format: %s", cfg.LogFormat)
}

switch cfg.MetricFormat {
case RemovedGraphiteFormat:
return fmt.Errorf("support for the graphite metric format was removed, please use prometheus or otlp instead")
case RemovedCarbon2Format:
return fmt.Errorf("support for the carbon2 metric format was removed, please use prometheus or otlp instead")
case PrometheusFormat:
case OTLPMetricFormat:
default:
return fmt.Errorf("unexpected metric format: %s", cfg.MetricFormat)
}

switch cfg.ClientConfig.Compression {
case configcompression.TypeGzip:
case configcompression.TypeDeflate:
case configcompression.TypeZstd:
case NoCompression:

default:
return fmt.Errorf("invalid compression encoding type: %v", cfg.ClientConfig.Compression)
}

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 {
return fmt.Errorf("queue settings has invalid configuration: %w", err)
}

return nil
}
91 changes: 26 additions & 65 deletions exporter/sumologicexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,11 @@ type sumologicexporter struct {
host component.Host
logger *zap.Logger

sources sourceFormats
filter filter
prometheusFormatter prometheusFormatter
settings component.TelemetrySettings

clientLock sync.RWMutex
client *http.Client

prometheusFormatter prometheusFormatter

// Lock around data URLs is needed because the reconfiguration of the exporter
// can happen asynchronously whenever the exporter is re registering.
dataURLsLock sync.RWMutex
Expand All @@ -60,65 +57,35 @@ type sumologicexporter struct {
id component.ID
}

func initExporter(cfg *Config, settings component.TelemetrySettings) (*sumologicexporter, error) {

if cfg.MetricFormat == RemovedGraphiteFormat {
settings.Logger.Error("`metric_format: graphite` nad `graphite_template` are no longer supported. See https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/sumologicexporter#migration-to-new-architecture for more information")
}

if cfg.MetricFormat == RemovedCarbon2Format {
settings.Logger.Error("`metric_format: carbon` is no longer supported. See https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/sumologicexporter#migration-to-new-architecture for more information")
}

if len(cfg.MetadataAttributes) > 0 {
settings.Logger.Warn("`metadata_attributes: []` is deprecated and is going to be removed in the future. See https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/sumologicexporter#migration-to-new-architecture for more information")
}

if cfg.SourceCategory != "" {
settings.Logger.Warn("`source_category: <template>` is deprecated and is going to be removed in the future. See https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/sumologicexporter#migration-to-new-architecture for more information")
}

if cfg.SourceHost != "" {
settings.Logger.Warn("`source_host: <template>` is deprecated and is going to be removed in the future. See https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/sumologicexporter#migration-to-new-architecture for more information")
}

if cfg.SourceName != "" {
settings.Logger.Warn("`source_name: <template>` is deprecated and is going to be removed in the future. See https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/sumologicexporter#migration-to-new-architecture for more information")
}

sfs := newSourceFormats(cfg)

f, err := newFilter(cfg.MetadataAttributes)
if err != nil {
return nil, err
}

pf := newPrometheusFormatter()

func initExporter(cfg *Config, createSettings exporter.CreateSettings) *sumologicexporter {
se := &sumologicexporter{
logger: settings.Logger,
config: cfg,
sources: sfs,
filter: f,
prometheusFormatter: pf,
settings: settings,
config: cfg,
logger: createSettings.Logger,
// NOTE: client is now set in start()
prometheusFormatter: newPrometheusFormatter(),
id: createSettings.ID,
foundSumologicExtension: false,
}

return se, nil
se.logger.Info(
"Sumo Logic Exporter configured",
zap.String("log_format", string(cfg.LogFormat)),
zap.String("metric_format", string(cfg.MetricFormat)),
)

return se
}

func newLogsExporter(
ctx context.Context,
params exporter.CreateSettings,
cfg *Config,
set exporter.CreateSettings,
) (exporter.Logs, error) {
se, err := initExporter(cfg, set.TelemetrySettings)
if err != nil {
return nil, fmt.Errorf("failed to initialize the logs exporter: %w", err)
}
se := initExporter(cfg, params)

return exporterhelper.NewLogsExporter(
context.TODO(),
set,
ctx,
params,
cfg,
se.pushLogsData,
// Disable exporterhelper Timeout, since we are using a custom mechanism
Expand All @@ -132,17 +99,15 @@ func newLogsExporter(
}

func newMetricsExporter(
ctx context.Context,
params exporter.CreateSettings,
cfg *Config,
set exporter.CreateSettings,
) (exporter.Metrics, error) {
se, err := initExporter(cfg, set.TelemetrySettings)
if err != nil {
return nil, err
}
se := initExporter(cfg, params)

return exporterhelper.NewMetricsExporter(
context.TODO(),
set,
ctx,
params,
cfg,
se.pushMetricsData,
// Disable exporterhelper Timeout, since we are using a custom mechanism
Expand Down Expand Up @@ -286,8 +251,6 @@ func (se *sumologicexporter) pushLogsData(ctx context.Context, ld plog.Logs) err
se.logger,
se.config,
se.getHTTPClient(),
se.filter,
se.sources,
se.prometheusFormatter,
metricsURL,
logsURL,
Expand Down Expand Up @@ -365,8 +328,6 @@ func (se *sumologicexporter) pushMetricsData(ctx context.Context, md pmetric.Met
se.logger,
se.config,
se.getHTTPClient(),
se.filter,
se.sources,
se.prometheusFormatter,
metricsURL,
logsURL,
Expand Down
Loading

0 comments on commit b9ea5c1

Please sign in to comment.