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

Added MarshalerSizer Interface to facilitate creation of Sizer implementations #5929

Merged
merged 5 commits into from
Aug 18, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

### 💡 Enhancements 💡

- Added `MarshalerSizer` interface to `ptrace`, `plog`, and `pmetric` packages. `NewProtoMarshaler` now returns a `MarshalerSizer` (#5929)
- Add support to unmarshalls bytes into pmetric.Metrics with `jsoniter` in jsonUnmarshaler(#5433)
- Add httpprovider to allow loading config files stored in HTTP (#5810)
- Added `service.telemetry.traces.propagators` configuration to set propagators for collector's internal spans. (#5572)
Expand Down
6 changes: 6 additions & 0 deletions pdata/plog/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@

package plog // import "go.opentelemetry.io/collector/pdata/plog"

// MarshalerSizer is the interface that groups the basic Marshal and Size methods
type MarshalerSizer interface {
Marshaler
Sizer
}

// Marshaler marshals pdata.Logs into bytes.
type Marshaler interface {
// MarshalLogs the given pdata.Logs into bytes.
Expand Down
6 changes: 3 additions & 3 deletions pdata/plog/pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import (
otlplogs "go.opentelemetry.io/collector/pdata/internal/data/protogen/logs/v1"
)

// NewProtoMarshaler returns a Marshaler. Marshals to OTLP binary protobuf bytes.
func NewProtoMarshaler() Marshaler {
// NewProtoMarshaler returns a MarshalerSizer.
// Marshals to OTLP binary protobuf bytes and calculates the size of the marshaled Logs.
func NewProtoMarshaler() MarshalerSizer {
return newPbMarshaler()
}

// TODO(#3842): Figure out how we want to represent/return *Sizers.
type pbMarshaler struct{}

func newPbMarshaler() *pbMarshaler {
Expand Down
3 changes: 1 addition & 2 deletions pdata/plog/pb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ func TestProtoLogsUnmarshaler_error(t *testing.T) {
}

func TestProtoSizer(t *testing.T) {
sizer := NewProtoMarshaler().(Sizer)
marshaler := NewProtoMarshaler()
ld := NewLogs()
ld.ResourceLogs().AppendEmpty().ScopeLogs().AppendEmpty().LogRecords().AppendEmpty().SetSeverityText("error")

size := sizer.LogsSize(ld)
size := marshaler.LogsSize(ld)

bytes, err := marshaler.MarshalLogs(ld)
require.NoError(t, err)
Expand Down
6 changes: 6 additions & 0 deletions pdata/pmetric/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@

package pmetric // import "go.opentelemetry.io/collector/pdata/pmetric"

// MarshalerSizer is the interface that groups the basic Marshal and Size methods
type MarshalerSizer interface {
Marshaler
Sizer
}

// Marshaler marshals pmetric.Metrics into bytes.
type Marshaler interface {
// MarshalMetrics the given pmetric.Metrics into bytes.
Expand Down
6 changes: 3 additions & 3 deletions pdata/pmetric/pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import (
otlpmetrics "go.opentelemetry.io/collector/pdata/internal/data/protogen/metrics/v1"
)

// NewProtoMarshaler returns a Marshaler. Marshals to OTLP binary protobuf bytes.
func NewProtoMarshaler() Marshaler {
// NewProtoMarshaler returns a MarshalerSizer.
// Marshals to OTLP binary protobuf bytes and calculates the size of the marshaled Metrics.
func NewProtoMarshaler() MarshalerSizer {
return newPbMarshaler()
}

// TODO(#3842): Figure out how we want to represent/return *Sizers.
type pbMarshaler struct{}

func newPbMarshaler() *pbMarshaler {
Expand Down
3 changes: 1 addition & 2 deletions pdata/pmetric/pb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ func TestProtoMetricsUnmarshaler_error(t *testing.T) {
}

func TestProtoSizer(t *testing.T) {
sizer := NewProtoMarshaler().(Sizer)
marshaler := NewProtoMarshaler()
md := NewMetrics()
md.ResourceMetrics().AppendEmpty().ScopeMetrics().AppendEmpty().Metrics().AppendEmpty().SetName("foo")

size := sizer.MetricsSize(md)
size := marshaler.MetricsSize(md)

bytes, err := marshaler.MarshalMetrics(md)
require.NoError(t, err)
Expand Down
6 changes: 6 additions & 0 deletions pdata/ptrace/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@

package ptrace // import "go.opentelemetry.io/collector/pdata/ptrace"

// MarshalerSizer is the interface that groups the basic Marshal and Size methods
type MarshalerSizer interface {
Marshaler
Sizer
}

// Marshaler marshals pdata.Traces into bytes.
type Marshaler interface {
// MarshalTraces the given pdata.Traces into bytes.
Expand Down
6 changes: 3 additions & 3 deletions pdata/ptrace/pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import (
otlptrace "go.opentelemetry.io/collector/pdata/internal/data/protogen/trace/v1"
)

// NewProtoMarshaler returns a Marshaler. Marshals to OTLP binary protobuf bytes.
func NewProtoMarshaler() Marshaler {
// NewProtoMarshaler returns a MarshalerSizer.
// Marshals to OTLP binary protobuf bytes and calculates the size of the marshaled Traces.
func NewProtoMarshaler() MarshalerSizer {
return newPbMarshaler()
}

// TODO(#3842): Figure out how we want to represent/return *Sizers.
type pbMarshaler struct{}

func newPbMarshaler() *pbMarshaler {
Expand Down
3 changes: 1 addition & 2 deletions pdata/ptrace/pb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ func TestProtoTracesUnmarshaler_error(t *testing.T) {
}

func TestProtoSizer(t *testing.T) {
sizer := NewProtoMarshaler().(Sizer)
marshaler := NewProtoMarshaler()
td := NewTraces()
rms := td.ResourceSpans()
rms.AppendEmpty().ScopeSpans().AppendEmpty().Spans().AppendEmpty().SetName("foo")

size := sizer.TracesSize(td)
size := marshaler.TracesSize(td)

bytes, err := marshaler.MarshalTraces(td)
require.NoError(t, err)
Expand Down