readproof

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package readproof holds the untagged half of the read-latency proof (issue #289, decision #281): the result schema, exact ordered percentiles, threshold evaluation and the JSON writer. The tagged half (build tag readproof) starts the exact binary, prefills a shape and fills these structures in.

The JSON is the source of truth. Every objective produces an assertion that carries the measured number and the objective; missing evidence is a failed assertion with its reason, never a blank.

Index

Constants

View Source
const (
	RSSMetric              = "otelcontext_process_resident_memory_bytes"
	HeapMetric             = "otelcontext_go_heap_inuse_bytes"
	RegistryEntriesMetric  = "otelcontext_resource_registry_entries"
	GraphRAGEntitiesMetric = "otelcontext_graphrag_store_entities"
	GraphRAGEdgesMetric    = "otelcontext_graphrag_store_edges"
	ReadCacheEntriesMetric = "otelcontext_read_cache_entries"
)

Metric names the proof reads from the server's Prometheus exposition.

View Source
const FileName = "read-latency-v1.json"

FileName is the artifact written into OTELCONTEXT_PROOF_DIR.

View Source
const MiB = 1 << 20

MiB is the unit the memory objectives are written in.

View Source
const SchemaVersion = "otelcontext.read-latency.v1"

SchemaVersion identifies the artifact layout.

Variables

This section is empty.

Functions

func Gauge

func Gauge(samples []MetricSample, name string) (float64, error)

Gauge returns the single unlabelled sample of name.

func GaugeByLabel

func GaugeByLabel(samples []MetricSample, name, label string) map[string]int64

GaugeByLabel maps one label's values to the sample values for name.

func GaugeSum

func GaugeSum(samples []MetricSample, name string, want map[string]string) int64

GaugeSum adds every sample of name whose labels include want.

func NearestRank

func NearestRank(samples []float64, q float64) float64

NearestRank returns the exact ordered q-quantile of samples (0 < q <= 1): the value at rank ceil(q*n), never interpolated. Zero when empty.

func SummarizeRSS

func SummarizeRSS(r *RSS, steadyFrom float64)

SummarizeRSS fills the peaks and the exact ordered p95 over samples taken at or after steadyFrom seconds.

Types

type Assertion

type Assertion struct {
	Name      string  `json:"name"`
	Passed    bool    `json:"passed"`
	Measured  float64 `json:"measured"`
	Objective float64 `json:"objective"`
	Unit      string  `json:"unit"`
	Detail    string  `json:"detail"`
}

Assertion is one named check carrying its number and its objective.

func Evaluate

func Evaluate(p *Proof) []Assertion

Evaluate scores every asserted measurement against the objectives. Each asserted endpoint yields exactly two assertions, whether or not it was measured: a missing or failed measurement fails both with the reason. An RSS objective (#283) adds one more, `rss.steady_p95_bytes`.

func Failed

func Failed(assertions []Assertion) []Assertion

Failed lists the assertions that did not pass.

type Call

type Call struct {
	MS       float64 `json:"ms"`
	Status   int     `json:"status"`
	Bytes    int     `json:"bytes"`
	Coverage string  `json:"coverage"`
	// BodyCoverage is the `coverage` field of an object-shaped body; the
	// dashboard and service-map views carry coverage there, not in the header.
	BodyCoverage string `json:"body_coverage,omitempty"`
	Error        string `json:"error,omitempty"`
}

Call is one recorded response.

type Mappings

type Mappings struct {
	Seconds    float64 `json:"t_s"`
	TotalBytes int64   `json:"total_bytes"`
	// GoHeapBytes is "[anon: Go: heap]": the runtime heap arenas.
	GoHeapBytes int64 `json:"go_heap_bytes"`
	// GoRuntimeBytes is every other named Go mapping (metadata, GC bits,
	// spans, scavenger structures) plus the main thread stack and vDSO.
	GoRuntimeBytes int64 `json:"go_runtime_bytes"`
	// OtherAnonBytes is unnamed anonymous memory: with the pure-Go SQLite
	// driver this is modernc's libc allocator — the page cache, the sorter
	// and temp tables — plus anything else outside the Go heap.
	OtherAnonBytes int64 `json:"other_anon_bytes"`
	// FileBytes is file-backed and shmem-backed residency: an mmapped
	// database, shared libraries, tmpfs files.
	FileBytes int64 `json:"file_bytes"`
	// BinaryBytes is the executable's own text and data.
	BinaryBytes int64  `json:"binary_bytes"`
	Error       string `json:"error,omitempty"`
}

Mappings is the resident set broken down by mapping owner, in bytes, from one /proc/<pid>/smaps read. The Go runtime names its mappings (Linux prctl PR_SET_VMA), which is what separates the heap from everything else.

func ParseSmaps

func ParseSmaps(text, binary string) Mappings

ParseSmaps classifies every mapping in a /proc/<pid>/smaps payload and sums its Rss; binary is the executable path.

type Measurement

type Measurement struct {
	Name      string `json:"name"`
	Kind      string `json:"kind"` // rest | mcp
	Path      string `json:"path,omitempty"`
	Query     string `json:"query,omitempty"`
	Tool      string `json:"tool,omitempty"`
	Arguments string `json:"arguments,omitempty"`
	// Cache is "client" when the request is what a real client sends and
	// "miss" when an ignored nonce argument defeats the MCP result cache.
	Cache    string `json:"cache,omitempty"`
	Asserted bool   `json:"asserted"`

	Cold          Call        `json:"cold"`
	Warmup        int         `json:"warmup"`
	Requests      int         `json:"requests"`
	BudgetSeconds float64     `json:"budget_seconds"`
	Seconds       float64     `json:"seconds"`
	Latency       Percentiles `json:"latency"`
	SamplesMS     []float64   `json:"samples_ms"`
	Status        int         `json:"status"`
	Coverage      string      `json:"coverage"`
	BodyCoverage  string      `json:"body_coverage,omitempty"`
	// RequestedStart and EffectiveStart are the aggregate range-clamp
	// headers (#217), present only when the server shortened the range.
	RequestedStart string `json:"requested_start,omitempty"`
	EffectiveStart string `json:"effective_start,omitempty"`
	ResponseBytes  int    `json:"response_bytes"`
	MaxBytes       int    `json:"response_bytes_max"`
	CacheHits      int    `json:"cache_hits"`
	Errors         int    `json:"errors"`
	Error          string `json:"error,omitempty"`
}

Measurement is one endpoint's evidence.

type MemoryAccounting

type MemoryAccounting struct {
	Seconds        float64 `json:"t_s"`
	RSSBytes       int64   `json:"rss_bytes"`
	HeapInuseBytes int64   `json:"heap_inuse_bytes"`
	// Registry counts are summed over tenants: kind=pair entries and
	// kind=host distinct hosts.
	RegistryPairEntries int64 `json:"registry_pair_entries"`
	RegistryHostEntries int64 `json:"registry_host_entries"`
	// GraphRAG counts are the census gauges by entity kind and edge store.
	GraphRAGEntities map[string]int64 `json:"graphrag_entities"`
	GraphRAGEdges    map[string]int64 `json:"graphrag_edges"`
	// LatencySketchBytes is latency_sketches × the fixed size of one
	// aggregate.Sketch value.
	LatencySketchBytes int64 `json:"graphrag_latency_sketch_bytes"`
	// ReadCacheEntries is otelcontext_read_cache_entries by cache name.
	ReadCacheEntries map[string]int64 `json:"read_cache_entries"`
	// MappingsBefore and MappingsAfter break the RSS down by mapping owner
	// from /proc/<pid>/smaps at the start and the end of the read phase, so
	// growth under reads is attributed rather than guessed.
	MappingsBefore Mappings `json:"mappings_before_reads"`
	MappingsAfter  Mappings `json:"mappings_after_reads"`
	Error          string   `json:"error,omitempty"`
}

MemoryAccounting says where the memory sits at the end of the measurement phase: one /metrics read of the counts the resource registry, the GraphRAG stores (with the #291 latency sketches) and the read caches publish, next to the RSS and heap gauges scraped at the same instant.

func Account

func Account(samples []MetricSample, sketchBytes int64) MemoryAccounting

Account fills the accounting from one exposition read; sketchBytes is the size of one aggregate.Sketch value.

type MetricSample

type MetricSample struct {
	Name   string
	Labels map[string]string
	Value  float64
}

MetricSample is one line of Prometheus text exposition.

func ParseMetrics

func ParseMetrics(text string) ([]MetricSample, error)

ParseMetrics reads Prometheus text exposition into samples. Comment and blank lines are skipped; a malformed line is an error naming it.

type Objectives

type Objectives struct {
	Requests          int     `json:"requests"`
	WarmP99MS         float64 `json:"warm_p99_ms"`
	ColdMS            float64 `json:"cold_ms"`
	RSSSteadyP95Bytes int64   `json:"rss_steady_p95_bytes"`
}

Objectives are the decision's numbers for one shape: latency from #281, RSS steady p95 from #283.

type Percentiles

type Percentiles struct {
	P50 float64 `json:"p50_ms"`
	P90 float64 `json:"p90_ms"`
	P99 float64 `json:"p99_ms"`
	Max float64 `json:"max_ms"`
}

Percentiles are exact ordered (nearest-rank) statistics in milliseconds.

func Summarize

func Summarize(samples []float64) Percentiles

Summarize computes the four exact percentiles of a sample set.

type Prefill

type Prefill struct {
	Seconds  float64 `json:"seconds"`
	Services int     `json:"services"`
	Error    string  `json:"error,omitempty"`

	// Aggregate shape.
	Windows          int   `json:"windows,omitempty"`
	RequestedWindows int   `json:"requested_windows,omitempty"`
	Series           int   `json:"series,omitempty"`
	AggregateDBBytes int64 `json:"aggregate_db_bytes,omitempty"`

	// Legacy shape.
	Days       int   `json:"days,omitempty"`
	Traces     int   `json:"traces,omitempty"`
	Spans      int   `json:"spans,omitempty"`
	Logs       int   `json:"logs,omitempty"`
	MainDBByte int64 `json:"main_db_bytes,omitempty"`
}

Prefill describes the seeded history. Fields are shape-specific.

type Proof

type Proof struct {
	SchemaVersion string            `json:"schema_version"`
	Shape         string            `json:"shape"`
	GeneratedAt   string            `json:"generated_at"`
	GoVersion     string            `json:"go_version"`
	BinarySHA256  string            `json:"binary_sha256"`
	ServerEnv     map[string]string `json:"server_env"`
	Prefill       Prefill           `json:"prefill"`
	ReadySeconds  float64           `json:"ready_seconds"`
	Objectives    Objectives        `json:"objectives"`
	Measurements  []*Measurement    `json:"measurements"`
	RSS           RSS               `json:"rss"`
	Memory        MemoryAccounting  `json:"memory_accounting"`
	Assertions    []Assertion       `json:"assertions"`
	Duration      float64           `json:"duration_seconds"`
	Notes         []string          `json:"notes,omitempty"`
}

Proof is the artifact.

func (*Proof) Write

func (p *Proof) Write(dir string) (string, error)

Write evaluates the proof and writes it to dir/FileName.

type RSS

type RSS struct {
	Source            string      `json:"source"`
	Samples           []RSSSample `json:"samples"`
	PeakBytes         int64       `json:"peak_bytes"`
	HeapPeakBytes     int64       `json:"heap_inuse_peak_bytes"`
	SteadyFromSeconds float64     `json:"steady_from_s"`
	// SettleSeconds is how long the harness waited after seeding for the
	// runtime's first GC cycle; SteadyRule says how the window was chosen.
	SettleSeconds float64 `json:"settle_s"`
	SteadyRule    string  `json:"steady_rule"`
	// SteadyReached is false when the harness ran out of budget before the
	// RSS gauge plateaued under the read workload; SteadyReason says where
	// it stood. The assertion then fails: an under-sampled p95 is not
	// evidence.
	SteadyReached  bool   `json:"steady_reached"`
	SteadyReason   string `json:"steady_reason,omitempty"`
	SteadyP95Bytes int64  `json:"steady_p95_bytes"`
	SteadySamples  int    `json:"steady_samples"`
	Error          string `json:"error,omitempty"`
}

RSS is the server's resident-set series across the run, read from the server's /metrics every 5 s. Peak spans the whole run; the steady p95 is the exact ordered p95 over samples taken at or after SteadyFromSeconds — the start of the measurement phase, once prefill and readiness are done — and is what #283's objective is asserted against.

type RSSSample

type RSSSample struct {
	Seconds   float64 `json:"t_s"`
	Bytes     int64   `json:"bytes"`
	HeapBytes int64   `json:"heap_inuse_bytes"`
}

RSSSample is one scrape of the server's own memory gauges, offset from server start: otelcontext_process_resident_memory_bytes and otelcontext_go_heap_inuse_bytes.

Jump to

Keyboard shortcuts

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