notify

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package notify defines the notification seam fired on finding deltas (new blocker, became-ready, add-on entering the EOL window) — never on every snapshot. Implementations (Slack, generic webhook) live here too.

The server computes *what* changed (delta rules live in internal/server) and groups one evaluation pass's changes for one cluster into a single Notification; this package only knows how to deliver one somewhere. Delivery is at-least-once (the server's outbox retries), so receivers deduplicate by DeliveryID.

Index

Constants

View Source
const (
	KindNewBlocker     = "new-blocker"
	KindEOLApproaching = "eol-approaching"
	KindBecameReady    = "became-ready"
)

Change kinds (Change.Kind), the only three the delta rules emit.

View Source
const MaxRetryAfter = time.Duration(math.MaxUint32) * time.Second

MaxRetryAfter is the longest Retry-After delay reported: a delta-seconds value that does not fit 32 bits (about 136 years) is read as this rather than as absent. The server's outbox caps what it honours far below it.

View Source
const SchemaVersion = 1

SchemaVersion is the Notification payload version. A field is only ever added within a version; a rename or removal bumps it.

View Source
const SignatureHeader = "X-Upgradescope-Signature"

SignatureHeader carries the generic webhook's HMAC-SHA256 signature when a secret is configured: "sha256=" + hex(HMAC(secret, raw body)).

View Source
const TypeReadinessChanged = "readiness.changed"

TypeReadinessChanged is Notification.Type: one evaluation pass changed a cluster's readiness (new blockers, add-ons nearing EOL, or ready again).

Variables

This section is empty.

Functions

func CheckURL added in v0.2.0

func CheckURL(raw string) error

CheckURL reports whether raw is a URL a notifier can deliver to: an absolute http or https URL with a host, and nothing a request could not carry. Its error never repeats the URL, whose path or query may be the credential, nor any fragment of it: net/url's own error quotes the port or the escape it choked on, so a fixed text per failure class stands in.

func FormatText added in v0.2.0

func FormatText(n Notification) string

FormatText renders a notification as Slack message text. One change is one line:

[upgradescope] <cluster> → <targets>: <kind>: <title>

several are a header line and one bullet per change.

func RedactURL added in v0.2.0

func RedactURL(raw string) string

RedactURL is raw with nothing that could be a credential: its scheme and host (with the port), and "/…" when anything followed them. The path of a Slack incoming webhook is its secret, and a generic webhook's query often carries a token. A URL with an "@" anywhere after the scheme, userinfo or not, has its host withheld too: text cannot tell where a password holding "/" or "?" ends, so the host part could be the credential. So does one whose host is not plain host-name characters (it does not parse).

func RetryAfter added in v0.2.0

func RetryAfter(err error) (time.Duration, bool)

RetryAfter reports the delay a failed delivery's receiver asked for, if it asked (see RetryAfterError).

func Scrub added in v0.2.0

func Scrub(msg, rawURL string) string

Scrub is msg with every copy of rawURL in it, as written or as Go quotes it (%q, which *url.Error uses), replaced by RedactURL's form, and its path and query, when they are long enough to be a credential, by "…".

func Sign added in v0.2.0

func Sign(secret string, body []byte) string

Sign returns the SignatureHeader value for body under secret.

Types

type Change added in v0.2.0

type Change struct {
	Kind     string   `json:"kind"`               // KindNewBlocker | KindEOLApproaching | KindBecameReady
	Key      string   `json:"key,omitempty"`      // the finding's stable key (empty for became-ready)
	Severity string   `json:"severity,omitempty"` // the finding's severity: blocker | warning
	Title    string   `json:"title"`
	Detail   string   `json:"detail,omitempty"`
	Targets  []string `json:"targets"` // the targets the change applies to
}

Change is one entry of the findings delta.

type Cluster added in v0.2.0

type Cluster struct {
	ID   int64  `json:"id"`
	Name string `json:"name"`
}

Cluster identifies the cluster a notification is about.

type GenericWebhook

type GenericWebhook struct {
	URL    string
	Secret string // HMAC-SHA256 key for SignatureHeader; "" = unsigned
	// URLFunc and SecretFunc, when set, give the URL and the signing key at
	// each delivery in place of URL and Secret: values read from a mounted
	// Secret, which follow a rotation.
	URLFunc    func() string
	SecretFunc func() string
	Client     *http.Client
}

GenericWebhook POSTs the Notification as JSON to any HTTP endpoint, signed when Secret is set.

func NewGenericWebhook

func NewGenericWebhook(url string) *GenericWebhook

NewGenericWebhook returns an unsigned GenericWebhook with the 2s delivery timeout; set Secret to sign.

func (*GenericWebhook) Notify

func (g *GenericWebhook) Notify(ctx context.Context, n Notification) error

func (*GenericWebhook) Pin added in v0.2.0

func (g *GenericWebhook) Pin() (Notifier, string)

Pin is a notifier that posts to the URL g has now, signed with the key it has now, and that URL (URLSink).

func (*GenericWebhook) SinkURL added in v0.2.0

func (g *GenericWebhook) SinkURL() string

SinkURL is the URL g posts to (URLSink).

type NopNotifier

type NopNotifier struct{}

NopNotifier discards every notification. Useful default when no webhook is configured.

func (NopNotifier) Notify

type Notification added in v0.2.0

type Notification struct {
	SchemaVersion int       `json:"schemaVersion"`
	DeliveryID    string    `json:"deliveryId"` // stable across retries: deduplicate on it
	Type          string    `json:"type"`       // TypeReadinessChanged
	Timestamp     time.Time `json:"timestamp"`  // when the pass ran (UTC)
	Cluster       Cluster   `json:"cluster"`
	// Targets is the verdict after the pass for every target with a change.
	Targets []Target `json:"targets"`
	// Changes is the findings delta. A change found for several targets,
	// worded the same for each (an EOL add-on is a blocker for every
	// target), is one entry listing them all; wording that names the
	// target keeps an entry per target.
	Changes []Change `json:"changes"`
	// Omitted counts changes left out by the per-kind cap, by kind.
	Omitted map[string]int `json:"omitted,omitempty"`
}

Notification is one delivery: every change one evaluation pass found for one cluster, across all of its targets. It is the generic webhook's JSON body: api/webhook.schema.json, documented in docs/reference/webhook.md.

type Notifier

type Notifier interface {
	Notify(ctx context.Context, n Notification) error
}

func Members added in v0.2.0

func Members(n Notifier) []Notifier

Members flattens n into the individual notifiers it fans out to: a Multi's members (recursively), nothing for nil, otherwise n itself. The server queues one delivery per member so each is retried on its own.

func Multi

func Multi(notifiers ...Notifier) Notifier

Multi fans one notification out to every notifier. Individual failures are logged and skipped — the remaining notifiers still fire and the error is never propagated. The server does not use it to deliver (it queues one outbox message per member, see Members); Multi() with no arguments is a valid no-op.

type RetryAfterError added in v0.2.0

type RetryAfterError struct {
	Err   error
	After time.Duration
}

RetryAfterError is a delivery the receiver pushed back on: it answered 429 Too Many Requests or 503 Service Unavailable with a Retry-After header, asking not to be retried before After. The server's outbox waits at least that long, and sends that sink nothing else meanwhile.

func (*RetryAfterError) Error added in v0.2.0

func (e *RetryAfterError) Error() string

func (*RetryAfterError) Unwrap added in v0.2.0

func (e *RetryAfterError) Unwrap() error

type SlackNotifier

type SlackNotifier struct {
	URL string
	// URLFunc, when set, gives the URL at each delivery in place of URL: a
	// webhook URL read from a mounted Secret, which follows a rotation.
	URLFunc func() string
	Client  *http.Client // exported so tests shorten the timeout; never nil from NewSlack
}

SlackNotifier posts notifications to a Slack incoming webhook as text.

func NewSlack

func NewSlack(url string) *SlackNotifier

NewSlack returns a SlackNotifier with the 2s delivery timeout.

func (*SlackNotifier) Notify

func (s *SlackNotifier) Notify(ctx context.Context, n Notification) error

func (*SlackNotifier) Pin added in v0.2.0

func (s *SlackNotifier) Pin() (Notifier, string)

Pin is a notifier that posts to the URL s has now, and that URL (URLSink).

func (*SlackNotifier) SinkURL added in v0.2.0

func (s *SlackNotifier) SinkURL() string

SinkURL is the webhook URL s posts to (URLSink).

type Target added in v0.2.0

type Target struct {
	Target   string `json:"target"`
	Verdict  string `json:"verdict"` // ready | blocked | unknown
	Score    int    `json:"score"`
	Blockers int    `json:"blockers"`
}

Target is one target's verdict after the pass.

type URLSink added in v0.2.0

type URLSink interface {
	Notifier
	SinkURL() string
	Pin() (Notifier, string)
}

URLSink is a notifier that delivers to one URL, which may carry its credential (a Slack webhook's path, a webhook's ?token=): the server scrubs it (Scrub) from every error the notifier returns before logging or storing one.

A URL that follows a rotating file can change between the post and the scrub, which would scrub an error with a URL other than the one it names. Pin reads it once: the notifier to call for one delivery, which posts to the URL returned, and that URL, to scrub with.

Jump to

Keyboard shortcuts

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