Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
* Helper function to convert seconds to nanoseconds
  • Loading branch information
ssncferreira committed Jan 6, 2022
1 parent 91df28a commit d90902a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
9 changes: 4 additions & 5 deletions pkg/logql/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package logql
import (
"context"
"strings"
"time"

util_log "github.com/cortexproject/cortex/pkg/util/log"
"github.com/dustin/go-humanize"
Expand All @@ -13,7 +12,7 @@ import (
promql_parser "github.com/prometheus/prometheus/promql/parser"

"github.com/grafana/loki/pkg/logqlmodel"
"github.com/grafana/loki/pkg/logqlmodel/stats"
logql_stats "github.com/grafana/loki/pkg/logqlmodel/stats"
"github.com/grafana/loki/pkg/util/httpreq"
)

Expand Down Expand Up @@ -67,7 +66,7 @@ var (
})
)

func RecordMetrics(ctx context.Context, p Params, status string, stats stats.Result, result promql_parser.Value) {
func RecordMetrics(ctx context.Context, p Params, status string, stats logql_stats.Result, result promql_parser.Value) {
var (
logger = util_log.WithContext(ctx, util_log.Logger)
rt = string(GetRangeType(p))
Expand Down Expand Up @@ -100,13 +99,13 @@ func RecordMetrics(ctx context.Context, p Params, status string, stats stats.Res
"range_type", rt,
"length", p.End().Sub(p.Start()),
"step", p.Step(),
"duration", time.Duration(int64(stats.Summary.ExecTime * float64(time.Second))),
"duration", logql_stats.ConvertSecondsToNanoseconds(stats.Summary.ExecTime),
"status", status,
"limit", p.Limit(),
"returned_lines", returnedLines,
"throughput", strings.Replace(humanize.Bytes(uint64(stats.Summary.BytesProcessedPerSecond)), " ", "", 1),
"total_bytes", strings.Replace(humanize.Bytes(uint64(stats.Summary.TotalBytesProcessed)), " ", "", 1),
"queue_time", time.Duration(int64(stats.Summary.QueueTime * float64(time.Second))),
"queue_time", logql_stats.ConvertSecondsToNanoseconds(stats.Summary.QueueTime),
}...)

logValues = append(logValues, tagsToKeyValues(queryTags)...)
Expand Down
14 changes: 10 additions & 4 deletions pkg/logqlmodel/stats/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,14 @@ func (i *Ingester) Merge(m Ingester) {
func (r *Result) Merge(m Result) {
r.Querier.Merge(m.Querier)
r.Ingester.Merge(m.Ingester)
r.ComputeSummary(time.Duration(int64((r.Summary.ExecTime+m.Summary.ExecTime)*float64(time.Second))),
time.Duration(int64((r.Summary.QueueTime+m.Summary.QueueTime)*float64(time.Second))))
r.ComputeSummary(ConvertSecondsToNanoseconds(r.Summary.ExecTime+m.Summary.ExecTime),
ConvertSecondsToNanoseconds(r.Summary.QueueTime+m.Summary.QueueTime))
}

// ConvertSecondsToNanoseconds converts time.Duration representation of seconds (float64)
// into time.Duration representation of nanoseconds (int64)
func ConvertSecondsToNanoseconds(seconds float64) time.Duration {
return time.Duration(int64(seconds * float64(time.Second)))
}

func (r Result) ChunksDownloadTime() time.Duration {
Expand Down Expand Up @@ -284,7 +290,7 @@ func (s Summary) Log(log log.Logger) {
"Summary.LinesProcessedPerSecond", s.LinesProcessedPerSecond,
"Summary.TotalBytesProcessed", humanize.Bytes(uint64(s.TotalBytesProcessed)),
"Summary.TotalLinesProcessed", s.TotalLinesProcessed,
"Summary.ExecTime", time.Duration(int64(s.ExecTime*float64(time.Second))),
"Summary.QueueTime", time.Duration(int64(s.QueueTime*float64(time.Second))),
"Summary.ExecTime", ConvertSecondsToNanoseconds(s.ExecTime),
"Summary.QueueTime", ConvertSecondsToNanoseconds(s.QueueTime),
)
}

0 comments on commit d90902a

Please sign in to comment.