-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat(loadbalancingexporter): optimize metrics and traces export #30141
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
Merged
jpkrohling
merged 11 commits into
open-telemetry:main
from
mat-rumian:mat-rumian-lbe-imp
Jan 25, 2024
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a488fa7
feat: add metrics&traces merge fns
cbe2479
feat: optimize traces sent
6a4d717
feat: optimize metrics sent
bf8222a
chore: add changelog
4e08eba
Merge branch 'main' into mat-rumian-lbe-imp
mat-rumian bfb2837
fix: checks
d9d9ef7
fix: exporter type check
b445cb6
fix: tests and segregation assignments
fd6a12c
fix: mergering functions
b94780b
fix tests
cc1ae01
Merge branch 'main' into mat-rumian-lbe-imp
mat-rumian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Use this changelog template to create an entry for release notes. | ||
|
|
||
| # One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
| change_type: enhancement | ||
|
|
||
| # The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
| component: loadbalancingexporter | ||
|
|
||
| # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
| note: "Optimize metrics and traces export" | ||
|
|
||
| # Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
| issues: [30141] | ||
|
|
||
| # (Optional) One or more lines of additional information to render under the primary note. | ||
| # These lines will be padded with 2 spaces and then inserted directly into the document. | ||
| # Use pipe (|) for multiline entries. | ||
| subtext: | ||
|
|
||
| # If your change doesn't affect end users or the exported elements of any package, | ||
| # you should instead start your pull request title with [chore] or use the "Skip Changelog" label. | ||
| # Optional: The change log or logs in which this entry should be included. | ||
| # e.g. '[user]' or '[user, api]' | ||
| # Include 'user' if the change is relevant to end users. | ||
| # Include 'api' if there is a change to a library API. | ||
| # Default: '[user]' | ||
| change_logs: [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package loadbalancingexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/loadbalancingexporter" | ||
|
|
||
| import ( | ||
| "go.opentelemetry.io/collector/pdata/pmetric" | ||
| "go.opentelemetry.io/collector/pdata/ptrace" | ||
| ) | ||
|
|
||
| // mergeTraces concatenates multiple ptrace.Traces into a single ptrace.Traces. | ||
| func mergeTraces(traces ...ptrace.Traces) ptrace.Traces { | ||
| merged := ptrace.NewTraces() | ||
| empty := ptrace.Traces{} | ||
|
|
||
| for _, trace := range traces { | ||
|
|
||
| if trace == empty { | ||
mat-rumian marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| continue | ||
| } | ||
|
|
||
| for i := 0; i < trace.ResourceSpans().Len(); i++ { | ||
| rs := trace.ResourceSpans().At(i) | ||
|
|
||
| newRS := merged.ResourceSpans().AppendEmpty() | ||
| rs.Resource().CopyTo(newRS.Resource()) | ||
| newRS.SetSchemaUrl(rs.SchemaUrl()) | ||
|
|
||
| for j := 0; j < rs.ScopeSpans().Len(); j++ { | ||
| ils := rs.ScopeSpans().At(j) | ||
|
|
||
| newILS := newRS.ScopeSpans().AppendEmpty() | ||
| ils.Scope().CopyTo(newILS.Scope()) | ||
| newILS.SetSchemaUrl(ils.SchemaUrl()) | ||
|
|
||
| for k := 0; k < ils.Spans().Len(); k++ { | ||
| span := ils.Spans().At(k) | ||
| newSpan := newILS.Spans().AppendEmpty() | ||
| span.CopyTo(newSpan) | ||
| } | ||
| } | ||
| } | ||
mat-rumian marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| } | ||
|
|
||
| return merged | ||
| } | ||
|
|
||
| // mergeTraces concatenates multiple pmetric.Metrics into a single pmetric.Metrics. | ||
mat-rumian marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| func mergeMetrics(metrics ...pmetric.Metrics) pmetric.Metrics { | ||
| merged := pmetric.NewMetrics() | ||
| empty := pmetric.Metrics{} | ||
|
|
||
| for _, metric := range metrics { | ||
|
|
||
| if metric == empty { | ||
| continue | ||
| } | ||
|
|
||
| for i := 0; i < metric.ResourceMetrics().Len(); i++ { | ||
| rs := metric.ResourceMetrics().At(i) | ||
|
|
||
| newRM := merged.ResourceMetrics().AppendEmpty() | ||
| rs.Resource().CopyTo(newRM.Resource()) | ||
| newRM.SetSchemaUrl(rs.SchemaUrl()) | ||
|
|
||
| for j := 0; j < rs.ScopeMetrics().Len(); j++ { | ||
| ilm := rs.ScopeMetrics().At(j) | ||
|
|
||
| newILM := newRM.ScopeMetrics().AppendEmpty() | ||
| ilm.Scope().CopyTo(newILM.Scope()) | ||
| newILM.SetSchemaUrl(ilm.SchemaUrl()) | ||
|
|
||
| for k := 0; k < ilm.Metrics().Len(); k++ { | ||
| m := ilm.Metrics().At(k) | ||
| newMetric := newILM.Metrics().AppendEmpty() | ||
| m.CopyTo(newMetric) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| return merged | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package loadbalancingexporter | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| "go.opentelemetry.io/collector/pdata/pmetric" | ||
| "go.opentelemetry.io/collector/pdata/ptrace" | ||
| conventions "go.opentelemetry.io/collector/semconv/v1.6.1" | ||
| ) | ||
|
|
||
| func TestMergeTracesTwoEmpty(t *testing.T) { | ||
| expectedEmpty := ptrace.NewTraces() | ||
| trace1 := ptrace.Traces{} | ||
| trace2 := ptrace.Traces{} | ||
|
|
||
| mergedTraces := mergeTraces(trace1, trace2) | ||
|
|
||
| require.Equal(t, expectedEmpty, mergedTraces) | ||
| } | ||
|
|
||
| func TestMergeTracesSingleEmpty(t *testing.T) { | ||
| expectedTraces := simpleTraces() | ||
|
|
||
| trace1 := ptrace.Traces{} | ||
| trace2 := simpleTraces() | ||
|
|
||
| mergedTraces := mergeTraces(trace1, trace2) | ||
|
|
||
| require.Equal(t, expectedTraces, mergedTraces) | ||
| } | ||
|
|
||
| func TestMergeTraces(t *testing.T) { | ||
jpkrohling marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| expectedTraces := ptrace.NewTraces() | ||
| expectedTraces.ResourceSpans().EnsureCapacity(3) | ||
| aspans := expectedTraces.ResourceSpans().AppendEmpty() | ||
| aspans.Resource().Attributes().PutStr(conventions.AttributeServiceName, "service-name-1") | ||
| aspans.ScopeSpans().AppendEmpty().Spans().AppendEmpty().SetTraceID([16]byte{1, 2, 3, 4}) | ||
| bspans := expectedTraces.ResourceSpans().AppendEmpty() | ||
| bspans.Resource().Attributes().PutStr(conventions.AttributeServiceName, "service-name-2") | ||
| bspans.ScopeSpans().AppendEmpty().Spans().AppendEmpty().SetTraceID([16]byte{1, 2, 3, 2}) | ||
| cspans := expectedTraces.ResourceSpans().AppendEmpty() | ||
| cspans.Resource().Attributes().PutStr(conventions.AttributeServiceName, "service-name-3") | ||
| cspans.ScopeSpans().AppendEmpty().Spans().AppendEmpty().SetTraceID([16]byte{1, 2, 3, 3}) | ||
|
|
||
| trace1 := ptrace.NewTraces() | ||
| trace1.ResourceSpans().EnsureCapacity(2) | ||
| t1aspans := trace1.ResourceSpans().AppendEmpty() | ||
| t1aspans.Resource().Attributes().PutStr(conventions.AttributeServiceName, "service-name-1") | ||
| t1aspans.ScopeSpans().AppendEmpty().Spans().AppendEmpty().SetTraceID([16]byte{1, 2, 3, 4}) | ||
| t1bspans := trace1.ResourceSpans().AppendEmpty() | ||
| t1bspans.Resource().Attributes().PutStr(conventions.AttributeServiceName, "service-name-2") | ||
| t1bspans.ScopeSpans().AppendEmpty().Spans().AppendEmpty().SetTraceID([16]byte{1, 2, 3, 2}) | ||
|
|
||
| trace2 := ptrace.NewTraces() | ||
| trace2.ResourceSpans().EnsureCapacity(1) | ||
| t2cspans := trace2.ResourceSpans().AppendEmpty() | ||
| t2cspans.Resource().Attributes().PutStr(conventions.AttributeServiceName, "service-name-3") | ||
| t2cspans.ScopeSpans().AppendEmpty().Spans().AppendEmpty().SetTraceID([16]byte{1, 2, 3, 3}) | ||
|
|
||
| mergedTraces := mergeTraces(trace1, trace2) | ||
|
|
||
| require.Equal(t, expectedTraces, mergedTraces) | ||
| } | ||
|
|
||
| func TestMergeMetricsTwoEmpty(t *testing.T) { | ||
| expectedEmpty := pmetric.NewMetrics() | ||
| metric1 := pmetric.Metrics{} | ||
| metric2 := pmetric.Metrics{} | ||
|
|
||
| mergedMetrics := mergeMetrics(metric1, metric2) | ||
|
|
||
| require.Equal(t, expectedEmpty, mergedMetrics) | ||
| } | ||
|
|
||
| func TestMergeMetricsSingleEmpty(t *testing.T) { | ||
| expectedMetrics := simpleMetricsWithResource() | ||
|
|
||
| metric1 := pmetric.Metrics{} | ||
| metric2 := simpleMetricsWithResource() | ||
|
|
||
| mergedMetrics := mergeMetrics(metric1, metric2) | ||
|
|
||
| require.Equal(t, expectedMetrics, mergedMetrics) | ||
| } | ||
|
|
||
| func TestMergeMetrics(t *testing.T) { | ||
| expectedMetrics := pmetric.NewMetrics() | ||
| expectedMetrics.ResourceMetrics().EnsureCapacity(3) | ||
| ametrics := expectedMetrics.ResourceMetrics().AppendEmpty() | ||
| ametrics.Resource().Attributes().PutStr(conventions.AttributeServiceName, "service-name-1") | ||
| ametrics.ScopeMetrics().AppendEmpty().Metrics().AppendEmpty().SetName("m1") | ||
| bmetrics := expectedMetrics.ResourceMetrics().AppendEmpty() | ||
| bmetrics.Resource().Attributes().PutStr(conventions.AttributeServiceName, "service-name-2") | ||
| bmetrics.ScopeMetrics().AppendEmpty().Metrics().AppendEmpty().SetName("m1") | ||
| cmetrics := expectedMetrics.ResourceMetrics().AppendEmpty() | ||
| cmetrics.Resource().Attributes().PutStr(conventions.AttributeServiceName, "service-name-3") | ||
| cmetrics.ScopeMetrics().AppendEmpty().Metrics().AppendEmpty().SetName("m2") | ||
|
|
||
| metric1 := pmetric.NewMetrics() | ||
| metric1.ResourceMetrics().EnsureCapacity(2) | ||
| m1ametrics := metric1.ResourceMetrics().AppendEmpty() | ||
| m1ametrics.Resource().Attributes().PutStr(conventions.AttributeServiceName, "service-name-1") | ||
| m1ametrics.ScopeMetrics().AppendEmpty().Metrics().AppendEmpty().SetName("m1") | ||
| m1bmetrics := metric1.ResourceMetrics().AppendEmpty() | ||
| m1bmetrics.Resource().Attributes().PutStr(conventions.AttributeServiceName, "service-name-2") | ||
| m1bmetrics.ScopeMetrics().AppendEmpty().Metrics().AppendEmpty().SetName("m1") | ||
|
|
||
| metric2 := pmetric.NewMetrics() | ||
| metric2.ResourceMetrics().EnsureCapacity(1) | ||
| m2cmetrics := metric2.ResourceMetrics().AppendEmpty() | ||
| m2cmetrics.Resource().Attributes().PutStr(conventions.AttributeServiceName, "service-name-3") | ||
| m2cmetrics.ScopeMetrics().AppendEmpty().Metrics().AppendEmpty().SetName("m2") | ||
|
|
||
| mergedMetrics := mergeMetrics(metric1, metric2) | ||
|
|
||
| require.Equal(t, expectedMetrics, mergedMetrics) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.