From 6bec1ad06b58b394ad4f621d087fd5f71ca08a2b Mon Sep 17 00:00:00 2001 From: Mend Renovate Date: Mon, 23 Dec 2024 14:55:08 +0100 Subject: [PATCH 1/2] fix(deps): update module google.golang.org/protobuf to v1.36.1 (#6395) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [google.golang.org/protobuf](https://redirect.github.com/protocolbuffers/protobuf-go) | `v1.36.0` -> `v1.36.1` | [![age](https://developer.mend.io/api/mc/badges/age/go/google.golang.org%2fprotobuf/v1.36.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/go/google.golang.org%2fprotobuf/v1.36.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/go/google.golang.org%2fprotobuf/v1.36.0/v1.36.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/go/google.golang.org%2fprotobuf/v1.36.0/v1.36.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes
protocolbuffers/protobuf-go (google.golang.org/protobuf) ### [`v1.36.1`](https://redirect.github.com/protocolbuffers/protobuf-go/releases/tag/v1.36.1) [Compare Source](https://redirect.github.com/protocolbuffers/protobuf-go/compare/v1.36.0...v1.36.1) **Full Changelog**: https://github.com/protocolbuffers/protobuf-go/compare/v1.36.0...v1.36.1 Bug fixes: [CL/638495](https://go-review.googlesource.com/c/protobuf/+/638495): internal/impl: revert IsSynthetic() check to fix panic Maintenance: [CL/637475](https://go-review.googlesource.com/c/protobuf/+/637475): internal/errors: delete compatibility code for Go before 1.13
--- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/jaegertracing/jaeger). Signed-off-by: Mend Renovate --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 762d0f365f4..a7eafab345e 100644 --- a/go.mod +++ b/go.mod @@ -98,7 +98,7 @@ require ( golang.org/x/net v0.33.0 golang.org/x/sys v0.28.0 google.golang.org/grpc v1.69.2 - google.golang.org/protobuf v1.36.0 + google.golang.org/protobuf v1.36.1 gopkg.in/yaml.v3 v3.0.1 ) diff --git a/go.sum b/go.sum index 5d8e67a5e7a..d694e4003f1 100644 --- a/go.sum +++ b/go.sum @@ -964,8 +964,8 @@ google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= -google.golang.org/protobuf v1.36.0 h1:mjIs9gYtt56AzC4ZaffQuh88TZurBGhIJMBZGSxNerQ= -google.golang.org/protobuf v1.36.0/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +google.golang.org/protobuf v1.36.1 h1:yBPeRvTftaleIgM3PZ/WBIZ7XM/eEYAaEyCwvyjq/gk= +google.golang.org/protobuf v1.36.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From 4ecb0860ce7ae901f8d77261b4022e5030288073 Mon Sep 17 00:00:00 2001 From: Mahad Zaryab <43658574+mahadzaryab1@users.noreply.github.com> Date: Mon, 23 Dec 2024 12:00:46 -0500 Subject: [PATCH 2/2] [v2][adjuster] Implement otlp to model translator with post processing (#6394) ## Which problem is this PR solving? - Towards #6344 ## Description of the changes - Implemented a translator in `jptrace` with a function `ProtoFromTraces` that is a wrapper of the upstream `ProtoFromTraces` in opentelemetry-collector-contrib jaeger translator. This function appends the warnings in `jaeger.internal.warnings` to the corresponding warnings field in the proto model. ## How was this change tested? - Added unit tests ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [x] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `npm run lint` and `npm run test` --------- Signed-off-by: Mahad Zaryab --- .golangci.yml | 8 +++ cmd/collector/app/handler/otlp_receiver.go | 4 +- .../processors/adaptivesampling/processor.go | 4 +- cmd/query/app/otlp_translator.go | 4 +- internal/jptrace/translator.go | 58 +++++++++++++++++++ internal/jptrace/translator_test.go | 55 ++++++++++++++++++ model/ids.go | 16 +++++ model/ids_test.go | 52 +++++++++++++++++ storage_v2/v1adapter/writer.go | 4 +- 9 files changed, 197 insertions(+), 8 deletions(-) create mode 100644 internal/jptrace/translator.go create mode 100644 internal/jptrace/translator_test.go diff --git a/.golangci.yml b/.golangci.yml index 5427041391e..2cca15f1d14 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -139,6 +139,14 @@ linters-settings: files: - "**_test.go" + # TODO: enable after import is not used anywhere + # disallow-otel-contrib-translator: + # deny: + # - pkg: github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger + # desc: "Use jptrace package instead of opentelemetry-collector-contrib/pkg/translator/jaeger" + # files: + # - "!**/jptrace/**" + goimports: local-prefixes: github.com/jaegertracing/jaeger gosec: diff --git a/cmd/collector/app/handler/otlp_receiver.go b/cmd/collector/app/handler/otlp_receiver.go index ba450e4a298..ebde8d2ba38 100644 --- a/cmd/collector/app/handler/otlp_receiver.go +++ b/cmd/collector/app/handler/otlp_receiver.go @@ -7,7 +7,6 @@ import ( "context" "fmt" - otlp2jaeger "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componentstatus" "go.opentelemetry.io/collector/config/confignet" @@ -23,6 +22,7 @@ import ( "github.com/jaegertracing/jaeger/cmd/collector/app/flags" "github.com/jaegertracing/jaeger/cmd/collector/app/processor" + "github.com/jaegertracing/jaeger/internal/jptrace" "github.com/jaegertracing/jaeger/pkg/tenancy" ) @@ -108,7 +108,7 @@ type consumerDelegate struct { } func (c *consumerDelegate) consume(ctx context.Context, td ptrace.Traces) error { - batches := otlp2jaeger.ProtoFromTraces(td) + batches := jptrace.ProtoFromTraces(td) for _, batch := range batches { err := c.batchConsumer.consume(ctx, batch) if err != nil { diff --git a/cmd/jaeger/internal/processors/adaptivesampling/processor.go b/cmd/jaeger/internal/processors/adaptivesampling/processor.go index 4d14f7f99c4..7a0ca2a0641 100644 --- a/cmd/jaeger/internal/processors/adaptivesampling/processor.go +++ b/cmd/jaeger/internal/processors/adaptivesampling/processor.go @@ -7,12 +7,12 @@ import ( "context" "fmt" - otlp2jaeger "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/pdata/ptrace" "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/samplingstrategy" "github.com/jaegertracing/jaeger/cmd/jaeger/internal/extension/remotesampling" + "github.com/jaegertracing/jaeger/internal/jptrace" "github.com/jaegertracing/jaeger/internal/metrics/otelmetrics" "github.com/jaegertracing/jaeger/plugin/sampling/strategyprovider/adaptive" ) @@ -65,7 +65,7 @@ func (tp *traceProcessor) close(context.Context) error { } func (tp *traceProcessor) processTraces(_ context.Context, td ptrace.Traces) (ptrace.Traces, error) { - batches := otlp2jaeger.ProtoFromTraces(td) + batches := jptrace.ProtoFromTraces(td) for _, batch := range batches { for _, span := range batch.Spans { if span.Process == nil { diff --git a/cmd/query/app/otlp_translator.go b/cmd/query/app/otlp_translator.go index 06f7c63e440..daaaabf2aeb 100644 --- a/cmd/query/app/otlp_translator.go +++ b/cmd/query/app/otlp_translator.go @@ -6,9 +6,9 @@ package app import ( "fmt" - model2otel "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger" "go.opentelemetry.io/collector/pdata/ptrace" + "github.com/jaegertracing/jaeger/internal/jptrace" "github.com/jaegertracing/jaeger/model" ) @@ -18,7 +18,7 @@ func otlp2traces(otlpSpans []byte) ([]*model.Trace, error) { if err != nil { return nil, fmt.Errorf("cannot unmarshal OTLP : %w", err) } - jaegerBatches := model2otel.ProtoFromTraces(otlpTraces) + jaegerBatches := jptrace.ProtoFromTraces(otlpTraces) var traces []*model.Trace traceMap := make(map[model.TraceID]*model.Trace) for _, batch := range jaegerBatches { diff --git a/internal/jptrace/translator.go b/internal/jptrace/translator.go new file mode 100644 index 00000000000..7480b2b5075 --- /dev/null +++ b/internal/jptrace/translator.go @@ -0,0 +1,58 @@ +// Copyright (c) 2024 The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 + +package jptrace + +import ( + jaegerTranslator "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger" + "go.opentelemetry.io/collector/pdata/ptrace" + + "github.com/jaegertracing/jaeger/model" +) + +// ProtoFromTraces converts OpenTelemetry traces (ptrace.Traces) +// to Jaeger model batches ([]*model.Batch). +func ProtoFromTraces(traces ptrace.Traces) []*model.Batch { + batches := jaegerTranslator.ProtoFromTraces(traces) + spanMap := createSpanMapFromBatches(batches) + transferWarnings(traces, spanMap) + return batches +} + +func createSpanMapFromBatches(batches []*model.Batch) map[model.SpanID]*model.Span { + spanMap := make(map[model.SpanID]*model.Span) + for _, batch := range batches { + for _, span := range batch.Spans { + spanMap[span.SpanID] = span + } + } + return spanMap +} + +func transferWarnings(traces ptrace.Traces, spanMap map[model.SpanID]*model.Span) { + resources := traces.ResourceSpans() + for i := 0; i < resources.Len(); i++ { + scopes := resources.At(i).ScopeSpans() + for j := 0; j < scopes.Len(); j++ { + spans := scopes.At(j).Spans() + for k := 0; k < spans.Len(); k++ { + otelSpan := spans.At(k) + warnings := GetWarnings(otelSpan) + span := spanMap[model.SpanIDFromOTEL(otelSpan.SpanID())] + span.Warnings = append(span.Warnings, warnings...) + // filter out the warning tag + span.Tags = filterTags(span.Tags, warningsAttribute) + } + } + } +} + +func filterTags(tags []model.KeyValue, keyToRemove string) []model.KeyValue { + var filteredTags []model.KeyValue + for _, tag := range tags { + if tag.Key != keyToRemove { + filteredTags = append(filteredTags, tag) + } + } + return filteredTags +} diff --git a/internal/jptrace/translator_test.go b/internal/jptrace/translator_test.go new file mode 100644 index 00000000000..5ff3129a00f --- /dev/null +++ b/internal/jptrace/translator_test.go @@ -0,0 +1,55 @@ +// Copyright (c) 2024 The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 + +package jptrace + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "go.opentelemetry.io/collector/pdata/pcommon" + "go.opentelemetry.io/collector/pdata/ptrace" + + "github.com/jaegertracing/jaeger/model" +) + +func TestProtoFromTraces_AddsWarnings(t *testing.T) { + traces := ptrace.NewTraces() + rs1 := traces.ResourceSpans().AppendEmpty() + ss1 := rs1.ScopeSpans().AppendEmpty() + span1 := ss1.Spans().AppendEmpty() + span1.SetName("test-span-1") + span1.SetSpanID(pcommon.SpanID([8]byte{1, 2, 3, 4, 5, 6, 7, 8})) + AddWarning(span1, "test-warning-1") + AddWarning(span1, "test-warning-2") + span1.Attributes().PutStr("key", "value") + + ss2 := rs1.ScopeSpans().AppendEmpty() + span2 := ss2.Spans().AppendEmpty() + span2.SetName("test-span-2") + span2.SetSpanID(pcommon.SpanID([8]byte{9, 10, 11, 12, 13, 14, 15, 16})) + + rs2 := traces.ResourceSpans().AppendEmpty() + ss3 := rs2.ScopeSpans().AppendEmpty() + span3 := ss3.Spans().AppendEmpty() + span3.SetName("test-span-3") + span3.SetSpanID(pcommon.SpanID([8]byte{17, 18, 19, 20, 21, 22, 23, 24})) + AddWarning(span3, "test-warning-3") + + batches := ProtoFromTraces(traces) + + assert.Len(t, batches, 2) + + assert.Len(t, batches[0].Spans, 2) + assert.Equal(t, "test-span-1", batches[0].Spans[0].OperationName) + assert.Equal(t, []string{"test-warning-1", "test-warning-2"}, batches[0].Spans[0].Warnings) + assert.Equal(t, []model.KeyValue{{Key: "key", VStr: "value"}}, batches[0].Spans[0].Tags) + assert.Equal(t, "test-span-2", batches[0].Spans[1].OperationName) + assert.Empty(t, batches[0].Spans[1].Warnings) + assert.Empty(t, batches[0].Spans[1].Tags) + + assert.Len(t, batches[1].Spans, 1) + assert.Equal(t, "test-span-3", batches[1].Spans[0].OperationName) + assert.Equal(t, []string{"test-warning-3"}, batches[1].Spans[0].Warnings) + assert.Empty(t, batches[1].Spans[0].Tags) +} diff --git a/model/ids.go b/model/ids.go index 5bf93dc43be..4c7b77c6aa9 100644 --- a/model/ids.go +++ b/model/ids.go @@ -261,3 +261,19 @@ func (s *SpanID) UnmarshalJSON(data []byte) error { func (s *SpanID) UnmarshalJSONPB(_ *jsonpb.Unmarshaler, b []byte) error { return s.UnmarshalJSON(b) } + +// ToOTELSpanID converts the SpanID to OTEL's representation of a span identitfier. +// This was taken from +// https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/internal/coreinternal/idutils/big_endian_converter.go. +func (s SpanID) ToOTELSpanID() pcommon.SpanID { + spanID := [8]byte{} + binary.BigEndian.PutUint64(spanID[:], uint64(s)) + return pcommon.SpanID(spanID) +} + +// ToOTELSpanID converts OTEL's SpanID to the model representation of a span identitfier. +// This was taken from +// https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/internal/coreinternal/idutils/big_endian_converter.go. +func SpanIDFromOTEL(spanID pcommon.SpanID) SpanID { + return SpanID(binary.BigEndian.Uint64(spanID[:])) +} diff --git a/model/ids_test.go b/model/ids_test.go index 40c6f801a5c..ef2a9a65beb 100644 --- a/model/ids_test.go +++ b/model/ids_test.go @@ -137,3 +137,55 @@ func TestTraceIDFromOTEL(t *testing.T) { } require.Equal(t, expected, model.TraceIDFromOTEL(otelTraceID)) } + +func TestToOTELSpanID(t *testing.T) { + tests := []struct { + name string + spanID model.SpanID + expected pcommon.SpanID + }{ + { + name: "zero span ID", + spanID: model.NewSpanID(0), + expected: pcommon.NewSpanIDEmpty(), + }, + { + name: "non-zero span ID", + spanID: model.NewSpanID(1), + expected: pcommon.SpanID([8]byte{0, 0, 0, 0, 0, 0, 0, 1}), + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + actual := test.spanID.ToOTELSpanID() + assert.Equal(t, test.expected, actual) + }) + } +} + +func TestSpanIDFromOTEL(t *testing.T) { + tests := []struct { + name string + otelSpanID pcommon.SpanID + expected model.SpanID + }{ + { + name: "zero span ID", + otelSpanID: pcommon.NewSpanIDEmpty(), + expected: model.NewSpanID(0), + }, + { + name: "non-zero span ID", + otelSpanID: pcommon.SpanID([8]byte{0, 0, 0, 0, 0, 0, 0, 1}), + expected: model.NewSpanID(1), + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + actual := model.SpanIDFromOTEL(test.otelSpanID) + assert.Equal(t, test.expected, actual) + }) + } +} diff --git a/storage_v2/v1adapter/writer.go b/storage_v2/v1adapter/writer.go index c0a9d4ced99..b16b54ed43e 100644 --- a/storage_v2/v1adapter/writer.go +++ b/storage_v2/v1adapter/writer.go @@ -7,9 +7,9 @@ import ( "context" "errors" - otlp2jaeger "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger" "go.opentelemetry.io/collector/pdata/ptrace" + "github.com/jaegertracing/jaeger/internal/jptrace" "github.com/jaegertracing/jaeger/storage/spanstore" "github.com/jaegertracing/jaeger/storage_v2/tracestore" ) @@ -26,7 +26,7 @@ func NewTraceWriter(spanWriter spanstore.Writer) tracestore.Writer { // WriteTraces implements tracestore.Writer. func (t *TraceWriter) WriteTraces(ctx context.Context, td ptrace.Traces) error { - batches := otlp2jaeger.ProtoFromTraces(td) + batches := jptrace.ProtoFromTraces(td) var errs []error for _, batch := range batches { for _, span := range batch.Spans {