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

[wip][chore] migrate away from opencensus over to otel #33664

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

# splunk_hec

## Internal Telemetry

The following telemetry is emitted by this component.

### otelcol_exporter_splunkhec_heartbeats_failed

number of heartbeats failed

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

### otelcol_exporter_splunkhec_heartbeats_sent

number of heartbeats sent

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

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

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

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

6 changes: 3 additions & 3 deletions exporter/splunkhecexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ require (
go.opentelemetry.io/collector/config/confighttp v0.103.0
go.opentelemetry.io/collector/config/configopaque v1.10.0
go.opentelemetry.io/collector/config/configretry v0.103.0
go.opentelemetry.io/collector/config/configtelemetry v0.103.0
go.opentelemetry.io/collector/config/configtls v0.103.0
go.opentelemetry.io/collector/confmap v0.103.0
go.opentelemetry.io/collector/consumer v0.103.0
go.opentelemetry.io/collector/exporter v0.103.0
go.opentelemetry.io/collector/pdata v1.10.0
go.opentelemetry.io/collector/semconv v0.103.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/multierr v1.11.0
Expand Down Expand Up @@ -91,17 +94,14 @@ require (
go.opentelemetry.io/collector v0.103.0 // indirect
go.opentelemetry.io/collector/config/configauth v0.103.0 // indirect
go.opentelemetry.io/collector/config/configcompression v1.10.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.103.0 // indirect
go.opentelemetry.io/collector/config/internal v0.103.0 // indirect
go.opentelemetry.io/collector/extension v0.103.0 // indirect
go.opentelemetry.io/collector/extension/auth v0.103.0 // indirect
go.opentelemetry.io/collector/featuregate v1.10.0 // indirect
go.opentelemetry.io/collector/receiver v0.103.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
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.26.0 // indirect
Expand Down
67 changes: 16 additions & 51 deletions exporter/splunkhecexporter/heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,15 @@
"runtime"
"time"

"go.opencensus.io/stats"
"go.opencensus.io/stats/view"
"go.opencensus.io/tag"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/splunkhecexporter/internal/metadata"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk"
)

const (
metricsPrefix = "otelcol_exporter_splunkhec_"
defaultHBSentMetricsName = metricsPrefix + "heartbeats_sent"
defaultHBFailedMetricsName = metricsPrefix + "heartbeats_failed"
)

type heartbeater struct {
hbDoneChan chan struct{}
}
Expand All @@ -42,46 +36,20 @@
return nil
}

var heartbeatsSent, heartbeatsFailed *stats.Int64Measure
var tagMutators []tag.Mutator
var telemetryBuilder *metadata.TelemetryBuilder
var attrs attribute.Set
if config.Telemetry.Enabled {
overrides := config.Telemetry.OverrideMetricsNames
// TODO: handle overrides, this could be done w/ views in configuration
// overrides := config.Telemetry.OverrideMetricsNames
extraAttributes := config.Telemetry.ExtraAttributes
var tags []tag.Key
tagMutators = []tag.Mutator{}
var attributes []attribute.KeyValue
for key, val := range extraAttributes {
newTag, _ := tag.NewKey(key)
tags = append(tags, newTag)
tagMutators = append(tagMutators, tag.Insert(newTag, val))
}

heartbeatsSent = stats.Int64(
getMetricsName(overrides, defaultHBSentMetricsName),
"number of heartbeats sent",
stats.UnitDimensionless)

heartbeatsSentView := &view.View{
Name: heartbeatsSent.Name(),
Description: heartbeatsSent.Description(),
TagKeys: tags,
Measure: heartbeatsSent,
Aggregation: view.Sum(),
}

heartbeatsFailed = stats.Int64(
getMetricsName(overrides, defaultHBFailedMetricsName),
"number of heartbeats failed",
stats.UnitDimensionless)

heartbeatsFailedView := &view.View{
Name: heartbeatsFailed.Name(),
Description: heartbeatsFailed.Description(),
TagKeys: tags,
Measure: heartbeatsFailed,
Aggregation: view.Sum(),
attributes = append(attributes, attribute.String(key, val))
}
attrs = attribute.NewSet(attributes...)

if err := view.Register(heartbeatsSentView, heartbeatsFailedView); err != nil {
var err error
if telemetryBuilder, err = metadata.NewTelemetryBuilder(); err != nil {

Check failure on line 52 in exporter/splunkhecexporter/heartbeat.go

View workflow job for this annotation

GitHub Actions / govulncheck (cmd-1)

not enough arguments in call to metadata.NewTelemetryBuilder

Check failure on line 52 in exporter/splunkhecexporter/heartbeat.go

View workflow job for this annotation

GitHub Actions / govulncheck (exporter-3)

not enough arguments in call to metadata.NewTelemetryBuilder

Check failure on line 52 in exporter/splunkhecexporter/heartbeat.go

View workflow job for this annotation

GitHub Actions / lint-matrix (linux, other)

not enough arguments in call to metadata.NewTelemetryBuilder

Check failure on line 52 in exporter/splunkhecexporter/heartbeat.go

View workflow job for this annotation

GitHub Actions / lint-matrix (windows, other)

not enough arguments in call to metadata.NewTelemetryBuilder

Check failure on line 52 in exporter/splunkhecexporter/heartbeat.go

View workflow job for this annotation

GitHub Actions / unittest-matrix (1.21.11, ubuntu-latest, other)

not enough arguments in call to metadata.NewTelemetryBuilder

Check failure on line 52 in exporter/splunkhecexporter/heartbeat.go

View workflow job for this annotation

GitHub Actions / unittest-matrix (1.21.11, ubuntu-latest, other)

not enough arguments in call to metadata.NewTelemetryBuilder

Check failure on line 52 in exporter/splunkhecexporter/heartbeat.go

View workflow job for this annotation

GitHub Actions / unittest-matrix (1.22.4, ubuntu-latest, other)

not enough arguments in call to metadata.NewTelemetryBuilder

Check failure on line 52 in exporter/splunkhecexporter/heartbeat.go

View workflow job for this annotation

GitHub Actions / unittest-matrix (1.22.4, ubuntu-latest, other)

not enough arguments in call to metadata.NewTelemetryBuilder
return nil
}
}
Expand All @@ -99,7 +67,7 @@
case <-ticker.C:
err := hbter.sendHeartbeat(config, buildInfo, pushLogFn)
if config.Telemetry.Enabled {
observe(heartbeatsSent, heartbeatsFailed, tagMutators, err)
observe(telemetryBuilder, attrs, err)
}
}
}
Expand All @@ -116,14 +84,11 @@
}

// there is only use case for open census metrics recording for now. Extend to use open telemetry in the future.
func observe(heartbeatsSent *stats.Int64Measure, heartbeatsFailed *stats.Int64Measure, tagMutators []tag.Mutator, err error) {
var counter *stats.Int64Measure
func observe(telemetryBuilder *metadata.TelemetryBuilder, attrs attribute.Set, err error) {
if err == nil {
counter = heartbeatsSent
} else {
counter = heartbeatsFailed
telemetryBuilder.OtelcolExporterSplunkhecHeartbeatsSent.Add(context.Background(), 1, metric.WithAttributeSet(attrs))
}
_ = stats.RecordWithTags(context.Background(), tagMutators, counter.M(1))
telemetryBuilder.OtelcolExporterSplunkhecHeartbeatsFailed.Add(context.Background(), 1, metric.WithAttributeSet(attrs))
}

func generateHeartbeatLog(hecToOtelAttrs splunk.HecToOtelAttrs, buildInfo component.BuildInfo) plog.Logs {
Expand Down

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

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

22 changes: 17 additions & 5 deletions exporter/splunkhecexporter/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,20 @@ tests:
retry_on_failure:
enabled: false
expect_consumer_error: true
goleak:
ignore:
top:
# See https://github.com/census-instrumentation/opencensus-go/issues/1191 for more information.
- "go.opencensus.io/stats/view.(*worker).start"

telemetry:
metrics:
otelcol_exporter_splunkhec_heartbeats_sent:
enabled: true
description: number of heartbeats sent
unit: "1"
sum:
value_type: int
monotonic: true
otelcol_exporter_splunkhec_heartbeats_failed:
enabled: true
description: number of heartbeats failed
unit: "1"
sum:
value_type: int
monotonic: true
Loading