supportmetrics

package
v1.0.310 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package supportmetrics implements the M7 scoped support-metric registry (roadmap/M7-proactive-telemetry-plan.md §6). It is deliberately NOT a canonical mirror of every culvert_* Prometheus/OTLP metric — it governs only the small support-health scalar set shared by three surfaces: support-bundle evidence, the telemetry preview, and the future telemetry sender. Metric values themselves live wherever the real subsystem state lives (package main); this package owns only the descriptor schema, the default-deny/justification/label-free invariants, the deterministic registry_hash, and the pure sample builder.

Index

Constants

View Source
const SchemaVersion = 3

SchemaVersion is the governed telemetry wire-schema version for the support-metric registry (roadmap/M7-proactive-telemetry-plan.md §3.2/§3.3/§8, which fix it at 3 for the binding wire contract). It is a fixed constant, not derived — bump it only for a deliberate, reviewed wire schema change coordinated with the merged design.

Variables

View Source
var CAExpiryBucketLadder = &BucketLadder{
	Labels:     []string{"gt90d", "le90d", "le30d", "le7d"},
	Thresholds: []float64{7, 30, 90},
	Descending: true,
}

CAExpiryBucketLadder is the canonical, hash-participating definition for support_health_ca_expiry_bucket (§7: ">90d/<=90/<=30/<=7"). Descending: MORE days remaining is healthier (bucket 0), FEWER (or negative — no usable cert) is more urgent (bucket 3).

View Source
var UptimeBucketLadder = &BucketLadder{
	Labels:     []string{"lt1d", "lt7d", "lt30d", "ge30d"},
	Thresholds: []float64{1, 7, 30},
	Descending: false,
}

UptimeBucketLadder is the canonical, hash-participating definition for support_uptime_bucket (§7: "<1d/<7/<30/>=30"), expressed in days. Non-descending: longer uptime is a later (more stable) bucket.

Functions

func CAExpiryBucket

func CAExpiryBucket(daysUntilExpiry int) float64

CAExpiryBucket maps days-until-CA-expiry to the coarse bucket that avoids exposing a precise cert-timeline fingerprint. A negative daysUntilExpiry (no usable CA / already expired) maps to the most urgent bucket (le7d) — the CA is not merely "nearing" expiry, it is unusable, at least as urgent as the closest named boundary.

func UptimeBucket

func UptimeBucket(d time.Duration) float64

UptimeBucket maps a process uptime duration to the coarse restart-cadence bucket — a coarse stability signal; exact uptime is deliberately rejected (fingerprint/correlation risk).

Types

type BucketLadder

type BucketLadder struct {
	Labels     []string  // len N; Labels[i] names bucket i
	Thresholds []float64 // len N-1, ascending
	Descending bool
}

BucketLadder is a canonical, single-source-of-truth definition of a coarse bucket function: an ordered set of Labels (len N) and the ascending Thresholds (len N-1) that separate them. The SAME BucketLadder value is used both to EVALUATE a raw value (Index) and to CONTRIBUTE to registry_hash (via its canonical encoding in hash.go) — so changing a threshold or label is structurally impossible without also changing the hash; there is no second, separately-maintained copy of the boundaries to drift out of sync.

Descending controls direction: false means higher raw values map to HIGHER bucket indices (e.g. uptime: longer uptime = a later/healthier bucket); true means higher raw values map to LOWER bucket indices (e.g. days-until-expiry: more days remaining = an earlier/healthier bucket).

func (*BucketLadder) Index

func (b *BucketLadder) Index(x float64) float64

Index evaluates x against the ladder and returns its bucket index (as a float64, matching the Descriptor.Read signature). For a non-Descending ladder, Index is the count of thresholds x is >= to (an ascending step function). For a Descending ladder, Index is (N-1) minus the count of thresholds x is > (so a larger x — further from any threshold — lands in the lowest, "healthiest" bucket).

func (*BucketLadder) Validate

func (b *BucketLadder) Validate() error

Validate enforces the structural invariants a BucketLadder must satisfy to be a well-formed, unambiguous step function: at least one label, exactly len(Labels)-1 thresholds, no empty or duplicate label, and thresholds that are finite and strictly ascending (a non-ascending or repeated threshold would make Index's step function ambiguous, and NaN/Inf can never be a meaningful day/duration cut point). A nil ladder is valid (it simply means "this descriptor has no bucket definition").

type Descriptor

type Descriptor struct {
	ID                string
	Type              MetricType
	PrivacyClass      PrivacyClass
	InSupportBundle   bool
	TelemetryEligible bool
	TelemetryReason   string
	Buckets           *BucketLadder
	Read              func() float64
}

Descriptor is one governed support-health metric. Conceptually equivalent to the merged design's supportMetricDescriptor (§6): a stable ID, its wire type, its privacy classification, whether it belongs to the support bundle's health section, whether it is approved for telemetry (default DENY — the zero value is false), a mandatory justification when eligible, and the live read. Buckets is populated only for coarse-bucketed metrics and is the SAME BucketLadder value the Read closure evaluates against (see buckets.go) — it participates in registry_hash so a threshold change is a governed schema change, not a silent behavior change.

Descriptors are read-only after Registry construction: nothing in this package mutates a Descriptor once assembled into a Registry.

type MetricType

type MetricType int

MetricType is the wire kind of a governed metric. Every value is a label-free scalar regardless of kind — Counter is reserved for a future monotonic support-health signal; Slice 1 uses Gauge exclusively. The zero value is MetricTypeUnknown (fails Validate) rather than a real kind like Gauge, so an omitted/forgotten classification is caught, not silently treated as valid (fail-closed).

const (
	MetricTypeUnknown MetricType = iota
	Gauge
	Counter
)

MetricType values.

func (MetricType) String

func (t MetricType) String() string

type PrivacyClass

type PrivacyClass int

PrivacyClass records why a metric is (or would be) safe to leave the appliance. The zero value is PrivacyClassUnknown (fails Validate) rather than Public, so an omitted classification is caught instead of defaulting to the most permissive class (fail-closed). LocalOnly is defined for completeness/future entries that are support-bundle-only and must never be telemetry-eligible — enforced below.

const (
	PrivacyClassUnknown PrivacyClass = iota
	Public
	Aggregate
	LocalOnly
)

PrivacyClass values.

func (PrivacyClass) String

func (c PrivacyClass) String() string

type Registry

type Registry []Descriptor

Registry is a scoped, immutable-after-construction set of support-health metric descriptors. It is NOT a general-purpose metrics registry — see the package doc comment.

func (Registry) BuildSample

func (r Registry) BuildSample(now time.Time, epoch string, sequence uint64) (Sample, error)

BuildSample constructs ONE immutable telemetry sample from the registry's current TelemetryEligible descriptors. It is side-effect-free: it only calls each eligible descriptor's Read() closure, performs no I/O, starts no goroutine, persists nothing, and never mutates the receiver.

now, epoch, and sequence are all caller-supplied (never generated internally) — mirroring the merged design's conceptual buildSupportTelemetrySample(now, epoch, sequence) signature (§5). Slice 1 has no persistent per-process epoch generator or delivery sequence counter (that machinery belongs to Slice 3's sender/spool); the preview caller supplies a process-lifetime epoch and sequence 0 (see support_telemetry_registry.go), and a future sender supplies its own real epoch/sequence through this same, unchanged function.

Caller-supplied inputs are validated, not merely trusted: now must be non-zero, epoch must be exactly a 128-bit lowercase-hex token (the wire format, §5), and every eligible metric's Read() value must be finite (a NaN/Inf would serialize as invalid or misleading JSON and has no legitimate meaning for any of the §7 gauge/bucket metrics).

func (Registry) BundleSnapshot

func (r Registry) BundleSnapshot() (map[string]float64, error)

BundleSnapshot reads every InSupportBundle descriptor's current value. This is what makes the registry an ACTUAL shared source for support-bundle health (§6) rather than only a metadata claim: the support bundle's health section (package main) calls this directly — the exact same Read closures and the exact same registry the telemetry sample/preview use — so a metric present in the bundle is provably the same metric (and the same live value) telemetry would show, not a separately-maintained mirror. Side-effect-free, like BuildSample.

func (Registry) Eligible

func (r Registry) Eligible() []Descriptor

Eligible returns the subset of descriptors approved for telemetry, in registry order.

func (Registry) Hash

func (r Registry) Hash() string

Hash computes the deterministic registry_hash (§8): a lowercase-hex SHA-256 over the governed schema — SchemaVersion plus, for EVERY descriptor sorted by ID, (ID, Type, PrivacyClass, TelemetryEligible, bucket ladder). It is:

  • stable across process restarts (pure function of the descriptor values, no randomness, no wall-clock);
  • independent of the registry's construction/iteration order (sorted internally);
  • independent of metric VALUES (Read is never called here);
  • changed by any eligibility change, and by any change to a governed bucket ladder's labels OR thresholds — Descriptor.Buckets is the SAME *BucketLadder value Read evaluates against (buckets.go), so a threshold edit cannot silently diverge from what the hash commits to.

Every field is either drawn from a closed, code-controlled vocabulary (idPattern-constrained IDs, the fixed Type/PrivacyClass enum strings) or written through writeBucketLadder's length-prefixed / fixed-width encoding — never a delimiter-joined string, so no field value can forge a collision with its neighbor.

func (Registry) InBundle

func (r Registry) InBundle() []Descriptor

InBundle returns the subset of descriptors marked InSupportBundle, in registry order.

func (Registry) Validate

func (r Registry) Validate() error

Validate enforces the structural invariants every descriptor must satisfy: non-empty label-free-safe ID, no duplicate IDs, a valid (non-Unknown) Type and PrivacyClass, a live Read callback, and — the default-deny contract — a non-empty TelemetryReason on every TelemetryEligible entry, which must also be marked InSupportBundle (the telemetry-eligible set is always a subset of the support-bundle set, §15 TestSupportTelemetrySubset) and must NOT be PrivacyClass LocalOnly (a LocalOnly classification is a positive declaration that the value must never leave the box; TelemetryEligible on such an entry is a contradiction, not a policy choice).

type Sample

type Sample struct {
	// contains filtered or unexported fields
}

Sample is one immutable support-telemetry sample: the governed schema identity (SchemaVersion + RegistryHash), the delivery-identity fields the merged wire contract carries in its inner sealed plaintext (SampleEpoch + Sequence, §5 — non-identifying: SampleEpoch is a random per-process-epoch token, Sequence a per-epoch counter; Slice 1 does not generate or persist these — the caller supplies them, see BuildSample), a generation timestamp, and the current value of every telemetry-eligible metric. It carries no stable appliance identity — no node id, hostname, IP, tenant id, or credential — by construction.

EVERY field is unexported. Once BuildSample returns a Sample, there is no exported API — field, method, or otherwise — that can change what it reports: each accessor either returns an immutable value type (int, string, time.Time, uint64) or, for Metrics(), a fresh defensive copy of the internal map. MarshalJSON serializes the Sample's OWN internal state directly, never a copy a caller could have mutated in between. This is what lets the preview handler and a future sender share the exact same built Sample without either one being able to invalidate the other's view of it, and it is what makes "the preview is the exact sample" a provable claim rather than a comment.

func (Sample) GeneratedAt

func (s Sample) GeneratedAt() time.Time

GeneratedAt is the RFC3339 UTC timestamp this sample was built.

func (Sample) MarshalJSON

func (s Sample) MarshalJSON() ([]byte, error)

MarshalJSON serializes the sample's own internal state directly (not a copy obtained through an accessor), so canonical-bytes comparisons (§8 TestSupportTelemetryPreviewMatchesBuiltSample) are comparing the one built Sample, not two independently-copied views of it. This IS the complete §3.3 inner-sample shape — a preview that renders a Sample via this method is losslessly rendering the exact sample a future sender would seal, not a partial projection of it.

func (Sample) Metrics

func (s Sample) Metrics() map[string]float64

Metrics returns a defensive copy of the sample's telemetry-eligible metric id → value map. Mutating the returned map never affects the Sample.

func (Sample) RegistryHash

func (s Sample) RegistryHash() string

RegistryHash is the registry_hash this sample's schema was built against.

func (Sample) SampleEpoch

func (s Sample) SampleEpoch() string

SampleEpoch is the caller-supplied, non-identifying process/reset-epoch token (§5) — never a stable appliance fingerprint.

func (Sample) SchemaVersion

func (s Sample) SchemaVersion() int

SchemaVersion is the governed telemetry wire-schema version this sample was built against.

func (Sample) Sequence

func (s Sample) Sequence() uint64

Sequence is the caller-supplied per-epoch delivery sequence number (§5).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL