Skip to content

Commit

Permalink
[7.x] Update opentelemetry-collector to v0.30.0 (backport #5749) (#5792)
Browse files Browse the repository at this point in the history
* Update opentelemetry-collector to v0.30.0 (#5749)

* Update opentelemetry-collector to v0.30.0

* Replace glog

* Adapt code to opentelemetry-collector API changes

(cherry picked from commit 3de7384)

# Conflicts:
#	NOTICE.txt
#	go.mod
#	go.sum

* fix merge conflicts

Co-authored-by: Andrew Wilkins <axw@elastic.co>
  • Loading branch information
mergify[bot] and axw authored Jul 27, 2021
1 parent 9e4b1f9 commit 613849d
Show file tree
Hide file tree
Showing 398 changed files with 8,160 additions and 30,788 deletions.
5,271 changes: 3,084 additions & 2,187 deletions NOTICE.txt

Large diffs are not rendered by default.

14 changes: 5 additions & 9 deletions beater/jaeger/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/consumer/pdata"
"go.opentelemetry.io/collector/model/pdata"
"go.opentelemetry.io/collector/translator/trace/jaeger"

"github.com/elastic/beats/v7/libbeat/common"
Expand Down Expand Up @@ -81,18 +81,14 @@ func (tc *testGRPCCollector) setup(t *testing.T) {
beatertest.ClearRegistry(gRPCCollectorMonitoringMap)
if tc.request == nil {
traces := pdata.NewTraces()
resourceSpans := pdata.NewResourceSpans()
spans := pdata.NewInstrumentationLibrarySpans()
span0 := pdata.NewSpan()
resourceSpans := traces.ResourceSpans().AppendEmpty()
spans := resourceSpans.InstrumentationLibrarySpans().AppendEmpty()
span0 := spans.Spans().AppendEmpty()
span0.SetTraceID(pdata.NewTraceID([16]byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}))
span0.SetSpanID(pdata.NewSpanID([8]byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}))
span1 := pdata.NewSpan()
span1 := spans.Spans().AppendEmpty()
span1.SetTraceID(pdata.NewTraceID([16]byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}))
span1.SetSpanID(pdata.NewSpanID([8]byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}))
spans.Spans().Append(span0)
spans.Spans().Append(span1)
resourceSpans.InstrumentationLibrarySpans().Append(spans)
traces.ResourceSpans().Append(resourceSpans)

batches, err := jaeger.InternalTracesToJaegerProto(traces)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion beater/jaeger/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
jaegerthrift "github.com/jaegertracing/jaeger/thrift-gen/jaeger"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/consumer/pdata"
"go.opentelemetry.io/collector/model/pdata"

"github.com/elastic/apm-server/beater/beatertest"
"github.com/elastic/apm-server/beater/request"
Expand Down
4 changes: 2 additions & 2 deletions beater/otlp/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ func RegisterGRPCServices(grpcServer *grpc.Server, processor model.BatchProcesso
// dynamically registered and unregistered.
setCurrentMonitoredConsumer(consumer)

if err := otlpreceiver.RegisterTraceReceiver(context.Background(), consumer, grpcServer, nil); err != nil {
if err := otlpreceiver.RegisterTraceReceiver(context.Background(), consumer, grpcServer); err != nil {
return errors.Wrap(err, "failed to register OTLP trace receiver")
}
if err := otlpreceiver.RegisterMetricsReceiver(context.Background(), consumer, grpcServer, nil); err != nil {
if err := otlpreceiver.RegisterMetricsReceiver(context.Background(), consumer, grpcServer); err != nil {
return errors.Wrap(err, "failed to register OTLP metrics receiver")
}
return nil
Expand Down
110 changes: 21 additions & 89 deletions beater/otlp/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@ package otlp_test

import (
"context"
"encoding/json"
"errors"
"net"
"reflect"
"strings"
"testing"

"github.com/gogo/protobuf/proto"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/model/otlpgrpc"
"go.opentelemetry.io/collector/model/pdata"
"google.golang.org/grpc"
"google.golang.org/grpc/status"

Expand All @@ -39,13 +37,6 @@ import (
"github.com/elastic/beats/v7/libbeat/monitoring"
)

var (
exportMetricsServiceRequestType = proto.MessageType("opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest")
exportMetricsServiceResponseType = proto.MessageType("opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceResponse")
exportTraceServiceRequestType = proto.MessageType("opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest")
exportTraceServiceResponseType = proto.MessageType("opentelemetry.proto.collector.trace.v1.ExportTraceServiceResponse")
)

func TestConsumeTraces(t *testing.T) {
var batches []model.Batch
var reportError error
Expand All @@ -54,41 +45,23 @@ func TestConsumeTraces(t *testing.T) {
return reportError
}

conn := newServer(t, batchProcessor)
client := otlpgrpc.NewTracesClient(conn)

// Send a minimal trace to verify that everything is connected properly.
//
// We intentionally do not check the published event contents; those are
// tested in processor/otel.
cannedRequest := jsonExportTraceServiceRequest(`{
"resource_spans": [
{
"instrumentation_library_spans": [
{
"spans": [
{
"trace_id": "0123456789abcdef0123456789abcdef",
"span_id": "945254c567a5417e",
"name": "operation_name"
}
]
}
]
}
]
}`)
traces := pdata.NewTraces()
span := traces.ResourceSpans().AppendEmpty().InstrumentationLibrarySpans().AppendEmpty().Spans().AppendEmpty()
span.SetName("operation_name")

conn := newServer(t, batchProcessor)
err := conn.Invoke(
context.Background(), "/opentelemetry.proto.collector.trace.v1.TraceService/Export",
cannedRequest, newExportTraceServiceResponse(),
)
_, err := client.Export(context.Background(), traces)
assert.NoError(t, err)
require.Len(t, batches, 1)

reportError = errors.New("failed to publish events")
err = conn.Invoke(
context.Background(), "/opentelemetry.proto.collector.trace.v1.TraceService/Export",
cannedRequest, newExportTraceServiceResponse(),
)
_, err = client.Export(context.Background(), traces)
assert.Error(t, err)
errStatus := status.Convert(err)
assert.Equal(t, "failed to publish events", errStatus.Message())
Expand Down Expand Up @@ -117,39 +90,26 @@ func TestConsumeMetrics(t *testing.T) {
return reportError
}

conn := newServer(t, batchProcessor)
client := otlpgrpc.NewMetricsClient(conn)

// Send a minimal metric to verify that everything is connected properly.
//
// We intentionally do not check the published event contents; those are
// tested in processor/otel.
cannedRequest := jsonExportMetricsServiceRequest(`{
"resource_metrics": [
{
"instrumentation_library_metrics": [
{
"metrics": [
{
"name": "metric_name"
}
]
}
]
}
]
}`)
metrics := pdata.NewMetrics()
metric := metrics.ResourceMetrics().AppendEmpty().InstrumentationLibraryMetrics().AppendEmpty().Metrics().AppendEmpty()
metric.SetName("metric_type")
metric.SetDataType(pdata.MetricDataTypeSummary)
metric.Summary().DataPoints().AppendEmpty()

conn := newServer(t, batchProcessor)
err := conn.Invoke(
context.Background(), "/opentelemetry.proto.collector.metrics.v1.MetricsService/Export",
cannedRequest, newExportMetricsServiceResponse(),
)
_, err := client.Export(context.Background(), metrics)
assert.NoError(t, err)

reportError = errors.New("failed to publish events")
err = conn.Invoke(
context.Background(), "/opentelemetry.proto.collector.metrics.v1.MetricsService/Export",
cannedRequest, newExportMetricsServiceResponse(),
)
_, err = client.Export(context.Background(), metrics)
assert.Error(t, err)

errStatus := status.Convert(err)
assert.Equal(t, "failed to publish events", errStatus.Message())

Expand All @@ -173,34 +133,6 @@ func TestConsumeMetrics(t *testing.T) {
}, actual)
}

func jsonExportTraceServiceRequest(j string) interface{} {
request := reflect.New(exportTraceServiceRequestType.Elem()).Interface()
decoder := json.NewDecoder(strings.NewReader(j))
decoder.DisallowUnknownFields()
if err := decoder.Decode(request); err != nil {
panic(err)
}
return request
}

func newExportTraceServiceResponse() interface{} {
return reflect.New(exportTraceServiceResponseType.Elem()).Interface()
}

func jsonExportMetricsServiceRequest(j string) interface{} {
request := reflect.New(exportMetricsServiceRequestType.Elem()).Interface()
decoder := json.NewDecoder(strings.NewReader(j))
decoder.DisallowUnknownFields()
if err := decoder.Decode(request); err != nil {
panic(err)
}
return request
}

func newExportMetricsServiceResponse() interface{} {
return reflect.New(exportMetricsServiceResponseType.Elem()).Interface()
}

func newServer(t *testing.T, batchProcessor model.BatchProcessor) *grpc.ClientConn {
lis, err := net.Listen("tcp", "localhost:0")
require.NoError(t, err)
Expand Down
29 changes: 18 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.13
require (
github.com/DataDog/zstd v1.4.4 // indirect
github.com/akavel/rsrc v0.10.2 // indirect
github.com/apache/thrift v0.14.1
github.com/apache/thrift v0.14.2
github.com/cespare/xxhash/v2 v2.1.1
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e
github.com/dgraph-io/badger/v2 v2.2007.3-0.20201012072640-f5a7e0a1c83b
Expand All @@ -28,13 +28,14 @@ require (
github.com/go-sourcemap/sourcemap v2.1.3+incompatible
github.com/gofrs/uuid v4.0.0+incompatible
github.com/gogo/protobuf v1.3.2
github.com/google/pprof v0.0.0-20210323184331-8eee2492667d
github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9
github.com/gorilla/websocket v1.4.2 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/golang-lru v0.5.4
github.com/jaegertracing/jaeger v1.23.0
github.com/jaegertracing/jaeger v1.24.0
github.com/josephspurrier/goversioninfo v1.2.0 // indirect
github.com/json-iterator/go v1.1.10
github.com/json-iterator/go v1.1.11
github.com/jstemmer/go-junit-report v0.9.1
github.com/magefile/mage v1.11.0
github.com/mattn/go-isatty v0.0.13 // indirect
Expand All @@ -45,8 +46,8 @@ require (
github.com/poy/eachers v0.0.0-20181020210610-23942921fe77 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/reviewdog/reviewdog v0.9.17
github.com/ryanuber/go-glob v0.0.0-20170128012129-256dc444b735
github.com/spf13/cobra v1.1.3
github.com/ryanuber/go-glob v1.0.0
github.com/spf13/cobra v1.2.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.7.0
github.com/t-yuki/gocover-cobertura v0.0.0-20180217150009-aaee18c8195c
Expand All @@ -61,16 +62,17 @@ require (
go.elastic.co/ecszap v1.0.0 // indirect
go.elastic.co/fastjson v1.1.0
go.elastic.co/go-licence-detector v0.5.0
go.opentelemetry.io/collector v0.28.0
go.uber.org/atomic v1.8.0
go.opentelemetry.io/collector v0.30.0
go.opentelemetry.io/collector/model v0.30.0
go.uber.org/atomic v1.9.0
go.uber.org/multierr v1.7.0 // indirect
go.uber.org/zap v1.18.1
golang.org/x/net v0.0.0-20210614182718-04defd469f4e
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba
golang.org/x/tools v0.1.4
google.golang.org/genproto v0.0.0-20210630183607-d20f26d13c79 // indirect
golang.org/x/time v0.0.0-20210611083556-38a9dc6acbc6
golang.org/x/tools v0.1.5
google.golang.org/genproto v0.0.0-20210716133855-ce7ef5c701ea // indirect
google.golang.org/grpc v1.39.0
gopkg.in/yaml.v2 v2.4.0
gotest.tools/gotestsum v0.6.0
Expand All @@ -82,6 +84,7 @@ replace (
github.com/Azure/go-autorest => github.com/Azure/go-autorest v12.2.0+incompatible
github.com/Microsoft/go-winio => github.com/bi-zone/go-winio v0.4.15
github.com/Shopify/sarama => github.com/elastic/sarama v1.19.1-0.20210120173147-5c8cb347d877
github.com/aws/aws-sdk-go-v2 => github.com/aws/aws-sdk-go-v2 v0.9.0
github.com/docker/docker => github.com/docker/engine v0.0.0-20191113042239-ea84732a7725
github.com/docker/go-plugins-helpers => github.com/elastic/go-plugins-helpers v0.0.0-20200207104224-bdf17607b79f
github.com/dop251/goja => github.com/andrewkroh/goja v0.0.0-20190128172624-dd2ac4456e20
Expand All @@ -96,4 +99,8 @@ replace (
k8s.io/client-go => k8s.io/client-go v0.19.4
)

// We replace golang/glog, which is used by ristretto, to avoid polluting the
// command line flags and conflicting with command line flags added by libbeat.
replace github.com/golang/glog => github.com/slok/noglog v0.2.0

replace go.opentelemetry.io/collector => ./internal/otel_collector
Loading

0 comments on commit 613849d

Please sign in to comment.