Skip to content

Commit fa53464

Browse files
committed
Use structured logging
1 parent 90f58ce commit fa53464

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

internal/store/builder.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ func (b *Builder) buildStores(
493493
composedMetricGenFuncs,
494494
)
495495
if b.fieldSelectorFilter != "" {
496-
klog.Infof("FieldSelector is used %s", b.fieldSelectorFilter)
496+
klog.InfoS("FieldSelector is used", "fieldSelector", b.fieldSelectorFilter)
497497
}
498498
listWatcher := listWatchFunc(b.kubeClient, v1.NamespaceAll, b.fieldSelectorFilter)
499499
b.startReflector(expectedType, store, listWatcher, useAPIServerCache)
@@ -507,7 +507,7 @@ func (b *Builder) buildStores(
507507
composedMetricGenFuncs,
508508
)
509509
if b.fieldSelectorFilter != "" {
510-
klog.Infof("FieldSelector is used %s", b.fieldSelectorFilter)
510+
klog.InfoS("FieldSelector is used", "fieldSelector", b.fieldSelectorFilter)
511511
}
512512
listWatcher := listWatchFunc(b.kubeClient, ns, b.fieldSelectorFilter)
513513
b.startReflector(expectedType, store, listWatcher, useAPIServerCache)
@@ -540,7 +540,7 @@ func (b *Builder) buildCustomResourceStores(resourceName string,
540540
composedMetricGenFuncs,
541541
)
542542
if b.fieldSelectorFilter != "" {
543-
klog.Infof("FieldSelector is used %s", b.fieldSelectorFilter)
543+
klog.InfoS("FieldSelector is used", "fieldSelector", b.fieldSelectorFilter)
544544
}
545545
listWatcher := listWatchFunc(customResourceClient, v1.NamespaceAll, b.fieldSelectorFilter)
546546
b.startReflector(expectedType, store, listWatcher, useAPIServerCache)
@@ -553,7 +553,7 @@ func (b *Builder) buildCustomResourceStores(resourceName string,
553553
familyHeaders,
554554
composedMetricGenFuncs,
555555
)
556-
klog.Infof("FieldSelector is used %s", b.fieldSelectorFilter)
556+
klog.InfoS("FieldSelector is used", "fieldSelector", b.fieldSelectorFilter)
557557
listWatcher := listWatchFunc(customResourceClient, ns, b.fieldSelectorFilter)
558558
b.startReflector(expectedType, store, listWatcher, useAPIServerCache)
559559
stores = append(stores, store)

internal/wrapper.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func RunKubeStateMetricsWrapper(opts *options.Options) {
5656
klog.FlushAndExit(klog.ExitFlushTimeout, 1)
5757
}
5858
cfgViper.OnConfigChange(func(e fsnotify.Event) {
59-
klog.Infof("Changes detected: %s\n", e.Name)
59+
klog.InfoS("Changes detected", "name", e.Name)
6060
cancel()
6161
// Wait for the ports to be released.
6262
<-time.After(3 * time.Second)
@@ -86,7 +86,7 @@ func RunKubeStateMetricsWrapper(opts *options.Options) {
8686
klog.FlushAndExit(klog.ExitFlushTimeout, 1)
8787
}
8888
crcViper.OnConfigChange(func(e fsnotify.Event) {
89-
klog.Infof("Changes detected: %s\n", e.Name)
89+
klog.InfoS("Changes detected", "name", e.Name)
9090
cancel()
9191
// Wait for the ports to be released.
9292
<-time.After(3 * time.Second)
@@ -95,7 +95,7 @@ func RunKubeStateMetricsWrapper(opts *options.Options) {
9595
})
9696
crcViper.WatchConfig()
9797
}
98-
klog.Infoln("Starting kube-state-metrics")
98+
klog.InfoS("Starting kube-state-metrics")
9999
KSMRunOrDie(ctx)
100100
select {}
101101
}

pkg/app/server.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ func RunKubeStateMetrics(ctx context.Context, opts *options.Options) error {
132132
if err != nil {
133133
// DO NOT end the process.
134134
// We want to allow the user to still be able to fix the misconfigured config (redeploy or edit the configmaps) and reload KSM automatically once that's done.
135-
klog.Warningf("failed to unmarshal opts config file: %v", err)
135+
klog.ErrorS(err, "failed to unmarshal opts config file")
136136
// Wait for the next reload.
137-
klog.Infof("misconfigured config detected, KSM will automatically reload on next write to the config")
138-
klog.Infof("waiting for config to be fixed")
137+
klog.InfoS("misconfigured config detected, KSM will automatically reload on next write to the config")
138+
klog.InfoS("waiting for config to be fixed")
139139
configSuccess.WithLabelValues("config", filepath.Clean(got)).Set(0)
140140
<-ctx.Done()
141141
} else {

0 commit comments

Comments
 (0)