Skip to content

Commit

Permalink
Change flag type
Browse files Browse the repository at this point in the history
Signed-off-by: Ganesh Vernekar <[email protected]>
  • Loading branch information
codesome committed Oct 4, 2024
1 parent 2f5d8f0 commit cb78eb1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

### Query-tee

* [FEATURE] Added `-proxy.compare-skip-samples-before` to skip samples before a given unix timestamp in seconds when comparing responses. #9515
* [FEATURE] Added `-proxy.compare-skip-samples-before` to skip samples before the given time when comparing responses. The time must be in RFC3339 format. #9515

### Documentation

Expand Down
3 changes: 2 additions & 1 deletion cmd/query-tee/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package main
import (
"flag"
"fmt"
"github.com/prometheus/common/model"
"io"
"os"

Expand Down Expand Up @@ -106,7 +107,7 @@ func mimirReadRoutes(cfg Config) []querytee.Route {
Tolerance: cfg.ProxyConfig.ValueComparisonTolerance,
UseRelativeError: cfg.ProxyConfig.UseRelativeError,
SkipRecentSamples: cfg.ProxyConfig.SkipRecentSamples,
SkipSamplesBefore: cfg.ProxyConfig.SkipSamplesBefore * 1000,
SkipSamplesBefore: model.Time(cfg.ProxyConfig.SkipSamplesBefore.UnixMilli()),
RequireExactErrorMatch: cfg.ProxyConfig.RequireExactErrorMatch,
})

Expand Down
13 changes: 11 additions & 2 deletions tools/querytee/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type ProxyConfig struct {
UseRelativeError bool
PassThroughNonRegisteredRoutes bool
SkipRecentSamples time.Duration
SkipSamplesBefore int64
SkipSamplesBefore time.Time
RequireExactErrorMatch bool
BackendSkipTLSVerify bool
AddMissingTimeParamToInstantQueries bool
Expand All @@ -66,11 +66,20 @@ func (cfg *ProxyConfig) RegisterFlags(f *flag.FlagSet) {
f.Float64Var(&cfg.ValueComparisonTolerance, "proxy.value-comparison-tolerance", 0.000001, "The tolerance to apply when comparing floating point values in the responses. 0 to disable tolerance and require exact match (not recommended).")
f.BoolVar(&cfg.UseRelativeError, "proxy.compare-use-relative-error", false, "Use relative error tolerance when comparing floating point values.")
f.DurationVar(&cfg.SkipRecentSamples, "proxy.compare-skip-recent-samples", 2*time.Minute, "The window from now to skip comparing samples. 0 to disable.")
f.Int64Var(&cfg.SkipSamplesBefore, "proxy.compare-skip-samples-before", 0, "Skip the samples before the given unix timestamp in seconds for comparison.")
f.BoolVar(&cfg.RequireExactErrorMatch, "proxy.compare-exact-error-matching", false, "If true, errors will be considered the same only if they are exactly the same. If false, errors will be considered the same if they are considered equivalent.")
f.BoolVar(&cfg.PassThroughNonRegisteredRoutes, "proxy.passthrough-non-registered-routes", false, "Passthrough requests for non-registered routes to preferred backend.")
f.BoolVar(&cfg.AddMissingTimeParamToInstantQueries, "proxy.add-missing-time-parameter-to-instant-queries", true, "Add a 'time' parameter to proxied instant query requests if they do not have one.")
f.Float64Var(&cfg.SecondaryBackendsRequestProportion, "proxy.secondary-backends-request-proportion", 1.0, "Proportion of requests to send to secondary backends. Must be between 0 and 1 (inclusive), and if not 1, then -backend.preferred must be set.")

var skipSamplesBefore string
f.StringVar(&skipSamplesBefore, "proxy.compare-skip-samples-before", "", "Skip the samples before the given time for comparison. The time must be in RFC3339 format.")
if skipSamplesBefore != "" {
var err error
cfg.SkipSamplesBefore, err = time.Parse(time.RFC3339, skipSamplesBefore)
if err != nil {
cfg.SkipSamplesBefore = time.Time{}
}
}
}

type Route struct {
Expand Down
28 changes: 14 additions & 14 deletions tools/querytee/response_comparator.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type SampleComparisonOptions struct {
Tolerance float64
UseRelativeError bool
SkipRecentSamples time.Duration
SkipSamplesBefore int64 // unix time in milliseconds
SkipSamplesBefore model.Time
RequireExactErrorMatch bool
}

Expand Down Expand Up @@ -252,16 +252,16 @@ func compareMatrix(expectedRaw, actualRaw json.RawMessage, queryEvaluationTime t

func compareMatrixSamples(expected, actual *model.SampleStream, queryEvaluationTime time.Time, opts SampleComparisonOptions) error {
expected.Values = trimBeginning(expected.Values, func(p model.SamplePair) bool {
return int64(p.Timestamp) < opts.SkipSamplesBefore
return p.Timestamp < opts.SkipSamplesBefore
})
actual.Values = trimBeginning(actual.Values, func(p model.SamplePair) bool {
return int64(p.Timestamp) < opts.SkipSamplesBefore
return p.Timestamp < opts.SkipSamplesBefore
})
expected.Histograms = trimBeginning(expected.Histograms, func(p model.SampleHistogramPair) bool {
return int64(p.Timestamp) < opts.SkipSamplesBefore
return p.Timestamp < opts.SkipSamplesBefore
})
actual.Histograms = trimBeginning(actual.Histograms, func(p model.SampleHistogramPair) bool {
return int64(p.Timestamp) < opts.SkipSamplesBefore
return p.Timestamp < opts.SkipSamplesBefore
})

expectedSamplesTail, actualSamplesTail, err := comparePairs(expected.Values, actual.Values, func(p1 model.SamplePair, p2 model.SamplePair) error {
Expand Down Expand Up @@ -296,11 +296,11 @@ func compareMatrixSamples(expected, actual *model.SampleStream, queryEvaluationT
}

skipAllFloatSamples := canSkipAllSamples(func(p model.SamplePair) bool {
return queryEvaluationTime.Sub(p.Timestamp.Time())-opts.SkipRecentSamples < 0 || int64(p.Timestamp) < opts.SkipSamplesBefore
return queryEvaluationTime.Sub(p.Timestamp.Time())-opts.SkipRecentSamples < 0 || p.Timestamp < opts.SkipSamplesBefore
}, expectedSamplesTail, actualSamplesTail)

skipAllHistogramSamples := canSkipAllSamples(func(p model.SampleHistogramPair) bool {
return queryEvaluationTime.Sub(p.Timestamp.Time())-opts.SkipRecentSamples < 0 || int64(p.Timestamp) < opts.SkipSamplesBefore
return queryEvaluationTime.Sub(p.Timestamp.Time())-opts.SkipRecentSamples < 0 || p.Timestamp < opts.SkipSamplesBefore
}, expectedHistogramSamplesTail, actualHistogramSamplesTail)

if skipAllFloatSamples && skipAllHistogramSamples {
Expand Down Expand Up @@ -401,14 +401,14 @@ func allMatrixSamplesOutsideComparableWindow(m model.Matrix, queryEvaluationTime
for _, series := range m {
for _, sample := range series.Values {
st := sample.Timestamp
if queryEvaluationTime.Sub(st.Time()) > opts.SkipRecentSamples && int64(st) >= opts.SkipSamplesBefore {
if queryEvaluationTime.Sub(st.Time()) > opts.SkipRecentSamples && st >= opts.SkipSamplesBefore {
return false
}
}

for _, sample := range series.Histograms {
st := sample.Timestamp
if queryEvaluationTime.Sub(st.Time()) > opts.SkipRecentSamples && int64(st) >= opts.SkipSamplesBefore {
if queryEvaluationTime.Sub(st.Time()) > opts.SkipRecentSamples && st >= opts.SkipSamplesBefore {
return false
}
}
Expand All @@ -435,10 +435,10 @@ func compareVector(expectedRaw, actualRaw json.RawMessage, queryEvaluationTime t
}

expected = filterSlice(expected, func(p *model.Sample) bool {
return int64(p.Timestamp) < opts.SkipSamplesBefore
return p.Timestamp < opts.SkipSamplesBefore
})
actual = filterSlice(actual, func(p *model.Sample) bool {
return int64(p.Timestamp) < opts.SkipSamplesBefore
return p.Timestamp < opts.SkipSamplesBefore
})

if len(expected) != len(actual) {
Expand Down Expand Up @@ -507,7 +507,7 @@ func allVectorSamplesOutsideComparableWindow(v model.Vector, queryEvaluationTime

for _, sample := range v {
st := sample.Timestamp
if queryEvaluationTime.Sub(st.Time()) > opts.SkipRecentSamples && int64(st) >= opts.SkipSamplesBefore {
if queryEvaluationTime.Sub(st.Time()) > opts.SkipRecentSamples && st >= opts.SkipSamplesBefore {
return false
}
}
Expand Down Expand Up @@ -542,7 +542,7 @@ func compareScalar(expectedRaw, actualRaw json.RawMessage, queryEvaluationTime t
}

func compareSamplePair(expected, actual model.SamplePair, queryEvaluationTime time.Time, opts SampleComparisonOptions) error {
if int64(expected.Timestamp) < opts.SkipSamplesBefore && int64(actual.Timestamp) < opts.SkipSamplesBefore {
if expected.Timestamp < opts.SkipSamplesBefore && actual.Timestamp < opts.SkipSamplesBefore {
return nil
}
if expected.Timestamp != actual.Timestamp {
Expand Down Expand Up @@ -573,7 +573,7 @@ func compareSampleValue(first, second float64, opts SampleComparisonOptions) boo
}

func compareSampleHistogramPair(expected, actual model.SampleHistogramPair, queryEvaluationTime time.Time, opts SampleComparisonOptions) error {
if int64(expected.Timestamp) < opts.SkipSamplesBefore {
if expected.Timestamp < opts.SkipSamplesBefore {
return nil
}

Expand Down

0 comments on commit cb78eb1

Please sign in to comment.