Skip to content

[2.10] [MOD-12070] Extend indexing metrics (#7669)#7766

Merged
lerman25 merged 3 commits into2.10from
backport-7669-to-2.10
Dec 15, 2025
Merged

[2.10] [MOD-12070] Extend indexing metrics (#7669)#7766
lerman25 merged 3 commits into2.10from
backport-7669-to-2.10

Conversation

@lerman25
Copy link
Collaborator

@lerman25 lerman25 commented Dec 14, 2025

backport #7669 to 2.10


Note

Adds global counters for total documents indexed (overall and per field type) and surfaces them in INFO MODULES, updating indexing paths to maintain these stats with tests.

  • Metrics/Global Stats:
    • Add FieldsGlobalStats_UpdateFieldDocsIndexed and new counters in FieldsGlobalStats for per-field-type document indexing totals.
    • Increment counters on successful indexing in src/document.c (fulltextPreprocessor, IndexerBulkAdd).
  • Indexes Aggregation:
    • Aggregate total_num_docs_in_indexes across all specs in IndexesInfo_TotalInfo and expose in index stats.
  • INFO MODULES Output:
    • Expose total_indexing_ops_{text|tag|numeric|geo|geoshape|vector}_fields and total_num_docs_in_indexes in src/info/info_redis.c.
  • Headers/Plumbing:
    • Update headers (global_stats.h, indexes_info.h) and includes to support new metrics.
  • Tests:
    • Add SA tests validating total_num_docs_in_indexes and per-field total_indexing_ops_* counters, including multi-value JSON behavior.

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

* Total num indexed metric

* total docs indexed by field type

* test total indexed metic

* test field metric

* format tests

* remove empty line

* remove unecessary wait

* meirav comments

* more comments + change metric name

* expose and test geometry

* Unify metric

* test multi json

(cherry picked from commit b346977)
RSGlobalStats.fieldsStats.geometryTotalDocsIndexed += toAdd;
break;
}
}
Copy link

Choose a reason for hiding this comment

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

Bug: Global stats update is not thread-safe

FieldsGlobalStats_UpdateFieldDocsIndexed updates RSGlobalStats.fieldsStats.*TotalDocsIndexed with non-atomic writes based on an assumption that indexing runs only on the main thread / with the GIL. It’s invoked from fulltextPreprocessor, which is documented as running with the GIL released, so concurrent indexing can race and lose increments or cause undefined behavior.

Additional Locations (1)

Fix in Cursor Fix in Web

RSGlobalStats.fieldsStats.geometryTotalDocsIndexed += toAdd;
break;
}
}
Copy link

Choose a reason for hiding this comment

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

Bug: Multi-type fields never increment indexing counters

FieldsGlobalStats_UpdateFieldDocsIndexed uses switch (fs->types) as if fs->types is a single value, but it’s a bitmask and can represent multiple types (especially for FieldSpec_Dynamic). In those cases no case matches, so the new total_indexing_ops_* metrics silently stop counting for multi-type fields.

Additional Locations (1)

Fix in Cursor Fix in Web

// Since we are here, the indexing was successful, update the global statistics.
FieldsGlobalStats_UpdateFieldDocsIndexed(fs, 1);

return 0;
Copy link

Choose a reason for hiding this comment

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

Bug: Metrics counted even when add fails

fulltextPreprocessor increments FieldsGlobalStats_UpdateFieldDocsIndexed() before Document_AddToIndexes() knows the document was successfully committed (e.g., if Indexer_Add() fails later). This can permanently inflate total_indexing_ops_text_fields even though the document wasn’t actually indexed.

Fix in Cursor Fix in Web

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why didn't it bother him in the previous pr?

Copy link
Collaborator

Choose a reason for hiding this comment

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

and remind me why wasnt the metric placed here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note that text fields are returned immediately in Indexer_Add() -> IndexerProcess()
if (ACTX_IS_INDEXED(aCtx) || aCtx->stateFlags & (ACTX_F_ERRORED)) { // Document is complete or errored. No need for further processing. if (!(aCtx->stateFlags & ACTX_F_EMPTY)) { return; } }

RSGlobalStats.fieldsStats.geometryTotalDocsIndexed += toAdd;
break;
}
}
Copy link

Choose a reason for hiding this comment

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

Bug: Negative updates underflow size_t counters

The function documents that toAdd “can be negative”, but it adds int toAdd into size_t fields like RSGlobalStats.fieldsStats.textTotalDocsIndexed. Any negative call will wrap/underflow and massively corrupt the counters.

Fix in Cursor Fix in Web

Copy link
Collaborator

@meiravgri meiravgri left a comment

Choose a reason for hiding this comment

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

small comments referencing cursor's concerns

// Since we are here, the indexing was successful, update the global statistics.
FieldsGlobalStats_UpdateFieldDocsIndexed(fs, 1);

return 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why didn't it bother him in the previous pr?

// Since we are here, the indexing was successful, update the global statistics.
FieldsGlobalStats_UpdateFieldDocsIndexed(fs, 1);

return 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

and remind me why wasnt the metric placed here?

@lerman25 lerman25 enabled auto-merge December 14, 2025 13:06
@lerman25 lerman25 added this pull request to the merge queue Dec 14, 2025
@codecov
Copy link

codecov bot commented Dec 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.41%. Comparing base (816fbb3) to head (2204869).
⚠️ Report is 2 commits behind head on 2.10.

Additional details and impacted files
@@            Coverage Diff             @@
##             2.10    #7766      +/-   ##
==========================================
- Coverage   89.41%   89.41%   -0.01%     
==========================================
  Files         210      210              
  Lines       36138    36177      +39     
==========================================
+ Hits        32314    32346      +32     
- Misses       3824     3831       +7     
Flag Coverage Δ
flow 84.08% <100.00%> (-0.12%) ⬇️
unit 42.08% <48.71%> (+<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.

@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 14, 2025
@lerman25 lerman25 added this pull request to the merge queue Dec 15, 2025
Merged via the queue into 2.10 with commit 8ea201f Dec 15, 2025
17 checks passed
@lerman25 lerman25 deleted the backport-7669-to-2.10 branch December 15, 2025 09:14
redisearch-backport-pull-request bot pushed a commit that referenced this pull request Dec 15, 2025
* [MOD-12070] Extend indexing metrics (#7669)

* Total num indexed metric

* total docs indexed by field type

* test total indexed metic

* test field metric

* format tests

* remove empty line

* remove unecessary wait

* meirav comments

* more comments + change metric name

* expose and test geometry

* Unify metric

* test multi json

(cherry picked from commit b346977)

* remove no json

* remove total indexing time

(cherry picked from commit 8ea201f)
@redisearch-backport-pull-request
Copy link
Contributor

Successfully created backport PR for 2.8:

github-merge-queue bot pushed a commit that referenced this pull request Dec 15, 2025
[2.10] [MOD-12070] Extend indexing metrics (#7669) (#7766)

* [MOD-12070] Extend indexing metrics (#7669)

* Total num indexed metric

* total docs indexed by field type

* test total indexed metic

* test field metric

* format tests

* remove empty line

* remove unecessary wait

* meirav comments

* more comments + change metric name

* expose and test geometry

* Unify metric

* test multi json

(cherry picked from commit b346977)

* remove no json

* remove total indexing time

(cherry picked from commit 8ea201f)

Co-authored-by: lerman25 <[email protected]>
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