hoststatus

package
v2.0.0-alpha.7 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const ReplicaStatsWindow int64 = 60

ReplicaStatsWindow is the sliding window (seconds) over which cumulative container counters are differenced to derive rate metrics. It matches the window used for host-level metrics in the status loop.

Variables

View Source
var (
	StatusSet sync.Map

	ActiveAppList syncx.Map

	ContainerList syncx.Map

	ImageList syncx.Map

	Active HostActiveConfig

	// Desired is the freshest view of which container names the zonelet leader
	// most recently reported as desired on this host (across all deploy
	// actions). It is rebuilt wholesale on every successful HostStatusUpdate
	// and is the authoritative comparison set for orphan-container detection:
	// unlike ActiveAppList (append-only), it can express "the leader no longer
	// delivers this instance".
	Desired desiredSnapshot

	AppWorkflow stateflow.AppStateWorkflow

	// ReplicaStages holds the host-side deploy stage progress per replica,
	// keyed by ReplicaStageKey(instanceName, repId). It is hostlet-local and
	// persisted across ticks; the status loop reports dirty entries upward
	// via HostStatusUpdate.
	ReplicaStages syncx.Map

	// ReplicaStatsSet holds the latest per-replica runtime metrics snapshot,
	// keyed by container name (i8k_<instance>_<repId>). Values are
	// *ReplicaStatsEntry. Host-local and in-memory only; it is never persisted
	// and is pruned when a container leaves the running set.
	ReplicaStatsSet sync.Map
)
View Source
var (
	HostReady      atomic.Bool
	ContainerReady atomic.Bool
)

Functions

func ParseReplicaStageKey

func ParseReplicaStageKey(key string) (string, uint32, bool)

ParseReplicaStageKey splits a ReplicaStageKey back into its instance name and replica id. ok is false if the key is malformed.

func ReplicaStageDelete

func ReplicaStageDelete(instanceName string, repId uint32)

ReplicaStageDelete removes the host-side stage entry for a replica.

func ReplicaStageKey

func ReplicaStageKey(instanceName string, repId uint32) string

ReplicaStageKey returns the map key for a (instanceName, repId) pair.

Types

type HostActiveConfig

type HostActiveConfig struct {
	AppInstances []*inapi.AppInstance `json:"app_instances,omitempty"`

	// AppliedRevisions records the last-applied Deploy.Revision per
	// container name. It is persisted to hostlet_active.json so that a
	// Deploy.Revision increment issued while the hostlet was down is still
	// detected after restart and triggers a container recreate.
	AppliedRevisions map[string]uint64 `json:"applied_revisions,omitempty"`

	// SecretKeys holds the per-replica inagent status API secret keyed by
	// container name. Persisted to hostlet_active.json so it survives hostlet
	// restart and stays consistent with the secret written into app_replica.json.
	SecretKeys map[string]string `json:"secret_keys,omitempty"`

	// DeletedInstances records app instances this hostlet has torn down for a
	// soft delete (Deploy.Action == delete), keyed by instance id, value is the
	// unix time of the teardown. Persisted so the hostlet keeps skipping them
	// across restarts until the zone TTL physically removes the instance.
	DeletedInstances map[string]int64 `json:"deleted_instances,omitempty"`

	// OrphanContainers records local containers that exist without a matching
	// desired app replica in the zonelet's fresh app list, keyed by container
	// name, value is the unix time the orphan was first observed. Persisted so
	// the removal grace window survives a hostlet restart. This is the
	// hostlet-local, leader-absence-driven cleanup state and is deliberately
	// separate from DeletedInstances (the leader-driven soft-delete flow).
	OrphanContainers map[string]int64 `json:"orphan_containers,omitempty"`
	// contains filtered or unexported fields
}

func (*HostActiveConfig) AppliedRevision

func (it *HostActiveConfig) AppliedRevision(containerName string) (uint64, bool)

AppliedRevision returns the last-applied Deploy.Revision for a container, or (0, false) if none is recorded.

func (*HostActiveConfig) ClearOrphan

func (it *HostActiveConfig) ClearOrphan(containerName string)

ClearOrphan removes the orphan tracking record for a container (used when the container returns to the desired set, or after it has been removed).

func (*HostActiveConfig) DeleteSecretKey

func (it *HostActiveConfig) DeleteSecretKey(containerName string)

DeleteSecretKey removes the inagent API secret for a container.

func (*HostActiveConfig) DeletedAt

func (it *HostActiveConfig) DeletedAt(instanceId string) (int64, bool)

DeletedAt returns the unix time at which an instance was torn down on this host, and whether such a record exists.

func (*HostActiveConfig) EnsureSecretKey

func (it *HostActiveConfig) EnsureSecretKey(containerName string) (string, bool)

EnsureSecretKey returns the existing inagent API secret for a container, generating a new random one if absent. changed is true if a new secret was created (the caller should persist the active config to disk).

func (*HostActiveConfig) MarkDeleted

func (it *HostActiveConfig) MarkDeleted(instanceId string, ts int64)

MarkDeleted records that this hostlet has torn down the container(s) for an instance at unix time ts, so the instance is skipped on subsequent syncs. It also prunes entries older than the zone soft-delete TTL window (plus a one-day slack) so the map cannot grow without bound across many deletions.

func (*HostActiveConfig) MarkOrphan

func (it *HostActiveConfig) MarkOrphan(containerName string, ts int64)

MarkOrphan records the first-seen time for a locally-orphaned container. It is a no-op if the container is already tracked, so the first-seen time is preserved across ticks until the orphan is cleared or removed. Safe for concurrent use.

func (*HostActiveConfig) MarshalJSON

func (it *HostActiveConfig) MarshalJSON() ([]byte, error)

MarshalJSON serializes the persisted fields under the read lock. The alias avoids recursing back into MarshalJSON.

func (*HostActiveConfig) OrphanFirstSeen

func (it *HostActiveConfig) OrphanFirstSeen(containerName string) (int64, bool)

OrphanFirstSeen returns the unix time at which a container was first observed as orphaned, and whether such a record exists.

func (*HostActiveConfig) Orphans

func (it *HostActiveConfig) Orphans() map[string]int64

Orphans returns a snapshot copy of the orphan container map. The copy lets callers iterate and mutate (ClearOrphan/MarkOrphan) without nesting the read lock behind a write lock.

func (*HostActiveConfig) SecretKey

func (it *HostActiveConfig) SecretKey(containerName string) string

SecretKey returns the inagent API secret for a container, or "" if none.

func (*HostActiveConfig) SetAppliedRevision

func (it *HostActiveConfig) SetAppliedRevision(containerName string, rev uint64)

SetAppliedRevision records the last-applied Deploy.Revision for a container. Safe for concurrent use.

func (*HostActiveConfig) SetSecretKey

func (it *HostActiveConfig) SetSecretKey(containerName, secret string)

SetSecretKey sets the inagent API secret for a container.

func (*HostActiveConfig) UnmarshalJSON

func (h *HostActiveConfig) UnmarshalJSON(data []byte) error

type ReplicaStageEntry

type ReplicaStageEntry struct {
	Stage    *inapi.AppDeployStage
	Dirty    bool
	Revision uint64 // AppDeploy.Revision this entry's stages are based on
	// contains filtered or unexported fields
}

ReplicaStageEntry holds the host-side stage node for a replica and a dirty flag indicating whether it needs to be reported upward. The mutex guards Stage/Dirty against concurrent access from the hostlet main loop and the inagent status HTTP handler.

func ReplicaStage

func ReplicaStage(instanceName string, repId uint32) *ReplicaStageEntry

ReplicaStage returns the host-side stage entry for the given replica, creating it if absent. The entry's Stage is a holder node whose children are the host-side deploy stages (host_recv, image_pull, ...).

func (*ReplicaStageEntry) ClearDirty

func (e *ReplicaStageEntry) ClearDirty()

ClearDirty clears the dirty flag. Called after a successful upward push.

func (*ReplicaStageEntry) MergeInagent

func (e *ReplicaStageEntry) MergeInagent(stages []*inapi.AppDeployStage)

MergeInagent replaces the inagent-owned children of this entry's stage with the reported stages, and marks the entry dirty. Host-side children are preserved. Safe for concurrent use.

func (*ReplicaStageEntry) SetFailed

func (e *ReplicaStageEntry) SetFailed(name, msg string)

func (*ReplicaStageEntry) SetInstant

func (e *ReplicaStageEntry) SetInstant(name, msg string)

func (*ReplicaStageEntry) SetRunning

func (e *ReplicaStageEntry) SetRunning(name, msg string)

func (*ReplicaStageEntry) SetSuccess

func (e *ReplicaStageEntry) SetSuccess(name, msg string)

func (*ReplicaStageEntry) SnapshotIfDirty

func (e *ReplicaStageEntry) SnapshotIfDirty() []*inapi.AppDeployStage

SnapshotIfDirty returns a clone of the stage children if the entry is dirty, or nil if nothing changed. It does not clear the dirty flag; the caller clears it via ClearDirty after a successful upward push so a failed push is retried on the next tick.

func (*ReplicaStageEntry) SyncRevision

func (e *ReplicaStageEntry) SyncRevision(rev uint64) bool

SyncRevision aligns the entry with the current AppDeploy.Revision. When the revision changed, all stage children are cleared (the prior revision's progress is stale) and the dirty flag is set so the reset propagates upward. Returns true if a reset occurred.

type ReplicaStatsEntry

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

ReplicaStatsEntry holds a per-container sliding counter (used to turn Docker's cumulative counters into windowed rate metrics) plus the latest computed NodeMetrics snapshot. It is the value type of ReplicaStatsSet and lives only in memory.

func ReplicaStats

func ReplicaStats(containerName string) *ReplicaStatsEntry

ReplicaStats loads or creates the per-container stats entry for a container.

func (*ReplicaStatsEntry) Counter

Counter returns the per-container sliding counter. Callers record cumulative raw values and read a windowed Delta to derive rates.

func (*ReplicaStatsEntry) Metrics

func (e *ReplicaStatsEntry) Metrics() *inapi.NodeMetrics

Metrics returns the latest metrics snapshot, or nil if none has been computed.

func (*ReplicaStatsEntry) SetMetrics

func (e *ReplicaStatsEntry) SetMetrics(m *inapi.NodeMetrics)

SetMetrics stores the latest computed metrics snapshot.

Jump to

Keyboard shortcuts

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