shadowsamples

package
v4.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package shadowsamples stores the sanitized shadow-mode mismatch samples package hosts report, and serves them to the route-mode administration.

A package host (sdk/pluginhostsdk.Router) keeps its latest mismatches, sanitized by sdk/shadowsample, in the shadow_samples list of its Health details document. The kernel polls Health; Collector reads the samples from each poll, drops those for routes the package does not own in the package extraction map, sanitizes every field again, replaces the path with the route's path template, and stores each sample once. A host has no other way to write the table, and only the fixed sample columns.

Retention: samples are deleted after Retention, and only the newest MaxPerRoute of a route are kept.

Index

Constants

View Source
const (
	// Retention is how long a sample is kept.
	Retention = 7 * 24 * time.Hour
	// MaxPerRoute is how many samples of one route are kept.
	MaxPerRoute = 100
	// MaxPerReport bounds the samples read from one Health details
	// document; a host reports at most 32.
	MaxPerReport = 32
)
View Source
const DefaultLimit = 50

DefaultLimit is how many samples List returns without a limit.

Variables

This section is empty.

Functions

func Prune

func Prune(db *gorm.DB, now time.Time) (int64, error)

Prune deletes samples older than Retention and trims every route to MaxPerRoute samples.

func Summaries

func Summaries(db *gorm.DB, packageID string) (map[string]map[string]Summary, error)

Summaries returns, by package and route, how many samples are stored and when the newest was observed. An empty packageID means every package.

Types

type Collector

type Collector struct {
	DB *gorm.DB
	// Route looks a route up in the package extraction map.
	Route func(routeID string) (RouteInfo, bool)
	// Now defaults to time.Now.
	Now func() time.Time
	// contains filtered or unexported fields
}

Collector stores the samples of Health reports.

func (*Collector) Collect

func (c *Collector) Collect(ctx context.Context, reports []Report) (int, error)

Collect ingests every report not read before and returns how many samples it stored. A failing report does not stop the others; the first error is returned.

func (*Collector) Ingest

func (c *Collector) Ingest(ctx context.Context, report Report) (int, error)

Ingest stores the new samples of one report and returns how many it stored. Samples of routes the reporting package does not own, malformed samples, and samples older than Retention are dropped.

type Filter

type Filter struct {
	PackageID string
	RouteID   string
	// Limit defaults to DefaultLimit and is at most MaxPerRoute.
	Limit int
}

Filter selects samples.

type Report

type Report struct {
	PackageID   string
	Version     string
	DetailsJSON string
	// CheckedAt is when the kernel read the document; Collect skips a
	// report it has already read.
	CheckedAt time.Time
}

Report is one package host's Health details document.

type RouteInfo

type RouteInfo struct {
	PackageID string
	// Path is the route's legacy path template.
	Path string
}

RouteInfo is what the kernel knows about a package route from the package extraction map.

type Sample

type Sample struct {
	ID             uint                     `json:"id"`
	SampleID       string                   `json:"sample_id"`
	PackageID      string                   `json:"package_id"`
	PackageVersion string                   `json:"package_version"`
	RouteID        string                   `json:"route_id"`
	Method         string                   `json:"method"`
	Path           string                   `json:"path"`
	LegacyStatus   int                      `json:"legacy_status"`
	NativeStatus   int                      `json:"native_status"`
	Diff           []shadowsample.DiffEntry `json:"diff"`
	DiffTruncated  bool                     `json:"diff_truncated"`
	RequestID      string                   `json:"request_id"`
	ObservedAt     time.Time                `json:"observed_at"`
}

Sample is a stored sample as the administration shows it.

func List

func List(db *gorm.DB, filter Filter) ([]Sample, error)

List returns the newest samples matching filter.

type Summary

type Summary struct {
	Stored         int64     `json:"stored"`
	LastObservedAt time.Time `json:"last_observed_at"`
}

Summary is what is stored about one route's mismatches.

Jump to

Keyboard shortcuts

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