Documentation
¶
Index ¶
- Constants
- func ApplyMacros(sql string, timeRange backend.TimeRange, tz string) string
- func ApplyMacrosWithSplit(sql string, chunk backend.TimeRange, originalRange backend.TimeRange, ...) string
- func JSONToDataFrame(result map[string]interface{}) (*data.Frame, error)
- func MsgpackToDataFrame(r io.Reader, maxElems int64) (*data.Frame, error)
- func OptimizeTimeSeriesQuery(sql string) string
- type ArcDataSourceSettings
- type ArcDatasource
- type ArcInstanceSettings
- type ArcQuery
Constants ¶
const ( ProtocolArrow = "arrow" ProtocolMsgpack = "msgpack" ProtocolJSON = "json" )
Wire protocols for Arc query responses. Arrow is the fastest and the default; MessagePack (stable since Arc 26.09.1) is a typed columnar binary envelope at roughly 78% of Arrow's decode throughput; JSON is the compatibility fallback.
const DefaultMaxInFlight = 32
DefaultMaxInFlight bounds simultaneous Arc requests per datasource across every panel and viewer. 32 keeps a busy dashboard responsive while still protecting Arc; 1.3.2 used MaxConcurrency (default 4) for both, so a 12-panel dashboard served requests four at a time.
const DefaultMaxResponseMB = 1024
DefaultMaxResponseMB is the default per-response body size cap when the user hasn't set `MaxResponseMB` in datasource settings. 1024 MiB fits roughly 30M rows with several float64 columns — well clear of the 6–10M-row analytical queries Arc serves in normal use (R2-CR7). The original hardcoded 256 MiB was reported truncating real workloads.
const MaxConcurrencyCap = 32
MaxConcurrencyCap is the upper bound on user-configurable parallel chunk fanout. Higher values risk file-descriptor pressure and TLS-handshake storms against Arc.
const MaxInFlightCap = 128
MaxInFlightCap bounds MaxInFlight. Beyond this, file-descriptor pressure and TLS-handshake storms against Arc become the limiting factor.
const MaxResponseMBCap = 8192
MaxResponseMBCap is the upper bound a user can set via `MaxResponseMB`. Higher values risk OOMing the plugin process on a runaway query; this is a defense in depth bound — set it as high as feels safe for the host's memory profile.
Variables ¶
This section is empty.
Functions ¶
func ApplyMacros ¶
ApplyMacros replaces Grafana macros in SQL query tz is the dashboard's IANA timezone; empty or unrecognised means UTC.
func ApplyMacrosWithSplit ¶ added in v1.1.0
func ApplyMacrosWithSplit(sql string, chunk backend.TimeRange, originalRange backend.TimeRange, tz string) string
ApplyMacrosWithSplit replaces macros using the chunk's time range for `$__timeFilter`/`$__timeFrom`/`$__timeTo`, but the ORIGINAL range for `$__interval` so bucket sizes stay consistent across chunks.
func JSONToDataFrame ¶
JSONToDataFrame converts Arc JSON response to Grafana DataFrame
func MsgpackToDataFrame ¶ added in v1.3.0
MsgpackToDataFrame decodes Arc's columnar MessagePack query envelope into a Grafana DataFrame. The envelope (Arc internal/api/query_msgpack.go) is:
map {
"success": bool
"columns": [string...]
"types": [string...] // frozen vocabulary, see decodeMsgpackColumn
"data": [[...]...] // COLUMN-major: one array per column
"row_count": uint
"execution_time_ms": uint
"timestamp": string
}
Key order is fixed by the server (columns and types always precede data), but this decoder only requires that ordering rather than assuming the full sequence, and skips unknown keys so additive server changes don't break it. Nulls are msgpack nil, in place inside the column arrays. Timestamps are the standard msgpack timestamp extension (type -1), already UTC instants.
maxElems caps every array-length header before allocation. msgpack length prefixes are attacker-controlled and DecodeArrayLen returns -1 for a nil value, so lengths are validated through checkedLen at every site: without it, `make` with a negative or multi-billion length panics or OOMs the plugin process before a single element byte is read.
func OptimizeTimeSeriesQuery ¶
OptimizeTimeSeriesQuery appends `ORDER BY time ASC` to a time-series query that does not already order its rows, so Grafana receives points in chronological order without sorting them in memory.
Only for `format: time_series` — a table panel must keep the row order the author asked for (CLAUDE.md gotcha 6).
Deliberately conservative, because this rewrites SQL the user wrote. A missing sort renders a zig-zag line, which is merely ugly; a misplaced ORDER BY either fails the query or, worse, silently changes WHICH ROWS a LIMIT selects. This feature was disabled during the 1.3.2 hardening for exactly that class of defect, so every ambiguous shape is declined:
- an existing ORDER BY, or no bare `time` column;
- any parenthesis — a subquery or CTE can bind a trailing clause to the wrong SELECT, and inserting before a nested LIMIT changes which rows that LIMIT returns (a silent wrong answer, the worst outcome here);
- a set operation or a multi-statement input;
- `FETCH`, or more than one LIMIT/OFFSET token, or `limit`/`offset` used as an identifier — all cases where the insertion point is ambiguous;
- a last line that opens a `--` comment, which would swallow the clause.
Types ¶
type ArcDataSourceSettings ¶
type ArcDataSourceSettings struct {
URL string `json:"url"`
Database string `json:"database"`
Timeout int `json:"timeout"` // seconds
Protocol string `json:"protocol"` // "arrow" (default), "msgpack", or "json" — wire format for query responses
UseArrow *bool `json:"useArrow"` // legacy toggle superseded by Protocol; pointer so unset (fresh install) is distinguishable from explicit false
MaxConcurrency int `json:"maxConcurrency"` // max parallel chunks WITHIN one split query (default 4)
// MaxInFlight bounds total simultaneous Arc requests for this datasource,
// across every panel and viewer. Separate from MaxConcurrency: that one
// shapes a single query's fan-out, while this one protects Arc and the
// plugin process. Collapsing them (1.3.2) meant a 12-panel dashboard
// queued behind 4 slots and panels timed out waiting their turn.
MaxInFlight int `json:"maxInFlight"` // default 32
MaxResponseMB int `json:"maxResponseMB"` // per-response body size cap in MiB (default 1024 — large analytical queries cross 256 MiB easily, R2-CR7)
// AllowPrivateIPs permits the Arc URL to resolve to an RFC1918/CGNAT
// address. Pointer so an absent key (a datasource created before 1.3) is
// distinguishable from an explicit false: absent defaults to TRUE, because
// self-hosted Arc normally lives on a private network or a Docker DNS name
// like `http://arc:8000`, and defaulting it off in 1.3.2 broke every such
// datasource with "Arc URL resolves to a blocked address". Link-local and
// cloud-metadata addresses stay blocked regardless of this setting.
AllowPrivateIPs *bool `json:"allowPrivateIPs"`
// AllowDatabaseOverride permits a per-query `database` field to override
// the datasource default. Pointer for the same reason: the override was an
// advertised feature from 1.1.0, and gating it off by default in 1.3.2
// turned working panels into "per-query database override is not enabled".
// Absent defaults to TRUE for legacy instances; the ConfigEditor writes an
// explicit value for datasources created from 1.4.0 on.
AllowDatabaseOverride *bool `json:"allowDatabaseOverride"`
}
ArcDataSourceSettings contains Arc connection settings
type ArcDatasource ¶
type ArcDatasource struct {
// contains filtered or unexported fields
}
ArcDatasource implements the Grafana datasource interface. The im field caches per-instance settings + HTTP client so QueryData does not pay the JSON-unmarshal-and-build-client cost on every refresh.
func NewArcDatasource ¶
func NewArcDatasource() *ArcDatasource
NewArcDatasource constructs the datasource with the SDK's InstanceManager wired up to the newArcInstance factory.
func (*ArcDatasource) CheckHealth ¶
func (d *ArcDatasource) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error)
CheckHealth validates the datasource connection
func (*ArcDatasource) QueryData ¶
func (d *ArcDatasource) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
QueryData handles query requests. RefIds within a single batch run concurrently; total in-flight HTTP requests are bounded by the shared semaphore on ArcInstanceSettings (R2-CR1 — refId × chunk fan-outs no longer multiply). Each refId is wrapped in a recover so a panic in one query fails only that query, not the whole batch (C1).
The errgroup is wired with ctx (R2-HI4 / gemini 3244629509): when Grafana cancels the parent QueryDataRequest, the dispatch loop notices via gctx.Done() and stops spawning new refId goroutines rather than queueing MaxConcurrency more HTTP round-trips behind the SetLimit gate.
type ArcInstanceSettings ¶
type ArcInstanceSettings struct {
// contains filtered or unexported fields
}
ArcInstanceSettings is the cached, parsed view of a datasource instance. One is constructed per (settings, secrets) revision by newArcInstance and reused across every QueryData / CheckHealth call until the datasource is edited. The embedded *http.Client is shared so connection pooling and TLS session resumption work — building a fresh client per query (the pre-P3 shape) defeated both.
`sem` is a shared weighted semaphore that bounds total in-flight Arc HTTP requests across BOTH the refId fan-out (QueryData) and the chunk fan-out (inside query()) — see R2-CR1. Previously each level had its own errgroup.SetLimit(MaxConcurrency), so a 6-panel × 4-chunk dashboard ran 24 in-flight requests, not 4. The semaphore is acquired before the HTTP dial and released after the response is fully read.
func (*ArcInstanceSettings) Dispose ¶ added in v1.3.0
func (s *ArcInstanceSettings) Dispose()
Dispose is called by the InstanceManager when the cached instance is being replaced. Closes idle HTTP connections so we don't leak sockets across settings updates.
type ArcQuery ¶
type ArcQuery struct {
RefID string `json:"refId"`
SQL string `json:"sql"`
RawSQL string `json:"rawSql"` // Postgres/MySQL/MSSQL/ClickHouse compatibility
Database string `json:"database"` // Per-query database override (empty = use datasource default)
Format string `json:"format"` // "time_series" or "table"
MaxDataPoints int64 `json:"maxDataPoints"`
SplitDuration string `json:"splitDuration"` // "auto" (default), "off", or explicit: "1h", "6h", "12h", "1d", "3d", "7d"
// Timezone is the dashboard's timezone as an IANA name, resolved by the
// frontend ("browser" is expanded there, where the browser is). Empty
// means UTC, which is what every build before 1.5.0 did.
Timezone string `json:"timezone"`
}
ArcQuery represents a query to Arc