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: Log a crude lag metric for how far behind a client is. #3236

Merged
merged 2 commits into from
Jan 28, 2021
Merged
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
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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we just look at the last entry for each stream instead ?

Copy link
Contributor

@cyriltovena cyriltovena Jan 26, 2021

Choose a reason for hiding this comment

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

if len(s.Entries) > 0 {
  last := s.Entries[len(s.Entries)-1].Timestamp
  if last.Timestamp.After(mostRecentEntry) {
    mostRecentEntry = last
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

if/when we support out of order the current implementation would handle that a little better but I agree this is a better optimization for our current constraints

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