Skip to content

[8.2] [MOD-12694] [MOD-12069] Add active_worker_threads metric#7564

Merged
redisearch-backport-pull-request[bot] merged 7 commits into8.2from
backport-7538-to-8.2
Dec 1, 2025
Merged

[8.2] [MOD-12694] [MOD-12069] Add active_worker_threads metric#7564
redisearch-backport-pull-request[bot] merged 7 commits into8.2from
backport-7538-to-8.2

Conversation

@redisearch-backport-pull-request
Copy link
Contributor

@redisearch-backport-pull-request redisearch-backport-pull-request bot commented Nov 27, 2025

Description

Backport of #7538 to 8.2.


Note

Adds active_worker_threads to multi-threading stats and INFO output, sourcing from the workers thread pool, with supporting API and tests.

  • Metrics/Info:
    • Add active_worker_threads to MultiThreadingStats and export it in INFO MODULES under search_multi_threading.
    • Compute via workersThreadPool_WorkingThreadCount() in GlobalStats_GetMultiThreadingStats(); assert pool exists.
  • Workers API:
    • Add workersThreadPool_isCreated() in util/workers.{h,c}.
  • Code Touches:
    • Include util/workers.h in src/info/global_stats.c.
  • Tests:
    • Add helper call_and_store in tests/pytests/common.py.
    • New tests validating search_active_worker_threads in standalone and cluster (test_active_worker_threads_SA, test_active_worker_threads_cluster).

Written by Cursor Bugbot for commit eb09a94. This will update automatically on new commits. Configure here.

* add "active_worker_threads" metric

* fix declartion

* remove coord threads

* make the tests run...

* introduce workersThreadPool_isInitialized
assert is initizlied in GlobalStats_GetMultiThreadingStats

* cleanup

* rename workersThreadPool_isCreated

* Unskip test_active_io_threads_stats

Removed skip decorator from test_active_io_threads_stats.

(cherry picked from commit d9574d8)
MultiThreadingStats stats;
stats.active_io_threads = READ(RSGlobalStats.totalStats.multi_threading.active_io_threads);
RS_ASSERT(workersThreadPool_isCreated()); // In production workers threadpool is created at startup.
stats.active_worker_threads = workersThreadPool_WorkingThreadCount();
Copy link

Choose a reason for hiding this comment

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

Bug: RS_ASSERT is NOP in production causing potential NULL dereference

The RS_ASSERT(workersThreadPool_isCreated()) call provides no protection in production builds because RS_ASSERT is defined as a no-op when ENABLE_ASSERT is not defined. If _workers_thpool is NULL when workersThreadPool_WorkingThreadCount() is called, redisearch_thpool_num_jobs_in_progress will dereference a NULL pointer and crash. Other functions in workers.c like workersThreadPool_getStats() use proper null checks with fallback values rather than relying on assertions.

Fix in Cursor Fix in Web

meiravgri
meiravgri previously approved these changes Nov 28, 2025
@meiravgri meiravgri requested a review from JoanFM November 28, 2025 05:41
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Removed function still referenced in test file

The countFlatElements function was removed from common.py but is still being used in tests/pytests/test_debug_commands.py (lines 1367-1368). The test file imports from common import *, so when those tests execute, they will fail with a NameError because countFlatElements no longer exists. This appears to be an incomplete cleanup where the function was removed without updating all references.

tests/pytests/common.py#L139-L140

def assertInfoField(env, idx, field, expected, delta=None):

Fix in Cursor Fix in Web


@codecov
Copy link

codecov bot commented Dec 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.48%. Comparing base (e2b405d) to head (eb09a94).
⚠️ Report is 2 commits behind head on 8.2.

Additional details and impacted files
@@            Coverage Diff             @@
##              8.2    #7564      +/-   ##
==========================================
- Coverage   89.54%   89.48%   -0.06%     
==========================================
  Files         253      253              
  Lines       41197    41202       +5     
  Branches     3725     3725              
==========================================
- Hits        36889    36870      -19     
- Misses       4259     4283      +24     
  Partials       49       49              
Flag Coverage Δ
flow 82.31% <100.00%> (-0.55%) ⬇️
unit 47.46% <80.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

import signal
import platform
import itertools
import threading
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do we need this import?

Copy link
Collaborator

Choose a reason for hiding this comment

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

it is used in test_info_modules for the bg queries
i include it here to align with master and avoid future conflicts

@redisearch-backport-pull-request redisearch-backport-pull-request bot added this pull request to the merge queue Dec 1, 2025
Merged via the queue into 8.2 with commit e77dda8 Dec 1, 2025
23 checks passed
@redisearch-backport-pull-request redisearch-backport-pull-request bot deleted the backport-7538-to-8.2 branch December 1, 2025 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants