Documentation
¶
Overview ¶
Package benchmark reduces fixture-supplied benchmark observations into a deterministic, versioned report. It performs no workload execution or external I/O.
Index ¶
- Constants
- func CanonicalJSON(value any) ([]byte, error)
- func EncodeAccuracyReport(w io.Writer, report AccuracyReport) error
- func EncodeReport(w io.Writer, report Report) error
- func SHA256Digest(data []byte) string
- func StrictDecode(reader io.Reader, destination any) error
- func ValidateJSONDocument(reader io.Reader) error
- func WriteCanonicalJSON(writer io.Writer, encoded []byte) error
- type APIFailoverObservation
- type APIFailoverSummary
- type AccuracyInput
- type AccuracyObservation
- type AccuracyReport
- type CorrectnessObservation
- type CorrectnessSummary
- type EvidenceGrowth
- type EvidenceGrowthSummary
- type GroupAccuracy
- type Input
- type Metadata
- type Metrics
- type MigrationObservation
- type PoolObservation
- type PoolSummary
- type Quantiles
- type QueueObservation
- type QueueSummary
- type Report
- type RequestObservation
- type RequestSummary
- type Throughput
- type Window
Constants ¶
const ( // AccuracyInputSchemaVersion / AccuracyReportSchemaVersion version the accuracy // document shapes independently of the throughput benchmark schemas above. AccuracyInputSchemaVersion = "synapse-accuracy-input-v1" AccuracyReportSchemaVersion = "synapse-accuracy-report-v1" )
const ( InputSchemaVersion = "synapse-benchmark-input-v1" OutputSchemaVersion = "synapse-benchmark-report-v1" )
const MaxJSONBytes int64 = 8 << 20
MaxJSONBytes bounds one untrusted benchmark JSON document before decoding or publication.
Variables ¶
This section is empty.
Functions ¶
func CanonicalJSON ¶
CanonicalJSON encodes a value with encoding/json's deterministic struct and map ordering. Callers must canonicalize order-insensitive slices before calling it.
func EncodeAccuracyReport ¶
func EncodeAccuracyReport(w io.Writer, report AccuracyReport) error
EncodeAccuracyReport writes one stable, indented JSON document followed by a newline.
func EncodeReport ¶
EncodeReport writes one stable, indented JSON document followed by a newline.
func SHA256Digest ¶
SHA256Digest returns a lower-case immutable SHA-256 digest with its algorithm prefix.
func StrictDecode ¶
StrictDecode validates one bounded JSON document, recursively rejects unknown object fields, and decodes it.
func ValidateJSONDocument ¶
ValidateJSONDocument applies bounded, UTF-8, depth, duplicate-key, and single-value checks.
Types ¶
type APIFailoverObservation ¶
type APIFailoverSummary ¶
type AccuracyInput ¶
type AccuracyInput struct {
SchemaVersion string `json:"schema_version"`
Observations []AccuracyObservation `json:"observations"`
}
AccuracyInput is a set of observations to reduce.
func DecodeAccuracyInput ¶
func DecodeAccuracyInput(r io.Reader) (AccuracyInput, error)
DecodeAccuracyInput reads exactly one accuracy input document, rejecting unknown fields.
type AccuracyObservation ¶
type AccuracyObservation struct {
Case string `json:"case"`
Group string `json:"group,omitempty"`
Expected []string `json:"expected"`
Produced []string `json:"produced"`
}
AccuracyObservation is one evaluation case: the ground-truth detection keys and the keys the engine produced for the same input. Keys are opaque, already-normalized strings (the caller decides the vocabulary, e.g. "component|CVE-id"); matching here is exact set membership. Group buckets the case (e.g. by ecosystem) for a per-group ratchet; an empty Group counts only toward the overall totals.
type AccuracyReport ¶
type AccuracyReport struct {
SchemaVersion string `json:"schema_version"`
Cases int64 `json:"cases"`
Overall Metrics `json:"overall"`
Groups []GroupAccuracy `json:"groups"`
}
AccuracyReport is the deterministic reduction of an AccuracyInput.
func EvaluateAccuracy ¶
func EvaluateAccuracy(input AccuracyInput) (AccuracyReport, error)
EvaluateAccuracy validates and reduces the observations. It makes no measurements.
type CorrectnessObservation ¶
type CorrectnessSummary ¶
type EvidenceGrowth ¶
type EvidenceGrowthSummary ¶
type EvidenceGrowthSummary struct {
DatabaseBeforeBytes int64 `json:"database_before_bytes"`
DatabaseAfterBytes int64 `json:"database_after_bytes"`
DatabaseGrowthBytes int64 `json:"database_growth_bytes"`
ObjectBeforeBytes int64 `json:"object_before_bytes"`
ObjectAfterBytes int64 `json:"object_after_bytes"`
ObjectGrowthBytes int64 `json:"object_growth_bytes"`
}
type GroupAccuracy ¶
type GroupAccuracy struct {
Group string `json:"group"`
Cases int64 `json:"cases"`
Metrics Metrics `json:"metrics"`
}
GroupAccuracy is the reduction for one group, identified by its label.
type Input ¶
type Input struct {
SchemaVersion string `json:"schema_version"`
Metadata Metadata `json:"metadata"`
Window Window `json:"window"`
Requests []RequestObservation `json:"requests"`
Queue QueueObservation `json:"queue"`
Pool PoolObservation `json:"pool"`
Evidence EvidenceGrowth `json:"evidence"`
Migration MigrationObservation `json:"migration"`
APIFailovers []APIFailoverObservation `json:"api_failovers"`
Correctness []CorrectnessObservation `json:"correctness"`
}
Input is a fixture or runner-produced set of measured benchmark observations.
type Metadata ¶
type Metadata struct {
Environment string `json:"environment"`
EnvironmentDigest string `json:"environment_digest"`
Release string `json:"release"`
ReleaseDigest string `json:"release_digest"`
DataDigest string `json:"data_digest"`
}
Metadata identifies exactly what was measured without deriving release or data state.
type Metrics ¶
type Metrics struct {
TruePositives int64 `json:"true_positives"`
FalsePositives int64 `json:"false_positives"`
FalseNegatives int64 `json:"false_negatives"`
Precision float64 `json:"precision"`
Recall float64 `json:"recall"`
F1 float64 `json:"f1"`
FalseDiscoveryRate float64 `json:"false_discovery_rate"`
FalseNegativeRate float64 `json:"false_negative_rate"`
}
Metrics is the reduced confusion-matrix summary. Rates use these conventions so the no-data cases never produce a NaN that would make a ratchet undefined:
- Precision = TP/(TP+FP); 1.0 when nothing was produced (no false alarms).
- Recall = TP/(TP+FN); 1.0 when nothing was expected (nothing to miss).
- F1 = 2PR/(P+R); 0 when P+R == 0.
- FalseDiscoveryRate = FP/(TP+FP) = 1 - Precision; 0 when nothing was produced. This is deliberately the false-discovery rate, not the textbook false-positive rate FP/(FP+TN): detection has no bounded universe of true negatives to count, so FPR is not computable.
- FalseNegativeRate = FN/(TP+FN) = 1 - Recall (the miss rate); 0 when nothing was expected.
type MigrationObservation ¶
type MigrationObservation struct {
DurationMilliseconds int64 `json:"duration_milliseconds"`
}
type PoolObservation ¶
type PoolSummary ¶
type Quantiles ¶
type Quantiles struct {
Count int64 `json:"count"`
P50 int64 `json:"p50"`
P95 int64 `json:"p95"`
P99 int64 `json:"p99"`
}
Quantiles use the nearest-rank method: rank=ceil(p*n), with the first value at rank 1.
type QueueObservation ¶
type QueueSummary ¶
type Report ¶
type Report struct {
SchemaVersion string `json:"schema_version"`
Metadata Metadata `json:"metadata"`
Throughput Throughput `json:"throughput"`
Requests RequestSummary `json:"requests"`
Queue QueueSummary `json:"queue"`
Pool PoolSummary `json:"pool"`
Evidence EvidenceGrowthSummary `json:"evidence"`
Migration MigrationObservation `json:"migration"`
APIFailover APIFailoverSummary `json:"api_failover"`
Correctness CorrectnessSummary `json:"correctness"`
}
Report is a deterministic reduction of Input. It never asserts an SLO or target.