Skip to content

Commit

Permalink
Loki: Log a crude lag metric for how far behind a client is. (#3236)
Browse files Browse the repository at this point in the history
* Log the difference in time between the most recently received log entry and the current time as a crude measure of how far behind a promtail instance is.

* fix lint
  • Loading branch information
slim-bean authored Jan 28, 2021
1 parent 1a36874 commit 51952da
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/distributor/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package distributor
import (
"math"
"net/http"
"time"

"github.com/cortexproject/cortex/pkg/util"
"github.com/dustin/go-humanize"
Expand Down Expand Up @@ -72,11 +73,16 @@ func ParseRequest(r *http.Request) (*logproto.PushRequest, error) {
totalEntries int64
)

mostRecentEntry := time.Unix(0, 0)

for _, s := range req.Streams {
streamLabelsSize += int64(len(s.Labels))
for _, e := range s.Entries {
totalEntries++
entriesSize += int64(len(e.Line))
if e.Timestamp.After(mostRecentEntry) {
mostRecentEntry = e.Timestamp
}
}
}

Expand All @@ -96,6 +102,7 @@ func ParseRequest(r *http.Request) (*logproto.PushRequest, error) {
"streamLabelsSize", humanize.Bytes(uint64(streamLabelsSize)),
"entriesSize", humanize.Bytes(uint64(entriesSize)),
"totalSize", humanize.Bytes(uint64(entriesSize+streamLabelsSize)),
"mostRecentLagMs", time.Since(mostRecentEntry).Milliseconds(),
)
}()

Expand Down

0 comments on commit 51952da

Please sign in to comment.