QdrantSearch: Add health checks.

This commit is contained in:
Lain Soykaf 2024-05-27 14:21:55 +04:00
parent ec3f3fef77
commit f4c04e6b2d
3 changed files with 23 additions and 4 deletions

View File

@ -919,6 +919,9 @@ config :pleroma, Pleroma.Search.QdrantSearch,
qdrant_url: "http://127.0.0.1:6333/", qdrant_url: "http://127.0.0.1:6333/",
qdrant_api_key: "", qdrant_api_key: "",
openai_url: "http://127.0.0.1:11345", openai_url: "http://127.0.0.1:11345",
# The healthcheck url has to be set to nil when used with the real openai
# API, as it doesn't have a healthcheck endpoint.
openai_healthcheck_url: "http://127.0.0.1:11345/health",
openai_model: "snowflake/snowflake-arctic-embed-xs", openai_model: "snowflake/snowflake-arctic-embed-xs",
openai_api_key: "", openai_api_key: "",
qdrant_index_configuration: %{ qdrant_index_configuration: %{

View File

@ -148,7 +148,9 @@ defmodule Pleroma.Search.QdrantSearch do
|> Map.put(:path, "/healthz") |> Map.put(:path, "/healthz")
|> URI.to_string() |> URI.to_string()
[qdrant_health] openai_health = Config.get([Pleroma.Search.QdrantSearch, :openai_healthcheck_url])
[qdrant_health, openai_health] |> Enum.filter(& &1)
end end
end end

View File

@ -16,15 +16,29 @@ defmodule Pleroma.Search.QdrantSearchTest do
describe "Qdrant search" do describe "Qdrant search" do
test "returns the correct healthcheck endpoints" do test "returns the correct healthcheck endpoints" do
# No openai healthcheck URL
Config Config
|> expect(:get, 1, fn |> expect(:get, 2, fn
[Pleroma.Search.QdrantSearch, key], nil -> [Pleroma.Search.QdrantSearch, key], nil ->
%{qdrant_url: "https://qdrant.url"}[key] %{qdrant_url: "https://qdrant.url"}[key]
end) end)
health_endpoints = QdrantSearch.healthcheck_endpoints() [health_endpoint] = QdrantSearch.healthcheck_endpoints()
assert "https://qdrant.url/healthz" in health_endpoints assert "https://qdrant.url/healthz" == health_endpoint
# Set openai healthcheck URL
Config
|> expect(:get, 2, fn
[Pleroma.Search.QdrantSearch, key], nil ->
%{qdrant_url: "https://qdrant.url", openai_healthcheck_url: "https://openai.url/health"}[
key
]
end)
[_, health_endpoint] = QdrantSearch.healthcheck_endpoints()
assert "https://openai.url/health" == health_endpoint
end end
test "searches for a term by encoding it and sending it to qdrant" do test "searches for a term by encoding it and sending it to qdrant" do