Skip to content

Timx 638 publish index doc count metric to cloudwatch#393

Merged
jonavellecuerdo merged 1 commit into
mainfrom
TIMX-638-publish-index-doc-count-metric-to-cloudwatch
Jul 16, 2026
Merged

Timx 638 publish index doc count metric to cloudwatch#393
jonavellecuerdo merged 1 commit into
mainfrom
TIMX-638-publish-index-doc-count-metric-to-cloudwatch

Conversation

@jonavellecuerdo

@jonavellecuerdo jonavellecuerdo commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Purpose and background context

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.

At high-level, here are the key changes to review:

How can a reviewer manually see the effects of these changes?

image

Access the view above by visiting CloudWatch Metrics in Dev1.

  1. On the right menu bar, select Metrics -> Classic Metrics (guess it recently updated 👀 )
  2. Select Timdex namespace.
  3. Select index dimension.
  4. From the list of indexes, select the primary indexes for each source (i.e., what's shown in the screenshot)
  5. On the top-left corner, you can choose how to view the metrics--Data table was 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

  • Code review best practices are documented here and you are encouraged to have a constructive dialogue with your reviewers about their preferences and expectations.

@jonavellecuerdo
jonavellecuerdo force-pushed the TIMX-638-publish-index-doc-count-metric-to-cloudwatch branch 2 times, most recently from 863fb9a to 8ddf5d3 Compare July 16, 2026 17:47
@jonavellecuerdo
jonavellecuerdo requested a review from ehanson8 July 16, 2026 18:00
@jonavellecuerdo
jonavellecuerdo marked this pull request as ready for review July 16, 2026 18:00
@jonavellecuerdo
jonavellecuerdo requested a review from a team as a code owner July 16, 2026 18:00
@ehanson8
ehanson8 requested a review from Copilot July 16, 2026 18:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 via tim.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 in BulkActionError messages; 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.

Comment thread tim/cli.py
Comment thread tim/cli.py
Comment thread tim/cli.py
Comment thread tests/test_opensearch.py Outdated
jonavellecuerdo added a commit that referenced this pull request Jul 16, 2026
@jonavellecuerdo
jonavellecuerdo requested a review from JPrevost July 16, 2026 18:57

@ehanson8 ehanson8 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me and it's obviously publishing metrics in Dev1, great work! 2 optional suggestions

Comment thread tim/utils/aws/cloudwatch_metrics.py
Comment thread tim/cli.py Outdated
Comment thread tim/cli.py
Comment thread tim/errors.py
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
jonavellecuerdo force-pushed the TIMX-638-publish-index-doc-count-metric-to-cloudwatch branch from 4893ecc to d959a4c Compare July 16, 2026 20:12
@jonavellecuerdo
jonavellecuerdo merged commit 95449e4 into main Jul 16, 2026
5 checks passed
@jonavellecuerdo
jonavellecuerdo deleted the TIMX-638-publish-index-doc-count-metric-to-cloudwatch branch July 16, 2026 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants