Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loki: include the component in metrics.go log line #5379

Merged
merged 3 commits into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/logql/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (q *query) Exec(ctx context.Context) (logqlmodel.Result, error) {
}

if q.record {
RecordMetrics(ctx, q.params, status, statResult, data)
RecordMetrics(ctx, q.logger, q.params, status, statResult, data)
}

return logqlmodel.Result{
Expand Down
5 changes: 3 additions & 2 deletions pkg/logql/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"

"github.com/dustin/go-humanize"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
Expand Down Expand Up @@ -72,9 +73,9 @@ var (
linePerSecondLogUsage = usagestats.NewStatistics("query_log_lines_per_second")
)

func RecordMetrics(ctx context.Context, p Params, status string, stats logql_stats.Result, result promql_parser.Value) {
func RecordMetrics(ctx context.Context, log log.Logger, p Params, status string, stats logql_stats.Result, result promql_parser.Value) {
var (
logger = util_log.WithContext(ctx, util_log.Logger)
logger = util_log.WithContext(ctx, log)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 we should get rid off util_log.Logger altogether 🙂

rt = string(GetRangeType(p))
latencyType = latencyTypeFast
returnedLines = 0
Expand Down
2 changes: 1 addition & 1 deletion pkg/logql/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestLogSlowQuery(t *testing.T) {

ctx = context.WithValue(ctx, httpreq.QueryTagsHTTPHeader, "Source=logvolhist,Feature=Beta")

RecordMetrics(ctx, LiteralParams{
RecordMetrics(ctx, util_log.Logger, LiteralParams{
qs: `{foo="bar"} |= "buzz"`,
direction: logproto.BACKWARD,
end: now,
Expand Down
3 changes: 2 additions & 1 deletion pkg/loki/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/NYTimes/gziphandler"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/grafana/dskit/kv/codec"
"github.com/grafana/dskit/kv/memberlist"
Expand Down Expand Up @@ -621,7 +622,7 @@ func (t *Loki) initRuler() (_ services.Service, err error) {
return nil, err
}

engine := logql.NewEngine(t.Cfg.Querier.Engine, q, t.overrides, util_log.Logger)
engine := logql.NewEngine(t.Cfg.Querier.Engine, q, t.overrides, log.With(util_log.Logger, "component", "ruler"))

t.ruler, err = ruler.NewRuler(
t.Cfg.Ruler,
Expand Down
5 changes: 3 additions & 2 deletions pkg/querier/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"time"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/pkg/errors"
"github.com/prometheus/common/model"
Expand Down Expand Up @@ -89,13 +90,13 @@ func New(cfg Config, store storage.Store, ingesterQuerier *IngesterQuerier, limi
limits: limits,
}

querier.engine = logql.NewEngine(cfg.Engine, &querier, limits, util_log.Logger)
querier.engine = logql.NewEngine(cfg.Engine, &querier, limits, log.With(util_log.Logger, "component", "querier"))

return &querier, nil
}

func (q *Querier) SetQueryable(queryable logql.Querier) {
q.engine = logql.NewEngine(q.cfg.Engine, queryable, q.limits, util_log.Logger)
q.engine = logql.NewEngine(q.cfg.Engine, queryable, q.limits, log.With(util_log.Logger, "component", "querier"))
}

// Select Implements logql.Querier which select logs via matchers and regex filters.
Expand Down
4 changes: 3 additions & 1 deletion pkg/querier/queryrange/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strconv"
"time"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
promql_parser "github.com/prometheus/prometheus/promql/parser"
"github.com/weaveworks/common/middleware"
Expand All @@ -17,6 +18,7 @@ import (
"github.com/grafana/loki/pkg/logqlmodel"
"github.com/grafana/loki/pkg/logqlmodel/stats"
"github.com/grafana/loki/pkg/querier/queryrange/queryrangebase"
util_log "github.com/grafana/loki/pkg/util/log"
"github.com/grafana/loki/pkg/util/spanlogger"
)

Expand All @@ -26,7 +28,7 @@ const ctxKey ctxKeyType = "stats"

var (
defaultMetricRecorder = metricRecorderFn(func(data *queryData) {
logql.RecordMetrics(data.ctx, data.params, data.status, *data.statistics, data.result)
logql.RecordMetrics(data.ctx, log.With(util_log.Logger, "component", "frontend"), data.params, data.status, *data.statistics, data.result)
})
// StatsHTTPMiddleware is an http middleware to record stats for query_range filter.
StatsHTTPMiddleware = statsHTTPMiddleware(defaultMetricRecorder)
Expand Down