feat(responseobs): add subpackage for large-response observation#242
Open
adamyeats wants to merge 2 commits into
Open
feat(responseobs): add subpackage for large-response observation#242adamyeats wants to merge 2 commits into
adamyeats wants to merge 2 commits into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
responseobssubpackage:Thresholds,Observation,Observe(ctx, obs, t) bool. Emits a single structuredwarnlog when a response crosses either threshold; returnsboolso a future counter can piggyback.DriverSettings.ResponseThresholds→ newDBQuery.WithResponseThresholds(...)setter (non-breaking; matches theWithRowCapacityHintconvention). Defaults: 50 MiB bytes or 1M rows.observeResponseSizehook inconvertRowsToFrames— same call site as the histograms from feat: emit response-size histograms from DBQuery #241, extended to also hand rows/cells/duration/refID toresponseobs.Observe.Stacked on #241
This PR is based on
feat/response-size-histograms(#241), notmain. 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
sqlutil.FrameFromRowsor 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_urlinstead ofslug. The plan's log shape called forslug, but there's no dedicated slug accessor inbackend.GrafanaConfig— onlyAppURL(). Logging the URL verbatim is honest; operators can parse in Loki/PromQL. Happy to revisit if reviewers prefer a derivedslugfield.QueryHashdeferred. Field is onObservationbut not populated here — the plan lists normalization cost as an open question; we can add it in a follow-up.DBQuery.Settingswas declared but never populated (NewQuerydidn't assign it). Fixed as a drive-by so the new log fields can pull Type/UID/Name without plumbingPluginContext. Happy to split that off if reviewers prefer.NewQueryarg. Follows theWithRowCapacityHintpattern from a recent PR. External plugins callingNewQuerydirectly keep compiling; they opt in when they want thresholds.