From 457a793e565b0fa1de919945467682272194d013 Mon Sep 17 00:00:00 2001 From: nityanandagohain Date: Fri, 30 Aug 2024 13:24:56 +0530 Subject: [PATCH 1/3] fix: dont merge missed series if there is no overlap or has more points --- pkg/query-service/app/querier/querier.go | 17 +- pkg/query-service/app/querier/querier_test.go | 179 ++++++++++++++++++ pkg/query-service/app/querier/v2/querier.go | 17 +- .../app/querier/v2/querier_test.go | 179 ++++++++++++++++++ 4 files changed, 390 insertions(+), 2 deletions(-) diff --git a/pkg/query-service/app/querier/querier.go b/pkg/query-service/app/querier/querier.go index 64e4a33ed2..cf75f5d146 100644 --- a/pkg/query-service/app/querier/querier.go +++ b/pkg/query-service/app/querier/querier.go @@ -275,7 +275,22 @@ func mergeSerieses(cachedSeries, missedSeries []*v3.Series) []*v3.Series { seriesesByLabels[labelsToString(series.Labels)] = series continue } - seriesesByLabels[labelsToString(series.Labels)].Points = append(seriesesByLabels[labelsToString(series.Labels)].Points, series.Points...) + + series.SortPoints() + ls := len(series.Points) + // existing points are already sorted + cachedPoints := seriesesByLabels[labelsToString(series.Labels)].Points + lc := len(cachedPoints) + + // add to the series only if the missed series start or end lies in between the cached series + if (series.Points[0].Timestamp >= cachedPoints[0].Timestamp && series.Points[0].Timestamp <= cachedPoints[lc-1].Timestamp) || + (series.Points[ls-1].Timestamp >= cachedPoints[0].Timestamp && series.Points[len(series.Points)-1].Timestamp <= cachedPoints[lc-1].Timestamp) { + + seriesesByLabels[labelsToString(series.Labels)].Points = append(seriesesByLabels[labelsToString(series.Labels)].Points, series.Points...) + } else if ls > lc { + // replace if the new series has more points than the old one + seriesesByLabels[labelsToString(series.Labels)] = series + } } // Sort the points in each series by timestamp for idx := range seriesesByLabels { diff --git a/pkg/query-service/app/querier/querier_test.go b/pkg/query-service/app/querier/querier_test.go index 962ca3832a..b9e7837402 100644 --- a/pkg/query-service/app/querier/querier_test.go +++ b/pkg/query-service/app/querier/querier_test.go @@ -12,6 +12,185 @@ import ( v3 "go.signoz.io/signoz/pkg/query-service/model/v3" ) +func TestMergeSerieses(t *testing.T) { + testCases := []struct { + name string + cachedSeries []*v3.Series + missedSeries []*v3.Series + resultSeries []*v3.Series + }{ + { + name: "merge two series", + cachedSeries: []*v3.Series{ + { + Labels: map[string]string{ + "__name__": "http_server_requests_seconds_count", + }, + Points: []v3.Point{ + {Timestamp: 1675115596722, Value: 1}, + {Timestamp: 1675115596723, Value: 2}, + {Timestamp: 1675115596724, Value: 3}, + }, + }, + }, + missedSeries: []*v3.Series{ + { + Labels: map[string]string{ + "__name__": "http_server_requests_seconds_count", + }, + Points: []v3.Point{ + {Timestamp: 1675115596724, Value: 3}, + {Timestamp: 1675115596725, Value: 4}, + }, + }, + }, + resultSeries: []*v3.Series{ + { + Labels: map[string]string{ + "__name__": "http_server_requests_seconds_count", + }, + Points: []v3.Point{ + {Timestamp: 1675115596722, Value: 1}, + {Timestamp: 1675115596723, Value: 2}, + {Timestamp: 1675115596724, Value: 3}, + {Timestamp: 1675115596725, Value: 4}, + }, + }, + }, + }, + { + name: "dont merge if start of missed is after end of cached", + cachedSeries: []*v3.Series{ + { + Labels: map[string]string{ + "__name__": "http_server_requests_seconds_count", + }, + Points: []v3.Point{ + {Timestamp: 1675115596722, Value: 1}, + {Timestamp: 1675115596723, Value: 2}, + {Timestamp: 1675115596724, Value: 3}, + }, + }, + }, + missedSeries: []*v3.Series{ + { + Labels: map[string]string{ + "__name__": "http_server_requests_seconds_count", + }, + Points: []v3.Point{ + {Timestamp: 1675115596726, Value: 5}, + {Timestamp: 1675115596727, Value: 6}, + }, + }, + }, + resultSeries: []*v3.Series{ + { + Labels: map[string]string{ + "__name__": "http_server_requests_seconds_count", + }, + Points: []v3.Point{ + {Timestamp: 1675115596722, Value: 1}, + {Timestamp: 1675115596723, Value: 2}, + {Timestamp: 1675115596724, Value: 3}, + }, + }, + }, + }, + { + name: "dont merge if end of missed is before start of cached", + cachedSeries: []*v3.Series{ + { + Labels: map[string]string{ + "__name__": "http_server_requests_seconds_count", + }, + Points: []v3.Point{ + {Timestamp: 1675115596722, Value: 1}, + {Timestamp: 1675115596723, Value: 2}, + {Timestamp: 1675115596724, Value: 3}, + }, + }, + }, + missedSeries: []*v3.Series{ + { + Labels: map[string]string{ + "__name__": "http_server_requests_seconds_count", + }, + Points: []v3.Point{ + {Timestamp: 1675115596720, Value: 5}, + {Timestamp: 1675115596721, Value: 6}, + }, + }, + }, + resultSeries: []*v3.Series{ + { + Labels: map[string]string{ + "__name__": "http_server_requests_seconds_count", + }, + Points: []v3.Point{ + {Timestamp: 1675115596722, Value: 1}, + {Timestamp: 1675115596723, Value: 2}, + {Timestamp: 1675115596724, Value: 3}, + }, + }, + }, + }, + { + name: "replace if new series has more points than the old one", + cachedSeries: []*v3.Series{ + { + Labels: map[string]string{ + "__name__": "http_server_requests_seconds_count", + }, + Points: []v3.Point{ + {Timestamp: 1675115596720, Value: 5}, + {Timestamp: 1675115596721, Value: 6}, + }, + }, + }, + missedSeries: []*v3.Series{ + { + Labels: map[string]string{ + "__name__": "http_server_requests_seconds_count", + }, + Points: []v3.Point{ + {Timestamp: 1675115596722, Value: 1}, + {Timestamp: 1675115596723, Value: 2}, + {Timestamp: 1675115596724, Value: 3}, + }, + }, + }, + resultSeries: []*v3.Series{ + { + Labels: map[string]string{ + "__name__": "http_server_requests_seconds_count", + }, + Points: []v3.Point{ + {Timestamp: 1675115596722, Value: 1}, + {Timestamp: 1675115596723, Value: 2}, + {Timestamp: 1675115596724, Value: 3}, + }, + }, + }, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + res := mergeSerieses(tc.cachedSeries, tc.missedSeries) + for sIdx, series := range tc.resultSeries { + if len(res[sIdx].Points) != len(series.Points) { + t.Errorf("expected %d, got %d", len(series.Points), len(res[sIdx].Points)) + } + for pIdx, point := range series.Points { + if res[sIdx].Points[pIdx].Timestamp != point.Timestamp { + t.Errorf("expected %d, got %d", point.Timestamp, res[sIdx].Points[pIdx].Timestamp) + } + } + } + }) + } +} + func TestFindMissingTimeRangesZeroFreshNess(t *testing.T) { // There are five scenarios: // 1. Cached time range is a subset of the requested time range diff --git a/pkg/query-service/app/querier/v2/querier.go b/pkg/query-service/app/querier/v2/querier.go index 5e0c18afb5..84ba06b809 100644 --- a/pkg/query-service/app/querier/v2/querier.go +++ b/pkg/query-service/app/querier/v2/querier.go @@ -286,7 +286,22 @@ func mergeSerieses(cachedSeries, missedSeries []*v3.Series) []*v3.Series { seriesesByLabels[labelsToString(series.Labels)] = series continue } - seriesesByLabels[labelsToString(series.Labels)].Points = append(seriesesByLabels[labelsToString(series.Labels)].Points, series.Points...) + + series.SortPoints() + ls := len(series.Points) + // existing points are already sorted + cachedPoints := seriesesByLabels[labelsToString(series.Labels)].Points + lc := len(cachedPoints) + + // add to the series only if the missed series start or end lies in between the cached series + if (series.Points[0].Timestamp >= cachedPoints[0].Timestamp && series.Points[0].Timestamp <= cachedPoints[lc-1].Timestamp) || + (series.Points[ls-1].Timestamp >= cachedPoints[0].Timestamp && series.Points[len(series.Points)-1].Timestamp <= cachedPoints[lc-1].Timestamp) { + + seriesesByLabels[labelsToString(series.Labels)].Points = append(seriesesByLabels[labelsToString(series.Labels)].Points, series.Points...) + } else if ls > lc { + // replace if the new series has more points than the old one + seriesesByLabels[labelsToString(series.Labels)] = series + } } // Sort the points in each series by timestamp diff --git a/pkg/query-service/app/querier/v2/querier_test.go b/pkg/query-service/app/querier/v2/querier_test.go index b8309c68ff..bf4844387c 100644 --- a/pkg/query-service/app/querier/v2/querier_test.go +++ b/pkg/query-service/app/querier/v2/querier_test.go @@ -12,6 +12,185 @@ import ( v3 "go.signoz.io/signoz/pkg/query-service/model/v3" ) +func TestMergeSerieses(t *testing.T) { + testCases := []struct { + name string + cachedSeries []*v3.Series + missedSeries []*v3.Series + resultSeries []*v3.Series + }{ + { + name: "merge two series", + cachedSeries: []*v3.Series{ + { + Labels: map[string]string{ + "__name__": "http_server_requests_seconds_count", + }, + Points: []v3.Point{ + {Timestamp: 1675115596722, Value: 1}, + {Timestamp: 1675115596723, Value: 2}, + {Timestamp: 1675115596724, Value: 3}, + }, + }, + }, + missedSeries: []*v3.Series{ + { + Labels: map[string]string{ + "__name__": "http_server_requests_seconds_count", + }, + Points: []v3.Point{ + {Timestamp: 1675115596724, Value: 3}, + {Timestamp: 1675115596725, Value: 4}, + }, + }, + }, + resultSeries: []*v3.Series{ + { + Labels: map[string]string{ + "__name__": "http_server_requests_seconds_count", + }, + Points: []v3.Point{ + {Timestamp: 1675115596722, Value: 1}, + {Timestamp: 1675115596723, Value: 2}, + {Timestamp: 1675115596724, Value: 3}, + {Timestamp: 1675115596725, Value: 4}, + }, + }, + }, + }, + { + name: "dont merge if start of missed is after end of cached", + cachedSeries: []*v3.Series{ + { + Labels: map[string]string{ + "__name__": "http_server_requests_seconds_count", + }, + Points: []v3.Point{ + {Timestamp: 1675115596722, Value: 1}, + {Timestamp: 1675115596723, Value: 2}, + {Timestamp: 1675115596724, Value: 3}, + }, + }, + }, + missedSeries: []*v3.Series{ + { + Labels: map[string]string{ + "__name__": "http_server_requests_seconds_count", + }, + Points: []v3.Point{ + {Timestamp: 1675115596726, Value: 5}, + {Timestamp: 1675115596727, Value: 6}, + }, + }, + }, + resultSeries: []*v3.Series{ + { + Labels: map[string]string{ + "__name__": "http_server_requests_seconds_count", + }, + Points: []v3.Point{ + {Timestamp: 1675115596722, Value: 1}, + {Timestamp: 1675115596723, Value: 2}, + {Timestamp: 1675115596724, Value: 3}, + }, + }, + }, + }, + { + name: "dont merge if end of missed is before start of cached", + cachedSeries: []*v3.Series{ + { + Labels: map[string]string{ + "__name__": "http_server_requests_seconds_count", + }, + Points: []v3.Point{ + {Timestamp: 1675115596722, Value: 1}, + {Timestamp: 1675115596723, Value: 2}, + {Timestamp: 1675115596724, Value: 3}, + }, + }, + }, + missedSeries: []*v3.Series{ + { + Labels: map[string]string{ + "__name__": "http_server_requests_seconds_count", + }, + Points: []v3.Point{ + {Timestamp: 1675115596720, Value: 5}, + {Timestamp: 1675115596721, Value: 6}, + }, + }, + }, + resultSeries: []*v3.Series{ + { + Labels: map[string]string{ + "__name__": "http_server_requests_seconds_count", + }, + Points: []v3.Point{ + {Timestamp: 1675115596722, Value: 1}, + {Timestamp: 1675115596723, Value: 2}, + {Timestamp: 1675115596724, Value: 3}, + }, + }, + }, + }, + { + name: "replace if new series has more points than the old one", + cachedSeries: []*v3.Series{ + { + Labels: map[string]string{ + "__name__": "http_server_requests_seconds_count", + }, + Points: []v3.Point{ + {Timestamp: 1675115596720, Value: 5}, + {Timestamp: 1675115596721, Value: 6}, + }, + }, + }, + missedSeries: []*v3.Series{ + { + Labels: map[string]string{ + "__name__": "http_server_requests_seconds_count", + }, + Points: []v3.Point{ + {Timestamp: 1675115596722, Value: 1}, + {Timestamp: 1675115596723, Value: 2}, + {Timestamp: 1675115596724, Value: 3}, + }, + }, + }, + resultSeries: []*v3.Series{ + { + Labels: map[string]string{ + "__name__": "http_server_requests_seconds_count", + }, + Points: []v3.Point{ + {Timestamp: 1675115596722, Value: 1}, + {Timestamp: 1675115596723, Value: 2}, + {Timestamp: 1675115596724, Value: 3}, + }, + }, + }, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + res := mergeSerieses(tc.cachedSeries, tc.missedSeries) + for sIdx, series := range tc.resultSeries { + if len(res[sIdx].Points) != len(series.Points) { + t.Errorf("expected %d, got %d", len(series.Points), len(res[sIdx].Points)) + } + for pIdx, point := range series.Points { + if res[sIdx].Points[pIdx].Timestamp != point.Timestamp { + t.Errorf("expected %d, got %d", point.Timestamp, res[sIdx].Points[pIdx].Timestamp) + } + } + } + }) + } +} + func TestV2FindMissingTimeRangesZeroFreshNess(t *testing.T) { // There are five scenarios: // 1. Cached time range is a subset of the requested time range From f010628b80672be4d50d180b7ef83a960e573bcd Mon Sep 17 00:00:00 2001 From: nityanandagohain Date: Fri, 30 Aug 2024 13:29:07 +0530 Subject: [PATCH 2/3] fix: minor refactor --- pkg/query-service/app/querier/querier.go | 2 +- pkg/query-service/app/querier/v2/querier.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/query-service/app/querier/querier.go b/pkg/query-service/app/querier/querier.go index cf75f5d146..77279ec4aa 100644 --- a/pkg/query-service/app/querier/querier.go +++ b/pkg/query-service/app/querier/querier.go @@ -284,7 +284,7 @@ func mergeSerieses(cachedSeries, missedSeries []*v3.Series) []*v3.Series { // add to the series only if the missed series start or end lies in between the cached series if (series.Points[0].Timestamp >= cachedPoints[0].Timestamp && series.Points[0].Timestamp <= cachedPoints[lc-1].Timestamp) || - (series.Points[ls-1].Timestamp >= cachedPoints[0].Timestamp && series.Points[len(series.Points)-1].Timestamp <= cachedPoints[lc-1].Timestamp) { + (series.Points[ls-1].Timestamp >= cachedPoints[0].Timestamp && series.Points[ls-1].Timestamp <= cachedPoints[lc-1].Timestamp) { seriesesByLabels[labelsToString(series.Labels)].Points = append(seriesesByLabels[labelsToString(series.Labels)].Points, series.Points...) } else if ls > lc { diff --git a/pkg/query-service/app/querier/v2/querier.go b/pkg/query-service/app/querier/v2/querier.go index 84ba06b809..c224952e58 100644 --- a/pkg/query-service/app/querier/v2/querier.go +++ b/pkg/query-service/app/querier/v2/querier.go @@ -295,7 +295,7 @@ func mergeSerieses(cachedSeries, missedSeries []*v3.Series) []*v3.Series { // add to the series only if the missed series start or end lies in between the cached series if (series.Points[0].Timestamp >= cachedPoints[0].Timestamp && series.Points[0].Timestamp <= cachedPoints[lc-1].Timestamp) || - (series.Points[ls-1].Timestamp >= cachedPoints[0].Timestamp && series.Points[len(series.Points)-1].Timestamp <= cachedPoints[lc-1].Timestamp) { + (series.Points[ls-1].Timestamp >= cachedPoints[0].Timestamp && series.Points[ls-1].Timestamp <= cachedPoints[lc-1].Timestamp) { seriesesByLabels[labelsToString(series.Labels)].Points = append(seriesesByLabels[labelsToString(series.Labels)].Points, series.Points...) } else if ls > lc { From 9cd5b90d95718aed1cbe68d70f56678455cdd96b Mon Sep 17 00:00:00 2001 From: nityanandagohain Date: Fri, 30 Aug 2024 16:39:25 +0530 Subject: [PATCH 3/3] fix: update logic for merging series --- pkg/query-service/app/querier/querier.go | 9 ++-- pkg/query-service/app/querier/querier_test.go | 41 +++++++++++-------- pkg/query-service/app/querier/v2/querier.go | 9 ++-- .../app/querier/v2/querier_test.go | 41 +++++++++++-------- 4 files changed, 54 insertions(+), 46 deletions(-) diff --git a/pkg/query-service/app/querier/querier.go b/pkg/query-service/app/querier/querier.go index 77279ec4aa..d52c41b4e6 100644 --- a/pkg/query-service/app/querier/querier.go +++ b/pkg/query-service/app/querier/querier.go @@ -282,13 +282,12 @@ func mergeSerieses(cachedSeries, missedSeries []*v3.Series) []*v3.Series { cachedPoints := seriesesByLabels[labelsToString(series.Labels)].Points lc := len(cachedPoints) - // add to the series only if the missed series start or end lies in between the cached series - if (series.Points[0].Timestamp >= cachedPoints[0].Timestamp && series.Points[0].Timestamp <= cachedPoints[lc-1].Timestamp) || - (series.Points[ls-1].Timestamp >= cachedPoints[0].Timestamp && series.Points[ls-1].Timestamp <= cachedPoints[lc-1].Timestamp) { + // if cacheSeries Start or End lies in missed series it means it can be merged + if (cachedPoints[0].Timestamp >= series.Points[0].Timestamp && cachedPoints[0].Timestamp <= series.Points[ls-1].Timestamp) || + (cachedPoints[lc-1].Timestamp >= series.Points[0].Timestamp && cachedPoints[lc-1].Timestamp <= series.Points[ls-1].Timestamp) { seriesesByLabels[labelsToString(series.Labels)].Points = append(seriesesByLabels[labelsToString(series.Labels)].Points, series.Points...) - } else if ls > lc { - // replace if the new series has more points than the old one + } else { seriesesByLabels[labelsToString(series.Labels)] = series } } diff --git a/pkg/query-service/app/querier/querier_test.go b/pkg/query-service/app/querier/querier_test.go index b9e7837402..4a77074a5f 100644 --- a/pkg/query-service/app/querier/querier_test.go +++ b/pkg/query-service/app/querier/querier_test.go @@ -13,6 +13,7 @@ import ( ) func TestMergeSerieses(t *testing.T) { + testCases := []struct { name string cachedSeries []*v3.Series @@ -89,9 +90,8 @@ func TestMergeSerieses(t *testing.T) { "__name__": "http_server_requests_seconds_count", }, Points: []v3.Point{ - {Timestamp: 1675115596722, Value: 1}, - {Timestamp: 1675115596723, Value: 2}, - {Timestamp: 1675115596724, Value: 3}, + {Timestamp: 1675115596726, Value: 5}, + {Timestamp: 1675115596727, Value: 6}, }, }, }, @@ -104,9 +104,9 @@ func TestMergeSerieses(t *testing.T) { "__name__": "http_server_requests_seconds_count", }, Points: []v3.Point{ - {Timestamp: 1675115596722, Value: 1}, - {Timestamp: 1675115596723, Value: 2}, - {Timestamp: 1675115596724, Value: 3}, + {Timestamp: 1675115596722, Value: 8}, + {Timestamp: 1675115596723, Value: 9}, + {Timestamp: 1675115596724, Value: 10}, }, }, }, @@ -127,23 +127,23 @@ func TestMergeSerieses(t *testing.T) { "__name__": "http_server_requests_seconds_count", }, Points: []v3.Point{ - {Timestamp: 1675115596722, Value: 1}, - {Timestamp: 1675115596723, Value: 2}, - {Timestamp: 1675115596724, Value: 3}, + {Timestamp: 1675115596720, Value: 5}, + {Timestamp: 1675115596721, Value: 6}, }, }, }, }, { - name: "replace if new series has more points than the old one", + name: "cache is a subset of missed series", cachedSeries: []*v3.Series{ { Labels: map[string]string{ "__name__": "http_server_requests_seconds_count", }, Points: []v3.Point{ - {Timestamp: 1675115596720, Value: 5}, - {Timestamp: 1675115596721, Value: 6}, + {Timestamp: 1675115596723, Value: 3}, + {Timestamp: 1675115596724, Value: 4}, + {Timestamp: 1675115596725, Value: 5}, }, }, }, @@ -153,9 +153,11 @@ func TestMergeSerieses(t *testing.T) { "__name__": "http_server_requests_seconds_count", }, Points: []v3.Point{ - {Timestamp: 1675115596722, Value: 1}, - {Timestamp: 1675115596723, Value: 2}, - {Timestamp: 1675115596724, Value: 3}, + {Timestamp: 1675115596721, Value: 1}, + {Timestamp: 1675115596722, Value: 2}, + {Timestamp: 1675115596723, Value: 3}, + {Timestamp: 1675115596725, Value: 5}, + {Timestamp: 1675115596726, Value: 6}, }, }, }, @@ -165,9 +167,12 @@ func TestMergeSerieses(t *testing.T) { "__name__": "http_server_requests_seconds_count", }, Points: []v3.Point{ - {Timestamp: 1675115596722, Value: 1}, - {Timestamp: 1675115596723, Value: 2}, - {Timestamp: 1675115596724, Value: 3}, + {Timestamp: 1675115596721, Value: 1}, + {Timestamp: 1675115596722, Value: 2}, + {Timestamp: 1675115596723, Value: 3}, + {Timestamp: 1675115596724, Value: 4}, + {Timestamp: 1675115596725, Value: 5}, + {Timestamp: 1675115596726, Value: 6}, }, }, }, diff --git a/pkg/query-service/app/querier/v2/querier.go b/pkg/query-service/app/querier/v2/querier.go index c224952e58..ea72783953 100644 --- a/pkg/query-service/app/querier/v2/querier.go +++ b/pkg/query-service/app/querier/v2/querier.go @@ -293,13 +293,12 @@ func mergeSerieses(cachedSeries, missedSeries []*v3.Series) []*v3.Series { cachedPoints := seriesesByLabels[labelsToString(series.Labels)].Points lc := len(cachedPoints) - // add to the series only if the missed series start or end lies in between the cached series - if (series.Points[0].Timestamp >= cachedPoints[0].Timestamp && series.Points[0].Timestamp <= cachedPoints[lc-1].Timestamp) || - (series.Points[ls-1].Timestamp >= cachedPoints[0].Timestamp && series.Points[ls-1].Timestamp <= cachedPoints[lc-1].Timestamp) { + // if cacheSeries Start or End lies in missed series it means it can be merged + if (cachedPoints[0].Timestamp >= series.Points[0].Timestamp && cachedPoints[0].Timestamp <= series.Points[ls-1].Timestamp) || + (cachedPoints[lc-1].Timestamp >= series.Points[0].Timestamp && cachedPoints[lc-1].Timestamp <= series.Points[ls-1].Timestamp) { seriesesByLabels[labelsToString(series.Labels)].Points = append(seriesesByLabels[labelsToString(series.Labels)].Points, series.Points...) - } else if ls > lc { - // replace if the new series has more points than the old one + } else { seriesesByLabels[labelsToString(series.Labels)] = series } } diff --git a/pkg/query-service/app/querier/v2/querier_test.go b/pkg/query-service/app/querier/v2/querier_test.go index bf4844387c..f798d12539 100644 --- a/pkg/query-service/app/querier/v2/querier_test.go +++ b/pkg/query-service/app/querier/v2/querier_test.go @@ -13,6 +13,7 @@ import ( ) func TestMergeSerieses(t *testing.T) { + testCases := []struct { name string cachedSeries []*v3.Series @@ -89,9 +90,8 @@ func TestMergeSerieses(t *testing.T) { "__name__": "http_server_requests_seconds_count", }, Points: []v3.Point{ - {Timestamp: 1675115596722, Value: 1}, - {Timestamp: 1675115596723, Value: 2}, - {Timestamp: 1675115596724, Value: 3}, + {Timestamp: 1675115596726, Value: 5}, + {Timestamp: 1675115596727, Value: 6}, }, }, }, @@ -104,9 +104,9 @@ func TestMergeSerieses(t *testing.T) { "__name__": "http_server_requests_seconds_count", }, Points: []v3.Point{ - {Timestamp: 1675115596722, Value: 1}, - {Timestamp: 1675115596723, Value: 2}, - {Timestamp: 1675115596724, Value: 3}, + {Timestamp: 1675115596722, Value: 8}, + {Timestamp: 1675115596723, Value: 9}, + {Timestamp: 1675115596724, Value: 10}, }, }, }, @@ -127,23 +127,23 @@ func TestMergeSerieses(t *testing.T) { "__name__": "http_server_requests_seconds_count", }, Points: []v3.Point{ - {Timestamp: 1675115596722, Value: 1}, - {Timestamp: 1675115596723, Value: 2}, - {Timestamp: 1675115596724, Value: 3}, + {Timestamp: 1675115596720, Value: 5}, + {Timestamp: 1675115596721, Value: 6}, }, }, }, }, { - name: "replace if new series has more points than the old one", + name: "cache is a subset of missed series", cachedSeries: []*v3.Series{ { Labels: map[string]string{ "__name__": "http_server_requests_seconds_count", }, Points: []v3.Point{ - {Timestamp: 1675115596720, Value: 5}, - {Timestamp: 1675115596721, Value: 6}, + {Timestamp: 1675115596723, Value: 3}, + {Timestamp: 1675115596724, Value: 4}, + {Timestamp: 1675115596725, Value: 5}, }, }, }, @@ -153,9 +153,11 @@ func TestMergeSerieses(t *testing.T) { "__name__": "http_server_requests_seconds_count", }, Points: []v3.Point{ - {Timestamp: 1675115596722, Value: 1}, - {Timestamp: 1675115596723, Value: 2}, - {Timestamp: 1675115596724, Value: 3}, + {Timestamp: 1675115596721, Value: 1}, + {Timestamp: 1675115596722, Value: 2}, + {Timestamp: 1675115596723, Value: 3}, + {Timestamp: 1675115596725, Value: 5}, + {Timestamp: 1675115596726, Value: 6}, }, }, }, @@ -165,9 +167,12 @@ func TestMergeSerieses(t *testing.T) { "__name__": "http_server_requests_seconds_count", }, Points: []v3.Point{ - {Timestamp: 1675115596722, Value: 1}, - {Timestamp: 1675115596723, Value: 2}, - {Timestamp: 1675115596724, Value: 3}, + {Timestamp: 1675115596721, Value: 1}, + {Timestamp: 1675115596722, Value: 2}, + {Timestamp: 1675115596723, Value: 3}, + {Timestamp: 1675115596724, Value: 4}, + {Timestamp: 1675115596725, Value: 5}, + {Timestamp: 1675115596726, Value: 6}, }, }, },