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
- func CheckURL(raw string) error
- func FormatText(n Notification) string
- func RedactURL(raw string) string
- func RetryAfter(err error) (time.Duration, bool)
- func Scrub(msg, rawURL string) string
- func Sign(secret string, body []byte) string
- type Change
- type Cluster
- type GenericWebhook
- type NopNotifier
- type Notification
- type Notifier
- type RetryAfterError
- type SlackNotifier
- type Target
- type URLSink
Constants ¶
const ( KindNewBlocker = "new-blocker" KindEOLApproaching = "eol-approaching" KindBecameReady = "became-ready" )
Change kinds (Change.Kind), the only three the delta rules emit.
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.
const SchemaVersion = 1
SchemaVersion is the Notification payload version. A field is only ever added within a version; a rename or removal bumps it.
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)).
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
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
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
RetryAfter reports the delay a failed delivery's receiver asked for, if it asked (see RetryAfterError).
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 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 ¶
func (NopNotifier) Notify(context.Context, Notification) error
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
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 ¶
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
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
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.