Skip to content

Commit

Permalink
fix: update go.opentelemetry.io/collector/pdata from v0.48.0 to v0.49…
Browse files Browse the repository at this point in the history
….0 (#10984)
  • Loading branch information
jacobmarble authored and MyaLongmire committed Jul 6, 2022
1 parent 2e2d1de commit 742e4cf
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 45 deletions.
1 change: 1 addition & 0 deletions docs/LICENSE_OF_DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ following works:
- go.mongodb.org/mongo-driver [Apache License 2.0](https://github.com/mongodb/mongo-go-driver/blob/master/LICENSE)
- go.opencensus.io [Apache License 2.0](https://github.com/census-instrumentation/opencensus-go/blob/master/LICENSE)
- go.opentelemetry.io/collector/model [Apache License 2.0](https://github.com/open-telemetry/opentelemetry-collector/blob/main/LICENSE)
- go.opentelemetry.io/collector/pdata [Apache License 2.0](https://github.com/open-telemetry/opentelemetry-collector/blob/main/LICENSE)
- go.starlark.net [BSD 3-Clause "New" or "Revised" License](https://github.com/google/starlark-go/blob/master/LICENSE)
- go.uber.org/atomic [MIT License](https://pkg.go.dev/go.uber.org/atomic?tab=licenses)
- go.uber.org/multierr [MIT License](https://pkg.go.dev/go.uber.org/multierr?tab=licenses)
Expand Down
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ require (
github.com/hashicorp/consul/api v1.12.0
github.com/hashicorp/go-uuid v1.0.2
github.com/influxdata/go-syslog/v3 v3.0.0
github.com/influxdata/influxdb-observability/common v0.2.17
github.com/influxdata/influxdb-observability/influx2otel v0.2.17
github.com/influxdata/influxdb-observability/otel2influx v0.2.17
github.com/influxdata/influxdb-observability/common v0.2.18
github.com/influxdata/influxdb-observability/influx2otel v0.2.18
github.com/influxdata/influxdb-observability/otel2influx v0.2.18
github.com/influxdata/line-protocol/v2 v2.2.1
github.com/influxdata/tail v1.0.1-0.20210707231403-b283181d1fa7
github.com/influxdata/toml v0.0.0-20190415235208-270119a8ce65
Expand Down Expand Up @@ -139,7 +139,7 @@ require (
github.com/xdg/scram v1.0.5
github.com/yuin/goldmark v1.4.1
go.mongodb.org/mongo-driver v1.9.0
go.opentelemetry.io/collector/model v0.48.0
go.opentelemetry.io/collector/pdata v0.49.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.28.0
go.opentelemetry.io/otel/metric v0.28.0
go.opentelemetry.io/otel/sdk/metric v0.28.0
Expand Down Expand Up @@ -335,6 +335,7 @@ require (
github.com/yusufpapurcu/wmi v1.2.2 // indirect
go.etcd.io/etcd/api/v3 v3.5.0 // indirect
go.opencensus.io v0.23.0 // indirect
go.opentelemetry.io/collector/model v0.49.0 // indirect
go.opentelemetry.io/otel v1.6.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.6.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.28.0 // indirect
Expand Down
18 changes: 10 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1297,12 +1297,12 @@ github.com/influxdata/flux v0.65.1/go.mod h1:J754/zds0vvpfwuq7Gc2wRdVwEodfpCFM7m
github.com/influxdata/go-syslog/v3 v3.0.0 h1:jichmjSZlYK0VMmlz+k4WeOQd7z745YLsvGMqwtYt4I=
github.com/influxdata/go-syslog/v3 v3.0.0/go.mod h1:tulsOp+CecTAYC27u9miMgq21GqXRW6VdKbOG+QSP4Q=
github.com/influxdata/influxdb v1.8.4/go.mod h1:JugdFhsvvI8gadxOI6noqNeeBHvWNTbfYGtiAn+2jhI=
github.com/influxdata/influxdb-observability/common v0.2.17 h1:nl1BpGcs00mctFo4FzuB3jZKIoCEEuNr9SNBvmbijss=
github.com/influxdata/influxdb-observability/common v0.2.17/go.mod h1:fuVPmy5B3kp9xKiUhqAtsAd9s+7CXafOCdR/AkxVG/4=
github.com/influxdata/influxdb-observability/influx2otel v0.2.17 h1:kiWPPbAyzUTatUb2QCZPThY6yvwRZyvYU+WSDoWjREo=
github.com/influxdata/influxdb-observability/influx2otel v0.2.17/go.mod h1:JmAH/hVWjdvSEd9EjtYeX8K8Z4OOjPrjEI9SoHjMuNo=
github.com/influxdata/influxdb-observability/otel2influx v0.2.17 h1:7EspR0ClC+p7lFOajV+QmzgB6siO/qS6RxFNVfhQptY=
github.com/influxdata/influxdb-observability/otel2influx v0.2.17/go.mod h1:Qhw4L2S4ho6gTMIZHRSzxdKMJi4QsVn2J+NQp4f41Qw=
github.com/influxdata/influxdb-observability/common v0.2.18 h1:M+49hbNmZ5/bbUDMgtsbY4qqR/xtWEc3VnNAw/oa+Pk=
github.com/influxdata/influxdb-observability/common v0.2.18/go.mod h1:5wAWFtOFjmYo2tgi/S0wWC4z+inxFzOeAxEpYqIdcWg=
github.com/influxdata/influxdb-observability/influx2otel v0.2.18 h1:4pWyw6Jan9TTlSnc7N/sgfOSCSD/5fDtd/FP12uw7lE=
github.com/influxdata/influxdb-observability/influx2otel v0.2.18/go.mod h1:bU6jIF+uxOC0S3G2i9ilPFIQS0GJFSgUqVVqfJ7JzLA=
github.com/influxdata/influxdb-observability/otel2influx v0.2.18 h1:x1o5C36t6KBkx0//mRl3nMLBIJKLOe463kWhTRh12Uo=
github.com/influxdata/influxdb-observability/otel2influx v0.2.18/go.mod h1:A4Y9+52yOPuNXuvbHwKKX70RhrtfNfmoZCVG6xj6qoQ=
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
github.com/influxdata/influxql v1.1.1-0.20200828144457-65d3ef77d385/go.mod h1:gHp9y86a/pxhjJ+zMjNXiQAA197Xk9wLxaz+fGG+kWk=
github.com/influxdata/line-protocol v0.0.0-20180522152040-32c6aa80de5e/go.mod h1:4kt73NQhadE3daL3WhR5EJ/J2ocX0PZzwxQ0gXJ7oFE=
Expand Down Expand Up @@ -2284,8 +2284,10 @@ go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
go.opencensus.io v0.23.0 h1:gqCw0LfLxScz8irSi8exQc7fyQ0fKQU/qnC/X8+V/1M=
go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E=
go.opentelemetry.io/collector v0.28.0/go.mod h1:AP/BTXwo1eedoJO7V+HQ68CSvJU1lcdqOzJCgt1VsNs=
go.opentelemetry.io/collector/model v0.48.0 h1:xmN4LdZ92q6PZnaKhMdIlC5KGtPJeOYaWCnA1PQ2oZw=
go.opentelemetry.io/collector/model v0.48.0/go.mod h1:1QVYv8TqsTMt9wVC5BUF9fqMVtk2C5EclWDnuVqdKoU=
go.opentelemetry.io/collector/model v0.49.0 h1:mbUSNgpaBE3GWmzGsRb5t0xILpXIVYv7scPTTfoMt6c=
go.opentelemetry.io/collector/model v0.49.0/go.mod h1:nOYQv9KoFPs6ihJwOi24qB209EOhS9HkwhGj54YiEAw=
go.opentelemetry.io/collector/pdata v0.49.0 h1:aYj5rOlRC0x7lGXbc185LMsMMoY/pjOTXr5s1O2SzXs=
go.opentelemetry.io/collector/pdata v0.49.0/go.mod h1:YwmKuiFhNgtmhRdpi8Q8FAWPa0AwJTCSlssSsAtuRcY=
go.opentelemetry.io/otel v0.7.0/go.mod h1:aZMyHG5TqDOXEgH2tyLiXSUKly1jT3yqE9PmrzIeCdo=
go.opentelemetry.io/otel v1.6.0 h1:YV6GkGe/Ag2PKsm4rjlqdSNs0w0A5ZzxeGkxhx1T+t4=
go.opentelemetry.io/otel v1.6.0/go.mod h1:bfJD2DZVw0LBxghOTlgnlI0CV3hLDu9XF/QKOUXMTQQ=
Expand Down
22 changes: 12 additions & 10 deletions plugins/inputs/opentelemetry/grpc_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ package opentelemetry
import (
"context"
"fmt"
"go.opentelemetry.io/collector/pdata/plog/plogotlp"
"go.opentelemetry.io/collector/pdata/pmetric/pmetricotlp"
"go.opentelemetry.io/collector/pdata/ptrace/ptraceotlp"

"github.com/influxdata/influxdb-observability/common"
"github.com/influxdata/influxdb-observability/otel2influx"
"go.opentelemetry.io/collector/model/otlpgrpc"
)

type traceService struct {
converter *otel2influx.OtelTracesToLineProtocol
writer *writeToAccumulator
}

var _ otlpgrpc.TracesServer = (*traceService)(nil)
var _ ptraceotlp.Server = (*traceService)(nil)

func newTraceService(logger common.Logger, writer *writeToAccumulator) *traceService {
converter := otel2influx.NewOtelTracesToLineProtocol(logger)
Expand All @@ -24,17 +26,17 @@ func newTraceService(logger common.Logger, writer *writeToAccumulator) *traceSer
}
}

func (s *traceService) Export(ctx context.Context, req otlpgrpc.TracesRequest) (otlpgrpc.TracesResponse, error) {
func (s *traceService) Export(ctx context.Context, req ptraceotlp.Request) (ptraceotlp.Response, error) {
err := s.converter.WriteTraces(ctx, req.Traces(), s.writer)
return otlpgrpc.NewTracesResponse(), err
return ptraceotlp.NewResponse(), err
}

type metricsService struct {
converter *otel2influx.OtelMetricsToLineProtocol
writer *writeToAccumulator
}

var _ otlpgrpc.MetricsServer = (*metricsService)(nil)
var _ pmetricotlp.Server = (*metricsService)(nil)

var metricsSchemata = map[string]common.MetricsSchema{
"prometheus-v1": common.MetricsSchemaTelegrafPrometheusV1,
Expand All @@ -57,17 +59,17 @@ func newMetricsService(logger common.Logger, writer *writeToAccumulator, schema
}, nil
}

func (s *metricsService) Export(ctx context.Context, req otlpgrpc.MetricsRequest) (otlpgrpc.MetricsResponse, error) {
func (s *metricsService) Export(ctx context.Context, req pmetricotlp.Request) (pmetricotlp.Response, error) {
err := s.converter.WriteMetrics(ctx, req.Metrics(), s.writer)
return otlpgrpc.NewMetricsResponse(), err
return pmetricotlp.NewResponse(), err
}

type logsService struct {
converter *otel2influx.OtelLogsToLineProtocol
writer *writeToAccumulator
}

var _ otlpgrpc.LogsServer = (*logsService)(nil)
var _ plogotlp.Server = (*logsService)(nil)

func newLogsService(logger common.Logger, writer *writeToAccumulator) *logsService {
converter := otel2influx.NewOtelLogsToLineProtocol(logger)
Expand All @@ -77,7 +79,7 @@ func newLogsService(logger common.Logger, writer *writeToAccumulator) *logsServi
}
}

func (s *logsService) Export(ctx context.Context, req otlpgrpc.LogsRequest) (otlpgrpc.LogsResponse, error) {
func (s *logsService) Export(ctx context.Context, req plogotlp.Request) (plogotlp.Response, error) {
err := s.converter.WriteLogs(ctx, req.Logs(), s.writer)
return otlpgrpc.NewLogsResponse(), err
return plogotlp.NewResponse(), err
}
10 changes: 6 additions & 4 deletions plugins/inputs/opentelemetry/opentelemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package opentelemetry

import (
"fmt"
"go.opentelemetry.io/collector/pdata/plog/plogotlp"
"go.opentelemetry.io/collector/pdata/pmetric/pmetricotlp"
"go.opentelemetry.io/collector/pdata/ptrace/ptraceotlp"
"net"
"sync"
"time"
Expand All @@ -10,7 +13,6 @@ import (
"github.com/influxdata/telegraf/config"
"github.com/influxdata/telegraf/plugins/common/tls"
"github.com/influxdata/telegraf/plugins/inputs"
"go.opentelemetry.io/collector/model/otlpgrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
)
Expand Down Expand Up @@ -49,13 +51,13 @@ func (o *OpenTelemetry) Start(accumulator telegraf.Accumulator) error {
influxWriter := &writeToAccumulator{accumulator}
o.grpcServer = grpc.NewServer(grpcOptions...)

otlpgrpc.RegisterTracesServer(o.grpcServer, newTraceService(logger, influxWriter))
ptraceotlp.RegisterServer(o.grpcServer, newTraceService(logger, influxWriter))
ms, err := newMetricsService(logger, influxWriter, o.MetricsSchema)
if err != nil {
return err
}
otlpgrpc.RegisterMetricsServer(o.grpcServer, ms)
otlpgrpc.RegisterLogsServer(o.grpcServer, newLogsService(logger, influxWriter))
pmetricotlp.RegisterServer(o.grpcServer, ms)
plogotlp.RegisterServer(o.grpcServer, newLogsService(logger, influxWriter))

if o.listener == nil {
o.listener, err = net.Listen("tcp", o.ServiceAddress)
Expand Down
8 changes: 4 additions & 4 deletions plugins/outputs/opentelemetry/opentelemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package opentelemetry

import (
"context"
"go.opentelemetry.io/collector/pdata/pmetric/pmetricotlp"
"google.golang.org/grpc/credentials/insecure"
"time"

Expand All @@ -11,7 +12,6 @@ import (
"github.com/influxdata/telegraf/config"
"github.com/influxdata/telegraf/plugins/common/tls"
"github.com/influxdata/telegraf/plugins/outputs"
"go.opentelemetry.io/collector/model/otlpgrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"

Expand All @@ -33,7 +33,7 @@ type OpenTelemetry struct {

metricsConverter *influx2otel.LineProtocolToOtelMetrics
grpcClientConn *grpc.ClientConn
metricsServiceClient otlpgrpc.MetricsClient
metricsServiceClient pmetricotlp.Client
callOptions []grpc.CallOption
}

Expand Down Expand Up @@ -69,7 +69,7 @@ func (o *OpenTelemetry) Connect() error {
return err
}

metricsServiceClient := otlpgrpc.NewMetricsClient(grpcClientConn)
metricsServiceClient := pmetricotlp.NewClient(grpcClientConn)

o.metricsConverter = metricsConverter
o.grpcClientConn = grpcClientConn
Expand Down Expand Up @@ -117,7 +117,7 @@ func (o *OpenTelemetry) Write(metrics []telegraf.Metric) error {
}
}

md := otlpgrpc.NewMetricsRequest()
md := pmetricotlp.NewRequest()
md.SetMetrics(batch.GetMetrics())
if md.Metrics().ResourceMetrics().Len() == 0 {
return nil
Expand Down
30 changes: 15 additions & 15 deletions plugins/outputs/opentelemetry/opentelemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package opentelemetry

import (
"context"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/pdata/pmetric/pmetricotlp"
"google.golang.org/grpc/credentials/insecure"
"net"
"strings"
Expand All @@ -15,15 +18,12 @@ import (
"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/model/otlp"
"go.opentelemetry.io/collector/model/otlpgrpc"
"go.opentelemetry.io/collector/model/pdata"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
)

func TestOpenTelemetry(t *testing.T) {
expect := pdata.NewMetrics()
expect := pmetric.NewMetrics()
{
rm := expect.ResourceMetrics().AppendEmpty()
rm.Resource().Attributes().InsertString("host.name", "potato")
Expand All @@ -32,10 +32,10 @@ func TestOpenTelemetry(t *testing.T) {
ilm.Scope().SetName("My Library Name")
m := ilm.Metrics().AppendEmpty()
m.SetName("cpu_temp")
m.SetDataType(pdata.MetricDataTypeGauge)
m.SetDataType(pmetric.MetricDataTypeGauge)
dp := m.Gauge().DataPoints().AppendEmpty()
dp.Attributes().InsertString("foo", "bar")
dp.SetTimestamp(pdata.Timestamp(1622848686000000000))
dp.SetTimestamp(pcommon.Timestamp(1622848686000000000))
dp.SetDoubleVal(87.332)
}
m := newMockOtelService(t)
Expand All @@ -50,7 +50,7 @@ func TestOpenTelemetry(t *testing.T) {
Attributes: map[string]string{"attr-key": "attr-val"},
metricsConverter: metricsConverter,
grpcClientConn: m.GrpcClient(),
metricsServiceClient: otlpgrpc.NewMetricsClient(m.GrpcClient()),
metricsServiceClient: pmetricotlp.NewClient(m.GrpcClient()),
}

input := testutil.MustMetric(
Expand All @@ -76,24 +76,24 @@ func TestOpenTelemetry(t *testing.T) {

got := m.GotMetrics()

expectJSON, err := otlp.NewJSONMetricsMarshaler().MarshalMetrics(expect)
expectJSON, err := pmetric.NewJSONMarshaler().MarshalMetrics(expect)
require.NoError(t, err)

gotJSON, err := otlp.NewJSONMetricsMarshaler().MarshalMetrics(got)
gotJSON, err := pmetric.NewJSONMarshaler().MarshalMetrics(got)
require.NoError(t, err)

assert.JSONEq(t, string(expectJSON), string(gotJSON))
}

var _ otlpgrpc.MetricsServer = (*mockOtelService)(nil)
var _ pmetricotlp.Server = (*mockOtelService)(nil)

type mockOtelService struct {
t *testing.T
listener net.Listener
grpcServer *grpc.Server
grpcClient *grpc.ClientConn

metrics pdata.Metrics
metrics pmetric.Metrics
}

func newMockOtelService(t *testing.T) *mockOtelService {
Expand All @@ -107,7 +107,7 @@ func newMockOtelService(t *testing.T) *mockOtelService {
grpcServer: grpcServer,
}

otlpgrpc.RegisterMetricsServer(grpcServer, mockOtelService)
pmetricotlp.RegisterServer(grpcServer, mockOtelService)
go func() { assert.NoError(t, grpcServer.Serve(listener)) }()

grpcClient, err := grpc.Dial(listener.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
Expand All @@ -126,18 +126,18 @@ func (m *mockOtelService) GrpcClient() *grpc.ClientConn {
return m.grpcClient
}

func (m *mockOtelService) GotMetrics() pdata.Metrics {
func (m *mockOtelService) GotMetrics() pmetric.Metrics {
return m.metrics
}

func (m *mockOtelService) Address() string {
return m.listener.Addr().String()
}

func (m *mockOtelService) Export(ctx context.Context, request otlpgrpc.MetricsRequest) (otlpgrpc.MetricsResponse, error) {
func (m *mockOtelService) Export(ctx context.Context, request pmetricotlp.Request) (pmetricotlp.Response, error) {
m.metrics = request.Metrics().Clone()
ctxMetadata, ok := metadata.FromIncomingContext(ctx)
assert.Equal(m.t, []string{"header1"}, ctxMetadata.Get("test"))
assert.True(m.t, ok)
return otlpgrpc.MetricsResponse{}, nil
return pmetricotlp.Response{}, nil
}

0 comments on commit 742e4cf

Please sign in to comment.