fix(redis): poll FT.INFO to avoid flaky test_redis_query race condition#4767
Open
rajdhruvsingh wants to merge 2 commits into
Open
Conversation
9a47a6a to
98b5cba
Compare
FT.CREATE returns OK once the index is registered, but the backfill scan of pre-existing keys happens asynchronously. If FT.SEARCH is issued before the backfill completes, it intermittently returns total=0 instead of 1, causing test_redis_query to flake. Fix by polling FT.INFO after create_index() until indexing=0 and percent_indexed=1, with a 5s timeout. Fixes open-telemetry#4589
98b5cba to
4e1453c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #4589
FT.CREATEreturnsOKonce the index is registered, but the backfillscan of pre-existing keys happens asynchronously in the background.
In
TestRedisearchInstrument.setUp,prepare_data()writes a JSONdocument (
test:001) and thencreate_index()immediately creates anindex over the
test:prefix. Iftest_redis_queryissuesFT.SEARCHbefore the backfill completes, RediSearch returns
total=0instead of1, causing an intermittent assertion failure in CI.Fix by polling
FT.INFOaftercreate_index()returns untilindexing=0andpercent_indexed=1, with a 5s timeout and 50msinterval. On fast machines the poll exits on the first iteration with
zero overhead; on slower CI machines under load it waits as needed.
Type of change
How Has This Been Tested?
Ran
TestRedisearchInstrument::test_redis_queryin a 30-iterationloop locally against the
redis/redis-stack:7.2.0-v12Docker image(same image used in CI via
docker-compose.yml). All 30 runs passed.Also verified the poll logic by temporarily adding debug prints showing
indexingandpercent_indexedvalues fromFT.INFO— confirmed thefields are read correctly and the loop exits as expected.
To reproduce locally:
docker compose up -d otredis(fromtests/opentelemetry-docker-tests/tests/)pip install -e instrumentation/opentelemetry-instrumentation-redis/for i in $(seq 1 30); do python -m pytest tests/opentelemetry-docker-tests/tests/redis/test_redis_functional.py::TestRedisearchInstrument::test_redis_query -x -q; doneDoes This PR Require a Core Repo Change?
Checklist