Skip to content

Commit

Permalink
[chore] migrate fluentforward receiver to mdatagen (#33559)
Browse files Browse the repository at this point in the history
This migrates internal metrics from opencensus to mdatagen + otel

Fixes #33467

Signed-off-by: Alex Boten <[email protected]>
  • Loading branch information
codeboten authored Jun 14, 2024
1 parent 01efffd commit 753ecfd
Show file tree
Hide file tree
Showing 14 changed files with 287 additions and 227 deletions.
25 changes: 13 additions & 12 deletions receiver/fluentforwardreceiver/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,33 @@ package fluentforwardreceiver // import "github.com/open-telemetry/opentelemetry
import (
"context"

"go.opencensus.io/stats"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/receiver/receiverhelper"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/fluentforwardreceiver/observ"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/fluentforwardreceiver/internal/metadata"
)

// Collector acts as an aggregator of LogRecords so that we don't have to
// generate as many plog.Logs instances...we can pre-batch the LogRecord
// instances from several Forward events into one to hopefully reduce
// allocations and GC overhead.
type Collector struct {
nextConsumer consumer.Logs
eventCh <-chan Event
logger *zap.Logger
obsrecv *receiverhelper.ObsReport
nextConsumer consumer.Logs
eventCh <-chan Event
logger *zap.Logger
obsrecv *receiverhelper.ObsReport
telemetryBuilder *metadata.TelemetryBuilder
}

func newCollector(eventCh <-chan Event, next consumer.Logs, logger *zap.Logger, obsrecv *receiverhelper.ObsReport) *Collector {
func newCollector(eventCh <-chan Event, next consumer.Logs, logger *zap.Logger, obsrecv *receiverhelper.ObsReport, telemetryBuilder *metadata.TelemetryBuilder) *Collector {
return &Collector{
nextConsumer: next,
eventCh: eventCh,
logger: logger,
obsrecv: obsrecv,
nextConsumer: next,
eventCh: eventCh,
logger: logger,
obsrecv: obsrecv,
telemetryBuilder: telemetryBuilder,
}
}

Expand All @@ -55,7 +56,7 @@ func (c *Collector) processEvents(ctx context.Context) {
c.fillBufferUntilChanEmpty(logSlice)

logRecordCount := out.LogRecordCount()
stats.Record(context.Background(), observ.RecordsGenerated.M(int64(logRecordCount)))
c.telemetryBuilder.FluentRecordsGenerated.Add(ctx, int64(logRecordCount))
obsCtx := c.obsrecv.StartLogsOp(ctx)
err := c.nextConsumer.ConsumeLogs(obsCtx, out)
c.obsrecv.EndLogsOp(obsCtx, "fluent", logRecordCount, err)
Expand Down
47 changes: 47 additions & 0 deletions receiver/fluentforwardreceiver/documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[comment]: <> (Code generated by mdatagen. DO NOT EDIT.)

# fluentforward

## Internal Telemetry

The following telemetry is emitted by this component.

### fluent_closed_connections

Number of connections closed to the fluentforward receiver

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

### fluent_events_parsed

Number of Fluent events parsed successfully

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

### fluent_opened_connections

Number of connections opened to the fluentforward receiver

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

### fluent_parse_failures

Number of times Fluent messages failed to be decoded

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

### fluent_records_generated

Number of log records generated from Fluent forward input

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

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

2 changes: 1 addition & 1 deletion receiver/fluentforwardreceiver/generated_package_test.go

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

6 changes: 2 additions & 4 deletions receiver/fluentforwardreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.102.0
github.com/stretchr/testify v1.9.0
github.com/tinylib/msgp v1.1.9
go.opencensus.io v0.24.0
go.opentelemetry.io/collector/component v0.102.2-0.20240611143128-7dfb57b9ad1c
go.opentelemetry.io/collector/config/configtelemetry v0.102.2-0.20240611143128-7dfb57b9ad1c
go.opentelemetry.io/collector/confmap v0.102.2-0.20240611143128-7dfb57b9ad1c
go.opentelemetry.io/collector/consumer v0.102.2-0.20240611143128-7dfb57b9ad1c
go.opentelemetry.io/collector/pdata v1.9.1-0.20240611143128-7dfb57b9ad1c
go.opentelemetry.io/collector/receiver v0.102.2-0.20240611143128-7dfb57b9ad1c
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 @@ -26,7 +27,6 @@ require (
github.com/go-logr/stdr v1.2.2 // 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-20210331224755-41bb18bfe9da // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
Expand All @@ -44,11 +44,9 @@ require (
github.com/prometheus/common v0.54.0 // indirect
github.com/prometheus/procfs v0.15.0 // indirect
go.opentelemetry.io/collector v0.102.2-0.20240611143128-7dfb57b9ad1c // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.102.2-0.20240611143128-7dfb57b9ad1c // 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.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
Expand Down
Loading

0 comments on commit 753ecfd

Please sign in to comment.