This repository has been archived by the owner on Aug 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 180
Expose prometheus_tsdb_lowest_timestamp metric #363
Merged
gouthamve
merged 4 commits into
prometheus-junkyard:master
from
bobmshannon:bs/first_ts_metric
Sep 14, 2018
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,6 +123,7 @@ type dbMetrics struct { | |
compactionsTriggered prometheus.Counter | ||
cutoffs prometheus.Counter | ||
cutoffsFailed prometheus.Counter | ||
startTime prometheus.GaugeFunc | ||
tombCleanTimer prometheus.Histogram | ||
} | ||
|
||
|
@@ -157,6 +158,20 @@ func newDBMetrics(db *DB, r prometheus.Registerer) *dbMetrics { | |
Name: "prometheus_tsdb_retention_cutoffs_failures_total", | ||
Help: "Number of times the database failed to cut off block data from disk.", | ||
}) | ||
m.startTime = prometheus.NewGaugeFunc(prometheus.GaugeOpts{ | ||
Name: "prometheus_tsdb_start_time_seconds", | ||
Help: "Oldest timestamp stored in the database.", | ||
}, func() float64 { | ||
db.mtx.RLock() | ||
defer db.mtx.RUnlock() | ||
startTime := time.Now().Unix() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no reason to believe that the time stored is going to be the current time. For example, it could Further, the blocks are sorted by time. So doing just |
||
for _, b := range db.Blocks() { | ||
if b.meta.MinTime < startTime { | ||
startTime = b.meta.MinTime | ||
} | ||
} | ||
return float64(startTime) | ||
}) | ||
m.tombCleanTimer = prometheus.NewHistogram(prometheus.HistogramOpts{ | ||
Name: "prometheus_tsdb_tombstone_cleanup_seconds", | ||
Help: "The time taken to recompact blocks to remove tombstones.", | ||
|
@@ -170,6 +185,7 @@ func newDBMetrics(db *DB, r prometheus.Registerer) *dbMetrics { | |
m.cutoffs, | ||
m.cutoffsFailed, | ||
m.compactionsTriggered, | ||
m.startTime, | ||
m.tombCleanTimer, | ||
) | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prometheus_tsdb_lowest_timestamp
makes more sense here, as start_time could be confused with the process start time and it may or may not be seconds :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should keep the unit suffix and enforce the metric's value to be in seconds though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. From a general TSDB perspective, there is no reason that the time passed into
.Append(t int64, v float64)
, is a wall time. It could be anything, and people may even pass nano-seconds.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Does it make sense to have an "opaque" metric then? Wouldn't it be better to expose the raw value to the caller (eg Prometheus) and let it compute the metric?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If Prometheus appends millisecond timestamps to the TSDB, then this metric as collected might be slightly more difficult to work with using something like the built-in
time()
function for example. For that reason I agree that it would be nice to adhere to metric naming best practices and include the base unit as a suffix in the metric name, converting the millisecond timestamp to a unix timestamp if necessary. As @simonpasquier mentioned I would think that instrumenting this metric directly in Prometheus instead would allow for this.With that being said perhaps there are other consumers of the TSDB where exposing this lowest timestamp metric directly would still be useful.