Skip to content

Remove relative date in IndicesRequestCacheIT#20920

Merged
andrross merged 1 commit intoopensearch-project:mainfrom
andrross:IndicesRequestCacheIT-now
Mar 19, 2026
Merged

Remove relative date in IndicesRequestCacheIT#20920
andrross merged 1 commit intoopensearch-project:mainfrom
andrross:IndicesRequestCacheIT-now

Conversation

@andrross
Copy link
Member

The dates in the test are starting to fall out of the now-10y window. It should be fine to use a fixed date for the 'from' since the 'to' uses now.

Check List

  • Functionality includes testing.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@andrross andrross requested a review from a team as a code owner March 19, 2026 03:36
@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2026

PR Reviewer Guide 🔍

(Review updated until commit 29a5e3a)

Here are some key observations to aid the review process:

🧪 PR contains tests
🔒 No security concerns identified
✅ No TODO sections
🔀 No multiple PR themes
⚡ Recommended focus areas for review

Test Semantics

The replacement of now-10y with 2016-01-01 changes the nature of the test. The original intent was to use a relative date expression containing now to verify caching behavior. With a fixed date 2016-01-01, the range addRange("2016-01-01", "now") still contains now at the end, so the non-caching behavior for r5 should still hold. However, it's worth verifying that the fixed start date 2016-01-01 still correctly covers the test data (indexed around 2016-03-20 to 2016-03-26) and that the expected hit counts remain valid.

    .addAggregation(dateRange("foo").field("s").addRange("2016-01-01", "now"))
    .get();
OpenSearchAssertions.assertAllSuccessful(r5);
assertThat(r5.getHits().getTotalHits().value(), equalTo(7L));
assertCacheState(client, index, 0, 0);

// If size > 1 and cache flag is set on the request we should cache
final SearchResponse r6 = client.prepareSearch(index)
    .setSearchType(SearchType.QUERY_THEN_FETCH)
    .setSize(1)
    .setRequestCache(true)
    .setQuery(QueryBuilders.rangeQuery("s").gte("2016-03-21").lte("2016-03-27"))
    .get();
OpenSearchAssertions.assertAllSuccessful(r6);
assertThat(r6.getHits().getTotalHits().value(), equalTo(7L));
assertCacheState(client, index, 0, 2);

// If the request has a filter aggregation containing now we should cache since it gets rewritten
final SearchResponse r4 = client.prepareSearch(index)
    .setSearchType(SearchType.QUERY_THEN_FETCH)
    .setSize(0)
    .setRequestCache(true)
    .setQuery(QueryBuilders.rangeQuery("s").gte("2016-03-20").lte("2016-03-26"))
    .addAggregation(filter("foo", QueryBuilders.rangeQuery("s").from("2016-01-01").to("now")))

@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2026

PR Code Suggestions ✨

Latest suggestions up to 29a5e3a
Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Replace remaining relative date with absolute date

The test comment says "non-filter aggregation containing now we should not cache",
but the range still contains "now" as the upper bound. If the intent is to remove
relative dates to avoid flakiness, both bounds should be absolute dates. Using "now"
still introduces a relative date that could cause the test to behave differently
over time.

server/src/internalClusterTest/java/org/opensearch/indices/IndicesRequestCacheIT.java [555]

-.addAggregation(dateRange("foo").field("s").addRange("2016-01-01", "now"))
+.addAggregation(dateRange("foo").field("s").addRange("2016-01-01", "2016-03-27"))
Suggestion importance[1-10]: 5

__

Why: The suggestion raises a valid concern about using "now" in the test, but the test comment explicitly states "non-filter aggregation containing now we should not cache" - meaning the presence of "now" is intentional to test that behavior. The PR changed from "now-10y" to "2016-01-01" for the lower bound while keeping "now" to maintain the test's purpose of verifying that "now" prevents caching.

Low

Previous suggestions

Suggestions up to commit 14d37cd
CategorySuggestion                                                                                                                                    Impact
Possible issue
Replace remaining relative date with absolute date

The test comment says "non-filter aggregation containing now we should not cache",
but the range still ends with "now" which is a relative date. If the intent is to
remove relative dates entirely, both bounds should be absolute dates. If "now" is
intentionally kept to trigger the no-cache behavior, the comment and the symmetry
with the other fix should be reconsidered.

server/src/internalClusterTest/java/org/opensearch/indices/IndicesRequestCacheIT.java [555]

-.addAggregation(dateRange("foo").field("s").addRange("2016-01-01", "now"))
+.addAggregation(dateRange("foo").field("s").addRange("2016-01-01", "2016-03-26"))
Suggestion importance[1-10]: 3

__

Why: The suggestion raises a valid point about consistency, but the test comment explicitly states "non-filter aggregation containing now we should not cache" - keeping "now" in the range is intentional to trigger the no-cache behavior. Replacing it with an absolute date would change the test's purpose and potentially break the test logic.

Low

@github-actions
Copy link
Contributor

❌ Gradle check result for 14d37cd: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

The dates in the test are starting to fall out of the now-10y window. It
should be fine to use a fixed date for the 'from' since the 'to' uses
now.

Signed-off-by: Andrew Ross <andrross@amazon.com>
@andrross andrross force-pushed the IndicesRequestCacheIT-now branch from 14d37cd to 29a5e3a Compare March 19, 2026 06:06
@github-actions
Copy link
Contributor

Persistent review updated to latest commit 29a5e3a

@github-actions
Copy link
Contributor

❌ Gradle check result for 29a5e3a: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@kkewwei
Copy link
Contributor

kkewwei commented Mar 19, 2026

LGTM.

After analysis, the root cause is as follows:

  • Previously, the time range now-10y ~ now had an INTERSECTS relation with the data set (originally WITHIN). After the rewrite, from-to becomes null, so the second time parsing is skipped and the query should be cacheable = true.

  • However, since the relation between now-10y ~ now and the data set is still INTERSECTS, parseSource will rewrite the dynamic time now again, which results in cacheable = false.

@github-actions
Copy link
Contributor

✅ Gradle check result for 29a5e3a: SUCCESS

@codecov
Copy link

codecov bot commented Mar 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.21%. Comparing base (9f5d0e1) to head (29a5e3a).
⚠️ Report is 15 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main   #20920      +/-   ##
============================================
- Coverage     73.30%   73.21%   -0.10%     
+ Complexity    72484    72477       -7     
============================================
  Files          5819     5819              
  Lines        331155   331237      +82     
  Branches      47840    47860      +20     
============================================
- Hits         242769   242531     -238     
- Misses        68876    69227     +351     
+ Partials      19510    19479      -31     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@andrross andrross merged commit bbb28cd into opensearch-project:main Mar 19, 2026
40 of 48 checks passed
@andrross andrross deleted the IndicesRequestCacheIT-now branch March 19, 2026 16:26
kkewwei pushed a commit to kkewwei/OpenSearch that referenced this pull request Mar 20, 2026
The dates in the test are starting to fall out of the now-10y window. It
should be fine to use a fixed date for the 'from' since the 'to' uses
now.

Signed-off-by: Andrew Ross <andrross@amazon.com>
Signed-off-by: kkewwei <kkewwei@163.com>
@cwperks
Copy link
Member

cwperks commented Mar 20, 2026

How many other ticking time bombs do we have in the core or any other repo?

Speaking for security, I know we have some demo certs that expire in the future but for the most part the repo will generate certs on the fly for testing.

@cwperks cwperks added the backport 3.5 Backport to 3.5 branch label Mar 21, 2026
opensearch-trigger-bot bot pushed a commit that referenced this pull request Mar 21, 2026
The dates in the test are starting to fall out of the now-10y window. It
should be fine to use a fixed date for the 'from' since the 'to' uses
now.

Signed-off-by: Andrew Ross <andrross@amazon.com>
(cherry picked from commit bbb28cd)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
reta pushed a commit that referenced this pull request Mar 21, 2026
The dates in the test are starting to fall out of the now-10y window. It
should be fine to use a fixed date for the 'from' since the 'to' uses
now.

Signed-off-by: Andrew Ross <andrross@amazon.com>
(cherry picked from commit bbb28cd)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
cwperks pushed a commit that referenced this pull request Mar 21, 2026
The dates in the test are starting to fall out of the now-10y window. It
should be fine to use a fixed date for the 'from' since the 'to' uses
now.


(cherry picked from commit bbb28cd)

Signed-off-by: Andrew Ross <andrross@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 3.5 Backport to 3.5 branch skip-changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants