package hostedctl import ( "context" "errors" "net/netip" "time" "amadan.net/oficina/equipo/internal/isolatedjob" ) // Operator log records, at info, through Deps.Log. Each message is a fixed // string and each attribute a value the controller holds itself: a VM ref, // an attempt ID, controller times and durations, or a fixed kind word. No // record carries provider error text, request bodies or key material. func (c *Controller) logOrphanStopped(o orphan, now T) { c.log.Info("hosted controller: orphan VM stopped", "vm_ref", string(o.ref), "first_seen_ns", int64(o.firstSeen), "unclaimed_for", time.Duration(now-o.firstSeen), "grace", OrphanGrace, "seen_before_restart", c.store.Restarted() && o.firstSeen < c.store.OpenedAt()) } func (c *Controller) logOrphanStopFailed(o orphan) { c.log.Info("hosted controller: orphan VM stop call failed; sent again next pass", "vm_ref", string(o.ref), "first_seen_ns", int64(o.firstSeen), "grace", OrphanGrace) } func (c *Controller) logOrphanDeferred(o orphan, now T, dispatched int) { c.log.Info("hosted controller: orphan VM left running for a dispatched launch intent", "vm_ref", string(o.ref), "first_seen_ns", int64(o.firstSeen), "unclaimed_for", time.Duration(now-o.firstSeen), "grace", OrphanGrace, "dispatched_intents", dispatched) } func (c *Controller) logAuditFailed(at T, kinds []string) { c.log.Info("hosted controller: network audit failed; launches refused", "began_ns", int64(at), "kinds", kinds) } func (c *Controller) logRebased(attempt string, age, launchedBy, stopBy time.Duration) { c.log.Info("hosted controller: restart re-based a job from the provider's age", "attempt", attempt, "provider_age", age, "launched_moved_back", launchedBy, "stop_moved_back", stopBy) } func (c *Controller) logElapsedUnknown(attempt string) { c.log.Info("hosted controller: restart stop requested, elapsed time unknown", "attempt", attempt, "reason", reasonElapsedUnknown) } // auditCallKinds names, in fixed words, why reading the network settings // failed. func auditCallKinds(err error) []string { kinds := []string{"provider_read_failed"} switch { case errors.Is(err, context.Canceled), errors.Is(err, context.DeadlineExceeded): kinds = append(kinds, "cancelled_or_timed_out") case errors.Is(err, isolatedjob.ErrThrottled): kinds = append(kinds, "throttled") case errors.Is(err, isolatedjob.ErrNotFound): kinds = append(kinds, "not_found") } return kinds } // auditKinds names, in fixed words, each property of a that fails the // audit against want (see isolatedjob.NetworkAudit.OK). func auditKinds(a isolatedjob.NetworkAudit, want []netip.AddrPort) []string { var kinds []string if !a.ResolverDisabled { kinds = append(kinds, "resolver_enabled") } if !a.IngressClosed { kinds = append(kinds, "ingress_open") } if !a.RouteOutAbsent { kinds = append(kinds, "route_out_present") } a.ResolverDisabled, a.IngressClosed, a.RouteOutAbsent = true, true, true if a.OK(want) != nil { kinds = append(kinds, "egress_differs") } return kinds }