Repository navigation
Add rule importer to backfill - #7675
Conversation
Signed-off-by: jessicagreben <[email protected]>
| } | ||
|
|
||
| appender := importer.writer.Appender() | ||
| for ts.Before(end) { |
There was a problem hiding this comment.
You're still using the user-specified time for alignment, which won't work out.
There was a problem hiding this comment.
Yes, we just talked about this.
The idea would be starting from zero if no data is yet in Prom
But actually we could use instead of 0, a group hash as in Prometheus. The tricky part is a filename, as it obviously will be different.
// evalTimestamp returns the immediately preceding consistently slotted evaluation time.
func (g *Group) evalTimestamp() time.Time {
var (
offset = int64(g.hash() % uint64(g.interval))
now = time.Now().UnixNano()
adjNow = now - offset
base = adjNow - (adjNow % int64(g.interval))
)
return time.Unix(0, base+offset).UTC()
}
If the data exists we can fetch samples from Prometheus and aligned (:
There was a problem hiding this comment.
I exported the evalTimestamp on the Group and used that in my code for the alignment. Let me know if you see any glaring problems with that. I still need to test it, which I'm going to do today.
@bwplotka why will the filename obviously be different? And does it matter if it is? If the end user changes the filename, then the alignment will be different. That seems like it could be fine.
|
Let us know if it's ready to review! (: |
|
Sorry for the slow reply to comments (had some life stuff to take care of). I'm back at it now and aiming to have this PR ready for review in a week. Will ping you all when it's ready. |
Signed-off-by: jessicagreben <[email protected]>
|
@bwplotka and @brian-brazil I made some changes per your comments, not sure if I'm handling the alignment correctly and the queryRange API right. I would appreciate another review when you all have a free moment. Thanks so much for the help! Once I get a green light on the implementation I will start writing tests. |
Signed-off-by: jessicagreben <[email protected]>
brian-brazil
left a comment
There was a problem hiding this comment.
Overall approach seems okay, but some details need improvement.
|
Did you forget to push?
It should be a flag from the start I think, so you can pass in a smaller value if you've an expensive query. |
|
@brian-brazil I will add a flag, I will push a change in a bit. |
|
I have not looked at the implementation yet, but wanted to say that as with the normal backfill, we need to align the block boundaries of new blocks being created with existing blocks to avoid formation of a single huge block (vertical compaction merges all overlapping block into one). |
|
Ups, misclick I did not plan to put green mark yet ;p But very close! |
Signed-off-by: jessicagreben <[email protected]>
e03fd4e to
3ed6457
Compare
Signed-off-by: jessicagreben <[email protected]>
Signed-off-by: jessicagreben <[email protected]>
Signed-off-by: jessicagreben <[email protected]>
|
I collected a few thoughts about the command structure here, roughly continuing where we just ended the sync meeting. |
Signed-off-by: jessicagreben <[email protected]>
Signed-off-by: jessicagreben <[email protected]>
Signed-off-by: jessicagreben <[email protected]>
|
Its not quite ready. Needs a little more testing, but almost there. I have been busy with other things, but I can get back on it this week. |
Signed-off-by: jessicagreben <[email protected]>
Signed-off-by: jessicagreben <[email protected]>
Signed-off-by: jessicagreben <[email protected]>
Signed-off-by: jessicagreben <[email protected]>
roidelapluie
left a comment
There was a problem hiding this comment.
We have looked at this pull request during our contributor hour. The pull request is in a good shape and would be ready to be merged after we aligned blocks capped at the 2hrs mark.
We have agreed that staleness markers would be handled later, in a future pull request.
Signed-off-by: jessicagreben <[email protected]>
Signed-off-by: jessicagreben <[email protected]>
roidelapluie
left a comment
There was a problem hiding this comment.
Thank you again for your work!
I don't think we should have all those details in the command line. Let's instead work on documentation in the storage part in another pull request.
I have added a couple of small comments, then I think we are ready to go.
| // Flush implements the Writer interface. This is where actual block writing | ||
| // happens. After flush completes, no writes can be done. | ||
| func (w *BlockWriter) Flush(ctx context.Context) (ulid.ULID, error) { | ||
| seriesCount := w.head.NumSeries() |
There was a problem hiding this comment.
I was only trying to remove line 94-96 because if I backfill a recording rule and there are no series created for that rule, it errors on line 95. Plus when I flush when there are no series, it does not create a block so I'm not sure why the w.head.NumSeries() == 0 check was being made.
However I can keep line 93 and line 102 to log that info.
| importRulesStart := importRulesCmd.Flag("start", "The time to start backfilling the new rule from. It is required. Start time should be RFC3339 or Unix timestamp."). | ||
| Required().String() | ||
| importRulesEnd := importRulesCmd.Flag("end", "If an end time is provided, all recording rules in the rule files provided will be backfilled to the end time. Default will backfill up to 3 hours ago. End time should be RFC3339 or Unix timestamp.").String() | ||
| importRulesOutputDir := importRulesCmd.Flag("output-dir", "The filepath on the local filesystem to write the output to. Output will be blocks containing the data of the backfilled recording rules. Don't use an active Prometheus data directory. If command is run many times with same start/end time, it will create duplicate series.").Default("backfilldata/").String() |
There was a problem hiding this comment.
| importRulesOutputDir := importRulesCmd.Flag("output-dir", "The filepath on the local filesystem to write the output to. Output will be blocks containing the data of the backfilled recording rules. Don't use an active Prometheus data directory. If command is run many times with same start/end time, it will create duplicate series.").Default("backfilldata/").String() | |
| importRulesOutputDir := importRulesCmd.Flag("output-dir", "Output directory for generated blocks.").Default(defaultDBPath).String() |
There was a problem hiding this comment.
Those should go to the "storage" page in the documentation. We can do it in a second PR.
| Default("60s").Duration() | ||
| importRulesFiles := importRulesCmd.Arg( | ||
| "rule-files", | ||
| "A list of one or more files containing recording rules to be backfilled. All recording rules listed in the files will be backfilled. Alerting rules are not evaluated.", |
There was a problem hiding this comment.
| "A list of one or more files containing recording rules to be backfilled. All recording rules listed in the files will be backfilled. Alerting rules are not evaluated.", | |
| "A list of one or more files containing recording rules to be backfilled. Please refer to the storage docs for more details.", |
There was a problem hiding this comment.
I would prefer to make this change once we add the docs.
Signed-off-by: jessicagreben <[email protected]>
Signed-off-by: jessicagreben <[email protected]>
|
Thank you! Did you notice that the tests are failing? |
|
oops let me fix those failing tests |
Signed-off-by: jessicagreben <[email protected]>
|
As per message from @roidelapluie, merging this now. |
|
Wow, heroic year-long effort. Well done! |
|
Hello @JessicaGreben, when I discovered about this feature in the Medium article you wrote, I had to find this PR, to thank you. You are reducing my pain with Prometheus rules. Thanks again. |
This PR implements a solution for issue #11 to add the ability to retroactively evaluate new rules so that there is historical data for new rules. For details see design doc here.
This PR includes the following code changes:
promtool tsdb create-blocks-from rulesto execute backfilling data for a new ruleThings not in the PR that must be added:
Things not in this PR, but might be nice to add at a later date:
Example usage: