services

package
v1.4.9 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const ReportSettingsBlobName = "models/settings/report-settings"

ReportSettingsBlobName is the single blob the report settings live under, in the models/settings/ namespace (a sibling of the model-state artifacts, deliberately NOT the encrypted channel store).

Variables

View Source
var (
	// ErrReportDisabled is returned when the runtime report setting
	// enable is false.
	ErrReportDisabled = errors.New("report: feature disabled")
	// ErrReportRateLimited is returned when the per-window render/send
	// token bucket is exhausted.
	ErrReportRateLimited = errors.New("report: rate limited")
	// ErrReportNoRenderer is returned when no renderer is installed.
	ErrReportNoRenderer = errors.New("report: no renderer configured")
	// ErrReportNoStorage is returned when persistence is not configured.
	ErrReportNoStorage = errors.New("report: storage not configured")
	// ErrReportNoChannel is returned when no enabled channel resolves for
	// delivery.
	ErrReportNoChannel = errors.New("report: no enabled channel resolved")
)

Functions

func AnalyzeAgent added in v1.4.3

func AnalyzeAgent() core.AIAgent

AnalyzeAgent returns the installed analyze agent or nil.

func BuildAggregateReportModel added in v1.4.8

func BuildAggregateReportModel(recs []*storage.IncidentRecord, window string, start, end time.Time, unit string, scrubber core.Scrubber, includeCharts bool) core.ReportModel

BuildAggregateReportModel assembles the channel-agnostic, already-redacted aggregate ReportModel for a window. recs are the incidents whose CreatedAt falls in [start, end) (newest first). scrubber MUST be non-nil in production (callers pass reportScrubber()); it is the DLP boundary for every attacker-influenced label. window/start/end/unit come from WindowBounds.

func CreateIncident

func CreateIncident(teamID string, content *map[string]interface{}, params ...*map[string]string) error

func CreateIncidentFromFinding added in v1.4.0

func CreateIncidentFromFinding(f *core.AIFinding, r core.AgentResult, source, service string) error

CreateIncidentFromFinding maps an AI SRE finding into the standard content map and delegates to CreateIncident so all existing channels (Slack, Telegram, MS Teams, Lark, Email, Viber) and the on-call workflow trigger with no per-channel changes.

Source identifies the agent + signal source (e.g. "agent:elasticsearch:prod-app"). Service is the operator-facing service name extracted from the log pattern; "_unknown" when no service_pattern matched.

All keys added here are stable and additive — existing template files keep working unchanged. Operators who want to surface AI-specific detail can reference {{ .Summary }}, {{ .Suggestions }}, {{ .Confidence }}, {{ .PatternID }}, {{ .Verdict }}.

func RenderIncidentsReport added in v1.4.8

func RenderIncidentsReport(ctx context.Context, window string) (*core.ReportImage, error)

RenderIncidentsReport renders the aggregate report PNG for a window (preview / download). It is read-only over stored state.

func ReportRenderer added in v1.4.8

func ReportRenderer() core.ReportRenderer

ReportRenderer returns the installed report renderer, or nil.

func SaveReportSettings added in v1.4.8

func SaveReportSettings(st storage.Provider, s ReportSettings) error

SaveReportSettings persists the settings blob after sanitizing it. It returns ErrReportNoStorage when no backend is configured so the API can map it to 503, consistent with the render/send paths.

func SetAnalyzeAgent added in v1.4.3

func SetAnalyzeAgent(a core.AIAgent)

SetAnalyzeAgent installs the analyze agent used by the admin /analyze endpoint. Pass nil to disable analyze.

func SetReportRedactor added in v1.4.8

func SetReportRedactor(s core.Scrubber)

SetReportRedactor installs the DLP scrubber every report text field is run through before it reaches the card or a channel. Boot installs the operator-configured redactor; when none is installed a safe default (the built-in agent redaction rules) is used instead, so a report is NEVER rendered from unredacted text.

func SetReportRenderer added in v1.4.8

func SetReportRenderer(r core.ReportRenderer)

SetReportRenderer installs the renderer used by the report endpoints.

func SetStorage added in v1.3.9

func SetStorage(p storage.Provider)

SetStorage installs the storage provider used to persist incidents and record acks. Called once from main after config load.

func Storage added in v1.3.9

func Storage() storage.Provider

Storage returns the currently installed storage provider, or nil when the process is running without persistence (older tests).

func WindowBounds added in v1.4.8

func WindowBounds(window string, now time.Time) (start, end time.Time, unit string)

WindowBounds resolves a window label to a [start, end) UTC range and the trend unit ("hour" for today/24h, "day" for 7d). An unknown/absent window defaults to today. now is the reference time (UTC); callers pass time.Now().UTC() in production and a fixed time in tests.

Types

type ReportOutcome added in v1.4.8

type ReportOutcome struct {
	Window   string            `json:"window"`
	Sent     []string          `json:"sent"`
	Fallback []string          `json:"fallback"`
	Failed   map[string]string `json:"failed"`
	Bytes    int               `json:"bytes"`
}

ReportOutcome aggregates per-channel delivery results — never short-circuiting, exactly like AlertResult. Sent = image delivered; Fallback = text summary + note delivered (image-incapable channel); Failed = channel returned an error (the PNG is still downloadable).

func SendIncidentsReport added in v1.4.8

func SendIncidentsReport(ctx context.Context, opts ReportSendOptions) (*ReportOutcome, error)

SendIncidentsReport renders the aggregate report and delivers it to the resolved channel(s): image upload where supported, redacted text summary + note where not. Per-channel outcomes are aggregated without short-circuiting.

type ReportSendOptions added in v1.4.8

type ReportSendOptions struct {
	Window      string
	Channel     string
	RequestedBy string
}

ReportSendOptions selects the window and (optionally) the channel for an aggregate report send. Channel is the explicit target; empty falls through the resolution precedence (runtime default_channel → error).

type ReportSettings added in v1.4.8

type ReportSettings struct {
	Enable         bool   `json:"enable"`
	DefaultChannel string `json:"default_channel"`
	IncludeChart   bool   `json:"include_chart"`
	RatePerMinute  int    `json:"rate_per_minute"`
	DefaultWindow  string `json:"default_window"`
}

ReportSettings is the non-secret runtime configuration for the incidents analytics report. It is the JSON shape persisted in the settings blob and the shape the admin GET/PUT endpoints exchange.

func DefaultReportSettings added in v1.4.8

func DefaultReportSettings() ReportSettings

DefaultReportSettings is the built-in floor applied when the store holds no value: the feature is OFF, charts on, a 6/min render cap, and today as the default window. A fresh install therefore has the report disabled until an operator enables it in the UI.

func LoadReportSettings added in v1.4.8

func LoadReportSettings(st storage.Provider) ReportSettings

LoadReportSettings returns the effective report settings: the stored blob merged over the built-in defaults, sanitized. A nil store or an absent/empty/corrupt blob yields the built-in defaults (feature off) — never an error, mirroring the ReadBlob "fresh start" contract. Callers get a fresh value each time, so there is no shared mutable state to guard.

Jump to

Keyboard shortcuts

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