Repository navigation
add support for oss cluster - #37
YaacovHazan wants to merge 1 commit into
Conversation
new 'oss_client' client add to support oss cluster. the new client use CLUSTER_SLOTS command to retrive the key-->node mapping, create separate connection fot each node, and send the commands to the appropriate connection according to hash calculation.
| } | ||
| } | ||
|
|
||
| void shard_connection::setup_connection(int conn_id, oss_client* parent_client, abstract_protocol* abs_protocol) { |
There was a problem hiding this comment.
There is quite a lot of duplicate code between oss_client.c and client.c, I think it should be avoided.
| @@ -0,0 +1,79 @@ | |||
| // | |||
There was a problem hiding this comment.
Standard header is missing
| { | ||
| bool sent = false; | ||
|
|
||
| if (m_config->authenticate && m_authentication != auth_done) { |
There was a problem hiding this comment.
Unless I'm missing something here, the authentication and DB selection are always done on the main connection and never on the other connections.
In fact, the authentication and selected DB state belong to the shard connection rather than the client.
| port[mbulk_port_el->value_len] = '\0'; | ||
|
|
||
| // if it is the main connection, no need to add connection, just update range | ||
| if (strcmp(addr, m_config->server) == 0) { |
There was a problem hiding this comment.
There could be a few shards on the same server, you need to compare ports as well.
|
|
||
| benchmark_debug_log("WAIT num_slaves=%u timeout=%u\n", num_slaves, timeout); | ||
|
|
||
| // currently wait commands goes to main connection |
There was a problem hiding this comment.
Why only to the main connection? It means it's only effective for 1/N shards.
| conn->setup_events(m_event_base); | ||
|
|
||
| // call connect | ||
| if (::connect(conn->sockfd, |
There was a problem hiding this comment.
Again, low level networking code duplication should be avoided.
| } | ||
| } | ||
| // are we set or get? this depends on the ratio | ||
| else if (m_set_ratio_count < m_config->ratio.a) { |
There was a problem hiding this comment.
Once again, a huge part of this is duplicated with client.c with no apparent reason. It would make sense to pack it in a class hierarchy to share all identical behavior between the Redis Cluster and Standard Redis clients.
PR #432 added gap-mask SSL_OP_NO_TLSv1_x #ifdef blocks so the build works on OpenSSL 4.0 (where those constants are slated for removal). But a user passing a non-contiguous bitmask (e.g. tlsv1,tlsv1.2) on OpenSSL 4.0 would silently get the intermediate version enabled inside the envelope, with no warning. Adds parser-time validation: on OpenSSL >= 4.0 a non-contiguous bitmask is rejected at startup with an actionable error. On OpenSSL <= 3.x the gap-mask logic still enforces the user's selection. Refs: 2.4 review #37 (Review 14 + PR #432 review R4). Co-authored-by: Claude Sonnet 4.6 <[email protected]>
* feat(prom): add prometheus_metrics (POD, accumulator, renderer, bucket parser) + unit harness
Add the pure, config-free, libevent-free metrics layer of the Prometheus
exporter (PLAN.md v5 sections 3.1/3.3/3.5/3.7/4/5):
- prometheus_metrics.{h,cpp}: mt_counter enum, counter_set, metrics_snapshot
POD, monotonic_accumulator (base + per-thread last-seen fold, fold_final,
fill), prom::text_renderer (exposition, escaping, slot-edge-quantized HDR
bucket walk, %.12g le format with the division-form losslessness invariant),
parse_latency_buckets (1-64 tokens, hard cap 86400 s, slot-collision reject,
W2/W2b warn zones), validate_prom_label_name. The metric inventory lives in a
single kMetricDefs[] table. Honors the Decisions #52 purity contract (no
config.h/version.h/libevent; build_info via ctor string args) and mirrors the
run_stats SEC HDR triplet via PROM_HDR_* (Decisions #22).
- tests/unit/prometheus_metrics_test.cpp: unit tests U1-U8 (assert-style main,
no gtest), incl. the U2 clamp replica pinned to run_stats.cpp:46-47.
- Makefile.am: add the sources row (unconditional, not under HAVE_EVHTTP) and a
check_PROGRAMS/TESTS harness wired into make check.
Dead code; zero behavior change.
Co-Authored-By: Claude Fable 5 <[email protected]>
* test(statsd): pin per-metric wire value formats and hard-fail silent skips
Extend tests/test_statsd.py per PLAN §10 "StatsD wire pins" / Decisions #46
so a StatsD wire regression is RED instead of silently green:
- Add module-level per-metric value-format regexes (VALUE_FORMAT_RES):
INT_G ("%ld"|g), F6_G ("%.6f"|g), F3_MS ("%.3f"|ms), plus the
latency_p* class. progress_pct is pinned F6_G_OR_ZERO because the run-end
zeroing block emits it via gauge((long) 0) -> ":0|g". An unknown metric
name now FAILS (a renamed/new metric must update the pins).
- Convert the two post-run _skip() sites in test_statsd_metrics_emitted and
test_statsd_prefix_and_label (memtier exited non-zero / no datagrams) into
hard assertTrue(False) failures: these tests pass --statsd-host over
loopback with --test-time=3 (>=2 ticks), so silence IS the regression.
Soft skips kept where statsd was not requested (pre-bind, 8125-busy,
env-gated graphite).
Green against the unmodified master binary (4/4 PASS): the pins describe
today's wire before the A1.2b refactor.
Co-Authored-By: Claude Fable 5 <[email protected]>
* refactor(stats): statsd tick consumes the one-producer metrics_snapshot
Extract the 1 Hz StatsD emit block out of run_benchmark()'s progress loop
into a file-static statsd_publish_tick() that consumes a metrics_snapshot
(the one-producer POD from prometheus_metrics.h), per PLAN section 3.6c /
Decisions #37. This is the single producer the Prometheus transport will
later share; this commit is statsd-ONLY (no cfg->prometheus references, no
Prometheus wiring, no behavior change) and lives OUTSIDE any HAVE_EVHTTP
guard.
Byte-identical UDP wire is preserved: the gauge(double):92 vs gauge(long):97
overload selection is unchanged because the snapshot carries cur/avg ops/bytes
as long (cast at the fill site) -> gauge(long) "%ld"|g, progress_pct as
double -> gauge(double) "%.6f"|g, latencies via timing(double) "%.3f"|ms,
and the connection_errors >0 send condition is kept. The run-end zeroing
block, the run-start/end events, and the inst_hist_agg/realtime aggregation
(:3052-3066) are untouched. Snapshot read sites and benign-race discipline
match the inline block.
Verified: A1.2a's value-format-sensitive gate 4/4 PASS pre and post; wire
capture shows the identical metric set and printf shapes; make check +
make format-check green; test_realtime_latencies.py 3/3 PASS (shared inst
histogram path unchanged); grep-audit: gauge/timing only in
statsd_publish_tick + run-end zeroing, event exactly two sites, zero
prometheus references.
Co-Authored-By: Claude Fable 5 <[email protected]>
* feat(prom): configure gate, Makefile glue, bytes-split getters, TSan suppressions, harness override
Co-Authored-By: Claude Fable 5 <[email protected]>
* feat(prom): add prometheus_exporter (listener thread, hardening, render TTL, stop-event teardown)
Co-Authored-By: Claude Fable 5 <[email protected]>
* feat(prom): CLI flags, validation, usage, config dump
Add the four Prometheus exporter flags (PLAN.md v5 section 5), guarded by
HAVE_EVHTTP, parse-and-validate only (no exporter creation yet):
--prometheus-port absent = disabled; 0 = ephemeral; sentinel -1
--prometheus-bind-addr numeric IPv4/IPv6 only; localhost/hostnames
rejected; [::1] stripped in place
--prometheus-run-label repeatable KEY=VALUE; validated, dup/16-cap
--prometheus-latency-buckets parsed via prom::parse_latency_buckets
Wires every CLI touch point: anonymous enum, long_options[], case handlers
(port via the statsd strtoul pattern with range check before narrowing,
bind-addr bracket-strip + inet_pton, run-label via validate_prom_label_name,
buckets via parse_latency_buckets), config_init_defaults (127.0.0.1),
usage(), config_print() (prints prometheus-port = -1 when disabled),
config_print_to_json() (run-labels JSON-escaped; no secrets), the four
benchmark_config members, the prometheus_port sentinel init in main(),
the post-parse dependency check (E12) + one-shot non-loopback warning (W1)
via addr_is_loopback(), and the --version prometheus=yes/no token.
Canonical error strings E1-E12 and warning W1 pinned verbatim. Adds
explicit <arpa/inet.h>/<netinet/in.h> includes (previously only transitive).
Both configure flavors build; make check + make format-check green.
Co-Authored-By: Claude Fable 5 <[email protected]>
* feat(prom): wire exporter into main(), producer tick, --version token
Make the Prometheus exporter reachable for the first time (PLAN.md v5
sections 3.2, 3.6 a/b/d/e, 3.7), guarded by HAVE_EVHTTP:
- g_prom_exporter ownership handle next to g_threads; cfg.prometheus alias.
- Creation in main() after the statsd init block, after
evthread_use_pthreads() and config_init_defaults(): build options from
cfg, new prometheus_exporter, start() or exit(1) (deliberate leak,
LSan-reachable). Only when --prometheus-port was given.
- Producer wiring via a file-static prom_* helper island above
run_benchmark() (prom_observe_and_fill / prom_fold_thread /
prom_publish_tick / prom_publish_run_start/_end) with empty #else stubs
so the run loop stays ifdef-free. prom_publish_tick resets the scratch
tick histogram, runs the gated aggregate_inst_histogram_if_changed walk
over non-finished threads, fills the full snapshot (counters via the
rx/tx + ops/hits/misses/errors getters through the monotonic
accumulator), and publishes. Wired into the shared 1 Hz tick next to
statsd_publish_tick, run-start after the statsd start event, restart
fold between join() and restart(), and post-join reconcile + run-end
publish before the client_group deletion loop.
- Join point before the TLS cleanup: stop_and_join(); delete; NULL — the
first runtime exercise of the stop-event teardown (verified no hang,
clean rc 0, port released).
- --version token: prometheus=yes (HAVE_EVHTTP) / prometheus=no.
- --test-time threaded into memtier_config_test_time_seconds via a new
snapshot.test_time field stamped once in publish() from options.test_time
(single chokepoint; no fill-site or renderer-ctor churn).
Live smoke: /metrics serves 200 with Content-Type text/plain; version=0.0.4,
ops_total monotonic across scrapes, build_info / latency histogram / run
labels present, non-GET -> 501, /metrics/ -> 404, no secrets in the body,
clean process exit. StatsD test 4/4 PASS (no shared-producer regression).
Co-Authored-By: Claude Fable 5 <[email protected]>
* test(prom): CLI validation suite (ports, bind-addr, run-label, buckets)
Add tests/test_cli_validation_prometheus.py implementing V1-V19 from the
Prometheus-exporter plan (PLAN.md section 10): every --prometheus-* reject
case with its pinned exit code and canonical E1-E12 / W1 / W2 / W2b message,
every accept/warn-accept case, the bind-collision exit(1) path (no sanitizer
output), --show-config / mb.json config-dump pins, and the LSan
exit(1)-after-creation leak case. Mirrors test_cli_validation_read_preference
structure; drives MEMTIER_BINARY (prom flavor) and the optional
MEMTIER_NOPROM_BINARY for the compiled-out V16 case.
Co-Authored-By: Claude Fable 5 <[email protected]>
* test(prom): CLI-fuzz corpus entries for prometheus flags
Seed the Hypothesis CLI fuzzer (tests/cli_fuzz.py) with the four
--prometheus-* flags after --graphite-port: --prometheus-port gets the
weird-int corpus, the other three get the free-form string corpus. Their
parsers (inet_pton bind-addr, KEY=VALUE run-label validation, latency-bucket
list parsing) must reject malformed input cleanly and never crash. Verified
green at MEMTIER_FUZZ_MAX_EXAMPLES=100.
Co-Authored-By: Claude Fable 5 <[email protected]>
* docs(prom): man page + bash-completion for prometheus flags
Add the four --prometheus-* flags to bash-completion's options_no_comp list
(all take arguments) on the statsd/graphite continuation line, and regenerate
memtier_benchmark.1 via `make rebuild-man` (help2man harvests usage()). The
man-page regeneration also picks up other usage() flags whose stanzas had
drifted since the page was last generated, plus the prometheus=yes --version
token in the .TH header -- all faithful output of the repo's man mechanism.
Co-Authored-By: Claude Fable 5 <[email protected]>
* chore(prom): gitignore unit-test harness check artifacts
Co-Authored-By: Claude Fable 5 <[email protected]>
* test(prom): scrape helpers in tests/include.py
Add the shared exporter scrape utilities the functional suite (F1-F20) and
redaction suite build on, per PLAN.md §8/§10:
* PROM_LISTEN_RE -- captures the one-line stdout announce URL (IPv6 host
kept bracketed, RFC 3986).
* PROM_CONTENT_TYPE -- the byte-exact text/plain;version=0.0.4 pin.
* wait_for_prometheus_url -- poll a Popen stdout file for the announce line.
* prom_scrape -- HTTP GET (or arbitrary method) returning a PromScrape;
HTTP >=400 unwrapped to a real status, connection-level
failure reported as status=None (the F15 closed-outcome
"process beat the scrape to teardown" branch).
* prom_parse -- parse exposition via prometheus_client's official
parser into {sample_name: [Sample, ...]}.
* prom_sample_value -- first sample value by name + optional label subset.
Co-Authored-By: Claude Fable 5 <[email protected]>
* test(prom): functional exporter suite (scrape, counters, histogram, teardown)
F1-F20 + F15b against the RLTest harness via --prometheus-port=0 stdout
discovery: disabled-by-default, mid-run scrape shape, counter/histogram
monotonicity, run-fold accumulator, redaction, fixed-port announce,
run-label propagation, TTL clamp, hardening (501/404/oversize-header),
clean shutdown + port re-bind, teardown race window (F15/F15b stop-event
protocol), IPv6, connection-churn monotonicity, cluster smoke, stall
dedup (F19, Decisions #54), and the in-flight-cap 503 seam (F20).
F19 trailing-window freeze detection fixed: anchor to the most recent
sample >=1.8 s old (a trailing window) instead of the oldest qualifying
sample, which forever compared the live value against the pre-stall value
and never matched. The stall is a genuine DEBUG SLEEP on a dedicated
redis-py connection; the gate still proves _count stays flat while frozen.
Co-Authored-By: Claude Fable 5 <[email protected]>
* test(prom): /metrics redaction (no secrets, TLS paths)
Dedicated redaction suite (PLAN.md §6, the #440 precedent; modeled on
test_tls_logging.py::test_tls_paths_redacted_in_json). R1 sets a
requirepass canary on the target, runs an authenticated benchmark, and
asserts the live /metrics body contains none of: the password canary, a
server/host/addr/target identity label, the target host/port in an
identity context, any '/'-rooted path-like label value, nor (under TLS
cells) the --cert/--key/--cacert absolute paths or their basenames. R2
asserts the 404 body is the fixed string "not found\n" and never echoes
the requested URI. Runs under both plaintext and TLS (after
./tests/gen-test-certs.sh); 2/2 green in each flavor.
Co-Authored-By: Claude Fable 5 <[email protected]>
* ci(prom): sanitizer cells, promtool job, prometheus_client dep
PLAN.md §7.4:
- §7.4d: append test_prometheus.py to the standalone (misc) and cluster-TLS
(misc) sanitizer cells in asan.yml/tsan.yml (so F15/F15b teardown runs
under ASan/TSan -- the hang guard), test_prometheus_redaction.py to the
standalone (misc) cells, and test_cli_validation_prometheus.py to the
(cli) cells (runs V19 under detect_leaks=1).
- §7.4e: new self-contained promtool-lint job -- build default-on, scrape a
live /metrics, install promtool from the sha256-pinned
prometheus-2.53.2.linux-amd64.tar.gz, and fail on rc != 0 or ANY output;
uploads the scraped exposition as an artifact.
- §7.4a: complete build-notls -- assert the prometheus=yes/=no --version
token in each flavor and that --prometheus-port is rejected (rc 2 +
"unrecognized option") in the --disable-prometheus build (deferred by A1.3).
- tests/test_requirements.txt: add prometheus_client>=0.20 (the exposition
parser behind the functional + redaction suites).
CI-config-only: actionlint/pyyaml are unavailable locally, so the workflow
YAML is structurally hand-verified (indentation, no tabs) but not lint-run;
the test_requirements.txt change is locally exercised by the green suites.
Co-Authored-By: Claude Fable 5 <[email protected]>
* docs(prom): README, REALTIME_METRICS, DEVELOPMENT
- README.md: new "Prometheus /metrics exporter" subsection under Real-Time
Metrics -- enablement via --prometheus-port, ephemeral-port announce, the
four flags, exported families, and the no-identity-leak guarantee.
- docs/REALTIME_METRICS.md: full Prometheus section -- options, ephemeral-port
contract (stdout announce, IPv6 bracketing, GET-only/501/404/Content-Type),
metric mapping vs StatsD, the error model (phase-dependent ~50% capture,
stall dedup + residuals, run-tail loss, <=1% HDR quantization; end-of-run
output is authoritative), the threat model, and --cluster-mode /
--verify-only / --unix-socket interaction statements.
- DEVELOPMENT.md: raise the libevent prerequisite to 2.1.1 (evhttp floor) with
the --disable-prometheus escape, add the disable bullet, and a new
"### Prometheus exporter build flavor" section (default-on configure, the
evhttp >= 2.1.1 LINK test + loud failure, --version prometheus=yes/no token,
unit harness under both flavors).
Co-Authored-By: Claude Fable 5 <[email protected]>
* test(prom): run_local_gate.sh + make gate target
tests/run_local_gate.sh implements the consolidated local gate (PLAN.md §11),
S0-S10: prereqs + test venv, srcdir hygiene, sibling-VPATH both-flavor builds,
format-check, flavor asserts (prometheus=yes/no token, compiled-out flag
rejection), unit harness x2, the RLTest CLI/functional/redaction/statsd/
realtime/cluster suites (+ TLS redaction when certs present), the live HTTP
smoke (hardening, render-cache TTL, run-boundary monotonicity, verify-only
teardown loop), error paths + IPv6 + the in-flight-cap 503 seam, the ASan and
TSan cells, and the docs/completion/fuzz/purity grep audits. Adds the `gate`
Makefile target and the `make gate` paragraph to the DEVELOPMENT.md exporter
section (S10 staleness greps require the token).
Deviations from the §11 listing, both justified: (1) the Content-Type check
reads headers via `curl -fsS -D -` (a GET) instead of `curl -fsSI` (a HEAD) --
the exporter is GET-only and answers HEAD with 501 (hardening, F11), so -fsSI
fails spuriously; (2) the gate reuses an existing venv (.venv or .venv-tests)
carrying RLTest + prometheus_client rather than creating a fresh one, because
this host's python cannot bootstrap pip (no ensurepip); pip install runs only
when pip is present. The docker-promtool fallback degrades to warn+skip if the
pinned prom/prometheus image is unavailable offline.
Ran `make gate` end-to-end: GATE PASS (exit 0). All suites green
(19/21/2/4/3/21/2 targeted + 304/304 full-suite fuzz), ASan + TSan clean
(zero sanitizer reports), docker-promtool lint clean on the captured scrape.
Co-Authored-By: Claude Fable 5 <[email protected]>
* test(prom): TLS connection args and cluster-wide auth for CI cells
The functional and redaction suites only ran green locally in plaintext
standalone. CI exercises TLS and OSS-cluster variants where:
- the live memtier run and F19's DEBUG SLEEP client must speak TLS when the
env is TLS (server resets plaintext connections otherwise);
- requirepass must be set/cleared on every master node in a cluster, or
memtier restart-loops against shards that still reject AUTH and never exits.
Also convert a proc.wait timeout into a clean assertion instead of an
unhandled exception. Validated locally: test_prometheus 21/21 and redaction
2/2 across TLS-standalone, plaintext-cluster, and TLS-cluster.
Co-Authored-By: Claude Fable 5 <[email protected]>
* test(prom): tolerate sanitizer slowness in F15b verify wait
Under TSan/ASan builds (~5-10x slower) the 300k-key --verify-only run in
F15b does not finish within the 30s proc.wait deadline, so wait() raised an
unhandled TimeoutExpired. The zero-snapshot assertions (the test's purpose)
already passed by then. Use a generous 180s wait, tolerate a slow tail
(finally: _kill reaps the process), and raise the preload timeout to 300s.
Co-Authored-By: Claude Fable 5 <[email protected]>
* test(prom): generous exit-wait timeouts for sanitizer + cluster-TLS
F11/F15/F20 waited for a --test-time run to exit with timeouts (10-30s)
tuned for normal builds. Under sanitizer + OSS-cluster + TLS, startup
(cluster discovery, per-shard TLS handshakes) and teardown push total
runtime well past those, raising unhandled TimeoutExpired. Use 120s waits
that fail cleanly on a true hang. Validated under TLS-cluster locally.
Co-Authored-By: Claude Fable 5 <[email protected]>
* test(prom): trim exporter test durations; raise full-suite CI timeout
The functional suite added ~2 min to the serial full-suite Test cells
(Single Endpoint / OSS), tipping them past the 15-min step budget even
though every test passed. Trim gratuitously long --test-time runs (F2/F3/
F9/F17/F18) and F19's stall window, and cut F15's teardown iterations
20->8. Per-test redis env spin-up dominates the rest, so also raise the
matrix and coverage 'Run tests' step timeout 15->25 min (the suite grew
with a real feature; per-test timeouts still bound genuine hangs).
Co-Authored-By: Claude Fable 5 <[email protected]>
* fix(prom): render integer-valued gauges exactly, not via %.6g
memtier_connections/threads/run/configured_runs/config_test_time_seconds
are integer counts but were formatted with %.6g, which switches to
scientific notation past 6 significant digits (e.g. a large clients x
threads connection count would render as 1.23457e+06, losing fidelity).
Render them with integer formats. Prometheus parsed the floats fine, so
this is exposition-cleanliness, not a scrape correctness fix.
Co-Authored-By: Claude Fable 5 <[email protected]>
* fix(prom): report 0 active threads at run-end, not configured count
publish_run_end runs after the run's worker threads have joined, but set
memtier_threads to the configured --threads, so a scrape between runs
(--run-count > 1) showed every worker as active when none were. Report 0
active threads at run-end, consistent with the (already 0) connections
gauge. Addresses Cursor Bugbot review on PR #468.
Co-Authored-By: Claude Fable 5 <[email protected]>
* test(prom): tsan-suppress benign libevent fd-reuse race in exporter thread
Under TSan, the exporter's dedicated libevent event_base (epoll) thread races
with the main thread creating benchmark sockets (shard_connection::setup_socket
-> socket()) on a reused file-descriptor *number* — a known TSan fd-shadow
limitation, not a real race (independent kernel objects; epoll_ctl/socket are
kernel-thread-safe; the exporter never touches benchmark connection fds). This
surfaced as a ThreadSanitizer warning in memtier output that test_prometheus's
_no_sanitizer_output guard correctly flagged. Suppress via the exporter thread
frame, consistent with the existing libcrypto/stats-getter suppressions and the
design's proactive-suppression decision. TSAN_OPTIONS in tsan.yml passes this to
the memtier subprocess.
Co-Authored-By: Claude Fable 5 <[email protected]>
* fix(prom): announce listen URL only after start() fully succeeds
Move the 'Prometheus exporter listening on ...' stdout line from just-after-bind
to the end of start(), after HDR alloc + stop event + pthread_create all succeed.
Previously a failure in any later start() step exited 1 while stdout already
advertised a /metrics URL that was never brought up. Port is still resolved early;
only the announce is deferred. Addresses Cursor Bugbot review on PR #468.
Co-Authored-By: Claude Fable 5 <[email protected]>
* fix(prom): address 7-agent review — honest hits/misses HELP, age clamp, comment
From the adversarial review (1 major + 2 minors, 0 blockers):
- hits/misses HELP overpromised 'miss-tracked arbitrary commands'; the counters
source m_totals.m_hits/_misses, incremented only on the GET path (arbitrary
misses live in m_arbitrary_misses[], never folded into m_totals). Corrected
HELP to state GET-only coverage; arbitrary-command hit/miss totals are a PR2
item (live-summing m_arbitrary_misses would reintroduce the per-command race
v1 deliberately avoids).
- memtier_exporter_snapshot_age_seconds: 'now' is sampled before the snapshot
mutex, so a concurrent publish() could make published_at > now -> negative
gauge. Clamp age to >= 0.
- Fix a stale comment claiming the start()-failure exporter is leaked; it is
freed (delete + NULL) before exit(1).
Co-Authored-By: Claude Fable 5 <[email protected]>
* fix(prom): idle/ctor snapshot reports 0 active threads, not --threads
The constructor's initial zero snapshot set memtier_threads to --threads before
any worker existed, so a scrape during --verify-only or pre-run startup showed
live threads while memtier_run=0 and counters=0 — contradicting the idle-zero
snapshot and the run-end 0-threads behavior. Set active_threads=0 in the ctor
snapshot. Thread gauge is now consistent across all publish sites: ctor=0,
run_start=N, tick=live, run_end=0. Addresses Cursor Bugbot review on PR #468.
Co-Authored-By: Claude Fable 5 <[email protected]>
* fix(prom): per-bucket delta in gated histogram copy to stop double-count
copy_inst_histogram_if_changed() added the whole inst-totals histogram to
the lifetime histogram whenever total_count had changed since the last
gated copy. The inst histogram is reset only once per worker-second in
summarize_current_second(); when an exporter tick and that reset drift so
two 1 Hz ticks land within one worker-second, samples already folded on
the earlier tick were added again, inflating memtier_latency_seconds
buckets and _count (the metric is documented as a possible *under*count,
never an inflation).
Fix: keep a per-run_stats snapshot of the inst histogram as of the
previous gated copy (m_prom_last_inst, a deep-copyable safe_hdr_histogram
so run_stats stays value-copyable for post-join vector collection) and
add only the positive per-bucket delta versus that snapshot, so every
latency sample is folded at most once. A reset (cur total < last total)
re-adds the full current histogram. Frozen histograms (cur == last) are
still skipped, preserving the dead-client dedup (F19). In the rare window
where a reset is masked by net growth, some post-reset samples may be
dropped — an undercount consistent with the metric's non-authoritative
contract, never a double-count.
Verified: prometheus RLTest suite 20/21 pass locally (F19 fails only
because the local redis rejects DEBUG SLEEP, unrelated to this change);
redaction suite 2/2; clang-format clean.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
* test(prom): unit-test the gated-copy delta; extract hdr_add_positive_delta
Addresses the 7-agent adversarial review's one confirmed finding: no test
exercised the growing branch of copy_inst_histogram_if_changed that the
double-count fix (ec18e09) added. The only related test, F19, uses DEBUG
SLEEP to freeze the server, so it drives only the cur==last skip path —
byte-identical before and after the fix. Reverting the fix to "always
hdr_add the whole inst histogram" would still pass the entire suite.
- Extract the per-bucket positive-delta math into a pure free function
prom::hdr_add_positive_delta(target, cur, prev) in the always-linked,
libevent-free prometheus_metrics layer, so it is unit-testable in
isolation. run_stats::copy_inst_histogram_if_changed now calls it.
- Add U9 to tests/unit/prometheus_metrics_test.cpp: (a) only positive
per-bucket deltas are folded, shrinking buckets contribute 0; (b) a
two-ticks-within-one-worker-second growth scenario asserting the lifetime
histogram folds each sample exactly once (total 4, not the doubled 6 the
pre-fix always-add produced). This is the regression guard for ec18e09.
- copy_inst_histogram_if_changed returns void now: the bool was advertised
but the sole caller (aggregate_inst_histogram_if_changed) dropped it
(flagged as a dead contract by two review lenses). Header comment updated.
Verified: prometheus_metrics layer always compiled (no HAVE_EVHTTP guard),
so --disable-prometheus still links (built both flavors). make check passes
U1-U9; prometheus RLTest 20/21 (F19 fails only on local redis rejecting
DEBUG SLEEP); clang-format clean.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
---------
Co-authored-by: Claude Fable 5 <[email protected]>
new 'oss_client' client add to support oss cluster.
the new client use CLUSTER_SLOTS command to retrive the
key-->node mapping, create separate connection fot each node,
and send the commands to the appropriate connection according
to hash calculation.