@@ -18,9 +18,12 @@ import (
18
18
"context"
19
19
"fmt"
20
20
"log/slog"
21
+ "os"
21
22
"time"
22
23
23
24
"github.com/blang/semver/v4"
25
+ gokitlog "github.com/go-kit/log"
26
+ "github.com/go-kit/log/level"
24
27
"github.com/go-logr/logr"
25
28
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
26
29
promv1alpha1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1alpha1"
@@ -50,6 +53,8 @@ const (
50
53
)
51
54
52
55
func NewPrometheusCRWatcher (ctx context.Context , logger logr.Logger , cfg allocatorconfig.Config ) (* PrometheusCRWatcher , error ) {
56
+ // TODO: Remove this after go 1.23 upgrade
57
+ promLogger := level .NewFilter (gokitlog .NewLogfmtLogger (os .Stderr ), level .AllowWarn ())
53
58
slogger := slog .New (logr .ToSlogHandler (logger ))
54
59
var resourceSelector * prometheus.ResourceSelector
55
60
mClient , err := monitoringclient .NewForConfig (cfg .ClusterConfig )
@@ -90,7 +95,7 @@ func NewPrometheusCRWatcher(ctx context.Context, logger logr.Logger, cfg allocat
90
95
},
91
96
}
92
97
93
- generator , err := prometheus .NewConfigGenerator (slogger , prom , prometheus . WithEndpointSliceSupport () )
98
+ generator , err := prometheus .NewConfigGenerator (promLogger , prom , true )
94
99
95
100
if err != nil {
96
101
return nil , err
@@ -108,7 +113,7 @@ func NewPrometheusCRWatcher(ctx context.Context, logger logr.Logger, cfg allocat
108
113
logger .Error (err , "Retrying namespace informer creation in promOperator CRD watcher" )
109
114
return true
110
115
}, func () error {
111
- nsMonInf , err = getNamespaceInformer (ctx , map [string ]struct {}{v1 .NamespaceAll : {}}, slogger , clientset , operatorMetrics )
116
+ nsMonInf , err = getNamespaceInformer (ctx , map [string ]struct {}{v1 .NamespaceAll : {}}, promLogger , clientset , operatorMetrics )
112
117
return err
113
118
})
114
119
if getNamespaceInformerErr != nil {
@@ -158,7 +163,7 @@ type PrometheusCRWatcher struct {
158
163
store * assets.StoreBuilder
159
164
}
160
165
161
- func getNamespaceInformer (ctx context.Context , allowList map [string ]struct {}, promOperatorLogger * slog .Logger , clientset kubernetes.Interface , operatorMetrics * operator.Metrics ) (cache.SharedIndexInformer , error ) {
166
+ func getNamespaceInformer (ctx context.Context , allowList map [string ]struct {}, promOperatorLogger gokitlog .Logger , clientset kubernetes.Interface , operatorMetrics * operator.Metrics ) (cache.SharedIndexInformer , error ) {
162
167
kubernetesVersion , err := clientset .Discovery ().ServerVersion ()
163
168
if err != nil {
164
169
return nil , err
@@ -225,7 +230,7 @@ func (w *PrometheusCRWatcher) Watch(upstreamEvents chan Event, upstreamErrors ch
225
230
226
231
if w .nsInformer != nil {
227
232
go w .nsInformer .Run (w .stopChannel )
228
- if ok := cache .WaitForNamedCacheSync ("namespace" , w . stopChannel , w .nsInformer .HasSynced ); ! ok {
233
+ if ok := w .WaitForNamedCacheSync ("namespace" , w .nsInformer .HasSynced ); ! ok {
229
234
success = false
230
235
}
231
236
@@ -248,7 +253,7 @@ func (w *PrometheusCRWatcher) Watch(upstreamEvents chan Event, upstreamErrors ch
248
253
} {
249
254
sync , err := k8sutil .LabelSelectionHasChanged (old .Labels , cur .Labels , selector )
250
255
if err != nil {
251
- w .logger .Error (err . Error (), "Failed to check label selection between namespaces while handling namespace updates" , "selector" , name )
256
+ w .logger .Error ("Failed to check label selection between namespaces while handling namespace updates" , "selector" , name , "error" , err )
252
257
return
253
258
}
254
259
@@ -375,7 +380,7 @@ func (w *PrometheusCRWatcher) LoadConfig(ctx context.Context) (*promconfig.Confi
375
380
"" ,
376
381
nil ,
377
382
nil ,
378
- & monitoringv1.TSDBSpec {},
383
+ monitoringv1.TSDBSpec {},
379
384
nil ,
380
385
nil ,
381
386
serviceMonitorInstances ,
0 commit comments