1
0
Fork 0
mirror of https://github.com/prometheus-operator/prometheus-operator.git synced 2025-04-21 03:38:43 +00:00

Merge pull request from perebaj/chore/replace_gokitlogger_waitfornamedcachesync

replace goKitLogger in WaitForNamedCacheSync
This commit is contained in:
Arthur Silva Sens 2024-08-21 19:49:31 -03:00 committed by GitHub
commit 6a8feb97d1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 13 additions and 14 deletions
pkg
alertmanager
operator
prometheus
thanos

View file

@ -311,7 +311,7 @@ func (c *Operator) waitForCacheSync(ctx context.Context) error {
{"StatefulSet", c.ssetInfs},
} {
for _, inf := range infs.informersForResource.GetInformers() {
if !operator.WaitForNamedCacheSync(ctx, "alertmanager", log.With(c.goKitLogger, "informer", infs.name), inf.Informer()) {
if !operator.WaitForNamedCacheSync(ctx, "alertmanager", c.logger.With("informer", infs.name), inf.Informer()) {
return fmt.Errorf("failed to sync cache for %s informer", infs.name)
}
}
@ -324,7 +324,7 @@ func (c *Operator) waitForCacheSync(ctx context.Context) error {
{"AlertmanagerNamespace", c.nsAlrtInf},
{"AlertmanagerConfigNamespace", c.nsAlrtCfgInf},
} {
if !operator.WaitForNamedCacheSync(ctx, "alertmanager", log.With(c.goKitLogger, "informer", inf.name), inf.informer) {
if !operator.WaitForNamedCacheSync(ctx, "alertmanager", c.logger.With("informer", inf.name), inf.informer) {
return fmt.Errorf("failed to sync cache for %s informer", inf.name)
}
}

View file

@ -17,11 +17,10 @@ package operator
import (
"context"
"fmt"
"log/slog"
"sync"
"time"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
@ -431,7 +430,7 @@ func SanitizeSTS(sts *appsv1.StatefulSet) {
// than 1 minute, it means that something is stuck and the message will
// indicate to the admin which informer is the culprit.
// See https://github.com/prometheus-operator/prometheus-operator/issues/3347.
func WaitForNamedCacheSync(ctx context.Context, controllerName string, logger log.Logger, inf cache.SharedIndexInformer) bool {
func WaitForNamedCacheSync(ctx context.Context, controllerName string, logger *slog.Logger, inf cache.SharedIndexInformer) bool {
ctx, cancel := context.WithTimeout(ctx, 10*time.Minute)
defer cancel()
@ -442,7 +441,7 @@ func WaitForNamedCacheSync(ctx context.Context, controllerName string, logger lo
for {
select {
case <-t.C:
level.Warn(logger).Log("msg", "cache sync not yet completed")
logger.Warn("cache sync not yet completed")
case <-ctx.Done():
return
}
@ -451,9 +450,9 @@ func WaitForNamedCacheSync(ctx context.Context, controllerName string, logger lo
ok := cache.WaitForNamedCacheSync(controllerName, ctx.Done(), inf.HasSynced)
if !ok {
level.Error(logger).Log("msg", "failed to sync cache")
logger.Error("failed to sync cache")
} else {
level.Debug(logger).Log("msg", "successfully synced cache")
logger.Debug("successfully synced cache")
}
return ok

View file

@ -458,7 +458,7 @@ func (c *Operator) waitForCacheSync(ctx context.Context) error {
}
for _, inf := range infs.informersForResource.GetInformers() {
if !operator.WaitForNamedCacheSync(ctx, "prometheusagent", log.With(c.goKitLogger, "informer", infs.name), inf.Informer()) {
if !operator.WaitForNamedCacheSync(ctx, "prometheusagent", c.logger.With("informer", infs.name), inf.Informer()) {
return fmt.Errorf("failed to sync cache for %s informer", infs.name)
}
}
@ -471,7 +471,7 @@ func (c *Operator) waitForCacheSync(ctx context.Context) error {
{"PromNamespace", c.nsPromInf},
{"MonNamespace", c.nsMonInf},
} {
if !operator.WaitForNamedCacheSync(ctx, "prometheusagent", log.With(c.goKitLogger, "informer", inf.name), inf.informer) {
if !operator.WaitForNamedCacheSync(ctx, "prometheusagent", c.logger.With("informer", inf.name), inf.informer) {
return fmt.Errorf("failed to sync cache for %s informer", inf.name)
}
}

View file

@ -396,7 +396,7 @@ func (c *Operator) waitForCacheSync(ctx context.Context) error {
}
for _, inf := range infs.informersForResource.GetInformers() {
if !operator.WaitForNamedCacheSync(ctx, "prometheus", log.With(c.goKitLogger, "informer", infs.name), inf.Informer()) {
if !operator.WaitForNamedCacheSync(ctx, "prometheus", c.logger.With("informer", infs.name), inf.Informer()) {
return fmt.Errorf("failed to sync cache for %s informer", infs.name)
}
}
@ -409,7 +409,7 @@ func (c *Operator) waitForCacheSync(ctx context.Context) error {
{"PromNamespace", c.nsPromInf},
{"MonNamespace", c.nsMonInf},
} {
if !operator.WaitForNamedCacheSync(ctx, "prometheus", log.With(c.goKitLogger, "informer", inf.name), inf.informer) {
if !operator.WaitForNamedCacheSync(ctx, "prometheus", c.logger.With("informer", inf.name), inf.informer) {
return fmt.Errorf("failed to sync cache for %s informer", inf.name)
}
}

View file

@ -281,7 +281,7 @@ func (o *Operator) waitForCacheSync(ctx context.Context) error {
{"StatefulSet", o.ssetInfs},
} {
for _, inf := range infs.informersForResource.GetInformers() {
if !operator.WaitForNamedCacheSync(ctx, "thanos", log.With(o.goKitLogger, "informer", infs.name), inf.Informer()) {
if !operator.WaitForNamedCacheSync(ctx, "thanos", o.logger.With("informer", infs.name), inf.Informer()) {
return fmt.Errorf("failed to sync cache for %s informer", infs.name)
}
}
@ -294,7 +294,7 @@ func (o *Operator) waitForCacheSync(ctx context.Context) error {
{"ThanosRulerNamespace", o.nsThanosRulerInf},
{"RuleNamespace", o.nsRuleInf},
} {
if !operator.WaitForNamedCacheSync(ctx, "thanos", log.With(o.goKitLogger, "informer", inf.name), inf.informer) {
if !operator.WaitForNamedCacheSync(ctx, "thanos", o.logger.With("informer", inf.name), inf.informer) {
return fmt.Errorf("failed to sync cache for %s informer", inf.name)
}
}