Design
Scope
The deck writes measurements to InfluxDB™ and reads them back: line-protocol points built with point and the field and tag steps, written with write; InfluxQL™ queries with query, parsed into Series; Flux™ queries with queryFlux, returned as annotated CSV. It covers InfluxDB 1.x and 2.x, and 3.x as far as 3.x speaks those APIs.
It is deliberately not an administration client:
- No management APIs. Buckets, organizations, tokens, retention policies, tasks and dashboards are configured once, usually by hand or by infrastructure tooling; a program that pushes metrics does not need them. An InfluxQL statement that the 1.x
/queryendpoint takes (CREATE DATABASE, ...) still works throughquery. - No Flux result decoder. Flux answers in annotated CSV, which the bundled
csvmodule parses; a bespoke decoder would duplicate it. - No batching, buffering or retry queue.
writesends the points it is given in one request. When to flush and what to do with a failed batch is the caller's policy. - No 3.x SQL or Arrow Flight. 3.x takes
client2writes and InfluxQL through a 1.x client, which covers the push-metrics use.
Decisions
- A deck, not a bundled module. A client for one vendor's database belongs in the deck ecosystem. The deck is one of the bundled modules that
jennifermoves out (M30.1 in its milestones, formerly M28.32) and keeps the module's surface, so migrating changes only the import. - One
Client, aVersiondiscriminator.client/clientWithmake a 1.x client,client2a 2.x one;writedispatches onversion. The line protocol is the same for every generation, so thePointbuilders andlineare shared. Unused fields of the other generation stay"". - Points carry rendered fragments. Tags and fields are stored as escaped
key=valuestrings, so one point mixes float, integer (isuffix), string and boolean fields, which a homogeneous map could not hold. Every builder step returns a newPoint. - Strict line protocol. A point that is not valid line protocol throws instead of being sent: no fields, an empty measurement or one starting with
#(a comment line the server would drop), an empty tag or field key, or a newline anywhere (the point separator, with no escape, so it would corrupt the whole batch). A tag with an empty value is left out, as the official clients do. - Escaping that cannot be undone. Commas, spaces and equals signs are backslash-escaped where the protocol needs it. A backslash is doubled only where it would pair with what follows (a special character, another backslash, the end of the component), so a value ending in
\cannot escape the separator, and a lone backslash is kept, which 1.x stores literally where 2.x would unescape\\. - Nanosecond precision only. Writes send
precision=ns;attakes nanoseconds andatTimeatime.Time. - Query cells are strings. An InfluxQL result is a
ResultofSerieswhose rows arelist of list of string:timeas its RFC 3339 text, numbers in their shortest form, booleans as"true"/"false",nullas"". A typed cell union would cost every caller a match; a caller converts the columns it knows are numeric. - The statement goes in the body.
queryPOSTsq=...form-encoded rather than putting it in the URL, so statements (aCREATE USER ... WITH PASSWORDincluded) stay out of proxy and access logs and URL length limits. - Same result shape as the Prometheus™ deck. The parsed
Seriesmatches the retrieval half of@deckyard/prometheus, so code reading either looks alike.
Errors
InfluxdbError (kind "influxdb") is the one struct for every error of that kind: status is the HTTP status of the server's answer (0 when there was none) and code a 2.x error's code (unauthorized, not found, invalid, ...; "" when the answer had none). It is thrown for:
- a non-2xx answer, with the server's message (1.x
error, 2.xmessage) orrequest failed with HTTP <status>when the body has neither; - an error reported inside a
200InfluxQL result (top level or per statement,status0); - a
200query answer that is not JSON; - the point checks above, and a transport failure that is none of the generic kinds (malformed HTTP framing, a bad URL).
The generic kinds pass through unchanged, as the bundled module, which never wrapped transport failures, does: a socket failure (refused, reset, failed lookup, TLS) is http's net.NetError (kind "net", with op, reason, sent and replied), a reached cap or a query reply past json's decoding caps is "limit", a deadline "timeout", an answer cut short "closed", a cancelled task "cancelled". On interpreters without transport error kinds (M28.65) a socket failure arrives as kind "runtime" and is wrapped as an InfluxdbError.
Security and limits
- Credentials ride in headers. 1.x Basic auth and the 2.x
Authorization: Tokenheader never appear in the URL. - Redaction. Every
InfluxdbErrormessage passes throughredact: the wholeAuthorizationvalue first, then the bare token or password when it is at least 6 characters (shorter ones would match unrelated text). A generic-kind error is passed on only when its message holds no credential; otherwise it is wrapped and redacted. - Server text is cleaned. Text from the server goes into a message with control characters (except tab) replaced by spaces, so it cannot forge log lines or terminal output, and cut at 512 characters.
- Plain HTTP is allowed. InfluxDB's default endpoint is
http://localhost:8086and many installations run without TLS on a local network, so the deck does not refusehttp://; credentials sent to a remote host over it travel in the clear. TLS client certificates are not wired; use a reverse proxy for them. - Response size and deadlines are
http's defaults; JSON decoding is underjson's nesting and node caps.
Testing and validation
src/influxdb_test.j covers the line protocol directly (escaping of every component, backslashes, mixed field types, timestamps, every refused point), the request builders (endpoint, query parameters, auth headers, form body), query parsing (series, tags with / and ~ in their keys, top-level and per-statement errors), error extraction, cleaning and redaction, and the InfluxdbError fields. Writes, InfluxQL and Flux queries run against an httpd server on a loopback port that checks the method, path, parameters, auth and body as InfluxDB would. A refused connection is shown to arrive as a net.NetError with no credential in its message, and an over-deep query reply as kind "limit".
The module's 2.x and 3.x work (M23.7) was validated against an independent reference implementation when it was added. The tests never reach a real InfluxDB; examples/write.j writes and queries against a server named on its command line (default http://localhost:8086) and reports the error when none is running, so CI runs it offline.
Known limitations and open questions
- A result the server cut at its row limit (
"partial": true) comes back as far as it goes, without a flag; page withLIMIT/OFFSET. - Only nanosecond precision is written.
- No gzip request bodies, which large batches would benefit from.
Dependencies on the interpreter
- The floor is
>=0.27.0, for the UTF-8 codecs ofencoding.encode/decodeandstrings.replicate; the bundled module is deprecated from 0.26.0 (M30.1). - Thrown error structs are classified by kind in
testing.assertThrowsand accepted by lint's L104 (M28.51 / M28.50); a decoding cap is kind"limit"(M28.68); a socket failure is anet.NetError(M28.65). httpneeds thenetcapability, so writing and querying need the defaultjenniferbinary; building and rendering points also work onjennifer-tiny.