Skip to content

Commit

Permalink
add a log line request timings that could be propagated to usage
Browse files Browse the repository at this point in the history
insights within grafana cloud for grafana cloud logs users

Signed-off-by: Callum Styan <[email protected]>
  • Loading branch information
cstyan committed Dec 16, 2024
1 parent 33d5dcf commit 5e6e50b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pkg/ruler/evaluator_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"fmt"
"time"

"github.com/go-kit/kit/log/level"

Check failure on line 8 in pkg/ruler/evaluator_local.go

View workflow job for this annotation

GitHub Actions / check / golangciLint

import 'github.com/go-kit/kit/log/level' is not allowed from list 'main': Use github.com/go-kit/log instead of github.com/go-kit/kit/log (depguard)
"github.com/go-kit/log"
"github.com/grafana/loki/v3/pkg/util"

"github.com/grafana/loki/v3/pkg/logproto"
"github.com/grafana/loki/v3/pkg/logql"
Expand Down Expand Up @@ -49,5 +51,9 @@ func (l *LocalEvaluator) Eval(ctx context.Context, qs string, now time.Time) (*l
return nil, err
}

// Retrieve rule details from context
ruleName, ruleType := GetRuleDetailsFromContext(ctx)

level.Info(l.logger).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))
return &res, nil
}
4 changes: 3 additions & 1 deletion pkg/ruler/evaluator_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ func (r *RemoteEvaluator) query(ctx context.Context, orgID, query string, ts tim
level.Debug(log).Log("msg", "rule evaluation succeeded")
r.metrics.successfulEvals.WithLabelValues(orgID).Inc()

return r.decodeResponse(ctx, resp, orgID)
dr, err := r.decodeResponse(ctx, resp, orgID)
level.Info(log).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))
return dr, err
}

func (r *RemoteEvaluator) decodeResponse(ctx context.Context, resp *httpgrpc.HTTPResponse, orgID string) (*logqlmodel.Result, error) {
Expand Down

0 comments on commit 5e6e50b

Please sign in to comment.