Help us shape the future of Go! Take the 2026 Go Developer Survey

observe

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package observe shares what a runtime reports about an app between the requests that ask for it at the same moment (issue #72).

The console asks for an app's status every few seconds and for its usage a little less often, from every tab that has the app open. Each status is a container listing and an inspect per container; each usage reading samples container stats for about a second. With thousands of people looking at the same apps, asking the runtime once per request drives it harder than the apps it is running. So each replica asks once per app per short window and hands the answer to everyone who asked in it.

Only what the runtime reports is kept here. Whether the person asking may see it is decided per request, before the cache is consulted, and never stored (R-274): a cache of decisions would keep answering after a grant was revoked.

The reconciler does not use this. It needs the runtime's answer now, not one a status poll fetched two seconds ago (design 05).

Index

Constants

View Source
const (
	DefaultObserveTTL  = 2 * time.Second
	DefaultUsageTTL    = 5 * time.Second
	DefaultCallTimeout = 15 * time.Second

	// DefaultRuntimeTTL is how long what a runtime says about itself — its
	// capabilities and its capacity — is reused for a page that shows it
	// [P]. These change when an adapter is reconfigured or a host is added,
	// not between two polls of the same app.
	DefaultRuntimeTTL = 30 * time.Second
)

Defaults. Short enough that a person who just started or stopped an app sees it within a poll or two even on a replica that did not handle the request.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache is one replica's short-lived copy of runtime observations. The zero value is not usable; use New. A nil *Cache is: every call goes straight to the runtime.

Values handed out are shared between callers and must be treated as read-only.

func New

func New(opts ...Option) *Cache

New returns a Cache with the default TTLs.

func (*Cache) Capabilities

func (c *Cache) Capabilities(ctx context.Context, runtimeRef string, runtime api.RuntimeAdapter) (api.RuntimeCapabilities, error)

Capabilities returns what the runtime says it can do, asking it at most once per runtime TTL on this replica. Shown with a reading, not used to plan or enforce: the planner asks the runtime itself.

func (*Cache) Capacity

func (c *Cache) Capacity(ctx context.Context, runtimeRef string, runtime api.RuntimeAdapter) (api.Capacity, error)

Capacity returns the runtime's totals, asking it at most once per runtime TTL on this replica. For display, like Capabilities: the capacity check at plan time asks the runtime itself (R-242).

func (*Cache) Forget

func (c *Cache) Forget(appID string)

Forget drops what this replica holds for the app, so the next request asks the runtime. Called after an action that changes what is running. A call already in flight when Forget runs is not stored when it returns.

func (*Cache) Len

func (c *Cache) Len() int

Len reports how many answers are held, for tests.

func (*Cache) Observe

func (c *Cache) Observe(ctx context.Context, runtimeRef string, runtime api.RuntimeAdapter, appID string) (api.ObservedBundle, error)

Observe returns what runtime reports for the app's bundle, asking it at most once per TTL on this replica. runtimeRef is the adapter ref the app's spec names, and is part of the key.

func (*Cache) Usage

func (c *Cache) Usage(ctx context.Context, runtimeRef string, runtime api.RuntimeAdapter, appID string) (api.BundleUsage, error)

Usage returns the runtime's usage reading for the app's bundle, sampling at most once per TTL on this replica.

type Option

type Option func(*Cache)

Option configures a Cache.

func WithClock

func WithClock(c clock.Clock) Option

WithClock sets the time source, for tests.

func WithRuntimeTTL

func WithRuntimeTTL(d time.Duration) Option

WithRuntimeTTL sets how long a runtime's capabilities and capacity are reused.

Jump to

Keyboard shortcuts

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