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
- func Provided(ctx context.Context, lookup ServiceInstances, appID string, workloads []string) map[string]Dependency
- type Cache
- func (c *Cache) Capabilities(ctx context.Context, runtimeRef string, runtime api.RuntimeAdapter) (api.RuntimeCapabilities, error)
- func (c *Cache) Capacity(ctx context.Context, runtimeRef string, runtime api.RuntimeAdapter) (api.Capacity, error)
- func (c *Cache) Forget(appID string)
- func (c *Cache) Len() int
- func (c *Cache) Observe(ctx context.Context, runtimeRef string, runtime api.RuntimeAdapter, ...) (api.ObservedBundle, error)
- func (c *Cache) Usage(ctx context.Context, runtimeRef string, runtime api.RuntimeAdapter, ...) (api.BundleUsage, error)
- type Dependency
- type Option
- type ServiceInstances
Constants ¶
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 ¶
func Provided ¶ added in v0.15.0
func Provided(ctx context.Context, lookup ServiceInstances, appID string, workloads []string) map[string]Dependency
Provided says which of workloads — names the app's spec does not declare, so none of the app's own — are services Pando runs for it, and the dependency each fills. A workload is matched on the handle Pando recorded when it provisioned the service, not on any runtime's naming. A nil lookup, or one that fails, names nothing: the names are a label, and a status answers without them.
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 (*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 ¶
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) 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.
type Dependency ¶ added in v0.15.0
Dependency is the slot a provisioned workload fills.
type Option ¶
type Option func(*Cache)
Option configures a Cache.
func WithRuntimeTTL ¶
WithRuntimeTTL sets how long a runtime's capabilities and capacity are reused.
type ServiceInstances ¶ added in v0.15.0
type ServiceInstances interface {
ForApp(ctx context.Context, appID string) ([]state.ServiceInstance, error)
}
ServiceInstances lists the services Pando has provisioned for an app.