Skip to content

CMR-11039: reshard API validates that index exists#2372

Merged
zimzoom merged 2 commits intomasterfrom
CMR-11039
Jan 21, 2026
Merged

CMR-11039: reshard API validates that index exists#2372
zimzoom merged 2 commits intomasterfrom
CMR-11039

Conversation

@zimzoom
Copy link
Contributor

@zimzoom zimzoom commented Jan 15, 2026

Overview

What is the objective?

Fix bug that allows calling the start reshard endpoint on an index that no longer exists.

What are the changes?

Added new validation step for checking existence of index/alias earlier in flow, at the API receiving function where it was already doing other validation.

What areas of the application does this impact?

bootstrap-app

Required Checklist

  • [x ] New and existing unit and int tests pass locally and remotely
  • [x ] clj-kondo has been run locally and all errors in changed files are corrected
  • I have commented my code, particularly in hard-to-understand areas
  • I have made changes to the documentation (if necessary)
  • [x ] My changes generate no new warnings

Additional Checklist

  • [x ] I have removed unnecessary/dead code and imports in files I have changed
  • I have cleaned up integration tests by doing one or more of the following:
    • migrated any are2 tests to are3 in files I have changed
    • de-duped, consolidated, removed dead int tests
    • transformed applicable int tests into unit tests
    • reduced number of system state resets by updating fixtures. Ex) (use-fixtures :each (ingest/reset-fixture {})) to be :once instead of :each

Summary by CodeRabbit

  • Bug Fixes
    • Resharding now validates that target indexes exist before proceeding, reducing failed operations on missing indexes.
    • Error responses for missing indexes now include the Elasticsearch cluster name for clearer context in 404 messages.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 15, 2026

📝 Walkthrough

Walkthrough

Validates that the target Elasticsearch index or alias exists before starting resharding by adding a private validate-index-exists that obtains an ES connection and checks existence, and calling it early in the start flow; test expectations updated to include the ES cluster name in the error message.

Changes

Cohort / File(s) Summary
Resharding API implementation
bootstrap-app/src/cmr/bootstrap/api/resharding.clj
Added es-helper and es-index requires; introduced private validate-index-exists (uses es-index/context->conn and es-helper/exists?); call inserted into start flow; minor require reflow.
Integration test
system-int-test/test/cmr/system_int_test/bootstrap/reshard_index_test.clj
Updated test expectation for "index must exist" to include Elasticsearch cluster name in the 404 error message.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client
    participant API as Resharding API
    participant ESIdx as es-index (conn)
    participant ES as Elasticsearch
    Client->>API: POST /reshard/start (index, es-cluster-name)
    API->>API: validate-index-exists(context, index, es-cluster-name)
    API->>ESIdx: context->conn(context, es-cluster-name)
    ESIdx->>ES: exists?(index or alias)
    ES-->>ESIdx: exists? result (true/false)
    ESIdx-->>API: exists? result
    alt index exists
        API->>API: proceed with existing validations and start resharding
        API-->>Client: 200 Started
    else index missing
        API-->>Client: 404 "Index or alias [name] does not exist in the Elasticsearch cluster [cluster-name]"
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

hacktoberfest-accepted

Suggested reviewers

  • jceaser
  • eereiter

Poem

🐰 I sniffed the index, hopped to see,
If shards were safe for resharding spree.
I checked the cluster, called its name,
Now onward bounds the resharding game! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding validation that the index exists to the reshard API.
Description check ✅ Passed The PR description covers the objective and changes clearly. However, code comments section is unchecked and documentation changes are unchecked, indicating some required checklist items may not be fully addressed.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@jceaser jceaser self-requested a review January 15, 2026 21:26
(when (string/blank? es-cluster-name)
(errors/throw-service-error :bad-request "Empty elastic cluster name is not allowed.")))

(defn- validate-index-exists
Copy link
Contributor

Choose a reason for hiding this comment

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

doc string

[context index es-cluster-name]
(let [conn (es-index/context->conn context es-cluster-name)]
(when-not (or (es-helper/exists? conn index)
(es-helper/alias-exists? conn index))
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not think we allow resharding based on alias names. Can you check this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, I tested it and it does not allow aliases, it returns index doesn't exist error. I will remove the alias check to avoid confusion

@codecov-commenter
Copy link

codecov-commenter commented Jan 16, 2026

Codecov Report

❌ Patch coverage is 12.50000% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.01%. Comparing base (57b33e0) to head (6a19745).

Files with missing lines Patch % Lines
bootstrap-app/src/cmr/bootstrap/api/resharding.clj 12.50% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2372      +/-   ##
==========================================
- Coverage   58.02%   58.01%   -0.02%     
==========================================
  Files        1064     1064              
  Lines       72827    72835       +8     
  Branches     2115     2112       -3     
==========================================
- Hits        42258    42255       -3     
- Misses      28601    28610       +9     
- Partials     1968     1970       +2     

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

5 participants