-
Notifications
You must be signed in to change notification settings - Fork 300
feat(tracing): add tracing support and configuration options for BBR #2518
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 1 commit
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 |
|---|---|---|
|
|
@@ -42,8 +42,10 @@ import ( | |
| "sigs.k8s.io/gateway-api-inference-extension/pkg/bbr/metrics" | ||
| "sigs.k8s.io/gateway-api-inference-extension/pkg/bbr/plugins" | ||
| runserver "sigs.k8s.io/gateway-api-inference-extension/pkg/bbr/server" | ||
| "sigs.k8s.io/gateway-api-inference-extension/pkg/bbr/tracing" | ||
| logutil "sigs.k8s.io/gateway-api-inference-extension/pkg/common/observability/logging" | ||
| "sigs.k8s.io/gateway-api-inference-extension/pkg/common/observability/profiling" | ||
|
|
||
| "sigs.k8s.io/gateway-api-inference-extension/version" | ||
| ) | ||
|
|
||
|
|
@@ -102,6 +104,15 @@ func (r *Runner) Run(ctx context.Context) error { | |
| pflag.VisitAll(func(f *pflag.Flag) { | ||
| flags[f.Name] = f.Value | ||
| }) | ||
|
|
||
| if opts.Tracing { | ||
| err := tracing.InitTracing(ctx, setupLog) | ||
| if err != nil { | ||
| setupLog.Error(err, "failed to initialize tracing") | ||
| return err | ||
| } | ||
| } | ||
|
|
||
|
Comment on lines
+107
to
+114
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand that the intention is to keep separate traces between bbr/epp.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| setupLog.Info("Flags processed", "flags", flags) | ||
|
|
||
| logutil.InitLogging(&opts.ZapOptions) | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -33,13 +33,42 @@ spec: | |||||||||||||||||||||||||
| - {{ printf "%s:%s" .type .name | quote }} | ||||||||||||||||||||||||||
| {{- end }} | ||||||||||||||||||||||||||
| {{- end }} | ||||||||||||||||||||||||||
| {{- if not .Values.bbr.multiNamespace }} | ||||||||||||||||||||||||||
| {{- if .Values.bbr.tracing.enabled}} | ||||||||||||||||||||||||||
| - --tracing=true | ||||||||||||||||||||||||||
| {{- else}} | ||||||||||||||||||||||||||
| - --tracing=false | ||||||||||||||||||||||||||
| {{- end}} | ||||||||||||||||||||||||||
|
Comment on lines
+36
to
+40
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it possible to align with other flags using key/value in separate cmd-line flags? does it work?
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will not work because it resolves to |
||||||||||||||||||||||||||
| env: | ||||||||||||||||||||||||||
| {{- if not .Values.bbr.multiNamespace }} | ||||||||||||||||||||||||||
| - name: NAMESPACE | ||||||||||||||||||||||||||
| valueFrom: | ||||||||||||||||||||||||||
| fieldRef: | ||||||||||||||||||||||||||
| fieldPath: metadata.namespace | ||||||||||||||||||||||||||
| {{- end }} | ||||||||||||||||||||||||||
| {{- if .Values.bbr.tracing.enabled}} | ||||||||||||||||||||||||||
|
Comment on lines
+42
to
+48
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. out of curiosity, is leaving
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is valid and works, but it would be better to add another
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can leave it as is for now since empty |
||||||||||||||||||||||||||
| - name: OTEL_SERVICE_NAME | ||||||||||||||||||||||||||
| value: {{ .Values.bbr.tracing.otelServiceName | default "gateway-api-inference-extension/bbr" }} | ||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we move default to |
||||||||||||||||||||||||||
| - name: OTEL_EXPORTER_OTLP_ENDPOINT | ||||||||||||||||||||||||||
| value: {{ .Values.bbr.tracing.otelExporterEndpoint }} | ||||||||||||||||||||||||||
| - name: OTEL_RESOURCE_ATTRIBUTES_NODE_NAME | ||||||||||||||||||||||||||
| valueFrom: | ||||||||||||||||||||||||||
| fieldRef: | ||||||||||||||||||||||||||
| apiVersion: v1 | ||||||||||||||||||||||||||
| fieldPath: spec.nodeName | ||||||||||||||||||||||||||
| - name: OTEL_RESOURCE_ATTRIBUTES_POD_NAME | ||||||||||||||||||||||||||
| valueFrom: | ||||||||||||||||||||||||||
| fieldRef: | ||||||||||||||||||||||||||
| apiVersion: v1 | ||||||||||||||||||||||||||
| fieldPath: metadata.name | ||||||||||||||||||||||||||
| - name: OTEL_RESOURCE_ATTRIBUTES | ||||||||||||||||||||||||||
| value: 'k8s.namespace.name=$(NAMESPACE),k8s.node.name=$(OTEL_RESOURCE_ATTRIBUTES_NODE_NAME),k8s.pod.name=$(OTEL_RESOURCE_ATTRIBUTES_POD_NAME)' | ||||||||||||||||||||||||||
| - name: OTEL_TRACES_SAMPLER | ||||||||||||||||||||||||||
| value: {{ .Values.bbr.tracing.sampling.sampler | quote }} | ||||||||||||||||||||||||||
| - name: OTEL_TRACES_SAMPLER_ARG | ||||||||||||||||||||||||||
| value: {{ .Values.bbr.tracing.sampling.samplerArg | quote }} | ||||||||||||||||||||||||||
| - name: OTEL_TRACES_EXPORTER | ||||||||||||||||||||||||||
| value: otlp | ||||||||||||||||||||||||||
| {{- end}} | ||||||||||||||||||||||||||
| ports: | ||||||||||||||||||||||||||
| - containerPort: {{ .Values.bbr.port }} | ||||||||||||||||||||||||||
| # health check | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -14,6 +14,15 @@ bbr: | |||||
| # Log verbosity | ||||||
| v: 3 | ||||||
|
|
||||||
| tracing: | ||||||
| enabled: true | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you align with epp and put default
Suggested change
|
||||||
| # Sets Custom service name for traces if left empty it will default to `gateway-api-inference-extension/bbr` | ||||||
| otelServiceName: "" | ||||||
| otelExporterEndpoint: "http://localhost:4317" | ||||||
| sampling: | ||||||
| sampler: "parentbased_traceidratio" | ||||||
| samplerArg: "0.1" | ||||||
|
|
||||||
| provider: | ||||||
| name: none | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| Copyright 2026 The Kubernetes Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package tracing | ||
|
|
||
| import ( | ||
| "context" | ||
| "os" | ||
|
|
||
| "github.com/go-logr/logr" | ||
| "go.opentelemetry.io/otel" | ||
| "go.opentelemetry.io/otel/attribute" | ||
| "go.opentelemetry.io/otel/trace" | ||
| tracingutils "sigs.k8s.io/gateway-api-inference-extension/pkg/common/observability/tracing" | ||
| "sigs.k8s.io/gateway-api-inference-extension/version" | ||
| ) | ||
|
|
||
| const ( | ||
| defaultServiceName = "gateway-api-inference-extension/bbr" | ||
| extprocInstrumentationName = defaultServiceName + "/extproc" | ||
| ) | ||
|
|
||
| func InitTracing(ctx context.Context, logger logr.Logger) error { | ||
| _, ok := os.LookupEnv("OTEL_SERVICE_NAME") | ||
| if !ok { | ||
| os.Setenv("OTEL_SERVICE_NAME", defaultServiceName) | ||
| } | ||
|
|
||
| return tracingutils.InitTracing(ctx, logger) | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we instead pass in default service name and completely reuse in both places? |
||
|
|
||
| func GetExtProcTracer() trace.Tracer { | ||
| return otel.Tracer( | ||
| extprocInstrumentationName, | ||
| trace.WithInstrumentationVersion(version.BuildRef), | ||
| trace.WithInstrumentationAttributes( | ||
| attribute.String("commit-sha", version.CommitSHA), | ||
| ), | ||
| ) | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this looks different than what we have in epp.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like i mentioned earlier i do plan to make it uniform with EPP in future PR. The intention for adding these 2 funcs If you suggest, for now i can use default name in case of epp and pass bbr specific names to the common function. By removing the tracing package for now from bbr.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recommend to keep it aligned in both places. tracingServiceName := env.GetEnvString(envVar, "<THE-DEFAULT-PER-COMPONENT>", setupLog)
tracing.InitTracing(... current args ..., additional-arg: tracingServingName)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so instead of diverging, and then try to align things - it would probably be better to align on current tracing from epp, then if things need to be added (e.g., like CommitSHA and buildRef which seems useful), we add it in the common packages, and then both epp/bbr get those changes. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove extra space.