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 ¶
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.
const MaxBackoff = 15 * time.Minute
MaxBackoff caps the wait after repeated failures (console-connect#req:publishing-never-blocks-local-work).
const TaskKeyBytes = 32
TaskKeyBytes is the length of a task key.
const TaskKeyFile = "console-task-key"
TaskKeyFile is the task key's file name under the credentials directory.
Variables ¶
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.
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).
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 ¶
InstallTaskKey writes key to path with mode 0600. It refuses to replace a different existing key with ErrTaskKeyMismatch.
Types ¶
type Client ¶
type Client interface {
Publish(context.Context, console.SnapshotRequest) (console.SnapshotReceipt, error)
Heartbeat(context.Context, console.HeartbeatRequest) error
}
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 ¶
Diagnostic is the code of the last failed publish, else of the last failed heartbeat, else empty.
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 ¶
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 ¶
LoadOrCreateTaskKey reads the key at path, refusing a file other users can read, or creates one from random when none exists.
func NewTaskKey ¶
NewTaskKey draws a fresh key from random.
func ParseTaskKey ¶
ParseTaskKey decodes the text form of a key.
func (TaskKey) ID ¶
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.