server

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Overview

Package server is the upgradescope continuous-mode server: snapshot ingest, persisted evaluations, a read API, and on-demand what-if re-evaluation. Storage is behind store.Store; the CLI owns flag parsing and store construction (DB path never reaches this package).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeDelta

func ComputeDelta(prev *engine.Report, curr engine.Report) []notify.Event

ComputeDelta implements the notification delta rules (shared contract):

  • prev == nil (first-ever evaluation of this cluster+target) → no events.
  • Blocker findings added since prev (diff by stable finding key) → one new-blocker event each, capped at maxBlockerEvents, then a single "and N more".
  • Blocker count went >0 → 0 → one became-ready event.
  • eol-approaching warnings added since prev (by key) → one event each.

Identity is Finding.Key — deliberately count-free, so a title-only change ("3 objects" → "2 objects") never re-alerts the same blocker. Findings with an empty Key (reports stored before Key existed) fall back to Title. Duplicate keys within one report emit one event (first occurrence wins).

Event.Cluster is filled with curr.ClusterID (the inventory UID); the caller (notifyDelta) overwrites it with the human cluster name from the push envelope before delivery. Order is deterministic: new-blockers in report order, summary, became-ready, eol-approaching in report order.

func WhatIf

func WhatIf(ctx context.Context, st store.Store, k kb.KB, tm TeamMap, clusterID int64, target inventory.Version, now time.Time) (engine.Report, error)

WhatIf re-evaluates a cluster's latest stored snapshot against an arbitrary target using the server's KB. Nothing is stored. now is injected by the caller (the server passes s.now()) so EOL-window math stays deterministic and testable. tm (nil = no-op) applies the server's namespace→team override, matching what evaluateSnapshot stores. Returns store.ErrNotFound (wrapped) when the cluster has no snapshots.

Types

type Config

type Config struct {
	Listen       string          // listen address for Start, e.g. ":8080"
	Store        store.Store     // required
	KB           kb.KB           // evaluation knowledge base
	ExtraTargets []string        // minors evaluated for every snapshot, e.g. ["1.37"]
	Notifier     notify.Notifier // nil = notifications disabled
	IngestToken  string          // required bearer for POST /api/v1/snapshots
	ReadToken    string          // optional bearer for the read API; "" = open (document loudly)
	TeamMap      TeamMap         // optional namespace→team override, applied before every Evaluate
	Version      string          // build version stamped into SARIF tool metadata ("" = omitted)
}

Config wires a Server.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server serves the ingest + read API. Construct with New; a Server is single-use (one Start/Shutdown cycle).

func New

func New(cfg Config) (*Server, error)

New validates cfg and builds the route table.

func (*Server) Addr

func (s *Server) Addr() string

Addr returns the bound listen address ("" before Ready is closed).

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler exposes the full route table (API + dashboard fallback) for httptest and embedding.

func (*Server) Ready

func (s *Server) Ready() <-chan struct{}

Ready is closed once the listener is bound. It is NEVER closed when Listen fails — Start just returns the error — so callers must not block on Ready alone: run Start in a goroutine and select on Ready() AND the goroutine's error channel, or a bad Listen address hangs the caller.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown gracefully drains in-flight requests, then unblocks Start.

func (*Server) Start

func (s *Server) Start() error

Start binds Config.Listen and serves until Shutdown. It returns nil after a clean Shutdown, otherwise the listen/serve error. Once Ready() is closed, Addr() reports the bound address (Listen ":0" works in tests).

type TeamMap

type TeamMap []TeamMapRule

TeamMap is the server-side namespace→team override (spec: labels + server override). It is applied over the namespace team labels carried in the inventory at evaluation time — a matching rule replaces the label; a namespace matching no rule keeps its label. A nil/empty TeamMap is a no-op.

func LoadTeamMap

func LoadTeamMap(p string) (TeamMap, error)

LoadTeamMap reads and parses a --team-map YAML file.

func ParseTeamMap

func ParseTeamMap(data []byte) (TeamMap, error)

ParseTeamMap parses YAML of the form:

  • pattern: "payments-*" team: payments

Every rule must have a non-empty pattern (valid path.Match glob) and team.

func (TeamMap) Apply

Apply returns a rewritten copy of ns: for each namespace, the first rule whose glob matches sets the team; no match keeps the inventory label. The input slice is never mutated (it may alias a caller's inventory).

type TeamMapRule

type TeamMapRule struct {
	Pattern string `json:"pattern"`
	Team    string `json:"team"`
}

TeamMapRule maps namespaces matching a glob Pattern (path.Match grammar) to Team. Rules are ordered; the first matching pattern wins.

Directories

Path Synopsis
Package notify defines the notification seam fired on finding deltas (new blocker, became-ready, add-on entering the EOL window) — never on every snapshot.
Package notify defines the notification seam fired on finding deltas (new blocker, became-ready, add-on entering the EOL window) — never on every snapshot.
Package store persists clusters, snapshots and evaluations for the upgradescope server.
Package store persists clusters, snapshots and evaluations for the upgradescope server.
storetest
Package storetest pins the behavioral contract of store.Store.
Package storetest pins the behavioral contract of store.Store.

Jump to

Keyboard shortcuts

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