Skip to content

Commit

Permalink
adds support for getting health information about a Typesense node (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
runeanielsen authored Oct 23, 2023
1 parent 291febb commit 718f7ee
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/typesense/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
(let [query-parameter-map (merge common-search-params opt-query-params)]
(str uri "/multi_search" (util/map->url-parameter-string query-parameter-map))))

(defn- health-uri
([uri]
(str uri "/health")))

(defn create-collection-req
[{:keys [uri key]} schema]
{:uri (collection-uri uri)
Expand Down Expand Up @@ -236,3 +240,8 @@
[{:keys [uri key]} collection-name synonym-name]
{:uri (synonyms-uri uri collection-name synonym-name)
:req {:headers {api-key-header-name key}}})

(defn health-req
[{:keys [uri key]}]
{:uri (health-uri uri)
:req {:headers {api-key-header-name key}}})
7 changes: 7 additions & 0 deletions src/typesense/client.clj
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,10 @@
(try-typesense-api
(let [{:keys [uri req]} (api/delete-synonym-req settings collection-name synonym-name)]
(util/http-response-json->map (http/delete uri req)))))

(defn health
"Get health information about a Typesense node."
[settings]
(try-typesense-api
(let [{:keys [uri req]} (api/health-req settings)]
(util/http-response-json->map (http/get uri req)))))
7 changes: 7 additions & 0 deletions test/typesense/api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,10 @@
exp {:uri "http://localhost:8108/collections/products/synonyms/coat-synonyms"
:req {:headers {"X-TYPESENSE-API-KEY" "key"}}}]
(is (= exp req))))


(deftest health-test
(let [req (sut/health-req settings)
exp {:uri "http://localhost:8108/health"
:req {:headers {"X-TYPESENSE-API-KEY" "key"}}}]
(is (= exp req))))
6 changes: 5 additions & 1 deletion test/typesense/client_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -726,4 +726,8 @@
(let [id (-> (sut/list-api-keys settings) :keys first :id)
exp {:id id}
res (sut/delete-api-key! settings id)]
(is (= exp res)))))
(is (= exp res))))

(testing "Health"
(let [res (sut/health settings)]
(is (= res {:ok true})))))

0 comments on commit 718f7ee

Please sign in to comment.