Skip to content

Commit 2fa044e

Browse files
upgrade to latest dependencies
bumping knative.dev/reconciler-test bc8fcf4...e342acf: > e342acf fix: ConfigureObservability does not panic (# 809) > e7475ca Migrate to OTel (# 802) bumping knative.dev/eventing 51710e2...96629b6: > 96629b6 Injected tracing headers into jobsink event file (# 8626) > 02861b7 cleanup: drop pkg/tracing from test code (# 8654) > 3bdae0a drop use of tracing config map in webhook (# 8653) Signed-off-by: Knative Automation <automation@knative.team>
1 parent b2f4633 commit 2fa044e

24 files changed

Lines changed: 639 additions & 869 deletions

File tree

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ require (
3030
k8s.io/client-go v0.33.1
3131
k8s.io/code-generator v0.33.1
3232
k8s.io/utils v0.0.0-20241210054802-24370beab758
33-
knative.dev/eventing v0.46.1-0.20250805061645-51710e296f74
33+
knative.dev/eventing v0.46.1-0.20250806184748-96629b6daeaa
3434
knative.dev/hack v0.0.0-20250708013849-70d4b00da6ba
3535
knative.dev/pkg v0.0.0-20250804212045-2a0abb7b5eb3
36-
knative.dev/reconciler-test v0.0.0-20250805131045-bc8fcf423e5e
36+
knative.dev/reconciler-test v0.0.0-20250806183548-e342acf1222a
3737
)
3838

3939
require (

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,14 +1112,14 @@ k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff h1:/usPimJzUKKu+m+TE36gUy
11121112
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff/go.mod h1:5jIi+8yX4RIb8wk3XwBo5Pq2ccx4FP10ohkbSKCZoK8=
11131113
k8s.io/utils v0.0.0-20241210054802-24370beab758 h1:sdbE21q2nlQtFh65saZY+rRM6x6aJJI8IUa1AmH/qa0=
11141114
k8s.io/utils v0.0.0-20241210054802-24370beab758/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
1115-
knative.dev/eventing v0.46.1-0.20250805061645-51710e296f74 h1:Z+gYUj++s6v4qynhmK2EJMejTQGcq1gM59MOl8H2ICk=
1116-
knative.dev/eventing v0.46.1-0.20250805061645-51710e296f74/go.mod h1:BQNh9QU5WuRmVWKSTmTctaWdj1Ck4wyJvvug/0ogE6Y=
1115+
knative.dev/eventing v0.46.1-0.20250806184748-96629b6daeaa h1:ODQkc9RO2nFpdu3iyfgmHp0b6M1iqmC07Rb/65A9bGI=
1116+
knative.dev/eventing v0.46.1-0.20250806184748-96629b6daeaa/go.mod h1:BQNh9QU5WuRmVWKSTmTctaWdj1Ck4wyJvvug/0ogE6Y=
11171117
knative.dev/hack v0.0.0-20250708013849-70d4b00da6ba h1:PkOTBI8DRfvUKD8HTvYYT94NJ49J++llrDo3y0/ZAwc=
11181118
knative.dev/hack v0.0.0-20250708013849-70d4b00da6ba/go.mod h1:R0ritgYtjLDO9527h5vb5X6gfvt5LCrJ55BNbVDsWiY=
11191119
knative.dev/pkg v0.0.0-20250804212045-2a0abb7b5eb3 h1:5IWHlFvSTR/gZY+bShXCAHFFZ6rQqhYvx1KxVwlsnKw=
11201120
knative.dev/pkg v0.0.0-20250804212045-2a0abb7b5eb3/go.mod h1:qpyBu3z/r1fRfyLo/Zdpis1mmtixdXmsCPmJMz/BsLc=
1121-
knative.dev/reconciler-test v0.0.0-20250805131045-bc8fcf423e5e h1:/IuumrK2gVN2yUJtspseUNLS97Zcc3jbbY1J+3Z3zr0=
1122-
knative.dev/reconciler-test v0.0.0-20250805131045-bc8fcf423e5e/go.mod h1:xfGnTey3jlX2Nf2xw1UX4+JKCVb1Zn4A11boUsTj6IY=
1121+
knative.dev/reconciler-test v0.0.0-20250806183548-e342acf1222a h1:JFijhaQnYGxrG/8rkA79wBG8X4t3mXJI3T4M1gLoaWc=
1122+
knative.dev/reconciler-test v0.0.0-20250806183548-e342acf1222a/go.mod h1:Yrp3+hda56ss8D3lG42NTMSaeJ/cI2WkuhotcSpGKmg=
11231123
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
11241124
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
11251125
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=

vendor/knative.dev/pkg/test/helpers/dryrun.go renamed to vendor/knative.dev/eventing/pkg/observability/configmap/configmap.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
Copyright 2019 The Knative Authors
2+
Copyright 2025 The Knative Authors
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
66
You may obtain a copy of the License at
77
8-
http://www.apache.org/licenses/LICENSE-2.0
8+
http://www.apache.org/licenses/LICENSE-2.0
99
1010
Unless required by applicable law or agreed to in writing, software
1111
distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,19 +14,18 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package helpers
17+
package configmap
1818

1919
import (
20-
"log"
20+
corev1 "k8s.io/api/core/v1"
21+
"knative.dev/eventing/pkg/observability"
22+
o11yconfigmap "knative.dev/pkg/observability/configmap"
2123
)
2224

23-
// Run can run functions that needs dryrun support.
24-
func Run(message string, call func() error, dryrun bool) error {
25-
if dryrun {
26-
log.Print("[dry run] ", message)
27-
return nil
28-
}
29-
log.Print(message)
25+
func Name() string {
26+
return o11yconfigmap.Name()
27+
}
3028

31-
return call()
29+
func Parse(c *corev1.ConfigMap) (*observability.Config, error) {
30+
return observability.NewFromMap(c.Data)
3231
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
Copyright 2025 The Knative Authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package otel
18+
19+
import (
20+
"fmt"
21+
"net/http"
22+
23+
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
24+
"go.opentelemetry.io/otel/metric"
25+
"go.opentelemetry.io/otel/trace"
26+
27+
"knative.dev/pkg/network"
28+
"knative.dev/pkg/observability/tracing"
29+
)
30+
31+
func NewHandler(handler http.Handler, operation string, meterProvider metric.MeterProvider, traceProvider trace.TracerProvider, opts ...otelhttp.Option) http.Handler {
32+
opts = append(
33+
[]otelhttp.Option{
34+
otelhttp.WithMeterProvider(meterProvider),
35+
otelhttp.WithTracerProvider(traceProvider),
36+
otelhttp.WithFilter(func(r *http.Request) bool {
37+
return !network.IsKubeletProbe(r)
38+
}),
39+
otelhttp.WithPropagators(tracing.DefaultTextMapPropagator()),
40+
otelhttp.WithSpanNameFormatter(func(operation string, r *http.Request) string {
41+
if r.URL.Path == "" {
42+
return r.Method + " /"
43+
}
44+
return fmt.Sprintf("%s %s", r.Method, r.URL.Path)
45+
}),
46+
},
47+
opts...,
48+
)
49+
newHandler := otelhttp.NewHandler(
50+
handler,
51+
operation,
52+
opts...,
53+
)
54+
55+
return newHandler
56+
}
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/*
2+
Copyright 2025 The Knative Authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package otel
18+
19+
import (
20+
"context"
21+
22+
"go.opentelemetry.io/contrib/instrumentation/runtime"
23+
"go.opentelemetry.io/otel"
24+
"go.opentelemetry.io/otel/sdk/metric"
25+
sdkresource "go.opentelemetry.io/otel/sdk/resource"
26+
"go.opentelemetry.io/otel/sdk/trace"
27+
28+
"go.uber.org/zap"
29+
30+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
31+
"k8s.io/client-go/util/workqueue"
32+
33+
apierrors "k8s.io/apimachinery/pkg/api/errors"
34+
k8stoolmetrics "k8s.io/client-go/tools/metrics"
35+
"knative.dev/eventing/pkg/observability"
36+
"knative.dev/eventing/pkg/observability/configmap"
37+
kubeclient "knative.dev/pkg/client/injection/kube/client"
38+
"knative.dev/pkg/controller"
39+
o11yconfigmap "knative.dev/pkg/observability/configmap"
40+
"knative.dev/pkg/observability/metrics"
41+
k8smetrics "knative.dev/pkg/observability/metrics/k8s"
42+
"knative.dev/pkg/observability/resource"
43+
k8sruntime "knative.dev/pkg/observability/runtime/k8s"
44+
"knative.dev/pkg/observability/tracing"
45+
"knative.dev/pkg/system"
46+
)
47+
48+
func SetupObservabilityOrDie(
49+
ctx context.Context,
50+
component string,
51+
logger *zap.SugaredLogger,
52+
pprof *k8sruntime.ProfilingServer,
53+
) (*metrics.MeterProvider, *tracing.TracerProvider) {
54+
cfg, err := GetObservabilityConfig(ctx)
55+
if err != nil {
56+
logger.Fatalw("error loading observability configuration", zap.Error(err))
57+
}
58+
59+
pprof.UpdateFromConfig(cfg.Runtime)
60+
61+
otelResource := resource.Default(component)
62+
63+
meterProvider, err := metrics.NewMeterProvider(
64+
ctx,
65+
cfg.Metrics,
66+
metric.WithResource(otelResource),
67+
)
68+
if err != nil {
69+
logger.Fatalw("failed to set up meter provider", zap.Error(err))
70+
}
71+
72+
otel.SetMeterProvider(meterProvider)
73+
74+
workQueueMetrics, err := k8smetrics.NewWorkqueueMetricsProvider(
75+
k8smetrics.WithMeterProvider(meterProvider),
76+
)
77+
if err != nil {
78+
logger.Fatalw("failed to setup k8s workqueue metrics", zap.Error(err))
79+
}
80+
81+
workqueue.SetProvider(workQueueMetrics)
82+
controller.SetMetricsProvider(workQueueMetrics)
83+
84+
clientMetrics, err := k8smetrics.NewClientMetricProvider(
85+
k8smetrics.WithMeterProvider(meterProvider),
86+
)
87+
if err != nil {
88+
logger.Fatalw("failed to setup k8s client-go metrics", zap.Error(err))
89+
}
90+
91+
k8stoolmetrics.Register(k8stoolmetrics.RegisterOpts{
92+
RequestLatency: clientMetrics.RequestLatencyMetric(),
93+
RequestResult: clientMetrics.RequestResultMetric(),
94+
})
95+
96+
err = runtime.Start(
97+
runtime.WithMinimumReadMemStatsInterval(cfg.Runtime.ExportInterval),
98+
)
99+
if err != nil {
100+
logger.Fatalw("failed to start runtime metrics", zap.Error(err))
101+
}
102+
103+
tracerProvider, err := tracing.NewTracerProvider(
104+
ctx,
105+
cfg.Tracing,
106+
trace.WithResource(otelResource),
107+
)
108+
if err != nil {
109+
logger.Fatalw("failed to setup trace provider", zap.Error(err))
110+
}
111+
112+
otel.SetTextMapPropagator(tracing.DefaultTextMapPropagator())
113+
otel.SetTracerProvider(tracerProvider)
114+
115+
return meterProvider, tracerProvider
116+
}
117+
118+
func DefaultMeterProvider(ctx context.Context, resource *sdkresource.Resource) *metrics.MeterProvider {
119+
meterProvider, _ := metrics.NewMeterProvider(
120+
ctx,
121+
observability.DefaultConfig().Metrics,
122+
metric.WithResource(resource),
123+
)
124+
125+
return meterProvider
126+
}
127+
128+
func DefaultTraceProvider(ctx context.Context, resource *sdkresource.Resource) *tracing.TracerProvider {
129+
traceProvider, _ := tracing.NewTracerProvider(
130+
ctx,
131+
observability.DefaultConfig().Tracing,
132+
trace.WithResource(resource),
133+
)
134+
135+
return traceProvider
136+
}
137+
138+
// GetObservabilityConfig gets the observability config from the (in order):
139+
// 1. the provided context,
140+
// 2. from the API server,
141+
// 3. default values (if not found and there were no other errors in the api server request).
142+
func GetObservabilityConfig(ctx context.Context) (*observability.Config, error) {
143+
if cfg := observability.GetConfig(ctx); cfg != nil {
144+
return cfg, nil
145+
}
146+
147+
cm, err := kubeclient.Get(ctx).CoreV1().ConfigMaps(system.Namespace()).
148+
Get(ctx, o11yconfigmap.Name(), metav1.GetOptions{})
149+
150+
if apierrors.IsNotFound(err) {
151+
return observability.DefaultConfig(), nil
152+
} else if err != nil {
153+
return nil, err
154+
}
155+
156+
return configmap.Parse(cm)
157+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
Copyright 2025 The Knative Authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package resource
18+
19+
import (
20+
"errors"
21+
"fmt"
22+
"os"
23+
24+
"knative.dev/pkg/changeset"
25+
"knative.dev/pkg/system"
26+
27+
"go.opentelemetry.io/otel/attribute"
28+
"go.opentelemetry.io/otel/sdk/resource"
29+
semconv "go.opentelemetry.io/otel/semconv/v1.34.0"
30+
)
31+
32+
const (
33+
otelServiceNameKey = "OTEL_SERVICE_NAME"
34+
)
35+
36+
func Default(serviceName string) (*resource.Resource, error) {
37+
if name := os.Getenv(otelServiceNameKey); name != "" {
38+
serviceName = name
39+
}
40+
41+
attrs := []attribute.KeyValue{
42+
semconv.ServiceVersion(changeset.Get()),
43+
semconv.ServiceName(serviceName),
44+
}
45+
46+
var err error
47+
48+
if namespace := os.Getenv(system.NamespaceEnvKey); namespace != "" {
49+
attrs = append(attrs, semconv.K8SNamespaceName(namespace))
50+
} else {
51+
err = fmt.Errorf(
52+
"the environment variable %q is not set, not adding %q to otel attributes",
53+
system.NamespaceEnvKey,
54+
semconv.K8SNamespaceNameKey,
55+
)
56+
}
57+
58+
resource, resourceErr := resource.Merge(
59+
resource.Default(),
60+
resource.NewWithAttributes(
61+
semconv.SchemaURL,
62+
attrs...,
63+
),
64+
)
65+
66+
if resourceErr != nil {
67+
err = errors.Join(err, fmt.Errorf("encountered error while merging otel resources: %s", resourceErr.Error()))
68+
}
69+
70+
return resource, err
71+
}

0 commit comments

Comments
 (0)