Skip to content

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
    • Index existence is now validated as part of resharding operations, preventing attempts to operate on missing indexes and reducing failed jobs.
    • Error messages for missing indexes now include the Elasticsearch cluster name, giving clearer context in 404 responses and simplifying troubleshooting.

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

@coderabbitai
Copy link

coderabbitai bot commented Jan 15, 2026

📝 Walkthrough

Walkthrough

The resharding API now validates that the Elasticsearch index or alias exists before starting resharding. A new private function obtains an ES connection and checks index existence, returning a not-found service error that includes the Elasticsearch cluster name when the index is missing.

Changes

Cohort / File(s) Summary
Resharding API Implementation
bootstrap-app/src/cmr/bootstrap/api/resharding.clj
Adds es-helper and es-index requires; adds validate-index-exists (uses es-index/context->conn and es-helper/exists?); calls validation at start of start flow; minor require reflow
Integration Test
system-int-test/test/cmr/system_int_test/bootstrap/reshard_index_test.clj
Updates test expectation for the "index must exist" case to include Elasticsearch cluster name in the 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)
    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: connection + 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

  • eereiter
  • daniel-zamora
  • ygliuvt

Poem

🐰 I checked the index before the hop,
No missing shards to make me stop,
With a hop and a sniff and a careful cheer,
The cluster's named — the path is clear! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: adding index existence validation to the reshard API.
Description check ✅ Passed The description covers the objective, changes, and impacted areas with reasonable completeness, though some optional checklist items are unchecked.
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 29.13%. Comparing base (1f955f4) to head (cfc07e4).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
bootstrap-app/src/cmr/bootstrap/api/resharding.clj 12.50% 7 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (1f955f4) and HEAD (cfc07e4). Click for more details.

HEAD has 8 uploads less than BASE
Flag BASE (1f955f4) HEAD (cfc07e4)
12 4
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #2372       +/-   ##
===========================================
- Coverage   58.01%   29.13%   -28.88%     
===========================================
  Files        1063     1003       -60     
  Lines       72765    69349     -3416     
  Branches     2113     1196      -917     
===========================================
- Hits        42215    20207    -22008     
- Misses      28580    48007    +19427     
+ Partials     1970     1135      -835     

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

6 participants