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

feat(query-tee): improvements to skip samples outside comparison window #15794

Merged
merged 9 commits into from
Jan 22, 2025

Conversation

ashwanthgoli
Copy link
Contributor

@ashwanthgoli ashwanthgoli commented Jan 16, 2025

What this PR does / why we need it:

  • Adds support to skip comparison of samples that have a timestamp older than proxy.compare-skip-samples-before
  • cortex_querytee_responses_compared_total now reports skipped count which was previously getting counted as success
  • Updates the comparison operation for all response types to first filter out the samples that should be skipped and then comparing them
    • avoids stream count mismatch errors by entirely ignoring streams that have all samples outside the comparison window
    • avoid length mismatch errors for a given stream by only comparing samples that are within comparable window

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Checklist

  • Reviewed the CONTRIBUTING.md guide (required)
  • Documentation added
  • Tests updated
  • Title matches the required conventional commits format, see here
    • Note that Promtail is considered to be feature complete, and future development for logs collection will be in Grafana Alloy. As such, feat PRs are unlikely to be accepted unless a case can be made for the feature actually being a bug fix to existing behavior.
  • Changes that require user attention or interaction to upgrade are documented in docs/sources/setup/upgrade/_index.md
  • If the change is deprecating or removing a configuration option, update the deprecated-config.yaml and deleted-config.yaml files respectively in the tools/deprecated-config-checker directory. Example PR

@pull-request-size pull-request-size bot added size/L and removed size/M labels Jan 17, 2025
@ashwanthgoli ashwanthgoli changed the title query-tee: improvements to skip recent samples feat(query-tee): improvements to skip recent samples Jan 17, 2025
@ashwanthgoli ashwanthgoli marked this pull request as ready for review January 20, 2025 12:57
@ashwanthgoli ashwanthgoli requested a review from a team as a code owner January 20, 2025 12:57
@ashwanthgoli ashwanthgoli changed the title feat(query-tee): improvements to skip recent samples feat(query-tee): improvements to skip samples outside comparison window Jan 20, 2025
Comment on lines 107 to 170
func TestCompareMatrix_SamplesOutsideComparableWindow(t *testing.T) {
for _, tc := range []struct {
name string
expected json.RawMessage
actual json.RawMessage
skipSamplesBefore time.Time
skipRecentSamples time.Duration
evaluationTime time.Time
err error
}{
{
name: "skip samples before window",
expected: json.RawMessage(`[
{"metric":{"foo":"bar"},"values":[[0,"1"],[5,"2"],[15,"3"],[20,"4"]]}
]`),
actual: json.RawMessage(`[
{"metric":{"foo":"bar"},"values":[[5,"1"],[15,"3"],[20,"4"]]}
]`),
skipSamplesBefore: time.Unix(10, 0),
evaluationTime: time.Unix(100, 0),
},
{
name: "skip recent samples",
expected: json.RawMessage(`[
{"metric":{"foo":"bar"},"values":[[5,"1"],[25,"2"],[80,"3"],[94,"4"],[96,"5"]]}
]`),
actual: json.RawMessage(`[
{"metric":{"foo":"bar"},"values":[[5,"1"],[25,"2"],[80,"3"],[95, "4"]]}
]`),
skipRecentSamples: 10 * time.Second,
evaluationTime: time.Unix(100, 0),
},
{
name: "skip both recent and old samples",
expected: json.RawMessage(`[
{"metric":{"foo":"bar"},"values":[[5,"1"],[25,"2"],[80,"3"],[94,"4"],[96,"5"]]}
]`),
actual: json.RawMessage(`[
{"metric":{"foo":"bar"},"values":[[5,"0"],[25,"2"],[80,"3"],[95, "4"]]}
]`),
skipSamplesBefore: time.Unix(10, 0),
skipRecentSamples: 10 * time.Second,
evaluationTime: time.Unix(100, 0),
},
{
name: "skip entire series",
expected: json.RawMessage(`[
{"metric":{"foo":"bar"},"values":[[50,"1"],[75,"2"]]},
{"metric":{"foo":"buzz"},"values":[[5,"1"],[9,"4"],[96,"5"]]}
]`), // skip comparing {"foo":"buzz"}
actual: json.RawMessage(`[
{"metric":{"foo":"bar"},"values":[[50,"1"],[75,"2"],[95,"3"]]}
]`),
skipSamplesBefore: time.Unix(10, 0),
skipRecentSamples: 10 * time.Second,
evaluationTime: time.Unix(100, 0),
},
} {
t.Run(tc.name, func(t *testing.T) {
_, err := compareMatrix(tc.expected, tc.actual, tc.evaluationTime, SampleComparisonOptions{
SkipSamplesBefore: tc.skipSamplesBefore,
SkipRecentSamples: tc.skipRecentSamples,
})

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most places we tend to find mistakes/bugs etc are off by one errors and boundaries.

Could you add tests for the exact handoff time (skipSamplesBefore: time.Unix(10,0) and then have a sample at exactly 10 to make sure it does what you expect it to do, same with the skipRecentSamples.

@ashwanthgoli ashwanthgoli force-pushed the querytee-skiprecent-improvements branch from 4e5a2d2 to efebcce Compare January 21, 2025 14:24
Copy link
Collaborator

@slim-bean slim-bean left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ashwanthgoli ashwanthgoli merged commit 1e8d8a9 into main Jan 22, 2025
59 checks passed
@ashwanthgoli ashwanthgoli deleted the querytee-skiprecent-improvements branch January 22, 2025 05:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants