Skip to content

Commit

Permalink
fix unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Ye <ben.ye@bytedance.com>
  • Loading branch information
Ben Ye committed Aug 13, 2022
1 parent a34c0f5 commit 19e1dae
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 82 deletions.
60 changes: 30 additions & 30 deletions internal/cortex/util/metrics_helper_test.go
Expand Up @@ -651,38 +651,38 @@ func TestUserRegistries_RemoveUserRegistry_SoftRemoval(t *testing.T) {
# TYPE counter counter
# No change in counter
counter 75
# HELP counter_labels help
# TYPE counter_labels counter
# No change in counter per label.
counter_labels{label_one="a"} 75
# HELP counter_user help
# TYPE counter_user counter
# User 3 is now missing.
counter_user{user="1"} 5
counter_user{user="2"} 10
counter_user{user="4"} 20
counter_user{user="5"} 25
# HELP gauge help
# TYPE gauge gauge
# Drop in the gauge (value 3, counted 5 times)
gauge 60
# HELP gauge_labels help
# TYPE gauge_labels gauge
# Drop in the gauge (value 3, counted 5 times)
gauge_labels{label_one="a"} 60
# HELP gauge_user help
# TYPE gauge_user gauge
# User 3 is now missing.
gauge_user{user="1"} 5
gauge_user{user="2"} 10
gauge_user{user="4"} 20
gauge_user{user="5"} 25
# HELP histogram help
# TYPE histogram histogram
# No change in the histogram
Expand All @@ -692,7 +692,7 @@ func TestUserRegistries_RemoveUserRegistry_SoftRemoval(t *testing.T) {
histogram_bucket{le="+Inf"} 25
histogram_sum 75
histogram_count 25
# HELP histogram_labels help
# TYPE histogram_labels histogram
# No change in the histogram per label
Expand All @@ -702,19 +702,19 @@ func TestUserRegistries_RemoveUserRegistry_SoftRemoval(t *testing.T) {
histogram_labels_bucket{label_one="a",le="+Inf"} 25
histogram_labels_sum{label_one="a"} 75
histogram_labels_count{label_one="a"} 25
# HELP summary help
# TYPE summary summary
# No change in the summary
summary_sum 75
summary_count 25
# HELP summary_labels help
# TYPE summary_labels summary
# No change in the summary per label
summary_labels_sum{label_one="a"} 75
summary_labels_count{label_one="a"} 25
# HELP summary_user help
# TYPE summary_user summary
# Summary for user 3 is now missing.
Expand Down Expand Up @@ -742,38 +742,38 @@ func TestUserRegistries_RemoveUserRegistry_HardRemoval(t *testing.T) {
# TYPE counter counter
# Counter drop (reset!)
counter 60
# HELP counter_labels help
# TYPE counter_labels counter
# Counter drop (reset!)
counter_labels{label_one="a"} 60
# HELP counter_user help
# TYPE counter_user counter
# User 3 is now missing.
counter_user{user="1"} 5
counter_user{user="2"} 10
counter_user{user="4"} 20
counter_user{user="5"} 25
# HELP gauge help
# TYPE gauge gauge
# Drop in the gauge (value 3, counted 5 times)
gauge 60
# HELP gauge_labels help
# TYPE gauge_labels gauge
# Drop in the gauge (value 3, counted 5 times)
gauge_labels{label_one="a"} 60
# HELP gauge_user help
# TYPE gauge_user gauge
# User 3 is now missing.
gauge_user{user="1"} 5
gauge_user{user="2"} 10
gauge_user{user="4"} 20
gauge_user{user="5"} 25
# HELP histogram help
# TYPE histogram histogram
# Histogram drop (reset for sum and count!)
Expand All @@ -783,7 +783,7 @@ func TestUserRegistries_RemoveUserRegistry_HardRemoval(t *testing.T) {
histogram_bucket{le="+Inf"} 20
histogram_sum 60
histogram_count 20
# HELP histogram_labels help
# TYPE histogram_labels histogram
# No change in the histogram per label
Expand All @@ -793,19 +793,19 @@ func TestUserRegistries_RemoveUserRegistry_HardRemoval(t *testing.T) {
histogram_labels_bucket{label_one="a",le="+Inf"} 20
histogram_labels_sum{label_one="a"} 60
histogram_labels_count{label_one="a"} 20
# HELP summary help
# TYPE summary summary
# Summary drop!
summary_sum 60
summary_count 20
# HELP summary_labels help
# TYPE summary_labels summary
# Summary drop!
summary_labels_sum{label_one="a"} 60
summary_labels_count{label_one="a"} 20
# HELP summary_user help
# TYPE summary_user summary
# Summary for user 3 is now missing.
Expand Down Expand Up @@ -834,38 +834,38 @@ func TestUserRegistries_AddUserRegistry_ReplaceRegistry(t *testing.T) {
# TYPE counter counter
# No change in counter
counter 75
# HELP counter_labels help
# TYPE counter_labels counter
# No change in counter per label
counter_labels{label_one="a"} 75
# HELP counter_user help
# TYPE counter_user counter
# Per-user counter now missing.
counter_user{user="1"} 5
counter_user{user="2"} 10
counter_user{user="3"} 15
counter_user{user="4"} 20
# HELP gauge help
# TYPE gauge gauge
# Gauge drops by 25 (value for user 5, times 5)
gauge 50
# HELP gauge_labels help
# TYPE gauge_labels gauge
# Gauge drops by 25 (value for user 5, times 5)
gauge_labels{label_one="a"} 50
# HELP gauge_user help
# TYPE gauge_user gauge
# Gauge for user 5 is missing
gauge_user{user="1"} 5
gauge_user{user="2"} 10
gauge_user{user="3"} 15
gauge_user{user="4"} 20
# HELP histogram help
# TYPE histogram histogram
# No change in histogram
Expand All @@ -875,7 +875,7 @@ func TestUserRegistries_AddUserRegistry_ReplaceRegistry(t *testing.T) {
histogram_bucket{le="+Inf"} 25
histogram_sum 75
histogram_count 25
# HELP histogram_labels help
# TYPE histogram_labels histogram
# No change in histogram per label.
Expand All @@ -885,19 +885,19 @@ func TestUserRegistries_AddUserRegistry_ReplaceRegistry(t *testing.T) {
histogram_labels_bucket{label_one="a",le="+Inf"} 25
histogram_labels_sum{label_one="a"} 75
histogram_labels_count{label_one="a"} 25
# HELP summary help
# TYPE summary summary
# No change in summary
summary_sum 75
summary_count 25
# HELP summary_labels help
# TYPE summary_labels summary
# No change in summary per label
summary_labels_sum{label_one="a"} 75
summary_labels_count{label_one="a"} 25
# HELP summary_user help
# TYPE summary_user summary
# Summary for user 5 now zero (reset)
Expand Down
5 changes: 3 additions & 2 deletions pkg/queryfrontend/labels_codec_test.go
Expand Up @@ -211,6 +211,7 @@ func TestLabelsCodec_EncodeRequest(t *testing.T) {
end = "end"
startTime = "123"
endTime = "456"
trueStr = "true"
)
for _, tc := range []struct {
name string
Expand Down Expand Up @@ -253,7 +254,7 @@ func TestLabelsCodec_EncodeRequest(t *testing.T) {
return r.URL.Query().Get(start) == startTime &&
r.URL.Query().Get(end) == endTime &&
r.URL.Path == "/api/v1/label/__name__/values" &&
r.URL.Query().Get(queryv1.PartialResponseParam) == "true"
r.URL.Query().Get(queryv1.PartialResponseParam) == trueStr
},
},
{
Expand Down Expand Up @@ -291,7 +292,7 @@ func TestLabelsCodec_EncodeRequest(t *testing.T) {
checkFunc: func(r *http.Request) bool {
return r.FormValue(start) == startTime &&
r.FormValue(end) == endTime &&
r.FormValue(queryv1.DedupParam) == "true" &&
r.FormValue(queryv1.DedupParam) == trueStr &&
r.URL.Path == "/api/v1/series"
},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/queryfrontend/queryinstant_codec.go
Expand Up @@ -208,7 +208,7 @@ func (c queryInstantCodec) DecodeResponse(ctx context.Context, r *http.Response,

buf, err := queryrange.BodyBuffer(r)
if err != nil {
log.Error(err)
log.Error(err) //nolint:errcheck
return nil, err
}
log.LogFields(otlog.Int("bytes", len(buf)))
Expand Down
47 changes: 5 additions & 42 deletions pkg/queryfrontend/roundtrip_test.go
Expand Up @@ -97,19 +97,6 @@ func TestRoundTripRetryMiddleware(t *testing.T) {
fail bool
expected int
}{
{
name: "not query range, retry won't be triggered 1.",
maxRetries: 100,
req: &ThanosQueryRangeRequest{
Path: "/api/v1/query",
Start: 0,
End: 2 * hour,
Step: 10 * seconds,
},
codec: queryRangeCodec,
handlerFunc: promqlResults,
expected: 1,
},
{
name: "no retry, get counter value 1",
maxRetries: 0,
Expand Down Expand Up @@ -261,19 +248,6 @@ func TestRoundTripSplitIntervalMiddleware(t *testing.T) {
handlerFunc func(bool) (*int, http.Handler)
expected int
}{
{
name: "non query range request won't be split 1",
req: &ThanosQueryRangeRequest{
Path: "/api/v1/query",
Start: 0,
End: 2 * hour,
Step: 10 * seconds,
},
handlerFunc: promqlResults,
codec: queryRangeCodec,
splitInterval: time.Hour,
expected: 1,
},
{
name: "split interval == 0, disable split",
req: testRequest,
Expand Down Expand Up @@ -393,15 +367,6 @@ func TestRoundTripQueryRangeCacheMiddleware(t *testing.T) {
Dedup: false,
}

// Non query range request, won't be cached.
testRequestInstant := &ThanosQueryRangeRequest{
Path: "/api/v1/query",
Start: 0,
End: 2 * hour,
Step: 10 * seconds,
Dedup: true,
}

// Same query params as testRequest, different maxSourceResolution
// but still in the same downsampling level, so it will be cached in this case.
testRequestSameLevelDownsampling := &ThanosQueryRangeRequest{
Expand Down Expand Up @@ -472,11 +437,9 @@ func TestRoundTripQueryRangeCacheMiddleware(t *testing.T) {
{name: "first request", req: testRequest, expected: 1},
{name: "same request as the first one, directly use cache", req: testRequest, expected: 1},
{name: "same request as the first one but with dedup disabled, should not use cache", req: testRequestWithoutDedup, expected: 2},
{name: "non query range request won't be cached", req: testRequestInstant, expected: 3},
{name: "do it again", req: testRequestInstant, expected: 4},
{name: "different max source resolution but still same level", req: testRequestSameLevelDownsampling, expected: 4},
{name: "different max source resolution and different level", req: testRequestHigherLevelDownsampling, expected: 5},
{name: "storeMatchers requests won't go to cache", req: testRequestWithStoreMatchers, expected: 6},
{name: "different max source resolution but still same level", req: testRequestSameLevelDownsampling, expected: 2},
{name: "different max source resolution and different level", req: testRequestHigherLevelDownsampling, expected: 3},
{name: "storeMatchers requests won't go to cache", req: testRequestWithStoreMatchers, expected: 4},
{
name: "request but will be partitioned",
req: &ThanosQueryRangeRequest{
Expand All @@ -486,7 +449,7 @@ func TestRoundTripQueryRangeCacheMiddleware(t *testing.T) {
Step: 10 * seconds,
Dedup: true,
},
expected: 8,
expected: 6,
},
{
name: "same query as the previous one",
Expand All @@ -497,7 +460,7 @@ func TestRoundTripQueryRangeCacheMiddleware(t *testing.T) {
Step: 10 * seconds,
Dedup: true,
},
expected: 8,
expected: 6,
},
} {
if !t.Run(tc.name, func(t *testing.T) {
Expand Down
14 changes: 7 additions & 7 deletions scripts/genproto.sh
Expand Up @@ -58,12 +58,12 @@ for dir in ${CORTEX_DIRS}; do
-I=. \
${dir}/*.proto

pushd ${dir}
sed -i.bak -E 's/import _ \"gogoproto\"//g' *.pb.go
sed -i.bak -E 's/_ \"google\/protobuf\"//g' *.pb.go
sed -i.bak -E 's/\"cortex\/cortexpb\"/\"github.com\/thanos-io\/thanos\/internal\/cortex\/cortexpb\"/g' *.pb.go
rm -f *.bak
${GOIMPORTS_BIN} -w *.pb.go
popd
pushd ${dir}
sed -i.bak -E 's/import _ \"gogoproto\"//g' *.pb.go
sed -i.bak -E 's/_ \"google\/protobuf\"//g' *.pb.go
sed -i.bak -E 's/\"cortex\/cortexpb\"/\"github.com\/thanos-io\/thanos\/internal\/cortex\/cortexpb\"/g' *.pb.go
rm -f *.bak
${GOIMPORTS_BIN} -w *.pb.go
popd
done
popd

0 comments on commit 19e1dae

Please sign in to comment.