Skip to content

fix(extract): correct /metrics endpoint check and include TYPE headers - #20

Open
belowzeroff wants to merge 2 commits into
KxSystems:masterfrom
belowzeroff:fix/f001-f002
Open

fix(extract): correct /metrics endpoint check and include TYPE headers#20
belowzeroff wants to merge 2 commits into
KxSystems:masterfrom
belowzeroff:fix/f001-f002

Conversation

@belowzeroff

Copy link
Copy Markdown
Contributor

Bug 1: /metrics endpoint check (fix/f001-metrics-endpoint-check)

The HTTP endpoint check used "metrics"~msg 0 but should be "/metrics"~8#msg 0. The original check did not account for the leading / in the path.

Bug 2: Missing TYPE headers in Prometheus output (fix/f002-type-headers)

extractmetricval used first[dhdr]instead ofd[hdr], which only returned the first header line instead of all TYPE/HELP headers. This caused Prometheus to reject the output due to missing type information.

@sshanks-kx

Copy link
Copy Markdown
Collaborator

this pr includes a change to install.sh, some of #22 appears to have been committed on this one by accident.

The ph handler checked  but msg 0 is the request URI
which starts with . For , msg 0 is , so
the check never matched. The metrics extraction code path was dead,
making the exporter non-functional for Prometheus scraping.

Fix: match against  prefix using .
extractmetric used `first[d`hdr]` which only took the HELP line,
dropping the TYPE line. The hdr field is a 2-element list:
("# HELP ..."; "# TYPE ..."). Dropping TYPE violates the Prometheus
exposition format specification and causes metric type misclassification.

Fix: use `d[\`hdr]` instead of `first[d\`hdr]` to emit both headers.
@belowzeroff

Copy link
Copy Markdown
Contributor Author

This should now be fixed: the current PR diff only contains q/extract.q changes, and install.sh is no longer part of this PR.

@sshanks-kx

Copy link
Copy Markdown
Collaborator

May have broken things. in fresh checkout, in q dir running q exporter.q -p 8080. then in browser, visit http://localhost:8080/metrics , see

# HELP kdb_info process information
# TYPE kdb_info gauge
kdb_info{release_date="2025.07.09", release_version="4.1", os_version="m64", process_cores="8", license_expiry_date="2026.11.22"} 1
# HELP memory_usage_bytes memory allocated
# TYPE memory_usage_bytes gauge
memory_usage_bytes 433360
# HELP memory_heap_bytes memory available in the heap
# TYPE memory_heap_bytes gauge
...

with change, visiting url shows

html/metrics: not found

@sshanks-kx sshanks-kx left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

See previous comment. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants