Skip to content

feat(responseobs): add subpackage for large-response observation#242

Open
adamyeats wants to merge 2 commits into
mainfrom
feat/responseobs
Open

feat(responseobs): add subpackage for large-response observation#242
adamyeats wants to merge 2 commits into
mainfrom
feat/responseobs

Conversation

@adamyeats

Copy link
Copy Markdown
Contributor

Summary

  • Introduces a narrow responseobs subpackage: Thresholds, Observation, Observe(ctx, obs, t) bool. Emits a single structured warn log when a response crosses either threshold; returns bool so a future counter can piggyback.
  • Wires the helper through DriverSettings.ResponseThresholds → new DBQuery.WithResponseThresholds(...) setter (non-breaking; matches the WithRowCapacityHint convention). Defaults: 50 MiB bytes or 1M rows.
  • Observation fires from the existing observeResponseSize hook in convertRowsToFrames — same call site as the histograms from feat: emit response-size histograms from DBQuery #241, extended to also hand rows/cells/duration/refID to responseobs.Observe.

Stacked on #241

This PR is based on feat/response-size-histograms (#241), not main. Merge #241 first, then this will rebase cleanly. Review this diff against that branch to see only PR 2's additions.

Why

PR 2 of the measurement plan for grafana/data-sources#288 (PR 1 was sqlds#241). After maintainer guidance on SDK API stability and scope-beyond-datasources, the rich observation logic (threshold detection, structured log, and a counter in PR 3) lives in sqlds rather than the SDK. Only the transport-layer bytes observation in PR 4 stays SDK-side, because that's genuinely generic across plugin types.

Design notes worth flagging in review

  • Bytes at sqlds layer are always 0. Serialized wire size isn't cheaply measurable here — we'd need a hook inside sqlutil.FrameFromRows or an Arrow marshal. So only the rows threshold fires from sqlds. The bytes dimension remains in the API for layers that can measure it (and for operators who'd rather cap on bytes than rows once PR 4 lands).
  • app_url instead of slug. The plan's log shape called for slug, but there's no dedicated slug accessor in backend.GrafanaConfig — only AppURL(). Logging the URL verbatim is honest; operators can parse in Loki/PromQL. Happy to revisit if reviewers prefer a derived slug field.
  • QueryHash deferred. Field is on Observation but not populated here — the plan lists normalization cost as an open question; we can add it in a follow-up.
  • DBQuery.Settings was declared but never populated (NewQuery didn't assign it). Fixed as a drive-by so the new log fields can pull Type/UID/Name without plumbing PluginContext. Happy to split that off if reviewers prefer.
  • Setter instead of new NewQuery arg. Follows the WithRowCapacityHint pattern from a recent PR. External plugins calling NewQuery directly keep compiling; they opt in when they want thresholds.

Adds plugins_sql_response_rows and plugins_sql_response_cells
histograms labelled by datasource_type. Emitted from
convertRowsToFrames after successful frame conversion so the
observation reflects post-conversion shape (including LongToMulti
multi-frame results).

This is PR 1 of the response-size measurement plan for
grafana/data-sources#288 — giving operators an aggregate trend of
query payload sizes so large/OOM-causing queries become visible
without pod introspection. Subsequent PRs land in grafana-plugin-sdk-go.
Introduces github.com/grafana/sqlds/v5/responseobs, a narrow helper
that evaluates a SQL query response against configured size thresholds
and emits a single structured warn log when crossed. Returns a bool so
a downstream counter (follow-up PR) can piggyback on the same decision.

Defaults: 50 MiB bytes OR 1M rows; a zero on either field disables
that dimension (useful at the sqlds layer where bytes can't be
measured cheaply, so only the rows check fires from here).

Wires the helper in via DriverSettings.ResponseThresholds →
DBQuery.WithResponseThresholds(), following the WithRowCapacityHint
pattern introduced earlier. Non-breaking: NewQuery signature is
unchanged; plugins that don't opt in see zero thresholds and emit no
log.

This is PR 2 of the response-size measurement plan for
grafana/data-sources#288. Step 1 (rows/cells histograms) shipped in
sqlds#241. After maintainer guidance on SDK API stability and
scope-beyond-datasources, the rich observation logic (log here;
counter in PR 3) lives in sqlds; only a transport-layer bytes
observation goes to grafana-plugin-sdk-go in PR 4.
@adamyeats adamyeats requested a review from a team as a code owner April 22, 2026 12:15
Base automatically changed from feat/response-size-histograms to main April 28, 2026 20:11
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.

1 participant