From 6580a67f741fd88e20e257e6680962259b3113c3 Mon Sep 17 00:00:00 2001 From: Michal Zander Date: Mon, 23 Jun 2025 15:58:51 +0000 Subject: [PATCH 1/2] Add support for hivemind swagger --- caddy/Caddyfile | 2 +- hivemind.yaml | 3 ++- swagger.yaml | 3 ++- varnish/default.vcl | 22 ++++++++++++++++++++-- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/caddy/Caddyfile b/caddy/Caddyfile index b90646d..2dad1dd 100644 --- a/caddy/Caddyfile +++ b/caddy/Caddyfile @@ -141,7 +141,7 @@ } @rest_apis { - path /hafah-api/* /balance-api/* /reputation-api/* /hafbe-api/* /hivesense-api/* + path /hafah-api/* /balance-api/* /reputation-api/* /hafbe-api/* /hivesense-api/* /hivemind-api/* } handle @rest_apis { diff --git a/hivemind.yaml b/hivemind.yaml index ff26269..844c154 100644 --- a/hivemind.yaml +++ b/hivemind.yaml @@ -10,6 +10,7 @@ services: - "setup" - "--database-admin-url=postgresql://haf_admin@haf/haf_block_log" - "--statement-timeout=${HIVEMIND_STATEMENT_TIMEOUT:-5000}" + - "--swagger-url=${PUBLIC_HOSTNAME}" depends_on: haf: condition: service_healthy @@ -81,7 +82,7 @@ services: PGRST_DB_ANON_ROLE: hivemind_user PGRST_DB_POOL: 40 PGRST_DB_POOL_ACQUISITION_TIMEOUT: 10 - PGRST_OPENAPI_MODE: "disabled" # unclear why this is set, I guess because we currently only support json-rpc? + # PGRST_OPENAPI_MODE: "disabled" # unclear why this is set, I guess because we currently only support json-rpc? # when debugging, you can enable this # PGRST_DB_PLAN_ENABLED: true PGRST_LOG_LEVEL: ${HIVEMIND_SERVER_LOG_LEVEL:-error} diff --git a/swagger.yaml b/swagger.yaml index f520297..85a1f48 100644 --- a/swagger.yaml +++ b/swagger.yaml @@ -12,7 +12,8 @@ services: {url: "/balance-api/", name: "Balance Tracker"}, {url: "/reputation-api/", name: "Reputation Tracker"}, {url: "/hivesense-api/", name: "Hivesense"}, - {url: "/hafah-api/", name: "HAfAH"}] + {url: "/hafah-api/", name: "HAfAH"}, + {url: "/hivemind-api/", name: "Hivemind"}] networks: haf-network: #healthcheck: diff --git a/varnish/default.vcl b/varnish/default.vcl index fc18e09..7817687 100644 --- a/varnish/default.vcl +++ b/varnish/default.vcl @@ -46,6 +46,11 @@ backend hivesense { .port = "7011"; } +backend hivemind { + .host = "haproxy"; + .port = "7002"; +} + #backend hivesense_swagger { # .host = "hivesense-swagger"; # .port = "81"; @@ -122,6 +127,17 @@ sub vcl_recv { set req.url = regsub(req.url, "^/hivesense-api/(.*)$", "/\1"); set req.backend_hint = hivesense; + if (req.method == "POST") { + call recv_cachable_post; + } + } elseif (req.url == "/hivemind-api/") { + set req.url = "/"; + set req.backend_hint = hivemind; + } elseif (req.url ~ "^/hivemind-api/") { + # rewrite the URL to where PostgREST expects it + set req.url = regsub(req.url, "^/hivemind-api/(.*)$", "/\1"); + set req.backend_hint = hivemind; + if (req.method == "POST") { call recv_cachable_post; } @@ -139,7 +155,7 @@ sub vcl_backend_fetch { } sub vcl_backend_response { - if (bereq.backend == hafah || bereq.backend == balance_tracker || bereq.backend == reputation_tracker || bereq.backend == haf_block_explorer || bereq.backend == hivemind_rtracker || bereq.backend == hivesense) { + if (bereq.backend == hafah || bereq.backend == balance_tracker || bereq.backend == reputation_tracker || bereq.backend == haf_block_explorer || bereq.backend == hivemind_rtracker || bereq.backend == hivesense || bereq.backend == hivemind) { # PostgREST generates invalid content-range headers, and varnish will refuse to cache/proxy calls because of it. # Until they fix it, just remove the header. (see https://github.com/PostgREST/postgrest/issues/1089) unset beresp.http.Content-Range; @@ -171,7 +187,9 @@ sub vcl_hash { } else if (req.backend_hint == haf_block_explorer) { hash_data("hafbe-api"); } else if (req.backend_hint == hivesense) { - hash_data("hivesense-api"); + hash_data("hivesense-api"); + } else if (req.backend_hint == hivemind) { + hash_data("hivemind-api"); } # To cache POST and PUT requests -- GitLab From 531e493aa9739cafaf4d6e7a2a7574028b50763b Mon Sep 17 00:00:00 2001 From: SynaptiCAD User Date: Thu, 31 Jul 2025 00:04:00 +0000 Subject: [PATCH 2/2] add dependency so hivemind installs after hafah --- hafah.yaml | 1 + hivemind.yaml | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/hafah.yaml b/hafah.yaml index 1dd6347..75fc138 100644 --- a/hafah.yaml +++ b/hafah.yaml @@ -6,6 +6,7 @@ services: - hafah - hafbe - haf-block-explorer-drop-db + - hivemind environment: POSTGRES_URL: postgresql://haf_admin@haf/haf_block_log command: diff --git a/hivemind.yaml b/hivemind.yaml index 844c154..02b7984 100644 --- a/hivemind.yaml +++ b/hivemind.yaml @@ -14,6 +14,8 @@ services: depends_on: haf: condition: service_healthy + hafah-install: + condition: service_completed_successfully reputation-tracker-install: condition: service_completed_successfully @@ -46,8 +48,6 @@ services: depends_on: haf: condition: service_healthy - reputation-tracker-install: - condition: service_completed_successfully hivemind-install: condition: service_completed_successfully -- GitLab