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

[chore] migrate sumo exporter to mdatagen metrics #33663

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
39 changes: 39 additions & 0 deletions exporter/sumologicexporter/documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[comment]: <> (Code generated by mdatagen. DO NOT EDIT.)

# sumologic

## Internal Telemetry

The following telemetry is emitted by this component.

### exporter_requests_bytes

Total size of requests (in bytes)

| Unit | Metric Type | Value Type | Monotonic |
| ---- | ----------- | ---------- | --------- |
| By | Sum | Int | true |

### exporter_requests_duration

Duration of HTTP requests (in milliseconds)

| Unit | Metric Type | Value Type | Monotonic |
| ---- | ----------- | ---------- | --------- |
| ms | Sum | Int | true |

### exporter_requests_records

Total size of requests (in number of records)

| Unit | Metric Type | Value Type | Monotonic |
| ---- | ----------- | ---------- | --------- |
| {records} | Sum | Int | true |

### exporter_requests_sent

Number of requests

| Unit | Metric Type | Value Type | Monotonic |
| ---- | ----------- | ---------- | --------- |
| 1 | Sum | Int | true |
35 changes: 26 additions & 9 deletions exporter/sumologicexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"go.opentelemetry.io/collector/pdata/ptrace"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/sumologicexporter/internal/metadata"
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/sumologicextension"
)

Expand Down Expand Up @@ -55,18 +56,24 @@ type sumologicexporter struct {
stickySessionCookieLock sync.RWMutex
stickySessionCookie string

id component.ID
sender *sender
id component.ID
sender *sender
telemetryBuilder *metadata.TelemetryBuilder
}

func initExporter(cfg *Config, createSettings exporter.Settings) *sumologicexporter {
func initExporter(cfg *Config, set exporter.Settings) (*sumologicexporter, error) {
telemetryBuilder, err := metadata.NewTelemetryBuilder(set.TelemetrySettings)
if err != nil {
return nil, err
}
se := &sumologicexporter{
config: cfg,
logger: createSettings.Logger,
logger: set.Logger,
// NOTE: client is now set in start()
prometheusFormatter: newPrometheusFormatter(),
id: createSettings.ID,
id: set.ID,
foundSumologicExtension: false,
telemetryBuilder: telemetryBuilder,
}

se.logger.Info(
Expand All @@ -75,15 +82,18 @@ func initExporter(cfg *Config, createSettings exporter.Settings) *sumologicexpor
zap.String("metric_format", string(cfg.MetricFormat)),
)

return se
return se, nil
}

func newLogsExporter(
ctx context.Context,
params exporter.Settings,
cfg *Config,
) (exporter.Logs, error) {
se := initExporter(cfg, params)
se, err := initExporter(cfg, params)
if err != nil {
return nil, err
}

return exporterhelper.NewLogsExporter(
ctx,
Expand All @@ -105,7 +115,10 @@ func newMetricsExporter(
params exporter.Settings,
cfg *Config,
) (exporter.Metrics, error) {
se := initExporter(cfg, params)
se, err := initExporter(cfg, params)
if err != nil {
return nil, err
}

return exporterhelper.NewMetricsExporter(
ctx,
Expand All @@ -127,7 +140,10 @@ func newTracesExporter(
params exporter.Settings,
cfg *Config,
) (exporter.Traces, error) {
se := initExporter(cfg, params)
se, err := initExporter(cfg, params)
if err != nil {
return nil, err
}

return exporterhelper.NewTracesExporter(
ctx,
Expand Down Expand Up @@ -243,6 +259,7 @@ func (se *sumologicexporter) configure(ctx context.Context) error {
se.StickySessionCookie,
se.SetStickySessionCookie,
se.id,
se.telemetryBuilder,
)

return nil
Expand Down
22 changes: 8 additions & 14 deletions exporter/sumologicexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ import (
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/consumer/consumererror"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exportertest"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/pdata/ptrace"
"go.uber.org/zap"
)

func logRecordsToLogs(records []plog.LogRecord) plog.Logs {
Expand Down Expand Up @@ -54,14 +53,6 @@ func createTestConfig() *Config {
return config
}

func createExporterCreateSettings() exporter.Settings {
return exporter.Settings{
TelemetrySettings: component.TelemetrySettings{
Logger: zap.NewNop(),
},
}
}

// prepareExporterTest prepares an exporter test object using provided config
// and a slice of callbacks to be called for subsequent requests coming being
// sent to the server.
Expand Down Expand Up @@ -91,7 +82,8 @@ func prepareExporterTest(t *testing.T, cfg *Config, cb []func(w http.ResponseWri
cfg.ClientConfig.Endpoint = testServer.URL
cfg.ClientConfig.Auth = nil

exp := initExporter(cfg, createExporterCreateSettings())
exp, err := initExporter(cfg, exportertest.NewNopSettings())
require.NoError(t, err)

require.NoError(t, exp.start(context.Background(), componenttest.NewNopHost()))

Expand Down Expand Up @@ -244,7 +236,7 @@ func TestPartiallyFailed(t *testing.T) {
}

func TestInvalidHTTPCLient(t *testing.T) {
exp := initExporter(&Config{
exp, err := initExporter(&Config{
ClientConfig: confighttp.ClientConfig{
Endpoint: "test_endpoint",
TLSSetting: configtls.ClientConfig{
Expand All @@ -253,7 +245,8 @@ func TestInvalidHTTPCLient(t *testing.T) {
},
},
},
}, createExporterCreateSettings())
}, exportertest.NewNopSettings())
require.NoError(t, err)

assert.EqualError(t,
exp.start(context.Background(), componenttest.NewNopHost()),
Expand Down Expand Up @@ -516,7 +509,8 @@ func Benchmark_ExporterPushLogs(b *testing.B) {
cfg := createConfig()
cfg.ClientConfig.Endpoint = testServer.URL

exp := initExporter(cfg, createExporterCreateSettings())
exp, err := initExporter(cfg, exportertest.NewNopSettings())
require.NoError(b, err)
require.NoError(b, exp.start(context.Background(), componenttest.NewNopHost()))
defer func() {
require.NoError(b, exp.shutdown(context.Background()))
Expand Down

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

2 changes: 1 addition & 1 deletion exporter/sumologicexporter/generated_package_test.go

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

8 changes: 3 additions & 5 deletions exporter/sumologicexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ require (
github.com/klauspost/compress v1.17.9
github.com/open-telemetry/opentelemetry-collector-contrib/extension/sumologicextension v0.104.0
github.com/stretchr/testify v1.9.0
go.opencensus.io v0.24.0
go.opentelemetry.io/collector/component v0.104.0
go.opentelemetry.io/collector/config/configauth v0.104.0
go.opentelemetry.io/collector/config/configcompression v1.11.0
go.opentelemetry.io/collector/config/confighttp v0.104.0
go.opentelemetry.io/collector/config/configretry v1.11.0
go.opentelemetry.io/collector/config/configtelemetry v0.104.0
go.opentelemetry.io/collector/config/configtls v0.104.0
go.opentelemetry.io/collector/confmap v0.104.0
go.opentelemetry.io/collector/consumer v0.104.0
go.opentelemetry.io/collector/exporter v0.104.0
go.opentelemetry.io/collector/pdata v1.11.0
go.opentelemetry.io/otel v1.27.0
go.opentelemetry.io/otel/metric v1.27.0
go.opentelemetry.io/otel/sdk/metric v1.27.0
go.opentelemetry.io/otel/trace v1.27.0
go.uber.org/goleak v1.3.0
go.uber.org/zap v1.27.0
Expand All @@ -37,7 +39,6 @@ require (
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
Expand Down Expand Up @@ -65,17 +66,14 @@ require (
github.com/yusufpapurcu/wmi v1.2.4 // indirect
go.opentelemetry.io/collector v0.104.0 // indirect
go.opentelemetry.io/collector/config/configopaque v1.11.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.104.0 // indirect
go.opentelemetry.io/collector/config/internal v0.104.0 // indirect
go.opentelemetry.io/collector/extension v0.104.0 // indirect
go.opentelemetry.io/collector/extension/auth v0.104.0 // indirect
go.opentelemetry.io/collector/featuregate v1.11.0 // indirect
go.opentelemetry.io/collector/receiver v0.104.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0 // indirect
go.opentelemetry.io/otel v1.27.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.49.0 // indirect
go.opentelemetry.io/otel/sdk v1.27.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.27.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sys v0.21.0 // indirect
Expand Down
Loading