From 3d16cee5a3f53235b4f2153bf7d8fd33e4d7fda7 Mon Sep 17 00:00:00 2001 From: rashmichandrashekar Date: Mon, 13 Nov 2023 16:38:45 -0800 Subject: [PATCH] Add logging for prometheus operator in TargetAllocator's config generator (#2329) * add logging for prometheus operator * adding yaml for changelog * Adding tracking issue --- ...et-allocator-prometheus-operator-logging.yaml | 16 ++++++++++++++++ cmd/otel-allocator/watcher/promOperator.go | 6 +++++- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 .chloggen/target-allocator-prometheus-operator-logging.yaml diff --git a/.chloggen/target-allocator-prometheus-operator-logging.yaml b/.chloggen/target-allocator-prometheus-operator-logging.yaml new file mode 100644 index 0000000000..e823ee64d1 --- /dev/null +++ b/.chloggen/target-allocator-prometheus-operator-logging.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. operator, target allocator, github action) +component: target allocator + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Add logging for prometheus operator in TargetAllocator's config generator + +# One or more tracking issues related to the change +issues: [2348] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: diff --git a/cmd/otel-allocator/watcher/promOperator.go b/cmd/otel-allocator/watcher/promOperator.go index b687b96048..9f916c881e 100644 --- a/cmd/otel-allocator/watcher/promOperator.go +++ b/cmd/otel-allocator/watcher/promOperator.go @@ -17,9 +17,11 @@ package watcher import ( "context" "fmt" + "os" "time" "github.com/go-kit/log" + "github.com/go-kit/log/level" "github.com/go-logr/logr" monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" promv1alpha1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1alpha1" @@ -67,7 +69,9 @@ func NewPrometheusCRWatcher(logger logr.Logger, cfg allocatorconfig.Config) (*Pr }, } - generator, err := prometheus.NewConfigGenerator(log.NewNopLogger(), prom, true) // TODO replace Nop? + promOperatorLogger := level.NewFilter(log.NewLogfmtLogger(os.Stderr), level.AllowWarn()) + generator, err := prometheus.NewConfigGenerator(promOperatorLogger, prom, true) + if err != nil { return nil, err }