mergeAllPtrs on both histogram.Fixed and Snapshot folds a slice of pointers, so a histogram or snapshot that lives in another struct does not have to be copied into an array to be folded. mergeAll still takes a slice of values, and the two agree count for count.
Fixed.Bounds and Snapshot.Bounds are limits, lowercase because they hold a value and not a type.
histogram.Fixed(...).merge(other) adds a local histogram's buckets, count, and sum into another.
histogram.Fixed(...).mergeAll(histograms) folds a slice of local histograms into the Snapshot a scrape writes, in one call.
Snapshot.zero, Snapshot.merge(other), and Snapshot.mergeAll(snapshots) do the same for the snapshots an atomic histogram fills.
Snapshot.limits names the bucket limits a snapshot counts, the same decl Fixed carries, so a writer can take either without its type threaded alongside.
- Zig 0.17 only:
minimum_zig_version is 0.17.0, and 0.16 is no longer built or tested. Upgrade the toolchain before taking this version.
histogram.linear(start, width, count) and histogram.exponential(start, factor, count) build a histogram's bounds at comptime; the +Inf bucket stays implicit.
histogram.Fixed(...).Snapshot and snapshot(&out): an atomic histogram fills the caller's buffer with the bucket counts, the observation count, and the sum in one call.
histogram.counts takes *Counts and returns nothing. The buffer the caller passed is the whole result.
- A local histogram's
counts() lends its own bytes as []const u64, so reading one copies nothing.
count() and sumValue() are gone. Read histogram.observed.get() and histogram.total.get(), or take a Snapshot.
histogram.Fixed(S, bounds): a bucket array, a count, and a sum over the caller's recording counter type, with observe, count, sumValue, and counts. Buckets are cumulative at observe, the sum is exact because the slot is an integer counter, and the bounds are comptime.
gauge.Local(T) and gauge.Atomic(T): a number that moves both ways, with set, add, sub, inc, dec, get, and zero to make one. The integer may be signed, and the float is f32 or f64. An atomic float is an integer atomic holding the bit pattern, added through a compare-exchange loop.
counter.Local(T) and counter.Atomic(T): an unsigned integer and an add, with inc, add, and get. Both wrap at maxInt(T). There is no set and no write method.
- The recording types and the answer they write through are separate:
metrics.prometheus.Writer is one exposition format, and counter, gauge, and histogram sit beside it rather than inside it.
- The writer moved from
metrics.Writer to metrics.prometheus.Writer, so a second exposition format can sit beside it. This breaks every call site on 0.1.0; see the guide's install section for the import.
Writer is the expfmt cursor: help, kind, name, value, and line write one record each, and writeMetric, writeFamily, writeHistogram, and the series form are methods on it built only out of those five.
Writer.writeMetric writes one sample line, Writer.writeFamily writes # HELP and # TYPE and returns the handle for its samples, and Writer.writeHistogram writes a classic histogram. Each is built only from Writer methods.
FamilyWriter.writeHistogramSeries writes one series with no header, so a multi-series histogram family writes the header once and loops. sum is anytype in both histogram writers, so a u64 above 2^53 keeps every digit.
- Values follow
metrics/common's rule: a float that reads back as an integer is written as one, so 1e6 is 1000000 and -0 is 0; NaN and the infinities are canonical; everything else is Go's 'g' with the shortest digits. A value outside the i64 range falls through instead of trapping.
- Label values and help text are escaped. A metric name or label name a parser would reject does not compile, and a label in the reserved
__ namespace does not either.