mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-24 21:24:05 -08:00
fix panics
Signed-off-by: jessicagreben <jessicagrebens@gmail.com>
This commit is contained in:
parent
61c9a89120
commit
75654715d3
|
@ -139,11 +139,10 @@ func main() {
|
||||||
backfillRuleCmd := backfillCmd.Command("rules", "Backfill Prometheus data for new rules.")
|
backfillRuleCmd := backfillCmd.Command("rules", "Backfill Prometheus data for new rules.")
|
||||||
backfillRuleStart := backfillRuleCmd.Flag("start", "The time to start backfilling the new rule from. It is required. Start time should be RFC3339 or Unix timestamp.").
|
backfillRuleStart := backfillRuleCmd.Flag("start", "The time to start backfilling the new rule from. It is required. Start time should be RFC3339 or Unix timestamp.").
|
||||||
Required().String()
|
Required().String()
|
||||||
backfillRuleEnd := backfillRuleCmd.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 hrs ago. End time should be RFC3339 or Unix timestamp.").
|
backfillRuleEnd := backfillRuleCmd.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 hrs ago. End time should be RFC3339 or Unix timestamp.").String()
|
||||||
Default("-3h").String()
|
|
||||||
backfillOutputDir := backfillRuleCmd.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.").Default("backfilldata/").String()
|
backfillOutputDir := backfillRuleCmd.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.").Default("backfilldata/").String()
|
||||||
backfillRuleURL := backfillRuleCmd.Flag("url", "Prometheus API url with the data where the rule will be backfilled from.").Default("localhost:9090").String()
|
backfillRuleURL := backfillRuleCmd.Flag("url", "Prometheus API url with the data where the rule will be backfilled from.").Default("http://localhost:9090").String()
|
||||||
backfillRuleEvalInterval := backfillRuleCmd.Flag("evaluation_interval default", "How frequently to evaluate rules when backfilling. evaluation interval in the rules file will take precedence.").
|
backfillRuleEvalInterval := backfillRuleCmd.Flag("evaluation_interval_default", "How frequently to evaluate rules when backfilling if a value is not set in the rules file.").
|
||||||
Default("60s").Duration()
|
Default("60s").Duration()
|
||||||
backfillRuleFiles := backfillRuleCmd.Arg(
|
backfillRuleFiles := backfillRuleCmd.Arg(
|
||||||
"rule-files",
|
"rule-files",
|
||||||
|
@ -787,11 +786,29 @@ func (j *jsonPrinter) printLabelValues(v model.LabelValues) {
|
||||||
// at the outputDir location.
|
// at the outputDir location.
|
||||||
func BackfillRule(url, start, end, outputDir string, evalInterval time.Duration, files ...string) error {
|
func BackfillRule(url, start, end, outputDir string, evalInterval time.Duration, files ...string) error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
stime, etime, err := parseStartTimeAndEndTime(start, end)
|
var stime, etime time.Time
|
||||||
|
var err error
|
||||||
|
if end == "" {
|
||||||
|
etime = time.Now().Add(-3 * time.Hour)
|
||||||
|
} else {
|
||||||
|
etime, err = parseTime(end)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, "error parsing end time:", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stime, err = parseTime(start)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, "error parsing start time:", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !stime.Before(etime) {
|
||||||
|
fmt.Fprintln(os.Stderr, "start time is not before end time")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
cfg := ruleImporterConfig{
|
cfg := ruleImporterConfig{
|
||||||
Start: stime,
|
Start: stime,
|
||||||
End: etime,
|
End: etime,
|
||||||
|
|
|
@ -121,6 +121,7 @@ func (importer *ruleImporter) loadGroups(ctx context.Context, filenames []string
|
||||||
File: filename,
|
File: filename,
|
||||||
Interval: itv,
|
Interval: itv,
|
||||||
Rules: rgRules,
|
Rules: rgRules,
|
||||||
|
Opts: &rules.ManagerOptions{},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -474,8 +474,8 @@ func (g *Group) GetEvaluationTime() time.Duration {
|
||||||
return g.evaluationTime
|
return g.evaluationTime
|
||||||
}
|
}
|
||||||
|
|
||||||
// setEvaluationDuration sets the time in seconds the last evaluation took.
|
// setEvaluationTime sets the time in seconds the last evaluation took.
|
||||||
func (g *Group) setEvaluationDuration(dur time.Duration) {
|
func (g *Group) setEvaluationTime(dur time.Duration) {
|
||||||
g.metrics.groupLastDuration.WithLabelValues(GroupKey(g.file, g.name)).Set(dur.Seconds())
|
g.metrics.groupLastDuration.WithLabelValues(GroupKey(g.file, g.name)).Set(dur.Seconds())
|
||||||
|
|
||||||
g.mtx.Lock()
|
g.mtx.Lock()
|
||||||
|
@ -490,8 +490,8 @@ func (g *Group) GetLastEvaluation() time.Time {
|
||||||
return g.lastEvaluation
|
return g.lastEvaluation
|
||||||
}
|
}
|
||||||
|
|
||||||
// setEvaluationTimestamp updates evaluationTimestamp to the timestamp of when the rule group was last evaluated.
|
// setLastEvaluation updates evaluationTimestamp to the timestamp of when the rule group was last evaluated.
|
||||||
func (g *Group) setEvaluationTimestamp(ts time.Time) {
|
func (g *Group) setLastEvaluation(ts time.Time) {
|
||||||
g.metrics.groupLastEvalTime.WithLabelValues(GroupKey(g.file, g.name)).Set(float64(ts.UnixNano()) / 1e9)
|
g.metrics.groupLastEvalTime.WithLabelValues(GroupKey(g.file, g.name)).Set(float64(ts.UnixNano()) / 1e9)
|
||||||
|
|
||||||
g.mtx.Lock()
|
g.mtx.Lock()
|
||||||
|
|
|
@ -24,7 +24,6 @@ import (
|
||||||
"github.com/oklog/ulid"
|
"github.com/oklog/ulid"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/prometheus/prometheus/pkg/timestamp"
|
|
||||||
"github.com/prometheus/prometheus/storage"
|
"github.com/prometheus/prometheus/storage"
|
||||||
"github.com/prometheus/prometheus/tsdb/chunkenc"
|
"github.com/prometheus/prometheus/tsdb/chunkenc"
|
||||||
)
|
)
|
||||||
|
@ -85,7 +84,6 @@ func (w *BlockWriter) Appender(ctx context.Context) storage.Appender {
|
||||||
// Flush implements the Writer interface. This is where actual block writing
|
// Flush implements the Writer interface. This is where actual block writing
|
||||||
// happens. After flush completes, no writes can be done.
|
// happens. After flush completes, no writes can be done.
|
||||||
func (w *BlockWriter) Flush(ctx context.Context) (ulid.ULID, error) {
|
func (w *BlockWriter) Flush(ctx context.Context) (ulid.ULID, error) {
|
||||||
seriesCount := w.head.NumSeries()
|
|
||||||
if w.head.NumSeries() == 0 {
|
if w.head.NumSeries() == 0 {
|
||||||
return ulid.ULID{}, errors.New("no series appended, aborting")
|
return ulid.ULID{}, errors.New("no series appended, aborting")
|
||||||
}
|
}
|
||||||
|
@ -94,7 +92,6 @@ func (w *BlockWriter) Flush(ctx context.Context) (ulid.ULID, error) {
|
||||||
// Add +1 millisecond to block maxt because block intervals are half-open: [b.MinTime, b.MaxTime).
|
// Add +1 millisecond to block maxt because block intervals are half-open: [b.MinTime, b.MaxTime).
|
||||||
// Because of this block intervals are always +1 than the total samples it includes.
|
// Because of this block intervals are always +1 than the total samples it includes.
|
||||||
maxt := w.head.MaxTime() + 1
|
maxt := w.head.MaxTime() + 1
|
||||||
level.Info(w.logger).Log("msg", "flushing", "series_count", seriesCount, "mint", timestamp.Time(mint), "maxt", timestamp.Time(maxt))
|
|
||||||
|
|
||||||
compactor, err := NewLeveledCompactor(ctx,
|
compactor, err := NewLeveledCompactor(ctx,
|
||||||
nil,
|
nil,
|
||||||
|
|
Loading…
Reference in a new issue