Timx 638 publish index doc count metric to cloudwatch#393
Merged
jonavellecuerdo merged 1 commit intoJul 16, 2026
Merged
Conversation
jonavellecuerdo
force-pushed
the
TIMX-638-publish-index-doc-count-metric-to-cloudwatch
branch
2 times, most recently
from
July 16, 2026 17:47
863fb9a to
8ddf5d3
Compare
jonavellecuerdo
marked this pull request as ready for review
July 16, 2026 18:00
There was a problem hiding this comment.
Pull request overview
This PR adds CloudWatch metric publishing to track OpenSearch index document counts after bulk-update and reindex-source CLI runs, and extends the existing retry decorator to support retrying until a returned-value condition is met.
Changes:
- Introduces a small CloudWatch metrics utility (
CloudWatchMetricsClient,Metric) and exports it viatim.utils.aws. - Adds
helpers.retry(..., until_condition=...)support and uses it when querying index doc counts for metric publication. - Adds OpenSearch helpers (
get_index_doc_count,refresh_index) and includes status codes inBulkActionErrormessages; updates tests accordingly.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tim/utils/aws/cloudwatch_metrics.py | Adds CloudWatch metric publishing client + Metric dataclass. |
| tim/utils/aws/init.py | Exposes CloudWatch metrics utilities from the aws utils package. |
| tim/utils/init.py | Adds utils package initializer. |
| tim/opensearch.py | Adds index doc count + refresh helpers; includes status in raised bulk errors. |
| tim/helpers.py | Extends retry decorator with optional until_condition. |
| tim/errors.py | Updates BulkActionError to include HTTP status in the exception message. |
| tim/cli.py | Publishes “Index Doc Count” metric after bulk-update and reindex-source. |
| tests/test_opensearch.py | Updates tests around bulk ops (adds patching blocks). |
| tests/test_helpers.py | Adjusts retry tests (removes a freeze_time decorator). |
| tests/test_cli.py | Patches metric publishing in CLI tests; updates BulkActionError construction. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
jonavellecuerdo
added a commit
that referenced
this pull request
Jul 16, 2026
ehanson8
approved these changes
Jul 16, 2026
ehanson8
left a comment
Contributor
There was a problem hiding this comment.
Looks good to me and it's obviously publishing metrics in Dev1, great work! 2 optional suggestions
Why these changes are being introduced: * When the `bulk-update` or `reindex-source` CLI commands are executed, we want to understand the result of performed bulk actions on a given OpenSearch index. Publishing a metric (e.g., number of documents in an index) to CloudWatch will allow us to monitor the health of our OpenSearch indexes over time. How this addresses that need: * Add `CloudWatchMetricsClient` util * Add `until_condition` to retry decorator * TIM `bulk-update` and `reindex-source` CLI commands publish index doc counts Side effects of this change: * This may increase the duration of our TIM runs. Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/TIMX-638
jonavellecuerdo
force-pushed
the
TIMX-638-publish-index-doc-count-metric-to-cloudwatch
branch
from
July 16, 2026 20:12
4893ecc to
d959a4c
Compare
jonavellecuerdo
deleted the
TIMX-638-publish-index-doc-count-metric-to-cloudwatch
branch
July 16, 2026 20:16
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.
Purpose and background context
When the
bulk-updateorreindex-sourceCLI commands are executed, we want to understand the result of performed bulk actions on a given OpenSearch index. Publishing a metric (e.g., number of documents in an index) to CloudWatch will allow us to monitor the health of our OpenSearch indexes over time.At high-level, here are the key changes to review:
MetricsClientfrom DSC. This simplification is in congruence with our simple use case of CloudWatch metrics for TIM: we are only publishing a single metric to CloudWatch towards the end of abulk-updateorreindex-sourceCLI command execution.until_conditionuntil_conditionis provided and the decorated function returned a value (i.e.,get_index_doc_count()), the method will now also check if the provided condition is met; otherwise, retry until timeout, unexpected error or condition is met.bulk-updateCLI command publishes an 'Index Doc Count' metricget_index_doc_count()method is wrapped in a retry without anuntil_condition. At this point, no bulk actions have been performed so we can expect count to be accurate.until_conditionso that the retry will query counts until it is equal toinitial count - deleted countreindex-sourceCLI command publishes an 'Index Doc Count' metricreindex-sourcecreates a whole new index, theuntil_conditionfor the retry is to confirm that thecount == created countHow can a reviewer manually see the effects of these changes?
Access the view above by visiting CloudWatch Metrics in Dev1.
Metrics -> Classic Metrics(guess it recently updated 👀 )Timdexnamespace.indexdimension.Data tablewas selected for the screenshot above.It is likely we will have more ideas on how best to organize these metrics (i.e., add new "dimensions"), but this is a start! :)
Includes new or updated dependencies?
NO
Changes expectations for external applications?
YES-ish: This may increase the duration of our TIM runs.
What are the relevant tickets?
Code review