advisor

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package advisor detects well-known ISUCON-critical settings that are NOT configured (prepared-statement round trips, nginx gzip/keepalive, kernel limits, GOMAXPROCS vs CPU quota, MySQL sizing) and reports them so the dashboard always shows what standard lever has not been pulled yet. Every check is fail-open: inspection problems degrade to StatusSkip.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheTelemetry added in v1.1.0

type CacheTelemetry struct {
	Hits   uint64 `json:"hits"`
	Misses uint64 `json:"misses"`
	// Evictions counts entries removed before their TTL expired
	// (capacity pressure), e.g. memcached evictions / redis evicted_keys.
	Evictions uint64 `json:"evictions"`
}

CacheTelemetry is an interval-aligned application cache snapshot (memcached "stats", redis/valkey INFO stats, or equivalent). HTTP middleware cannot observe cache internals, so values must be explicit.

type Check

type Check struct {
	ID             string     `json:"id"`
	Title          string     `json:"title"`
	Status         Status     `json:"status"`
	Detail         string     `json:"detail,omitempty"`
	Recommendation string     `json:"recommendation,omitempty"`
	Provenance     Provenance `json:"provenance"`
}

Check is one advisor finding.

func Collect

func Collect(ctx context.Context, opts Options) []Check

Collect runs every check and returns findings sorted most-severe first.

func WithCacheTelemetry added in v1.1.0

func WithCacheTelemetry(checks []Check, telemetry *CacheTelemetry, err error) []Check

WithCacheTelemetry replaces the application cache check at snapshot time so hit/miss/eviction counters align with the measured interval.

func WithProtocolTraffic added in v1.1.0

func WithProtocolTraffic(checks []Check, source string, samples []ProtocolSample) []Check

WithProtocolTraffic replaces the dynamic HTTP/3 traffic check using one measurement source. Proxy access-log samples should be preferred because a reverse proxy hides the client protocol from application middleware.

func WithProtocolTrafficEvidence added in v1.1.0

func WithProtocolTrafficEvidence(checks []Check, source string, clientFacing bool, samples []ProtocolSample) []Check

WithProtocolTrafficEvidence replaces the traffic check and records whether the source observes the client-facing hop. Origin logs behind an edge must never be interpreted as client-to-edge HTTP/3 evidence.

func WithQUICTelemetry added in v1.1.0

func WithQUICTelemetry(checks []Check, telemetry *QUICTelemetry, err error) []Check

WithQUICTelemetry replaces the dynamic QUIC transport check at snapshot time. Reading telemetry late avoids freezing start-of-generation counters.

func WithQueryPlans added in v1.2.0

func WithQueryPlans(checks []Check, plans []QueryPlan, err error) []Check

WithQueryPlans replaces the query-plan checks at snapshot time, once plan 09's capture has run in the post-FinishRun enrich phase. err reports why capture could not run; like the other hooks it must carry a summary, never a driver error, because a driver message can embed a fragment of the sample SQL.

type Evidence added in v1.1.0

type Evidence string

Evidence is an explicit yes/no/unknown fact for conditions that this process cannot safely infer, such as an Internet-to-edge UDP path.

const (
	EvidenceUnknown Evidence = ""
	EvidenceYes     Evidence = "yes"
	EvidenceNo      Evidence = "no"
)

func ParseEvidence added in v1.1.0

func ParseEvidence(value string) Evidence

ParseEvidence parses environment-style readiness declarations.

type Options

type Options struct {
	DriverName string
	DSN        string
	// DB is an open raw (unproxied) connection for MySQL variable checks.
	// The caller owns closing it.
	DB *sql.DB
	// NginxConf is the concatenated nginx configuration content.
	NginxConf []byte
	// FS is the root filesystem ("/" in production, a fixture in tests).
	FS fs.FS
	// GOMAXPROCS is runtime.GOMAXPROCS(0); 0 skips the check.
	GOMAXPROCS int
	// Protocol supplies HTTP/3/QUIC readiness evidence. Configuration content
	// is inspected locally; off-host network and edge facts must be explicit.
	Protocol ProtocolOptions
	// Cache supplies application-side cache telemetry (memcached/redis
	// stats); nil skips the check. CacheError records why it could not be
	// read.
	Cache      *CacheTelemetry
	CacheError string
}

Options supplies the inspectable inputs. Zero values skip the related checks.

type PlanFreshness added in v1.2.0

type PlanFreshness string

PlanFreshness records whether a captured sample can be judged. It mirrors plan 09's FreshnessState; only "fresh" is judged, and everything else — including the zero value — is excluded from the warnings.

const (
	// PlanFreshnessFresh means the sample ran inside the measured interval.
	PlanFreshnessFresh PlanFreshness = "fresh"
	// PlanFreshnessStale means the sample ran outside the interval.
	PlanFreshnessStale PlanFreshness = "stale"
	// PlanFreshnessUnknown means freshness could not be decided (database
	// clock anomaly, missing clock, partial run, interval too short).
	PlanFreshnessUnknown PlanFreshness = "unknown"
)

type ProtocolOptions added in v1.1.0

type ProtocolOptions struct {
	ProxyKind       string
	ProxyConfig     []byte
	UDP443Reachable Evidence
	EdgeName        string
	EdgeHTTP3       Evidence
	QUIC            *QUICTelemetry
	QUICError       string
}

ProtocolOptions supplies HTTP/3/QUIC configuration and external evidence. ProxyKind accepts nginx, caddy, or envoy. An empty kind is auto-detected only when the configuration contains an unambiguous signature.

type ProtocolSample added in v1.1.0

type ProtocolSample struct {
	Protocol string
	Count    int64
	Errors   int64
	P95      time.Duration
}

ProtocolSample is one measured client-facing protocol aggregate.

type Provenance added in v1.5.0

type Provenance struct {
	RuleVersion string `json:"rule_version"`
	Category    string `json:"category"`
	Source      string `json:"source"`
	Freshness   string `json:"freshness"`
	Scope       string `json:"scope"`
	Formula     string `json:"formula"`
	Actual      string `json:"actual"`
	Unit        string `json:"unit"`
	Limitation  string `json:"limitation"`
	Docs        string `json:"docs"`
}

Provenance explains the deterministic rule without copying raw config, SQL, driver errors, DSNs or credentials into the report.

type QUICTelemetry added in v1.1.0

type QUICTelemetry struct {
	PacketsSent          uint64 `json:"packets_sent"`
	PacketsRetransmitted uint64 `json:"packets_retransmitted"`
	UDPDatagramsDropped  uint64 `json:"udp_datagrams_dropped"`
}

QUICTelemetry is an interval-aligned proxy transport snapshot. Values are normally supplied by Envoy QUIC/UDP stats or an equivalent server metric; HTTP middleware cannot observe packet retransmission or kernel UDP drops.

type QueryPlan added in v1.2.0

type QueryPlan struct {
	// TargetID names the database target, so a multi-host run can tell two
	// identical plans apart. Empty for a single-target run.
	TargetID string `json:"target_id,omitempty"`
	Digest   string `json:"digest"`
	// Query is the normalized statement text (plan 04's DIGEST_TEXT).
	Query string `json:"query,omitempty"`
	// Freshness decides whether this plan is judged at all.
	Freshness PlanFreshness `json:"freshness"`
	// FreshReason is plan 09's closed FreshReason enum ("in_interval",
	// "before_interval", "after_interval", "db_clock_anomaly",
	// "db_clock_missing", "run_partial", "interval_too_short"). Unrecognized
	// values are never echoed.
	FreshReason string `json:"fresh_reason,omitempty"`
	// Rows is the EXPLAIN output; empty when the capture failed.
	Rows []QueryPlanRow `json:"rows,omitempty"`
	// ErrClass is plan 09's closed PlanErrorClass ("timeout",
	// "budget_exhausted", "permission_denied", "syntax_or_truncated",
	// "object_missing", "sample_unavailable", "sample_possibly_truncated",
	// "connection_error", "other"). Unrecognized values are never echoed.
	ErrClass string `json:"err_class,omitempty"`
}

QueryPlan is one digest's captured plan. Query is the normalized DIGEST_TEXT supplied by plan 04, never the literal-bearing sample: plan 09 keeps the sample inside the capture callback and this type has no field able to hold it.

type QueryPlanRow added in v1.2.0

type QueryPlanRow struct {
	SelectType   *string `json:"select_type,omitempty"`
	Table        *string `json:"table,omitempty"`
	Type         *string `json:"type,omitempty"`
	Key          *string `json:"key,omitempty"`
	PossibleKeys *string `json:"possible_keys,omitempty"`
	Rows         *int64  `json:"rows,omitempty"`
	Extra        *string `json:"extra,omitempty"`
}

QueryPlanRow is one EXPLAIN output row. Every column is nullable in MySQL's classic EXPLAIN output, so each is a pointer and a nil is rendered as "なし" rather than treated as a parse failure.

type Status

type Status string

Status classifies one check result.

const (
	// StatusOK means the recommended setting is in place.
	StatusOK Status = "ok"
	// StatusMissing means a standard, high-impact setting is absent.
	StatusMissing Status = "missing"
	// StatusWarn means the current value is likely to hurt under load.
	StatusWarn Status = "warn"
	// StatusInfo is advisory context, not a defect.
	StatusInfo Status = "info"
	// StatusSkip means the check could not run (input unavailable).
	StatusSkip Status = "skip"
)

Jump to

Keyboard shortcuts

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