notify

package
v0.43.4 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 12 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 posts one sweep summary per team to the team's channel, through klaus-gateway's team-notice endpoint (POST /notices). The gateway owns the Slack app and the workspace credential; the sweep holds none.

The caller authenticates as itself: the projected ServiceAccount token the pod already carries, for the audience the gateway reviews. The file is read per call because the kubelet rotates it.

The summary is the run history of the scheduled sweep: no report repository and no database, so a channel that fills with runs that changed nothing stops being read. Silence is therefore part of the contract, and Client.Post refuses an empty message rather than posting a heartbeat.

Index

Constants

View Source
const (
	URLEnv       = "MARGE_NOTICES_URL"
	TokenFileEnv = "MARGE_NOTICES_TOKEN_FILE"
)

URLEnv carries the gateway's in-cluster base URL, TokenFileEnv the path of the projected ServiceAccount token.

View Source
const TextMax = 3000

TextMax is the gateway's own bound on a notice: one Slack section block, whose limit is 3000 characters. A longer summary is trimmed to whole lines rather than refused.

Variables

This section is empty.

Functions

func Fit added in v0.37.0

func Fit(text string) string

Fit trims a summary to the gateway's bound on whole lines, and says how many lines it dropped. A summary that silently loses its last section reads as a sweep that did less than it did. It is exported so a caller that renders a summary can hold its own lines to what a notice carries.

func Unavailable added in v0.43.4

func Unavailable(err error) bool

Unavailable reports that a post failed because the gateway could not take it at the time: a 5xx answer, or no answer before the timeout or a refused or reset connection. Any other failure, a 4xx answer above all, is a fault of the configuration (the token, the channel, the request) that no retry repairs.

Types

type Client

type Client struct {
	// BaseURL is the gateway as reached from the pod, without a trailing
	// path.
	BaseURL string
	// TokenFile holds the projected ServiceAccount token, read per post.
	TokenFile string
	HTTP      *http.Client
	// Backoff is the wait before the second attempt, doubled before each
	// later one. Zero means defaultBackoff.
	Backoff time.Duration
}

Client posts notices.

func LoadClient

func LoadClient() *Client

LoadClient returns the client the environment configures, or nil when it names no gateway, which is not an error: a sweep run by hand posts nothing. The caller reports the summary on its own output either way.

func (*Client) Post

func (c *Client) Post(ctx context.Context, team, channel, text string) error

Post sends text to channel as team's notice, and tries again with a doubling wait while the gateway is unavailable, up to attempts tries or until ctx ends. An empty channel or an empty text is an error: both mean the caller decided to post and then had nothing to say.

type StatusError added in v0.43.4

type StatusError struct {
	Channel string
	Code    int
	Status  string
	Reason  string
}

StatusError is a post the gateway answered with something other than 201 Created.

func (*StatusError) Error added in v0.43.4

func (e *StatusError) Error() string

Jump to

Keyboard shortcuts

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