Bump sigs.k8s.io/controller-runtime to v0.14.4 (#5507)
* Bump sigs.k8s.io/controller-runtime to v0.14.4 * Update gofmt
This commit is contained in:
92
vendor/k8s.io/component-base/tracing/tracing.go
generated
vendored
Normal file
92
vendor/k8s.io/component-base/tracing/tracing.go
generated
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
Copyright 2022 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"
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
utiltrace "k8s.io/utils/trace"
|
||||
)
|
||||
|
||||
const instrumentationScope = "k8s.io/component-base/tracing"
|
||||
|
||||
// Start creates spans using both OpenTelemetry, and the k8s.io/utils/trace package.
|
||||
// It only creates an OpenTelemetry span if the incoming context already includes a span.
|
||||
func Start(ctx context.Context, name string, attributes ...attribute.KeyValue) (context.Context, *Span) {
|
||||
// If the incoming context already includes an OpenTelemetry span, create a child span with the provided name and attributes.
|
||||
// If the caller is not using OpenTelemetry, or has tracing disabled (e.g. with a component-specific feature flag), this is a noop.
|
||||
ctx, otelSpan := trace.SpanFromContext(ctx).TracerProvider().Tracer(instrumentationScope).Start(ctx, name, trace.WithAttributes(attributes...))
|
||||
// If there is already a utiltrace span in the context, use that as our parent span.
|
||||
utilSpan := utiltrace.FromContext(ctx).Nest(name, attributesToFields(attributes)...)
|
||||
// Set the trace as active in the context so that subsequent Start calls create nested spans.
|
||||
return utiltrace.ContextWithTrace(ctx, utilSpan), &Span{
|
||||
otelSpan: otelSpan,
|
||||
utilSpan: utilSpan,
|
||||
}
|
||||
}
|
||||
|
||||
// Span is a component part of a trace. It represents a single named
|
||||
// and timed operation of a workflow being observed.
|
||||
// This Span is a combination of an OpenTelemetry and k8s.io/utils/trace span
|
||||
// to facilitate the migration to OpenTelemetry.
|
||||
type Span struct {
|
||||
otelSpan trace.Span
|
||||
utilSpan *utiltrace.Trace
|
||||
}
|
||||
|
||||
// AddEvent adds a point-in-time event with a name and attributes.
|
||||
func (s *Span) AddEvent(name string, attributes ...attribute.KeyValue) {
|
||||
s.otelSpan.AddEvent(name, trace.WithAttributes(attributes...))
|
||||
if s.utilSpan != nil {
|
||||
s.utilSpan.Step(name, attributesToFields(attributes)...)
|
||||
}
|
||||
}
|
||||
|
||||
// End ends the span, and logs if the span duration is greater than the logThreshold.
|
||||
func (s *Span) End(logThreshold time.Duration) {
|
||||
s.otelSpan.End()
|
||||
if s.utilSpan != nil {
|
||||
s.utilSpan.LogIfLong(logThreshold)
|
||||
}
|
||||
}
|
||||
|
||||
func attributesToFields(attributes []attribute.KeyValue) []utiltrace.Field {
|
||||
fields := make([]utiltrace.Field, len(attributes))
|
||||
for i := range attributes {
|
||||
attr := attributes[i]
|
||||
fields[i] = utiltrace.Field{Key: string(attr.Key), Value: attr.Value.AsInterface()}
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
// SpanFromContext returns the *Span from the current context. It is composed of the active
|
||||
// OpenTelemetry and k8s.io/utils/trace spans.
|
||||
func SpanFromContext(ctx context.Context) *Span {
|
||||
return &Span{
|
||||
otelSpan: trace.SpanFromContext(ctx),
|
||||
utilSpan: utiltrace.FromContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// ContextWithSpan returns a context with the Span included in the context.
|
||||
func ContextWithSpan(ctx context.Context, s *Span) context.Context {
|
||||
return trace.ContextWithSpan(utiltrace.ContextWithTrace(ctx, s.utilSpan), s.otelSpan)
|
||||
}
|
||||
38
vendor/k8s.io/component-base/tracing/utils.go
generated
vendored
38
vendor/k8s.io/component-base/tracing/utils.go
generated
vendored
@@ -21,8 +21,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||
"go.opentelemetry.io/otel/exporters/otlp"
|
||||
"go.opentelemetry.io/otel/exporters/otlp/otlpgrpc"
|
||||
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
@@ -32,22 +31,39 @@ import (
|
||||
"k8s.io/component-base/tracing/api/v1"
|
||||
)
|
||||
|
||||
// TracerProvider is an OpenTelemetry TracerProvider which can be shut down
|
||||
type TracerProvider interface {
|
||||
oteltrace.TracerProvider
|
||||
Shutdown(context.Context) error
|
||||
}
|
||||
|
||||
type noopTracerProvider struct {
|
||||
oteltrace.TracerProvider
|
||||
}
|
||||
|
||||
func (n *noopTracerProvider) Shutdown(context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewNoopTracerProvider() TracerProvider {
|
||||
return &noopTracerProvider{TracerProvider: oteltrace.NewNoopTracerProvider()}
|
||||
}
|
||||
|
||||
// NewProvider creates a TracerProvider in a component, and enforces recommended tracing behavior
|
||||
func NewProvider(ctx context.Context,
|
||||
tracingConfig *v1.TracingConfiguration,
|
||||
addedOpts []otlpgrpc.Option,
|
||||
addedOpts []otlptracegrpc.Option,
|
||||
resourceOpts []resource.Option,
|
||||
) (oteltrace.TracerProvider, error) {
|
||||
) (TracerProvider, error) {
|
||||
if tracingConfig == nil {
|
||||
return oteltrace.NewNoopTracerProvider(), nil
|
||||
return NewNoopTracerProvider(), nil
|
||||
}
|
||||
opts := append([]otlpgrpc.Option{}, addedOpts...)
|
||||
opts := append([]otlptracegrpc.Option{}, addedOpts...)
|
||||
if tracingConfig.Endpoint != nil {
|
||||
opts = append(opts, otlpgrpc.WithEndpoint(*tracingConfig.Endpoint))
|
||||
opts = append(opts, otlptracegrpc.WithEndpoint(*tracingConfig.Endpoint))
|
||||
}
|
||||
opts = append(opts, otlpgrpc.WithInsecure())
|
||||
driver := otlpgrpc.NewDriver(opts...)
|
||||
exporter, err := otlp.NewExporter(ctx, driver)
|
||||
opts = append(opts, otlptracegrpc.WithInsecure())
|
||||
exporter, err := otlptracegrpc.New(ctx, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -88,7 +104,7 @@ func WithTracing(handler http.Handler, tp oteltrace.TracerProvider, serviceName
|
||||
// Example usage:
|
||||
// tp := NewProvider(...)
|
||||
// config, _ := rest.InClusterConfig()
|
||||
// config.Wrap(WrapperFor(&tp))
|
||||
// config.Wrap(WrapperFor(tp))
|
||||
// kubeclient, _ := clientset.NewForConfig(config)
|
||||
func WrapperFor(tp oteltrace.TracerProvider) transport.WrapperFunc {
|
||||
return func(rt http.RoundTripper) http.RoundTripper {
|
||||
|
||||
Reference in New Issue
Block a user