Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

query/api: properly pass downsampling param #1144

Merged
merged 2 commits into from
May 15, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/query/api/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ func (api *API) parseDownsamplingParam(r *http.Request, step time.Duration) (max
return 0, &ApiError{errorBadData, errors.Errorf("negative '%s' is not accepted. Try a positive integer", maxSourceResolutionParam)}
}

/// We need this in milliseconds.
maxSourceResolution = maxSourceResolution / (1000 * 1000)

return maxSourceResolution, nil
}

Expand Down
69 changes: 69 additions & 0 deletions pkg/query/api/v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"time"

"github.com/go-kit/kit/log"
"github.com/improbable-eng/thanos/pkg/compact"
"github.com/improbable-eng/thanos/pkg/query"
"github.com/improbable-eng/thanos/pkg/testutil"
"github.com/opentracing/opentracing-go"
Expand Down Expand Up @@ -716,6 +717,74 @@ func TestParseTime(t *testing.T) {
}
}

func TestParseDownsamplingParam(t *testing.T) {
var tests = []struct {
maxSourceResolution string
result time.Duration
step time.Duration
fail bool
enableAutodownsampling bool
}{
{
maxSourceResolution: "0s",
enableAutodownsampling: false,
step: time.Hour,
result: time.Duration(compact.ResolutionLevelRaw),
fail: false,
},
{
maxSourceResolution: "5m",
step: time.Hour,
enableAutodownsampling: false,
result: time.Duration(compact.ResolutionLevel5m),
fail: false,
},
{
maxSourceResolution: "1h",
step: time.Hour,
enableAutodownsampling: false,
result: time.Duration(compact.ResolutionLevel1h),
fail: false,
},
{
maxSourceResolution: "",
enableAutodownsampling: true,
step: time.Hour,
result: time.Duration(time.Hour / (5 * 1000 * 1000)),
fail: false,
},
{
maxSourceResolution: "",
enableAutodownsampling: true,
step: time.Hour,
result: time.Duration((1 * time.Hour) / 6),
fail: true,
},
{
maxSourceResolution: "",
enableAutodownsampling: true,
step: time.Hour,
result: time.Duration((1 * time.Hour) / 6),
fail: true,
},
}

for i, test := range tests {
api := API{enableAutodownsampling: test.enableAutodownsampling}
v := url.Values{}
v.Set("max_source_resolution", test.maxSourceResolution)
r := http.Request{PostForm: v}

maxSourceRes, _ := api.parseDownsamplingParam(&r, test.step)
if test.fail == false {
testutil.Assert(t, maxSourceRes == test.result, "case %v: expected %v to be equal to %v", i, maxSourceRes, test.result)
} else {
testutil.Assert(t, maxSourceRes != test.result, "case %v: expected %v not to be equal to %v", i, maxSourceRes, test.result)
}

}
}

func TestParseDuration(t *testing.T) {
var tests = []struct {
input string
Expand Down