Skip to content

fix(http): negative questdb_json_queries_connections gauge #6444

Merged
bluestreak01 merged 13 commits intomasterfrom
nw_connection_gauge_bug
Nov 25, 2025
Merged

fix(http): negative questdb_json_queries_connections gauge #6444
bluestreak01 merged 13 commits intomasterfrom
nw_connection_gauge_bug

Conversation

@nwoolmer
Copy link
Copy Markdown
Contributor

@nwoolmer nwoolmer commented Nov 24, 2025

A bug was introduced in #6008

This bug caused the questdb_json_queries_connections gauge to be decremented by sources that would not also increment the gauge. For example, 'export' and 'other' sources would also trigger a decrement.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Nov 24, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The PR refactors active connection tracking by introducing HTTP-specific processor identifiers (PROCESSOR_EXPORT_HTTP, PROCESSOR_ILP_HTTP), renaming tracking API methods (inc/dec/get), replacing AtomicLong with AtomicLongGaugeImpl for counters, separating metrics-facing from local gauges, and updating connection lifecycle management and processor identifiers accordingly.

Changes

Cohort / File(s) Summary
Core Tracking API Refactor
core/src/main/java/io/questdb/cutlass/http/ActiveConnectionTracker.java
Introduces HTTP-specific constants (PROCESSOR_EXPORT_HTTP, PROCESSOR_ILP_HTTP); renames public methods (incrementActiveConnection→inc, decrementActiveConnection→dec, getActiveConnections→get); replaces AtomicLong fields with AtomicLongGaugeImpl; separates metrics-facing gauges from local gauges via getMetricsGauge and getLocalGauge; updates limit retrieval with nullable parameter and switch expression; refactors NO_TRACKING implementation.
Connection Tracking Delegation
core/src/main/java/io/questdb/ServerMain.java
Removes unused imports (Files, MmapCache); updates active connection retrieval to delegate to httpServer.getActiveConnectionTracker().get(processorName).
Connection Lifecycle Management
core/src/main/java/io/questdb/cutlass/http/HttpConnectionContext.java
Introduces connectionCounted flag for single-pass increment tracking; adds private incrementActiveConnections(fd) method; reworks decrementActiveConnections to only decrement when previously counted and to reset processorName; adjusts limit-exceeded handling to use new dec(processorName) method.
Processor Identifier Updates
core/src/main/java/io/questdb/cutlass/http/processors/ExportQueryProcessor.java, core/src/main/java/io/questdb/cutlass/http/processors/LineHttpPingProcessor.java, core/src/main/java/io/questdb/cutlass/http/processors/LineHttpProcessorImpl.java
Updates getName() return values to use new HTTP-specific constants (PROCESSOR_EXPORT_HTTP, PROCESSOR_ILP_HTTP).
Metrics Interface Extensions
core/src/main/java/io/questdb/metrics/AtomicLongGauge.java, core/src/main/java/io/questdb/metrics/AtomicLongGaugeImpl.java, core/src/main/java/io/questdb/metrics/NullLongGauge.java
Adds decrementAndGet() method to AtomicLongGauge interface; implements decrementAndGet() in AtomicLongGaugeImpl (delegates to internal AtomicLong) and NullLongGauge (returns 0).
Test Updates
core/src/test/java/io/questdb/test/cutlass/http/ExpParquetExportTest.java, core/src/test/java/io/questdb/test/cutlass/http/HttpConnectionCountTest.java
Updates processor constant references from PROCESSOR_EXPORT/PROCESSOR_ILP to HTTP variants; renames connection-limit error message identifiers to new canonical names (e.g., "json-http" → "http_json_connections"); adds concurrent export and JSON query integration test.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • ActiveConnectionTracker refactor: Significant API surface changes (method renaming), field type changes (AtomicLong→AtomicLongGaugeImpl), introduction of two separate gauge accessor methods, and nullable parameter handling require careful verification of all call sites and metric registration.
  • HttpConnectionContext lifecycle logic: New connectionCounted flag management and revised decrementActiveConnections behavior must be verified to prevent double-counting or under-counting in various error paths and request completion scenarios.
  • Propagation verification: Four processor implementations require alignment checks; ensure all getName() implementations reference correct constants and that no stale references remain elsewhere in codebase.
  • Test assertions: Error message string updates and constant references must align precisely with new ActiveConnectionTracker names to ensure test reliability.

Suggested labels

Core

Suggested reviewers

  • bluestreak01

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix: correcting a bug where the JSON queries connections gauge was being decremented incorrectly.
Description check ✅ Passed The description is related to the changeset, explaining the bug context and the source of the problem (PR #6008), though it references an incorrect PR number.

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nwoolmer nwoolmer added Bug Incorrect or unexpected behavior REST API Issues or changes relating to the HTTP endpoints labels Nov 24, 2025
@nwoolmer
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Nov 24, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nwoolmer nwoolmer changed the title fix(http): negative questdb_json_queries_connections gauge fix(http): negative questdb_json_queries_connections gauge Nov 24, 2025
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
core/src/main/java/io/questdb/cutlass/http/HttpConnectionContext.java (1)

470-479: Reset connectionCounted when you revert the increment.

In the reserved-admin slot branch we roll back the earlier increment by calling activeConnectionTracker.dec(processorName) and nulling out processorName, but we never clear connectionCounted. The context therefore still believes it’s counted, so any follow-up request on the same socket will skip the !connectionCounted guard and run untracked. Please either call decrementActiveConnections here or manually set connectionCounted = false so the internal state matches the tracker.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6b60f1d and e0def58.

📒 Files selected for processing (11)
  • core/src/main/java/io/questdb/ServerMain.java (1 hunks)
  • core/src/main/java/io/questdb/cutlass/http/ActiveConnectionTracker.java (3 hunks)
  • core/src/main/java/io/questdb/cutlass/http/HttpConnectionContext.java (5 hunks)
  • core/src/main/java/io/questdb/cutlass/http/processors/ExportQueryProcessor.java (1 hunks)
  • core/src/main/java/io/questdb/cutlass/http/processors/LineHttpPingProcessor.java (1 hunks)
  • core/src/main/java/io/questdb/cutlass/http/processors/LineHttpProcessorImpl.java (1 hunks)
  • core/src/main/java/io/questdb/metrics/AtomicLongGauge.java (1 hunks)
  • core/src/main/java/io/questdb/metrics/AtomicLongGaugeImpl.java (1 hunks)
  • core/src/main/java/io/questdb/metrics/NullLongGauge.java (1 hunks)
  • core/src/test/java/io/questdb/test/cutlass/http/ExpParquetExportTest.java (3 hunks)
  • core/src/test/java/io/questdb/test/cutlass/http/HttpConnectionCountTest.java (5 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-11-19T12:21:00.062Z
Learnt from: jerrinot
Repo: questdb/questdb PR: 6413
File: core/src/test/java/io/questdb/test/cutlass/pgwire/PGJobContextTest.java:11982-12002
Timestamp: 2025-11-19T12:21:00.062Z
Learning: QuestDB Java tests use a deterministic random seed. The test utilities (e.g., io.questdb.test.tools.TestUtils and io.questdb.std.Rnd) produce reproducible sequences, so rnd_* functions (including rnd_uuid4) yield deterministic outputs across runs. Do not flag tests in core/src/test/** that assert against values produced by rnd_* as flaky due to randomness.

Applied to files:

  • core/src/main/java/io/questdb/ServerMain.java
🧬 Code graph analysis (6)
core/src/main/java/io/questdb/cutlass/http/processors/LineHttpProcessorImpl.java (1)
core/src/main/java/io/questdb/cutlass/http/ActiveConnectionTracker.java (1)
  • ActiveConnectionTracker (34-125)
core/src/test/java/io/questdb/test/cutlass/http/HttpConnectionCountTest.java (2)
core/src/main/java/io/questdb/std/Chars.java (1)
  • Chars (43-1646)
core/src/main/java/io/questdb/cutlass/http/ActiveConnectionTracker.java (1)
  • ActiveConnectionTracker (34-125)
core/src/main/java/io/questdb/cutlass/http/processors/LineHttpPingProcessor.java (1)
core/src/main/java/io/questdb/cutlass/http/ActiveConnectionTracker.java (1)
  • ActiveConnectionTracker (34-125)
core/src/test/java/io/questdb/test/cutlass/http/ExpParquetExportTest.java (1)
core/src/main/java/io/questdb/cutlass/http/ActiveConnectionTracker.java (1)
  • ActiveConnectionTracker (34-125)
core/src/main/java/io/questdb/cutlass/http/processors/ExportQueryProcessor.java (1)
core/src/main/java/io/questdb/cutlass/http/ActiveConnectionTracker.java (1)
  • ActiveConnectionTracker (34-125)
core/src/main/java/io/questdb/cutlass/http/ActiveConnectionTracker.java (2)
core/src/main/java/io/questdb/metrics/AtomicLongGaugeImpl.java (1)
  • AtomicLongGaugeImpl (29-71)
core/src/main/java/io/questdb/metrics/NullLongGauge.java (1)
  • NullLongGauge (30-75)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (33)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-other)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-pgwire)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-cairo-sub)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-cairo-root)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-fuzz2)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-fuzz1)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-griffin-sub)
  • GitHub Check: New pull request (SelfHosted Running tests with cover on linux-griffin-root)
  • GitHub Check: New pull request (Rust Test and Lint on linux-jdk17)
  • GitHub Check: New pull request (SelfHosted Other tests on linux-x86-graal)
  • GitHub Check: New pull request (SelfHosted Other tests on linux-arm64)
  • GitHub Check: New pull request (SelfHosted Cairo tests on linux-x64-zfs)
  • GitHub Check: New pull request (SelfHosted Other tests on linux-x64-zfs)
  • GitHub Check: New pull request (SelfHosted Griffin tests on linux-arm64)
  • GitHub Check: New pull request (SelfHosted Cairo tests on linux-arm64)
  • GitHub Check: New pull request (SelfHosted Griffin tests on linux-x64-zfs)
  • GitHub Check: New pull request (SelfHosted Cairo tests on linux-x86-graal)
  • GitHub Check: New pull request (SelfHosted Griffin tests on linux-x86-graal)
  • GitHub Check: New pull request (Hosted Running tests on windows-other-2)
  • GitHub Check: New pull request (Hosted Running tests on windows-other-1)
  • GitHub Check: New pull request (Hosted Running tests on windows-pgwire)
  • GitHub Check: New pull request (Hosted Running tests on windows-cairo-2)
  • GitHub Check: New pull request (Hosted Running tests on windows-cairo-1)
  • GitHub Check: New pull request (Hosted Running tests on windows-fuzz2)
  • GitHub Check: New pull request (Hosted Running tests on windows-fuzz1)
  • GitHub Check: New pull request (Hosted Running tests on windows-griffin-sub)
  • GitHub Check: New pull request (Hosted Running tests on windows-griffin-base)
  • GitHub Check: New pull request (Hosted Running tests on mac-other)
  • GitHub Check: New pull request (Hosted Running tests on mac-pgwire)
  • GitHub Check: New pull request (Hosted Running tests on mac-cairo-fuzz)
  • GitHub Check: New pull request (Hosted Running tests on mac-cairo)
  • GitHub Check: New pull request (Hosted Running tests on mac-griffin)
  • GitHub Check: New pull request (Check Changes Check changes)
🔇 Additional comments (8)
core/src/main/java/io/questdb/ServerMain.java (1)

190-190: LGTM! API delegation updated correctly.

The change from getActiveConnections(processorName) to httpServer.getActiveConnectionTracker().get(processorName) correctly aligns with the updated ActiveConnectionTracker API introduced in this PR.

core/src/main/java/io/questdb/metrics/AtomicLongGauge.java (1)

28-29: LGTM! Interface extension is well-structured.

The addition of decrementAndGet() complements the existing incrementAndGet() method and provides a consistent API for atomic gauge operations. All known implementers (AtomicLongGaugeImpl and NullLongGauge) provide the required implementation.

core/src/main/java/io/questdb/metrics/NullLongGauge.java (1)

44-47: LGTM! No-op implementation is consistent.

The decrementAndGet() implementation correctly returns 0, maintaining consistency with other no-op methods in NullLongGauge (e.g., getValue(), incrementAndGet()).

core/src/main/java/io/questdb/cutlass/http/processors/LineHttpPingProcessor.java (1)

46-46: LGTM! Processor identifier updated correctly.

The change from PROCESSOR_ILP to PROCESSOR_ILP_HTTP correctly aligns this processor with the HTTP-specific naming scheme introduced to fix the connection gauge tracking bug. This ensures proper categorization and counting of ILP-over-HTTP connections.

core/src/main/java/io/questdb/cutlass/http/processors/LineHttpProcessorImpl.java (1)

75-75: LGTM! Processor identifier updated consistently.

The change to PROCESSOR_ILP_HTTP is consistent with the HTTP-specific processor naming pattern applied across all HTTP processors in this PR.

core/src/main/java/io/questdb/cutlass/http/processors/ExportQueryProcessor.java (1)

242-242: LGTM! Export processor correctly categorized.

The change to PROCESSOR_EXPORT_HTTP properly categorizes export operations with their own connection tracking, which is essential to the bug fix. Per the ActiveConnectionTracker implementation, export connections now have dedicated local gauges while using NullLongGauge for Prometheus metrics (intentional, as there's no corresponding Prometheus metric for exports).

core/src/main/java/io/questdb/metrics/AtomicLongGaugeImpl.java (1)

47-50: LGTM! Implementation is correct and consistent.

The decrementAndGet() implementation correctly delegates to the underlying AtomicLong.decrementAndGet() and mirrors the structure of the existing incrementAndGet() method.

core/src/test/java/io/questdb/test/cutlass/http/HttpConnectionCountTest.java (1)

142-143: LGTM! Test assertions updated correctly.

All test assertions have been consistently updated to reflect the new HTTP-specific processor naming scheme:

  • json-httphttp_json_connections
  • ilp-httphttp_ilp_connections
  • PROCESSOR_ILPPROCESSOR_ILP_HTTP

These changes ensure tests correctly validate the updated error messages and connection tracking behavior introduced by this bug fix.

Also applies to: 247-247, 251-251, 262-262, 274-274, 279-279, 390-390, 395-395

@glasstiger
Copy link
Copy Markdown
Contributor

[PR Coverage check]

😍 pass : 34 / 38 (89.47%)

file detail

path covered line new line coverage
🔵 io/questdb/cutlass/http/HttpConnectionContext.java 5 6 83.33%
🔵 io/questdb/cutlass/http/ActiveConnectionTracker.java 23 26 88.46%
🔵 io/questdb/cutlass/http/processors/LineHttpProcessorImpl.java 1 1 100.00%
🔵 io/questdb/metrics/NullLongGauge.java 1 1 100.00%
🔵 io/questdb/metrics/AtomicLongGaugeImpl.java 1 1 100.00%
🔵 io/questdb/cutlass/http/processors/LineHttpPingProcessor.java 1 1 100.00%
🔵 io/questdb/cutlass/http/processors/ExportQueryProcessor.java 1 1 100.00%
🔵 io/questdb/ServerMain.java 1 1 100.00%

@bluestreak01 bluestreak01 merged commit 81d1e25 into master Nov 25, 2025
41 checks passed
@bluestreak01 bluestreak01 deleted the nw_connection_gauge_bug branch November 25, 2025 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Incorrect or unexpected behavior REST API Issues or changes relating to the HTTP endpoints

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants