advisor

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 10 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"`
}

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.

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 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 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 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