From 117f108642c2437ccd472bd0363a55e9390b1b18 Mon Sep 17 00:00:00 2001 From: Karsten Jeschkies Date: Tue, 14 Nov 2023 10:30:20 +0100 Subject: [PATCH] Return error if span context was not found (#11207) **What this PR does / why we need it**: This is a follow up to https://github.com/grafana/loki/pull/10956. `lokigrpc.GetParentSpanForRequest` would ignore `opentracing.ErrSpanContextNotFound`. However, that should be up to the caller to decide whether this error should be ignored or not. **Checklist** - [ ] Reviewed the [`CONTRIBUTING.md`](https://github.com/grafana/loki/blob/main/CONTRIBUTING.md) guide (**required**) - [ ] Documentation added - [ ] Tests updated - [ ] `CHANGELOG.md` updated - [ ] If the change is worth mentioning in the release notes, add `add-to-release-notes` label - [ ] Changes that require user attention or interaction to upgrade are documented in `docs/sources/setup/upgrade/_index.md` - [ ] For Helm chart changes bump the Helm chart version in `production/helm/loki/Chart.yaml` and update `production/helm/loki/CHANGELOG.md` and `production/helm/loki/README.md`. [Example PR](https://github.com/grafana/loki/commit/d10549e3ece02120974929894ee333d07755d213) - [ ] If the change is deprecating or removing a configuration option, update the `deprecated-config.yaml` and `deleted-config.yaml` files respectively in the `tools/deprecated-config-checker` directory. [Example PR](https://github.com/grafana/loki/pull/10840/commits/0d4416a4b03739583349934b96f272fb4f685d15) --- pkg/scheduler/scheduler.go | 2 +- pkg/util/httpgrpc/carrier.go | 12 ++---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/pkg/scheduler/scheduler.go b/pkg/scheduler/scheduler.go index b5ff71b9ce188..305d47b17e571 100644 --- a/pkg/scheduler/scheduler.go +++ b/pkg/scheduler/scheduler.go @@ -333,7 +333,7 @@ func (s *Scheduler) enqueueRequest(frontendContext context.Context, frontendAddr // information, since that is a long-running request. tracer := opentracing.GlobalTracer() parentSpanContext, err := lokigrpc.GetParentSpanForRequest(tracer, msg) - if err != nil { + if err != nil && err != opentracing.ErrSpanContextNotFound { return err } diff --git a/pkg/util/httpgrpc/carrier.go b/pkg/util/httpgrpc/carrier.go index b52b51ae352b2..ab1753ef6c271 100644 --- a/pkg/util/httpgrpc/carrier.go +++ b/pkg/util/httpgrpc/carrier.go @@ -39,11 +39,7 @@ func GetParentSpanForHTTPRequest(tracer opentracing.Tracer, req *weaveworks_http } carrier := (*HeadersCarrier)(req) - extracted, err := tracer.Extract(opentracing.HTTPHeaders, carrier) - if err == opentracing.ErrSpanContextNotFound { - err = nil - } - return extracted, err + return tracer.Extract(opentracing.HTTPHeaders, carrier) } func GetParentSpanForQueryRequest(tracer opentracing.Tracer, req *queryrange.QueryRequest) (opentracing.SpanContext, error) { @@ -52,11 +48,7 @@ func GetParentSpanForQueryRequest(tracer opentracing.Tracer, req *queryrange.Que } carrier := opentracing.TextMapCarrier(req.Metadata) - extracted, err := tracer.Extract(opentracing.TextMap, carrier) - if err == opentracing.ErrSpanContextNotFound { - err = nil - } - return extracted, err + return tracer.Extract(opentracing.TextMap, carrier) } func GetParentSpanForRequest(tracer opentracing.Tracer, req Request) (opentracing.SpanContext, error) {