consolepublish

package
v0.216.3 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 19 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 consolepublish turns this machine's Cockpit export into the snapshot it publishes to Sneat Dev Console (spec/features/console-connect), applying the machine's detail level before anything leaves the machine.

Index

Constants

View Source
const FallbackWarning = "snapshot with its repositories copy is too large; published the full envelope alone"

FallbackWarning says a `full` snapshot was sent without its repositories copy because Console refused the pair as too large.

View Source
const MaxBackoff = 15 * time.Minute

MaxBackoff caps the wait after repeated failures (console-connect#req:publishing-never-blocks-local-work).

View Source
const TaskKeyBytes = 32

TaskKeyBytes is the length of a task key.

View Source
const TaskKeyFile = "console-task-key"

TaskKeyFile is the task key's file name under the credentials directory.

Variables

View Source
var ErrInvalidTaskKey = errors.New("console task key must be 32 bytes of base64url text")

ErrInvalidTaskKey is returned for a key that is not TaskKeyBytes of base64url text.

View Source
var ErrNothingToPublish = errors.New("export holds no publishable fleet")

ErrNothingToPublish is returned for an envelope that carries no fleet: a metrics-only export, a daemon warming up, or one that cannot list its repositories (console-connect#req:publish-on-change).

View Source
var ErrTaskKeyMismatch = errors.New("this machine already has a different Console task key")

ErrTaskKeyMismatch is returned when a different task key is already installed: a person's machines must agree on one, so it is never replaced.

Functions

func InstallTaskKey

func InstallTaskKey(path string, key TaskKey) error

InstallTaskKey writes key to path with mode 0600. It refuses to replace a different existing key with ErrTaskKeyMismatch.

Types

type Client

Client is the part of the Console client the daemon publisher uses.

type Publisher

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

Publisher is the daemon's Console publisher: it implements fleet.ConsolePublisher, publishing the reduced export when it changed, and, from the first pass on, sends a heartbeat on its own cadence (console-connect#req:publish-on-change, console-connect#req:heartbeat).

func NewPublisher

func NewPublisher(options PublisherOptions) *Publisher

NewPublisher returns a Publisher.

func (*Publisher) Diagnostic

func (p *Publisher) Diagnostic() string

Diagnostic is the code of the last failed publish, else of the last failed heartbeat, else empty.

func (*Publisher) Publish

func (p *Publisher) Publish(ctx context.Context, source fleet.ConsoleSource)

Publish implements fleet.ConsolePublisher. It also starts the heartbeats, for a caller that never called Start.

func (*Publisher) Start

func (p *Publisher) Start(ctx context.Context)

Start begins the heartbeats when the daemon starts, so a machine whose passes do not complete is still seen as running (console-connect#req:heartbeat).

type PublisherOptions

type PublisherOptions struct {
	Client            Client
	Detail            console.Level
	Key               TaskKey
	MinInterval       time.Duration
	HeartbeatInterval time.Duration
	WBVersion         string
	Now               func() time.Time
	// Wait waits d or until ctx ends (tests replace it).
	Wait func(ctx context.Context, d time.Duration) error
	Logf func(format string, args ...any)
}

PublisherOptions configures a Publisher.

type Publishing

type Publishing interface {
	Publish(context.Context, console.SnapshotRequest) (console.SnapshotReceipt, error)
}

Publishing is the part of a Console client that publishes snapshots.

type Snapshot

type Snapshot struct {
	Detail               console.Level
	TaskKeyID            string
	Envelope             []byte
	RepositoriesEnvelope []byte
	Hash                 string
}

Snapshot is a reduced, canonically encoded envelope ready to publish.

func PublishFalling

func PublishFalling(ctx context.Context, client Publishing, snapshot Snapshot, now time.Time) (Snapshot, console.SnapshotReceipt, bool, error)

PublishFalling publishes snapshot observed at now. When Console refuses a `full` snapshot with its repositories copy as too large, it publishes the full envelope alone, which a `full` request without the copy may always be (console-connect#req:bounded-payload). It reports what was sent and whether it fell back. The daemon and `wb console push` share it.

func Reduce

func Reduce(envelope fleet.Envelope, throughput *fleet.Throughput, level console.Level, key TaskKey) (Snapshot, error)

Reduce applies level to an export envelope and this machine's throughput, which the export itself leaves out (console-connect#req:detail-level-applied-on-the-machine). At `repositories` key is required: it keys the envelope. At `full` a usable key also builds a `repositories` reduction of the same document so Console can serve shares below `full` without reducing snapshots itself; without a usable key the `full` snapshot is sent alone, without that copy or a task key id.

func (Snapshot) Request

func (snapshot Snapshot) Request(observedAt time.Time) console.SnapshotRequest

Request is the publish request for this snapshot observed at observedAt.

func (Snapshot) WithoutRepositories

func (snapshot Snapshot) WithoutRepositories() Snapshot

WithoutRepositories is a `full` snapshot without its `repositories` copy and task key id, hashed as the one envelope it then sends: what the daemon publishes when the copy would put the request over the size bounds (console-connect#req:bounded-payload).

type TaskKey

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

TaskKey is the per-person secret under which task names and the entry ids derived from them are hashed at `repositories` detail (console-connect#req:task-keys-correlate-without-names). Console never holds it.

func LoadOrCreateTaskKey

func LoadOrCreateTaskKey(path string, random io.Reader) (key TaskKey, created bool, err error)

LoadOrCreateTaskKey reads the key at path, refusing a file other users can read, or creates one from random when none exists.

func NewTaskKey

func NewTaskKey(random io.Reader) (TaskKey, error)

NewTaskKey draws a fresh key from random.

func ParseTaskKey

func ParseTaskKey(text string) (TaskKey, error)

ParseTaskKey decodes the text form of a key.

func (TaskKey) ID

func (key TaskKey) ID() string

ID is the public fingerprint Console may hold: the first 8 bytes of the key's SHA-256, hex. It lets Console say that two machines use different keys.

func (TaskKey) Of

func (key TaskKey) Of(task string) string

Of is the task key of a task name: the first 16 bytes of its HMAC-SHA256, base64url. An empty name has no key.

func (TaskKey) Text

func (key TaskKey) Text() string

Text is the key's storage and transfer form.

Jump to

Keyboard shortcuts

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