-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[exporter/loadbalancingexporter] batch before exporting in load balancer #18273
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
Changes from 6 commits
480666d
557b28d
6d1a64b
b74a8e6
03c3682
7ed46ae
24b8879
e7baf84
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # 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: Add batching for each endpoint in the loadbalancingexporter. | ||
|
|
||
| # One or more tracking issues related to the change | ||
| issues: [17173] | ||
|
|
||
| # (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: | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,46 +90,59 @@ func (e *traceExporterImp) Shutdown(context.Context) error { | |
| func (e *traceExporterImp) ConsumeTraces(ctx context.Context, td ptrace.Traces) error { | ||
| var errs error | ||
| batches := batchpersignal.SplitTraces(td) | ||
| for _, batch := range batches { | ||
| errs = multierr.Append(errs, e.consumeTrace(ctx, batch)) | ||
| endpointToTraceData := make(map[string]ptrace.Traces) | ||
|
|
||
| // Map the trace data to their respective endpoints. | ||
| for batch := range batches { | ||
| routingIDs, err := routingIdentifiersFromTraces(batches[batch], e.routingKey) | ||
| errs = multierr.Append(errs, err) | ||
| for rid := range routingIDs { | ||
| endpoint := e.loadBalancer.Endpoint([]byte(rid)) | ||
| if _, ok := endpointToTraceData[endpoint]; ok { | ||
| // append | ||
| for i := 0; i < batches[batch].ResourceSpans().Len(); i++ { | ||
| batches[batch].ResourceSpans().At(i).CopyTo(endpointToTraceData[endpoint].ResourceSpans().AppendEmpty()) | ||
| } | ||
|
||
| } else { | ||
| newTrace := ptrace.NewTraces() | ||
| for i := 0; i < batches[batch].ResourceSpans().Len(); i++ { | ||
| batches[batch].ResourceSpans().At(i).CopyTo(newTrace.ResourceSpans().AppendEmpty()) | ||
| } | ||
| endpointToTraceData[endpoint] = newTrace | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Send the trace data off by endpoint. | ||
| for endpoint, traces := range endpointToTraceData { | ||
| errs = multierr.Append(errs, e.consumeTrace(ctx, traces, endpoint)) | ||
| } | ||
| return errs | ||
| } | ||
|
|
||
| func (e *traceExporterImp) consumeTrace(ctx context.Context, td ptrace.Traces) error { | ||
| var exp component.Component | ||
| routingIds, err := routingIdentifiersFromTraces(td, e.routingKey) | ||
| func (e *traceExporterImp) consumeTrace(ctx context.Context, td ptrace.Traces, endpoint string) error { | ||
| exp, err := e.loadBalancer.Exporter(endpoint) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| for rid := range routingIds { | ||
| endpoint := e.loadBalancer.Endpoint([]byte(rid)) | ||
| exp, err = e.loadBalancer.Exporter(endpoint) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| te, ok := exp.(exporter.Traces) | ||
| if !ok { | ||
| return fmt.Errorf("unable to export traces, unexpected exporter type: expected exporter.Traces but got %T", exp) | ||
| } | ||
|
|
||
| start := time.Now() | ||
| err = te.ConsumeTraces(ctx, td) | ||
| duration := time.Since(start) | ||
|
|
||
| if err == nil { | ||
| _ = stats.RecordWithTags( | ||
| ctx, | ||
| []tag.Mutator{tag.Upsert(endpointTagKey, endpoint), successTrueMutator}, | ||
| mBackendLatency.M(duration.Milliseconds())) | ||
| } else { | ||
| _ = stats.RecordWithTags( | ||
| ctx, | ||
| []tag.Mutator{tag.Upsert(endpointTagKey, endpoint), successFalseMutator}, | ||
| mBackendLatency.M(duration.Milliseconds())) | ||
| } | ||
| te, ok := exp.(exporter.Traces) | ||
| if !ok { | ||
| return fmt.Errorf("unable to export traces, unexpected exporter type: expected exporter.Traces but got %T", exp) | ||
| } | ||
| start := time.Now() | ||
| err = te.ConsumeTraces(ctx, td) | ||
| duration := time.Since(start) | ||
| if err == nil { | ||
| _ = stats.RecordWithTags( | ||
| ctx, | ||
| []tag.Mutator{tag.Upsert(endpointTagKey, endpoint), successTrueMutator}, | ||
| mBackendLatency.M(duration.Milliseconds())) | ||
| } else { | ||
| _ = stats.RecordWithTags( | ||
| ctx, | ||
| []tag.Mutator{tag.Upsert(endpointTagKey, endpoint), successFalseMutator}, | ||
| mBackendLatency.M(duration.Milliseconds())) | ||
| } | ||
| return err | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.