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 <callumstyan@gmail.com>
  • Loading branch information
cstyan committed Dec 16, 2024
1 parent 33d5dcf commit 0356675
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 @@ -6,6 +6,8 @@ import (
"time"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
"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 0356675

Please sign in to comment.