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

Change OTLP exporter/receiver and File exporter to use the new opentelemetry-proto v0.5.0 #1701

Merged
merged 1 commit into from
Aug 31, 2020
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## Unreleased

## 🛑 Breaking changes 🛑

- **Update OTLP to v0.5.0, incompatible metrics protocol.**
- Remove support for propagating summary metrics in OtelCollector.
- This is a temporary change, and will affect mostly OpenCensus users who use metrics.

## v0.9.0 Beta

## 🛑 Breaking changes 🛑
Expand Down
4 changes: 2 additions & 2 deletions exporter/fileexporter/file_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer/pdata"
"go.opentelemetry.io/collector/consumer/pdatautil"
"go.opentelemetry.io/collector/internal/data"
otlplogs "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/collector/logs/v1"
otlpmetrics "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/collector/metrics/v1"
otlptrace "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/collector/trace/v1"
"go.opentelemetry.io/collector/internal/dataold"
)

// Marshaler configuration used for marhsaling Protobuf to JSON. Use default config.
Expand All @@ -50,7 +50,7 @@ func (e *fileExporter) ConsumeTraces(_ context.Context, td pdata.Traces) error {

func (e *fileExporter) ConsumeMetrics(_ context.Context, md pdata.Metrics) error {
request := otlpmetrics.ExportMetricsServiceRequest{
ResourceMetrics: dataold.MetricDataToOtlp(pdatautil.MetricsToOldInternalMetrics(md)),
ResourceMetrics: data.MetricDataToOtlp(pdatautil.MetricsToInternalMetrics(md)),
}
return exportMessageAsLine(e, &request)
}
Expand Down
7 changes: 3 additions & 4 deletions exporter/fileexporter/file_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ import (

"go.opentelemetry.io/collector/consumer/pdata"
"go.opentelemetry.io/collector/consumer/pdatautil"
"go.opentelemetry.io/collector/internal/data"
collectorlogs "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/collector/logs/v1"
collectormetrics "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/collector/metrics/v1"
collectortrace "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/collector/trace/v1"
otlpcommon "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/common/v1"
logspb "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/logs/v1"
otresourcepb "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/resource/v1"
"go.opentelemetry.io/collector/internal/data/testdata"
"go.opentelemetry.io/collector/internal/dataold"
"go.opentelemetry.io/collector/internal/dataold/testdataold"
"go.opentelemetry.io/collector/testutil"
)

Expand All @@ -58,15 +57,15 @@ func TestFileMetricsExporterNoErrors(t *testing.T) {
lme := &fileExporter{file: mf}
require.NotNil(t, lme)

md := pdatautil.MetricsFromOldInternalMetrics(testdataold.GenerateMetricDataTwoMetrics())
md := pdatautil.MetricsFromInternalMetrics(testdata.GenerateMetricsTwoMetrics())
assert.NoError(t, lme.ConsumeMetrics(context.Background(), md))
assert.NoError(t, lme.Shutdown(context.Background()))

var unmarshaler = &jsonpb.Unmarshaler{}
var j collectormetrics.ExportMetricsServiceRequest
assert.NoError(t, unmarshaler.Unmarshal(mf, &j))

assert.EqualValues(t, dataold.MetricDataToOtlp(pdatautil.MetricsToOldInternalMetrics(md)), j.ResourceMetrics)
assert.EqualValues(t, data.MetricDataToOtlp(pdatautil.MetricsToInternalMetrics(md)), j.ResourceMetrics)
}

func TestFileLogsExporterNoErrors(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions exporter/otlpexporter/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ import (
"go.opentelemetry.io/collector/consumer/pdata"
"go.opentelemetry.io/collector/consumer/pdatautil"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/internal/data"
otlplogs "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/collector/logs/v1"
otlpmetrics "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/collector/metrics/v1"
otlptrace "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/collector/trace/v1"
"go.opentelemetry.io/collector/internal/dataold"
)

type exporterImp struct {
Expand Down Expand Up @@ -90,9 +90,9 @@ func (e *exporterImp) pushTraceData(ctx context.Context, td pdata.Traces) (int,
}

func (e *exporterImp) pushMetricsData(ctx context.Context, md pdata.Metrics) (int, error) {
imd := pdatautil.MetricsToOldInternalMetrics(md)
imd := pdatautil.MetricsToInternalMetrics(md)
request := &otlpmetrics.ExportMetricsServiceRequest{
ResourceMetrics: dataold.MetricDataToOtlp(imd),
ResourceMetrics: data.MetricDataToOtlp(imd),
}
err := e.w.exportMetrics(ctx, request)

Expand Down
12 changes: 3 additions & 9 deletions exporter/otlpexporter/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/consumer/pdata"
"go.opentelemetry.io/collector/consumer/pdatautil"
"go.opentelemetry.io/collector/internal/data"
otlplogs "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/collector/logs/v1"
otlpmetrics "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/collector/metrics/v1"
otlptraces "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/collector/trace/v1"
Expand Down Expand Up @@ -135,14 +136,7 @@ func (r *mockMetricsReceiver) Export(
req *otlpmetrics.ExportMetricsServiceRequest,
) (*otlpmetrics.ExportMetricsServiceResponse, error) {
atomic.AddInt32(&r.requestCount, 1)
recordCount := 0
for _, rs := range req.ResourceMetrics {
for _, il := range rs.InstrumentationLibraryMetrics {
for _, m := range il.Metrics {
recordCount += len(m.DoubleDataPoints) + len(m.Int64DataPoints) + len(m.HistogramDataPoints) + len(m.SummaryDataPoints)
}
}
}
_, recordCount := data.MetricDataFromOtlp(req.ResourceMetrics).MetricAndDataPointCount()
atomic.AddInt32(&r.totalItems, int32(recordCount))
r.lastRequest = req
r.metadata, _ = metadata.FromIncomingContext(ctx)
Expand Down Expand Up @@ -288,7 +282,7 @@ func TestSendMetrics(t *testing.T) {
md = pdatautil.MetricsFromOldInternalMetrics(testdataold.GenerateMetricDataTwoMetrics())

expectedOTLPReq := &otlpmetrics.ExportMetricsServiceRequest{
ResourceMetrics: testdataold.GenerateMetricOtlpTwoMetrics(),
ResourceMetrics: testdata.GenerateMetricsOtlpTwoMetrics(),
}

err = exp.ConsumeMetrics(context.Background(), md)
Expand Down

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

8 changes: 4 additions & 4 deletions receiver/otlpreceiver/metrics/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"go.opentelemetry.io/collector/client"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/consumer/pdatautil"
"go.opentelemetry.io/collector/internal/data"
collectormetrics "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/collector/metrics/v1"
"go.opentelemetry.io/collector/internal/dataold"
"go.opentelemetry.io/collector/obsreport"
)

Expand Down Expand Up @@ -52,7 +52,7 @@ const (
func (r *Receiver) Export(ctx context.Context, req *collectormetrics.ExportMetricsServiceRequest) (*collectormetrics.ExportMetricsServiceResponse, error) {
receiverCtx := obsreport.ReceiverContext(ctx, r.instanceName, receiverTransport, receiverTagValue)

md := dataold.MetricDataFromOtlp(req.ResourceMetrics)
md := data.MetricDataFromOtlp(req.ResourceMetrics)

err := r.sendToNextConsumer(receiverCtx, md)
if err != nil {
Expand All @@ -62,7 +62,7 @@ func (r *Receiver) Export(ctx context.Context, req *collectormetrics.ExportMetri
return &collectormetrics.ExportMetricsServiceResponse{}, nil
}

func (r *Receiver) sendToNextConsumer(ctx context.Context, md dataold.MetricData) error {
func (r *Receiver) sendToNextConsumer(ctx context.Context, md data.MetricData) error {
metricCount, dataPointCount := md.MetricAndDataPointCount()
if metricCount == 0 {
return nil
Expand All @@ -73,7 +73,7 @@ func (r *Receiver) sendToNextConsumer(ctx context.Context, md dataold.MetricData
}

ctx = obsreport.StartMetricsReceiveOp(ctx, r.instanceName, receiverTransport)
err := r.nextConsumer.ConsumeMetrics(ctx, pdatautil.MetricsFromOldInternalMetrics(md))
err := r.nextConsumer.ConsumeMetrics(ctx, pdatautil.MetricsFromInternalMetrics(md))
obsreport.EndMetricsReceiveOp(ctx, dataFormatProtobuf, dataPointCount, metricCount, err)

return err
Expand Down
84 changes: 45 additions & 39 deletions receiver/otlpreceiver/metrics/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import (
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/consumer/pdatautil"
"go.opentelemetry.io/collector/exporter/exportertest"
"go.opentelemetry.io/collector/internal/data"
collectormetrics "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/collector/metrics/v1"
otlpcommon "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/common/v1"
otlpmetrics "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/metrics/v1old"
"go.opentelemetry.io/collector/internal/dataold"
otlpmetrics "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/metrics/v1"
"go.opentelemetry.io/collector/obsreport"
"go.opentelemetry.io/collector/testutil"
)
Expand Down Expand Up @@ -60,34 +60,37 @@ func TestExport(t *testing.T) {
{
Metrics: []*otlpmetrics.Metric{
{
MetricDescriptor: &otlpmetrics.MetricDescriptor{
Name: "mymetric",
Description: "My metric",
Unit: "ms",
Type: otlpmetrics.MetricDescriptor_MONOTONIC_INT64,
},
Int64DataPoints: []*otlpmetrics.Int64DataPoint{
{
Labels: []*otlpcommon.StringKeyValue{
Name: "mymetric",
Description: "My metric",
Unit: "ms",
Data: &otlpmetrics.Metric_IntSum{
IntSum: &otlpmetrics.IntSum{
IsMonotonic: true,
AggregationTemporality: otlpmetrics.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
DataPoints: []*otlpmetrics.IntDataPoint{
{
Key: "key1",
Value: "value1",
Labels: []*otlpcommon.StringKeyValue{
{
Key: "key1",
Value: "value1",
},
},
StartTimeUnixNano: unixnanos1,
TimeUnixNano: unixnanos2,
Value: 123,
},
},
StartTimeUnixNano: unixnanos1,
TimeUnixNano: unixnanos2,
Value: 123,
},
{
Labels: []*otlpcommon.StringKeyValue{
{
Key: "key2",
Value: "value2",
Labels: []*otlpcommon.StringKeyValue{
{
Key: "key2",
Value: "value2",
},
},
StartTimeUnixNano: unixnanos1,
TimeUnixNano: unixnanos2,
Value: 456,
},
},
StartTimeUnixNano: unixnanos1,
TimeUnixNano: unixnanos2,
Value: 456,
},
},
},
Expand All @@ -99,7 +102,7 @@ func TestExport(t *testing.T) {

// Keep metric data to compare the test result against it
// Clone needed because OTLP proto XXX_ fields are altered in the GRPC downstream
metricData := dataold.MetricDataFromOtlp(resourceMetrics).Clone()
metricData := data.MetricDataFromOtlp(resourceMetrics).Clone()

req := &collectormetrics.ExportMetricsServiceRequest{
ResourceMetrics: resourceMetrics,
Expand All @@ -114,7 +117,7 @@ func TestExport(t *testing.T) {
require.Equal(t, 1, len(metricSink.AllMetrics()),
"unexpected length: %v", len(metricSink.AllMetrics()))

assert.EqualValues(t, metricData, pdatautil.MetricsToOldInternalMetrics(metricSink.AllMetrics()[0]))
assert.EqualValues(t, metricData, pdatautil.MetricsToInternalMetrics(metricSink.AllMetrics()[0]))
}

func TestExport_EmptyRequest(t *testing.T) {
Expand Down Expand Up @@ -153,18 +156,21 @@ func TestExport_ErrorConsumer(t *testing.T) {
{
Metrics: []*otlpmetrics.Metric{
{
MetricDescriptor: &otlpmetrics.MetricDescriptor{
Name: "mymetric",
Description: "My metric",
Unit: "ms",
Type: otlpmetrics.MetricDescriptor_MONOTONIC_INT64,
},
Int64DataPoints: []*otlpmetrics.Int64DataPoint{
{
Value: 123,
},
{
Value: 456,
Name: "mymetric",
Description: "My metric",
Unit: "ms",
Data: &otlpmetrics.Metric_IntSum{
IntSum: &otlpmetrics.IntSum{
IsMonotonic: true,
AggregationTemporality: otlpmetrics.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
DataPoints: []*otlpmetrics.IntDataPoint{
{
Value: 123,
},
{
Value: 456,
},
},
},
},
},
Expand Down