From 5cadb773bfcb1af2d7aaee7d92cfdf64a9b8499f Mon Sep 17 00:00:00 2001 From: wmousa Date: Tue, 1 Sep 2026 23:44:16 +0200 Subject: [PATCH 1/3] fix(monitoring): thanos-query must discover all sidecars, not one MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit prometheus, thanos-sidecar and thanos-store are all `mode: global`, so a 3-manager swarm runs three of each. thanos-query was pointed at them by bare service name: --store=thanos-store:10901 --store=thanos-sidecar:10901 so it saw exactly one of each. Its own startup log shows it, printing one line each instead of three: msg="adding new store with [storeEndpoints]" address=thanos-store:10901 msg="adding new sidecar with [storeEndpoints…]" address=thanos-sidecar:10901 Two separate prefixes are needed to fix it: * `dns+` makes Thanos treat the address as a DNS-discovered set and re-resolve it periodically, rather than as one static endpoint. * `tasks.` is required because these services use the default VIP endpoint mode, where the bare service name resolves to a single *virtual* IP. `dns+` alone would therefore still resolve to exactly one endpoint and fix nothing -- the routing mesh simply pins Thanos's long-lived gRPC connection to whichever task it first hit. `tasks.` returns every task's real IP; prometheus.yml.j2 already uses this idiom for tasks.node-exporter. Why this caused "no data" alerts: the most recent ~2h of samples exist only in each Prometheus's local TSDB and are served solely by *its own* sidecar; only older blocks reach the object store. Grafana alert rules evaluate recent data, so every evaluation depended on the single pinned sidecar. When that sidecar was slow the query came back EMPTY rather than failing -- presenting as `noDataState: NoData` (empty result set) instead of `execErrState: Error` -- and the alert self-cleared once it responded. Seen on a customer cluster as recurring "no data" alerts whose underlying Prometheus data was complete and healthy throughout (scrape_samples_scraped a continuous 3.65k-5.15k, count(lvol_status_code) a steady 90-140, never absent), alongside: "update of endpoint failed" err="getting metadata: fallback fetching info from thanos-sidecar:10901: rpc error: code = DeadlineExceeded" Note this is only reproducible with 2+ manager nodes; on a single-manager swarm there is one sidecar and the bug is invisible by construction. Unrelated to the /cluster/metrics series leak fixed in #1281 -- a read-path defect present since the monitoring stack was written. Same bug on main and R26.3. --- .../docker-compose-swarm-monitoring.yml | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/simplyblock_core/scripts/docker-compose-swarm-monitoring.yml b/simplyblock_core/scripts/docker-compose-swarm-monitoring.yml index 7042386440..e147e19fd9 100755 --- a/simplyblock_core/scripts/docker-compose-swarm-monitoring.yml +++ b/simplyblock_core/scripts/docker-compose-swarm-monitoring.yml @@ -134,8 +134,37 @@ services: command: - query - --http-address=0.0.0.0:9091 - - --store=thanos-store:10901 - - --store=thanos-sidecar:10901 + # Both prefixes are load-bearing. prometheus/thanos-sidecar/thanos-store + # are all `mode: global`, so a 3-manager swarm runs three of each. + # + # * `dns+` makes Thanos treat the address as a DNS-discovered SET and + # re-resolve it periodically. Without it the address is ONE static + # endpoint. + # * `tasks.` is the Swarm DNS name that returns every task's real IP. + # These services use the default VIP endpoint mode, so the bare + # service name resolves to a single *virtual* IP -- meaning `dns+` + # alone still yields exactly one endpoint and changes nothing, with + # the routing mesh pinning Thanos's long-lived gRPC connection to + # whichever task it first landed on. prometheus.yml.j2 already uses + # this idiom for tasks.node-exporter. + # + # Thanos's startup log shows the broken state directly, printing one + # "adding new sidecar" line instead of three. + # + # Why it caused "no data": the most recent ~2h of samples live only in + # each Prometheus's local TSDB and are served solely by *its own* + # sidecar; only older blocks reach the object store. Grafana alert rules + # evaluate recent data, so every evaluation depended on that one pinned + # sidecar. When it was slow the query returned an EMPTY result rather + # than an error -- surfacing as `noDataState: NoData`, not + # `execErrState: Error` -- and self-cleared once it answered again: + # "update of endpoint failed" err="getting metadata: fallback fetching + # info from thanos-sidecar:10901: rpc error: code = DeadlineExceeded" + # + # `--store` is v0.31's deprecated alias for `--endpoint`; left as-is to + # keep the diff to what actually fixes the fault. + - --store=dns+tasks.thanos-store:10901 + - --store=dns+tasks.thanos-sidecar:10901 deploy: mode: global placement: From ad00191ad8abc4a03fca504eae9bbdffffbf203d Mon Sep 17 00:00:00 2001 From: wmousa Date: Tue, 1 Sep 2026 23:45:28 +0200 Subject: [PATCH 2/3] fix(monitoring): give each Prometheus a replica label so Thanos can dedup All three Prometheus replicas shared one hardcoded external label set: external_labels: monitor: 'codelab-monitor' so every replica emitted series with byte-identical identity ({job, instance, monitor}). Two consequences: * thanos-query had nothing to deduplicate on, so a query merged three independent series claiming the same identity whose samples were taken at different seconds (observed: one replica scraping at :02, another at :56). The result is one interleaved, non-monotonic stream rather than a clean series -- unstable between evaluations for an alert rule using a `last` reducer over a short window. * all three sidecars uploaded blocks carrying identical external labels into the same bucket. Thanos treats those as overlapping and the compactor halts by default, consistent with a compactor that had done essentially nothing (18 MiB RSS, 0% CPU, 200 kB total network). Thanos identifies HA replicas by a label that differs per replica and drops it when deduplicating, so: * prometheus.yml.j2 gains `replica: '${REPLICA}'`; * prometheus gains --enable-feature=expand-external-labels, which expands ${REPLICA} from the environment. The indirection is required because prometheus.yml is bind-mounted -- every replica reads identical bytes and cannot self-identify from file content; * the compose sets REPLICA per task from the swarm node-hostname template; * thanos-query gains --query.replica-label=replica; * thanos-compactor gains --deduplication.replica-label=replica so it vertically compacts the overlap instead of halting on it. Note for anyone editing prometheus.yml.j2: it is Jinja-rendered before deployment, so a swarm template written literally with double braces in that file is evaluated as a Jinja expression and breaks rendering. The swarm template therefore lives in the compose file and the placeholder here is the shell-style ${REPLICA}. Verified: the template renders under Jinja with ${REPLICA} intact and basic_auth substitution unaffected, and the compose parses with the expected flags on all four services. --- .../scripts/docker-compose-swarm-monitoring.yml | 16 ++++++++++++++++ simplyblock_core/scripts/prometheus.yml.j2 | 17 +++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/simplyblock_core/scripts/docker-compose-swarm-monitoring.yml b/simplyblock_core/scripts/docker-compose-swarm-monitoring.yml index e147e19fd9..58c37f8529 100755 --- a/simplyblock_core/scripts/docker-compose-swarm-monitoring.yml +++ b/simplyblock_core/scripts/docker-compose-swarm-monitoring.yml @@ -87,6 +87,14 @@ services: - "--storage.tsdb.retention.time=${RETENTION_PERIOD}" - "--storage.tsdb.min-block-duration=2h" - "--storage.tsdb.max-block-duration=2h" + # Expands ${REPLICA} in prometheus.yml's external_labels from the env + # below. Required because prometheus.yml is bind-mounted: every replica + # reads identical bytes and cannot self-identify from file content. + - "--enable-feature=expand-external-labels" + environment: + # Swarm service template, evaluated per task, so each replica gets a + # distinct value -- this is what makes Thanos deduplication possible. + - "REPLICA={{.Node.Hostname}}" restart: "always" deploy: mode: global @@ -165,6 +173,10 @@ services: # keep the diff to what actually fixes the fault. - --store=dns+tasks.thanos-store:10901 - --store=dns+tasks.thanos-sidecar:10901 + # Drop the `replica` external label when merging series from the three + # Prometheus replicas, so a query yields one series instead of three + # same-identity ones with interleaved samples. + - --query.replica-label=replica deploy: mode: global placement: @@ -182,6 +194,10 @@ services: - --retention.resolution-5m=60d - --retention.resolution-1h=90d - --compact.concurrency=1 + # Vertically compact the replicas' overlapping blocks instead of halting + # on them, which is what a bucket fed by identically-labelled sidecars + # produces. + - --deduplication.replica-label=replica - --wait volumes: - ./objstore.yml:/etc/thanos/objstore.yml diff --git a/simplyblock_core/scripts/prometheus.yml.j2 b/simplyblock_core/scripts/prometheus.yml.j2 index 043f83669a..9981591018 100644 --- a/simplyblock_core/scripts/prometheus.yml.j2 +++ b/simplyblock_core/scripts/prometheus.yml.j2 @@ -2,6 +2,23 @@ global: scrape_interval: 60s external_labels: monitor: 'codelab-monitor' + # Thanos identifies an HA Prometheus group by a label that DIFFERS per + # replica, and drops it when deduplicating. Without one, all three + # replicas emit series with byte-identical identity ({job, instance, + # monitor}), so thanos-query has nothing to dedup on and all three + # sidecars upload blocks with identical external labels into the same + # bucket -- which the compactor treats as overlapping and halts on. + # + # This file is bind-mounted, so every replica reads the SAME bytes and the + # value cannot come from file content. ${REPLICA} is expanded from the + # environment by Prometheus (--enable-feature=expand-external-labels); the + # compose sets REPLICA per task from the swarm node-hostname template. + # + # Careful: this file is rendered by Jinja before deployment, so a swarm + # template written literally with double braces here would be evaluated as + # a Jinja expression and break rendering. Hence the shell-style ${REPLICA} + # placeholder, with the swarm template kept in the compose file. + replica: '${REPLICA}' scrape_configs: From d7f39437a682c27d5216a7ffa55c021d672d8211 Mon Sep 17 00:00:00 2001 From: wmousa Date: Tue, 1 Sep 2026 23:45:51 +0200 Subject: [PATCH 3/3] fix(monitoring): run a single thanos-compactor, not one per manager thanos-compactor was `mode: global`, so a 3-manager swarm ran three compactors against the same object-storage bucket. Thanos requires exactly one compactor per bucket; concurrent compactors rewriting the same blocks is a documented data-corruption risk, and with halt-on-overlap the three also contend for the same work. More pressing after the previous commit: with --deduplication.replica-label set the compactor performs vertical compaction of the replicas' overlapping blocks, so three racing on the same blocks is precisely the case Thanos warns about. thanos-store and thanos-query stay `mode: global` -- both read-only and safe to scale; only the compactor must be a singleton. --- .../scripts/docker-compose-swarm-monitoring.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/simplyblock_core/scripts/docker-compose-swarm-monitoring.yml b/simplyblock_core/scripts/docker-compose-swarm-monitoring.yml index 58c37f8529..5985dececd 100755 --- a/simplyblock_core/scripts/docker-compose-swarm-monitoring.yml +++ b/simplyblock_core/scripts/docker-compose-swarm-monitoring.yml @@ -203,7 +203,14 @@ services: - ./objstore.yml:/etc/thanos/objstore.yml - thanos_compactor_data:/data deploy: - mode: global + # Thanos requires a SINGLE compactor per bucket. `mode: global` ran one + # per manager -- three concurrent compactors rewriting the same blocks, + # which Thanos documents as a data-corruption risk. It matters more now + # that --deduplication.replica-label makes them perform vertical + # compaction. Store and query stay global (read-only, safe to scale); + # only the compactor is a singleton. + mode: replicated + replicas: 1 placement: constraints: [node.role == manager] networks: