Skip to content

Commit

Permalink
Recognize exemplar record type in WAL watcher metrics (#11008)
Browse files Browse the repository at this point in the history
* Add exemplar record case

Signed-off-by: Levi Harrison <git@leviharrison.dev>

* recordType() -> Type.String()

Signed-off-by: Levi Harrison <git@leviharrison.dev>
  • Loading branch information
LeviHarrison committed Jul 18, 2022
1 parent d41e5a5 commit 3d53835
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
15 changes: 15 additions & 0 deletions tsdb/record/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ const (
Exemplars Type = 4
)

func (rt Type) String() string {
switch rt {
case Series:
return "series"
case Samples:
return "samples"
case Exemplars:
return "exemplars"
case Tombstones:
return "tombstones"
default:
return "unknown"
}
}

// ErrNotFound is returned if a looked up resource was not found. Duplicate ErrNotFound from head.go.
var ErrNotFound = errors.New("not found")

Expand Down
17 changes: 2 additions & 15 deletions tsdb/wal/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ func (w *Watcher) readSegment(r *LiveReader, segmentNum int, tail bool) error {
)
for r.Next() && !isClosed(w.quit) {
rec := r.Record()
w.recordsReadMetric.WithLabelValues(recordType(dec.Type(rec))).Inc()
w.recordsReadMetric.WithLabelValues(dec.Type(rec).String()).Inc()

switch dec.Type(rec) {
case record.Series:
Expand Down Expand Up @@ -554,7 +554,7 @@ func (w *Watcher) readSegmentForGC(r *LiveReader, segmentNum int, _ bool) error
)
for r.Next() && !isClosed(w.quit) {
rec := r.Record()
w.recordsReadMetric.WithLabelValues(recordType(dec.Type(rec))).Inc()
w.recordsReadMetric.WithLabelValues(dec.Type(rec).String()).Inc()

switch dec.Type(rec) {
case record.Series:
Expand Down Expand Up @@ -583,19 +583,6 @@ func (w *Watcher) SetStartTime(t time.Time) {
w.startTimestamp = timestamp.FromTime(t)
}

func recordType(rt record.Type) string {
switch rt {
case record.Series:
return "series"
case record.Samples:
return "samples"
case record.Tombstones:
return "tombstones"
default:
return "unknown"
}
}

type segmentReadFn func(w *Watcher, r *LiveReader, segmentNum int, tail bool) error

// Read all the series records from a Checkpoint directory.
Expand Down

0 comments on commit 3d53835

Please sign in to comment.