Skip to content

Commit

Permalink
Enable same indexname for different target cluster (#1434)
Browse files Browse the repository at this point in the history
Ops uses the migration task to migrate to the new cluster, but they would like to preserve the same indices name.
This PR relaxes the migration params check constraints.
  • Loading branch information
ereteog committed Jul 1, 2024
1 parent 04fc99b commit e4c0e06
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
19 changes: 13 additions & 6 deletions src/ctia/task/migration/migrate_es_stores.clj
Original file line number Diff line number Diff line change
Expand Up @@ -284,19 +284,26 @@
[{:keys [prefix
restart?
store-keys
migrations]} :- mst/MigrationParams
migrations
store] :as params} :- mst/MigrationParams
get-in-config]
(when-not restart?
(assert prefix "Please provide an indexname prefix for target store creation")
(assert (seq store-keys) "Please provide the store-keys for source store to migrate")
(assert (seq migrations) "Please provide the migrations' ids to apply"))
(doseq [store-key store-keys]
(let [index (get-in-config [:ctia :store :es store-key :indexname])]
(when (= (mst/prefixed-index index prefix)
index)
(let [origin-store (get-in-config [:ctia :store :es store-key])
target-store (get-in store [:es store-key])
origin-indexname (:indexname origin-store)]
(when (and (= (mst/prefixed-index origin-indexname prefix)
origin-indexname)
(nil? (:host target-store))
(nil? (:indexname target-store)))
(throw (AssertionError.
(format "the source and target indices are identical: %s. The migration was misconfigured."
index))))))
(format "The migration setup is misconfigured.\nThe source and target indices are identical: %s\n%s\n."
(pr-str params)
(pr-str origin-store)
(pr-str target-store)))))))
true)

(s/defn prepare-params :- mst/MigrationParams
Expand Down
23 changes: 16 additions & 7 deletions test/ctia/task/migration/migrate_es_stores_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,7 @@
(with-each-fixtures #(-> %
(assoc-in [:ctia :store :es :investigation :indexname]
investigation-indexname)
(assoc-in [:malware 0 :state :props]
{:indexname malware-indexname
:auth {:type "basic"
:params {:user "basic"
:pwd "ductile"}}}))
(assoc-in [:malware 0 :state :props :indexname] malware-indexname))
app
(let [{:keys [get-in-config]} (helpers/get-service-map app :ConfigService)]
(let [v (get-in-config [:ctia :store :es :investigation :indexname])]
Expand All @@ -183,12 +179,25 @@
:migrations
conj
:bad-migration-id)
get-in-config))))))
get-in-config)))))))
(testing "properly configured migration"
(with-each-fixtures identity app
(let [{:keys [get-in-config]} (helpers/get-service-map app :ConfigService)]
(is (sut/check-migration-params migration-params
get-in-config))))))))
get-in-config)))))

(testing "different target cluster same indexname"
(let [malware-indexname (str "v1.2.0_ctia_malware" (UUID/randomUUID))
malware-target-store {:host "another-host-cluster"
:auth {:type :basic-auth
:params {:user "basic"
:pwd "ductile"}}}]
(with-each-fixtures #(assoc-in % [:ctia :store :es :malware :indexname] malware-indexname)
app
(let [{:keys [get-in-config]} (helpers/get-service-map app :ConfigService)]
(is (sut/check-migration-params (assoc (assoc migration-params :store-keys [:malware])
:store {:es {:malware malware-target-store}})
get-in-config))))))))

(deftest prepare-params-test
(let [migration-props {:buffer-size 3,
Expand Down

0 comments on commit e4c0e06

Please sign in to comment.