events

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 8 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 events is the Instance's change feed, served as server-sent events at /_emu/v1/events (FR-CORE-045, FR-UI-006): resource changes, Operation progress, Request log entries and IAM denials.

A Hub numbers every event and keeps the most recent ones so that a client reconnecting with Last-Event-ID receives what it missed. When it cannot (the events are gone, or the ID is from another process), the client is told it has a gap and must refetch everything.

Index

Constants

View Source
const (
	// Resource is a store key written or deleted (ResourceChange).
	Resource = "resource"
	// Operation is an Operation created, progressed or deleted (OperationChange).
	Operation = "operation"
	// Request is a Request log entry (reqlog.Entry).
	Request = "request"
	// IAMDenial is a call the audit IAM enforcement level would deny
	// (emu.Denial), without its advice.
	IAMDenial = "iamDenial"
	// Reset says all state was replaced (Reset or State snapshot restore).
	Reset = "reset"
	// Gap says events were missed and cannot be replayed. Only Subscribe
	// produces it.
	Gap = "gap"
)

Event types.

Variables

This section is empty.

Functions

func StoreObserver

func StoreObserver(h *Hub) store.Observer

StoreObserver returns a store.Observer publishing Resource and Operation events to h, and a Reset event when the store is replaced.

Types

type Event

type Event struct {
	// ID is "<epoch>-<seq>": epoch identifies the Hub, so that IDs from an
	// earlier process are recognised as a gap.
	ID   string
	Type string
	Data json.RawMessage
}

Event is one numbered event.

type Hub

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

Hub fans events out to subscribers and retains the latest ones.

func NewHub

func NewHub(size int) *Hub

NewHub returns a Hub retaining the last size events.

func (*Hub) Close

func (h *Hub) Close()

Close ends every subscription; later events are discarded.

func (*Hub) Publish

func (h *Hub) Publish(typ string, data any)

Publish sends an event of type typ with data marshalled as JSON. A nil Hub discards it.

func (*Hub) ServeHTTP

func (h *Hub) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP streams events as text/event-stream. A client resuming with the Last-Event-ID header (or lastEventId query parameter) first receives what it missed, or a Gap event.

func (*Hub) Subscribe

func (h *Hub) Subscribe(lastID string) (backlog []Event, ch <-chan Event, cancel func())

Subscribe returns the events after lastID (empty for none) and a channel of later ones. If the events after lastID are not all retained, backlog is a single Gap event. The channel is closed when the subscriber falls too far behind or the Hub closes; cancel releases it.

type OperationChange

type OperationChange struct {
	Service   string `json:"service"`
	Namespace string `json:"namespace"`
	// Name is the Operation's store key, or its name for
	// google.longrunning Operations.
	Name    string `json:"name"`
	Done    bool   `json:"done"`
	Deleted bool   `json:"deleted,omitempty"`
}

OperationChange is the data of an Operation event.

type ResourceChange

type ResourceChange struct {
	// Service is the namespace's first segment: a Service ID, or "core"
	// for state the emulator owns (Projects).
	Service   string `json:"service"`
	Namespace string `json:"namespace"`
	Key       string `json:"key"`
	Deleted   bool   `json:"deleted,omitempty"`
}

ResourceChange is the data of a Resource event.

Jump to

Keyboard shortcuts

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