Skip to content

Commit 562d87d

Browse files
salvacortssteffsas
andauthored
fix(logger): correct log level verbosity in rule evaluation (#19519) (backport release-3.5.x) (#19857)
Co-authored-by: Steffen Sassalla <[email protected]>
1 parent 5a9d3fd commit 562d87d

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

pkg/ruler/evaluator_local.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package ruler
33
import (
44
"context"
55
"fmt"
6-
"os"
76
"time"
87

98
"github.com/go-kit/log"
@@ -13,6 +12,7 @@ import (
1312
"github.com/grafana/loki/v3/pkg/logql"
1413
"github.com/grafana/loki/v3/pkg/logqlmodel"
1514
"github.com/grafana/loki/v3/pkg/util"
15+
util_log "github.com/grafana/loki/v3/pkg/util/log"
1616
)
1717

1818
const EvalModeLocal = "local"
@@ -32,7 +32,11 @@ func NewLocalEvaluator(engine *logql.Engine, logger log.Logger) (*LocalEvaluator
3232
return nil, fmt.Errorf("given engine is nil")
3333
}
3434

35-
return &LocalEvaluator{engine: engine, logger: logger, insightsLogger: log.NewLogfmtLogger(os.Stderr)}, nil
35+
return &LocalEvaluator{
36+
engine: engine,
37+
logger: logger,
38+
insightsLogger: log.With(util_log.Logger, "msg", "request timings", "insight", "true", "source", "loki_ruler"),
39+
}, nil
3640
}
3741

3842
func (l *LocalEvaluator) Eval(ctx context.Context, qs string, now time.Time) (*logqlmodel.Result, error) {
@@ -60,6 +64,6 @@ func (l *LocalEvaluator) Eval(ctx context.Context, qs string, now time.Time) (*l
6064
// Retrieve rule details from context
6165
ruleName, ruleType := GetRuleDetailsFromContext(ctx)
6266

63-
level.Info(l.insightsLogger).Log("msg", "request timings", "insight", "true", "source", "loki_ruler", "rule_name", ruleName, "rule_type", ruleType, "total", res.Statistics.Summary.ExecTime, "total_bytes", res.Statistics.Summary.TotalBytesProcessed, "query_hash", util.HashedQuery(qs))
67+
level.Info(l.insightsLogger).Log("rule_name", ruleName, "rule_type", ruleType, "total", res.Statistics.Summary.ExecTime, "total_bytes", res.Statistics.Summary.TotalBytesProcessed, "query_hash", util.HashedQuery(qs))
6468
return &res, nil
6569
}

pkg/ruler/evaluator_remote.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"net/http"
1616
"net/textproto"
1717
"net/url"
18-
"os"
1918
"strconv"
2019
"time"
2120

@@ -41,6 +40,7 @@ import (
4140
"github.com/grafana/loki/v3/pkg/util/build"
4241
"github.com/grafana/loki/v3/pkg/util/constants"
4342
"github.com/grafana/loki/v3/pkg/util/httpreq"
43+
util_log "github.com/grafana/loki/v3/pkg/util/log"
4444
"github.com/grafana/loki/v3/pkg/util/spanlogger"
4545
)
4646

@@ -86,7 +86,7 @@ func NewRemoteEvaluator(client httpgrpc.HTTPClient, overrides RulesLimits, logge
8686
client: client,
8787
overrides: overrides,
8888
logger: logger,
89-
insightsLogger: log.NewLogfmtLogger(os.Stderr),
89+
insightsLogger: log.With(util_log.Logger, "msg", "request timings", "insight", "true", "source", "loki_ruler", "rule_name"),
9090
metrics: newMetrics(registerer),
9191
}, nil
9292
}
@@ -292,7 +292,7 @@ func (r *RemoteEvaluator) query(ctx context.Context, orgID, query string, ts tim
292292
if err != nil {
293293
return nil, err
294294
}
295-
level.Info(r.insightsLogger).Log("msg", "request timings", "insight", "true", "source", "loki_ruler", "rule_name", ruleName, "rule_type", ruleType, "total", dr.Statistics.Summary.ExecTime, "total_bytes", dr.Statistics.Summary.TotalBytesProcessed, "query_hash", util.HashedQuery(query))
295+
level.Info(r.insightsLogger).Log(ruleName, "rule_type", ruleType, "total", dr.Statistics.Summary.ExecTime, "total_bytes", dr.Statistics.Summary.TotalBytesProcessed, "query_hash", util.HashedQuery(query))
296296
return dr, err
297297
}
298298

0 commit comments

Comments
 (0)