*: reflow comments to 80 characters
This reformats the entire Metropolis codebase to have comments no longer
than 80 characters, implementing CR/66.
This has been done half manually, as we don't have a good integration
between commentwrap/Bazel, but that can be implemented if we decide to
go for this tool/limit.
Change-Id: If1fff0b093ef806f5dc00551c11506e8290379d0
diff --git a/metropolis/pkg/supervisor/supervisor.go b/metropolis/pkg/supervisor/supervisor.go
index c37b590..f26732d 100644
--- a/metropolis/pkg/supervisor/supervisor.go
+++ b/metropolis/pkg/supervisor/supervisor.go
@@ -16,9 +16,10 @@
package supervisor
-// The service supervision library allows for writing of reliable, service-style software within a Metropolis node.
-// It builds upon the Erlang/OTP supervision tree system, adapted to be more Go-ish.
-// For detailed design see go/supervision.
+// The service supervision library allows for writing of reliable,
+// service-style software within a Metropolis node. It builds upon the
+// Erlang/OTP supervision tree system, adapted to be more Go-ish. For detailed
+// design see go/supervision.
import (
"context"
@@ -28,17 +29,21 @@
"source.monogon.dev/metropolis/pkg/logtree"
)
-// A Runnable is a function that will be run in a goroutine, and supervised throughout its lifetime. It can in turn
-// start more runnables as its children, and those will form part of a supervision tree.
-// The context passed to a runnable is very important and needs to be handled properly. It will be live (non-errored) as
-// long as the runnable should be running, and canceled (ctx.Err() will be non-nil) when the supervisor wants it to
-// exit. This means this context is also perfectly usable for performing any blocking operations.
+// A Runnable is a function that will be run in a goroutine, and supervised
+// throughout its lifetime. It can in turn start more runnables as its
+// children, and those will form part of a supervision tree.
+// The context passed to a runnable is very important and needs to be handled
+// properly. It will be live (non-errored) as long as the runnable should be
+// running, and canceled (ctx.Err() will be non-nil) when the supervisor wants
+// it to exit. This means this context is also perfectly usable for performing
+// any blocking operations.
type Runnable func(ctx context.Context) error
-// RunGroup starts a set of runnables as a group. These runnables will run together, and if any one of them quits
-// unexpectedly, the result will be canceled and restarted.
-// The context here must be an existing Runnable context, and the spawned runnables will run under the node that this
-// context represents.
+// RunGroup starts a set of runnables as a group. These runnables will run
+// together, and if any one of them quits unexpectedly, the result will be
+// canceled and restarted.
+// The context here must be an existing Runnable context, and the spawned
+// runnables will run under the node that this context represents.
func RunGroup(ctx context.Context, runnables map[string]Runnable) error {
node, unlock := fromContext(ctx)
defer unlock()
@@ -52,8 +57,9 @@
})
}
-// Signal tells the supervisor that the calling runnable has reached a certain state of its lifecycle. All runnables
-// should SignalHealthy when they are ready with set up, running other child runnables and are now 'serving'.
+// Signal tells the supervisor that the calling runnable has reached a certain
+// state of its lifecycle. All runnables should SignalHealthy when they are
+// ready with set up, running other child runnables and are now 'serving'.
func Signal(ctx context.Context, signal SignalType) {
node, unlock := fromContext(ctx)
defer unlock()
@@ -63,28 +69,34 @@
type SignalType int
const (
- // The runnable is healthy, done with setup, done with spawning more Runnables, and ready to serve in a loop.
- // The runnable needs to check the parent context and ensure that if that context is done, the runnable exits.
+ // The runnable is healthy, done with setup, done with spawning more
+ // Runnables, and ready to serve in a loop. The runnable needs to check
+ // the parent context and ensure that if that context is done, the runnable
+ // exits.
SignalHealthy SignalType = iota
- // The runnable is done - it does not need to run any loop. This is useful for Runnables that only set up other
- // child runnables. This runnable will be restarted if a related failure happens somewhere in the supervision tree.
+ // The runnable is done - it does not need to run any loop. This is useful
+ // for Runnables that only set up other child runnables. This runnable will
+ // be restarted if a related failure happens somewhere in the supervision
+ // tree.
SignalDone
)
-// supervisor represents and instance of the supervision system. It keeps track of a supervision tree and a request
-// channel to its internal processor goroutine.
+// supervisor represents and instance of the supervision system. It keeps track
+// of a supervision tree and a request channel to its internal processor
+// goroutine.
type supervisor struct {
// mu guards the entire state of the supervisor.
mu sync.RWMutex
- // root is the root node of the supervision tree, named 'root'. It represents the Runnable started with the
- // supervisor.New call.
+ // root is the root node of the supervision tree, named 'root'. It
+ // represents the Runnable started with the supervisor.New call.
root *node
// logtree is the main logtree exposed to runnables and used internally.
logtree *logtree.LogTree
// ilogger is the internal logger logging to "supervisor" in the logtree.
ilogger logtree.LeveledLogger
- // pReq is an interface channel to the lifecycle processor of the supervisor.
+ // pReq is an interface channel to the lifecycle processor of the
+ // supervisor.
pReq chan *processorRequest
// propagate panics, ie. don't catch them.
@@ -95,8 +107,9 @@
type SupervisorOpt func(s *supervisor)
var (
- // WithPropagatePanic prevents the Supervisor from catching panics in runnables and treating them as failures.
- // This is useful to enable for testing and local debugging.
+ // WithPropagatePanic prevents the Supervisor from catching panics in
+ // runnables and treating them as failures. This is useful to enable for
+ // testing and local debugging.
WithPropagatePanic = func(s *supervisor) {
s.propagatePanic = true
}
diff --git a/metropolis/pkg/supervisor/supervisor_node.go b/metropolis/pkg/supervisor/supervisor_node.go
index a7caf82..a3bf5e4 100644
--- a/metropolis/pkg/supervisor/supervisor_node.go
+++ b/metropolis/pkg/supervisor/supervisor_node.go
@@ -25,23 +25,28 @@
"github.com/cenkalti/backoff/v4"
)
-// node is a supervision tree node. It represents the state of a Runnable within this tree, its relation to other tree
-// elements, and contains supporting data needed to actually supervise it.
+// node is a supervision tree node. It represents the state of a Runnable
+// within this tree, its relation to other tree elements, and contains
+// supporting data needed to actually supervise it.
type node struct {
- // The name of this node. Opaque string. It's used to make up the 'dn' (distinguished name) of a node within
- // the tree. When starting a runnable inside a tree, this is where that name gets used.
+ // The name of this node. Opaque string. It's used to make up the 'dn'
+ // (distinguished name) of a node within the tree. When starting a runnable
+ // inside a tree, this is where that name gets used.
name string
runnable Runnable
// The supervisor managing this tree.
sup *supervisor
- // The parent, within the tree, of this node. If this is the root node of the tree, this is nil.
+ // The parent, within the tree, of this node. If this is the root node of
+ // the tree, this is nil.
parent *node
- // Children of this tree. This is represented by a map keyed from child node names, for easy access.
+ // Children of this tree. This is represented by a map keyed from child
+ // node names, for easy access.
children map[string]*node
- // Supervision groups. Each group is a set of names of children. Sets, and as such groups, don't overlap between
- // each other. A supervision group indicates that if any child within that group fails, all others should be
- // canceled and restarted together.
+ // Supervision groups. Each group is a set of names of children. Sets, and
+ // as such groups, don't overlap between each other. A supervision group
+ // indicates that if any child within that group fails, all others should
+ // be canceled and restarted together.
groups []map[string]bool
// The current state of the runnable in this node.
@@ -55,19 +60,21 @@
ctxC context.CancelFunc
}
-// nodeState is the state of a runnable within a node, and in a way the node itself.
-// This follows the state diagram from go/supervision.
+// nodeState is the state of a runnable within a node, and in a way the node
+// itself. This follows the state diagram from go/supervision.
type nodeState int
const (
- // A node that has just been created, and whose runnable has been started already but hasn't signaled anything yet.
+ // A node that has just been created, and whose runnable has been started
+ // already but hasn't signaled anything yet.
nodeStateNew nodeState = iota
- // A node whose runnable has signaled being healthy - this means it's ready to serve/act.
+ // A node whose runnable has signaled being healthy - this means it's ready
+ // to serve/act.
nodeStateHealthy
// A node that has unexpectedly returned or panicked.
nodeStateDead
- // A node that has declared that its done with its work and should not be restarted, unless a supervision tree
- // failure requires that.
+ // A node that has declared that its done with its work and should not be
+ // restarted, unless a supervision tree failure requires that.
nodeStateDone
// A node that has returned after being requested to cancel.
nodeStateCanceled
@@ -101,8 +108,9 @@
dnKey = contextKey("dn")
)
-// fromContext retrieves a tree node from a runnable context. It takes a lock on the tree and returns an unlock
-// function. This unlock function needs to be called once mutations on the tree/supervisor/node are done.
+// fromContext retrieves a tree node from a runnable context. It takes a lock
+// on the tree and returns an unlock function. This unlock function needs to be
+// called once mutations on the tree/supervisor/node are done.
func fromContext(ctx context.Context) (*node, func()) {
sup, ok := ctx.Value(supervisorKey).(*supervisor)
if !ok {
@@ -120,12 +128,13 @@
return sup.nodeByDN(dnParent), sup.mu.Unlock
}
-// All the following 'internal' supervisor functions must only be called with the supervisor lock taken. Getting a lock
-// via fromContext is enough.
+// All the following 'internal' supervisor functions must only be called with
+// the supervisor lock taken. Getting a lock via fromContext is enough.
-// dn returns the distinguished name of a node. This distinguished name is a period-separated, inverse-DNS-like name.
-// For instance, the runnable 'foo' within the runnable 'bar' will be called 'root.bar.foo'. The root of the tree is
-// always named, and has the dn, 'root'.
+// dn returns the distinguished name of a node. This distinguished name is a
+// period-separated, inverse-DNS-like name. For instance, the runnable 'foo'
+// within the runnable 'bar' will be called 'root.bar.foo'. The root of the
+// tree is always named, and has the dn, 'root'.
func (n *node) dn() string {
if n.parent != nil {
return fmt.Sprintf("%s.%s", n.parent.dn(), n.name)
@@ -133,8 +142,9 @@
return n.name
}
-// groupSiblings is a helper function to get all runnable group siblings of a given runnable name within this node.
-// All children are always in a group, even if that group is unary.
+// groupSiblings is a helper function to get all runnable group siblings of a
+// given runnable name within this node. All children are always in a group,
+// even if that group is unary.
func (n *node) groupSiblings(name string) map[string]bool {
for _, m := range n.groups {
if _, ok := m[name]; ok {
@@ -144,11 +154,12 @@
return nil
}
-// newNode creates a new node with a given parent. It does not register it with the parent (as that depends on group
-// placement).
+// newNode creates a new node with a given parent. It does not register it with
+// the parent (as that depends on group placement).
func newNode(name string, runnable Runnable, sup *supervisor, parent *node) *node {
- // We use exponential backoff for failed runnables, but at some point we cap at a given backoff time.
- // To achieve this, we set MaxElapsedTime to 0, which will cap the backoff at MaxInterval.
+ // We use exponential backoff for failed runnables, but at some point we
+ // cap at a given backoff time. To achieve this, we set MaxElapsedTime to
+ // 0, which will cap the backoff at MaxInterval.
bo := backoff.NewExponentialBackOff()
bo.MaxElapsedTime = 0
@@ -165,11 +176,12 @@
return n
}
-// resetNode sets up all the dynamic fields of the node, in preparation of starting a runnable. It clears the node's
-// children, groups and resets its context.
+// resetNode sets up all the dynamic fields of the node, in preparation of
+// starting a runnable. It clears the node's children, groups and resets its
+// context.
func (n *node) reset() {
- // Make new context. First, acquire parent context. For the root node that's Background, otherwise it's the
- // parent's context.
+ // Make new context. First, acquire parent context. For the root node
+ // that's Background, otherwise it's the parent's context.
var pCtx context.Context
if n.parent == nil {
pCtx = context.Background()
@@ -263,7 +275,8 @@
return nil
}
-// signal sequences state changes by signals received from runnables and updates a node's status accordingly.
+// signal sequences state changes by signals received from runnables and
+// updates a node's status accordingly.
func (n *node) signal(signal SignalType) {
switch signal {
case SignalHealthy:
diff --git a/metropolis/pkg/supervisor/supervisor_processor.go b/metropolis/pkg/supervisor/supervisor_processor.go
index 965a667..5fa759e 100644
--- a/metropolis/pkg/supervisor/supervisor_processor.go
+++ b/metropolis/pkg/supervisor/supervisor_processor.go
@@ -24,11 +24,13 @@
"time"
)
-// The processor maintains runnable goroutines - ie., when requested will start one, and then once it exists it will
-// record the result and act accordingly. It is also responsible for detecting and acting upon supervision subtrees that
-// need to be restarted after death (via a 'GC' process)
+// The processor maintains runnable goroutines - ie., when requested will start
+// one, and then once it exists it will record the result and act accordingly.
+// It is also responsible for detecting and acting upon supervision subtrees
+// that need to be restarted after death (via a 'GC' process)
-// processorRequest is a request for the processor. Only one of the fields can be set.
+// processorRequest is a request for the processor. Only one of the fields can
+// be set.
type processorRequest struct {
schedule *processorRequestSchedule
died *processorRequestDied
@@ -40,7 +42,8 @@
dn string
}
-// processorRequestDied is a signal from a runnable goroutine that the runnable has died.
+// processorRequestDied is a signal from a runnable goroutine that the runnable
+// has died.
type processorRequestDied struct {
dn string
err error
@@ -57,8 +60,10 @@
// Waiters waiting for the GC to be settled.
var waiters []chan struct{}
- // The GC will run every millisecond if needed. Any time the processor requests a change in the supervision tree
- // (ie a death or a new runnable) it will mark the state as dirty and run the GC on the next millisecond cycle.
+ // The GC will run every millisecond if needed. Any time the processor
+ // requests a change in the supervision tree (ie a death or a new runnable)
+ // it will mark the state as dirty and run the GC on the next millisecond
+ // cycle.
gc := time.NewTicker(1 * time.Millisecond)
defer gc.Stop()
clean := true
@@ -85,7 +90,8 @@
clean = true
cleanCycles += 1
- // This threshold is somewhat arbitrary. It's a balance between test speed and test reliability.
+ // This threshold is somewhat arbitrary. It's a balance between
+ // test speed and test reliability.
if cleanCycles > 50 {
for _, w := range waiters {
close(w)
@@ -109,8 +115,9 @@
}
}
-// processKill cancels all nodes in the supervision tree. This is only called right before exiting the processor, so
-// they do not get automatically restarted.
+// processKill cancels all nodes in the supervision tree. This is only called
+// right before exiting the processor, so they do not get automatically
+// restarted.
func (s *supervisor) processKill() {
s.mu.Lock()
defer s.mu.Unlock()
@@ -138,7 +145,8 @@
}
}
-// processSchedule starts a node's runnable in a goroutine and records its output once it's done.
+// processSchedule starts a node's runnable in a goroutine and records its
+// output once it's done.
func (s *supervisor) processSchedule(r *processorRequestSchedule) {
s.mu.Lock()
defer s.mu.Unlock()
@@ -169,8 +177,9 @@
}()
}
-// processDied records the result from a runnable goroutine, and updates its node state accordingly. If the result
-// is a death and not an expected exit, related nodes (ie. children and group siblings) are canceled accordingly.
+// processDied records the result from a runnable goroutine, and updates its
+// node state accordingly. If the result is a death and not an expected exit,
+// related nodes (ie. children and group siblings) are canceled accordingly.
func (s *supervisor) processDied(r *processorRequestDied) {
s.mu.Lock()
defer s.mu.Unlock()
@@ -195,14 +204,16 @@
break
}
- // Simple case: the context was canceled and the returned error is the context error.
+ // Simple case: the context was canceled and the returned error is the
+ // context error.
if err := ctx.Err(); err != nil && perr == err {
// Mark the node as canceled successfully.
n.state = nodeStateCanceled
return
}
- // Otherwise, the Runnable should not have died or quit. Handle accordingly.
+ // Otherwise, the Runnable should not have died or quit. Handle
+ // accordingly.
err := r.err
// A lack of returned error is also an error.
if err == nil {
@@ -225,27 +236,33 @@
continue
}
sibling := n.parent.children[name]
- // TODO(q3k): does this need to run in a goroutine, ie. can a context cancel block?
+ // TODO(q3k): does this need to run in a goroutine, ie. can a
+ // context cancel block?
sibling.ctxC()
}
}
}
-// processGC runs the GC process. It's not really Garbage Collection, as in, it doesn't remove unnecessary tree nodes -
-// but it does find nodes that need to be restarted, find the subset that can and then schedules them for running.
-// As such, it's less of a Garbage Collector and more of a Necromancer. However, GC is a friendlier name.
+// processGC runs the GC process. It's not really Garbage Collection, as in, it
+// doesn't remove unnecessary tree nodes - but it does find nodes that need to
+// be restarted, find the subset that can and then schedules them for running.
+// As such, it's less of a Garbage Collector and more of a Necromancer.
+// However, GC is a friendlier name.
func (s *supervisor) processGC() {
s.mu.Lock()
defer s.mu.Unlock()
- // The 'GC' serves is the main business logic of the supervision tree. It traverses a locked tree and tries to
- // find subtrees that must be restarted (because of a DEAD/CANCELED runnable). It then finds which of these
- // subtrees that should be restarted can be restarted, ie. which ones are fully recursively DEAD/CANCELED. It
- // also finds the smallest set of largest subtrees that can be restarted, ie. if there's multiple DEAD runnables
- // that can be restarted at once, it will do so.
+ // The 'GC' serves is the main business logic of the supervision tree. It
+ // traverses a locked tree and tries to find subtrees that must be
+ // restarted (because of a DEAD/CANCELED runnable). It then finds which of
+ // these subtrees that should be restarted can be restarted, ie. which ones
+ // are fully recursively DEAD/CANCELED. It also finds the smallest set of
+ // largest subtrees that can be restarted, ie. if there's multiple DEAD
+ // runnables that can be restarted at once, it will do so.
// Phase one: Find all leaves.
- // This is a simple DFS that finds all the leaves of the tree, ie all nodes that do not have children nodes.
+ // This is a simple DFS that finds all the leaves of the tree, ie all nodes
+ // that do not have children nodes.
leaves := make(map[string]bool)
queue := []*node{s.root}
for {
@@ -264,14 +281,17 @@
}
}
- // Phase two: traverse tree from node to root and make note of all subtrees that can be restarted.
- // A subtree is restartable/ready iff every node in that subtree is either CANCELED, DEAD or DONE.
- // Such a 'ready' subtree can be restarted by the supervisor if needed.
+ // Phase two: traverse tree from node to root and make note of all subtrees
+ // that can be restarted.
+ // A subtree is restartable/ready iff every node in that subtree is either
+ // CANCELED, DEAD or DONE. Such a 'ready' subtree can be restarted by the
+ // supervisor if needed.
// DNs that we already visited.
visited := make(map[string]bool)
// DNs whose subtrees are ready to be restarted.
- // These are all subtrees recursively - ie., root.a.a and root.a will both be marked here.
+ // These are all subtrees recursively - ie., root.a.a and root.a will both
+ // be marked here.
ready := make(map[string]bool)
// We build a queue of nodes to visit, starting from the leaves.
@@ -299,17 +319,20 @@
}
}
- // If no decision about children is available, it means we ended up in this subtree through some shorter path
- // of a shorter/lower-order leaf. There is a path to a leaf that's longer than the one that caused this node
- // to be enqueued. Easy solution: just push back the current element and retry later.
+ // If no decision about children is available, it means we ended up in
+ // this subtree through some shorter path of a shorter/lower-order
+ // leaf. There is a path to a leaf that's longer than the one that
+ // caused this node to be enqueued. Easy solution: just push back the
+ // current element and retry later.
if !allVisited {
// Push back to queue and wait for a decision later.
queue = append(queue, cur)
continue
}
- // All children have been visited and we have an idea about whether they're ready/restartable. All of the node's
- // children must be restartable in order for this node to be restartable.
+ // All children have been visited and we have an idea about whether
+ // they're ready/restartable. All of the node's children must be
+ // restartable in order for this node to be restartable.
childrenReady := true
for _, c := range cur.children {
if !ready[c.dn()] {
@@ -318,7 +341,8 @@
}
}
- // In addition to children, the node itself must be restartable (ie. DONE, DEAD or CANCELED).
+ // In addition to children, the node itself must be restartable (ie.
+ // DONE, DEAD or CANCELED).
curReady := false
switch cur.state {
case nodeStateDone:
@@ -329,7 +353,8 @@
curReady = true
}
- // Note down that we have an opinion on this node, and note that opinion down.
+ // Note down that we have an opinion on this node, and note that
+ // opinion down.
visited[curDn] = true
ready[curDn] = childrenReady && curReady
@@ -339,15 +364,17 @@
}
}
- // Phase 3: traverse tree from root to find largest subtrees that need to be restarted and are ready to be
- // restarted.
+ // Phase 3: traverse tree from root to find largest subtrees that need to
+ // be restarted and are ready to be restarted.
// All DNs that need to be restarted by the GC process.
want := make(map[string]bool)
- // All DNs that need to be restarted and can be restarted by the GC process - a subset of 'want' DNs.
+ // All DNs that need to be restarted and can be restarted by the GC process
+ // - a subset of 'want' DNs.
can := make(map[string]bool)
- // The set difference between 'want' and 'can' are all nodes that should be restarted but can't yet (ie. because
- // a child is still in the process of being canceled).
+ // The set difference between 'want' and 'can' are all nodes that should be
+ // restarted but can't yet (ie. because a child is still in the process of
+ // being canceled).
// DFS from root.
queue = []*node{s.root}
@@ -366,14 +393,16 @@
// If it should be restarted and is ready to be restarted...
if want[cur.dn()] && ready[cur.dn()] {
- // And its parent context is valid (ie hasn't been canceled), mark it as restartable.
+ // And its parent context is valid (ie hasn't been canceled), mark
+ // it as restartable.
if cur.parent == nil || cur.parent.ctx.Err() == nil {
can[cur.dn()] = true
continue
}
}
- // Otherwise, traverse further down the tree to see if something else needs to be done.
+ // Otherwise, traverse further down the tree to see if something else
+ // needs to be done.
for _, c := range cur.children {
queue = append(queue, c)
}
@@ -383,13 +412,15 @@
for dn, _ := range can {
n := s.nodeByDN(dn)
- // Only back off when the node unexpectedly died - not when it got canceled.
+ // Only back off when the node unexpectedly died - not when it got
+ // canceled.
bo := time.Duration(0)
if n.state == nodeStateDead {
bo = n.bo.NextBackOff()
}
- // Prepare node for rescheduling - remove its children, reset its state to new.
+ // Prepare node for rescheduling - remove its children, reset its state
+ // to new.
n.reset()
s.ilogger.Infof("rescheduling supervised node %s with backoff %s", dn, bo.String())
diff --git a/metropolis/pkg/supervisor/supervisor_support.go b/metropolis/pkg/supervisor/supervisor_support.go
index c2b569c..5f69104 100644
--- a/metropolis/pkg/supervisor/supervisor_support.go
+++ b/metropolis/pkg/supervisor/supervisor_support.go
@@ -16,21 +16,26 @@
package supervisor
-// Supporting infrastructure to allow running some non-Go payloads under supervision.
+// Supporting infrastructure to allow running some non-Go payloads under
+// supervision.
import (
"context"
"net"
"os/exec"
+
"source.monogon.dev/metropolis/pkg/logtree"
"google.golang.org/grpc"
)
-// GRPCServer creates a Runnable that serves gRPC requests as longs as it's not canceled.
-// If graceful is set to true, the server will be gracefully stopped instead of plain stopped. This means all pending
-// RPCs will finish, but also requires streaming gRPC handlers to check their context liveliness and exit accordingly.
-// If the server code does not support this, `graceful` should be false and the server will be killed violently instead.
+// GRPCServer creates a Runnable that serves gRPC requests as longs as it's not
+// canceled.
+// If graceful is set to true, the server will be gracefully stopped instead of
+// plain stopped. This means all pending RPCs will finish, but also requires
+// streaming gRPC handlers to check their context liveliness and exit
+// accordingly. If the server code does not support this, `graceful` should be
+// false and the server will be killed violently instead.
func GRPCServer(srv *grpc.Server, lis net.Listener, graceful bool) Runnable {
return func(ctx context.Context) error {
Signal(ctx, SignalHealthy)
@@ -52,7 +57,8 @@
}
}
-// RunCommand will create a Runnable that starts a long-running command, whose exit is determined to be a failure.
+// RunCommand will create a Runnable that starts a long-running command, whose
+// exit is determined to be a failure.
func RunCommand(ctx context.Context, cmd *exec.Cmd, opts ...RunCommandOption) error {
Signal(ctx, SignalHealthy)
@@ -86,8 +92,8 @@
parseKlog bool
}
-// ParseKLog signals that the command being run will return klog-compatible logs
-// to stdout and/or stderr, and these will be re-interpreted as structured
+// ParseKLog signals that the command being run will return klog-compatible
+// logs to stdout and/or stderr, and these will be re-interpreted as structured
// logging and emitted to the supervisor's logger.
func ParseKLog() RunCommandOption {
return RunCommandOption{
diff --git a/metropolis/pkg/supervisor/supervisor_test.go b/metropolis/pkg/supervisor/supervisor_test.go
index 9c7bdb7..db84163 100644
--- a/metropolis/pkg/supervisor/supervisor_test.go
+++ b/metropolis/pkg/supervisor/supervisor_test.go
@@ -76,7 +76,8 @@
}
}
-// rc is a Remote Controlled runnable. It is a generic runnable used for testing the supervisor.
+// rc is a Remote Controlled runnable. It is a generic runnable used for
+// testing the supervisor.
type rc struct {
req chan rcRunnableRequest
}
@@ -129,7 +130,8 @@
}
func (r *rc) waitState(s rcRunnableState) {
- // This is poll based. Making it non-poll based would make the RC runnable logic a bit more complex for little gain.
+ // This is poll based. Making it non-poll based would make the RC runnable
+ // logic a bit more complex for little gain.
for {
got := r.state()
if got == s {
@@ -384,12 +386,14 @@
}, WithPropagatePanic)
one.becomeHealthy()
- // Die a bunch of times in a row, this brings up the next exponential backoff to over a second.
+ // Die a bunch of times in a row, this brings up the next exponential
+ // backoff to over a second.
for i := 0; i < 4; i += 1 {
one.die()
one.waitState(rcRunnableStateNew)
}
- // Measure how long it takes for the runnable to respawn after a number of failures
+ // Measure how long it takes for the runnable to respawn after a number of
+ // failures
start := time.Now()
one.die()
one.becomeHealthy()
@@ -411,8 +415,9 @@
}
}
-// TestResilience throws some curveballs at the supervisor - either programming errors or high load. It then ensures
-// that another runnable is running, and that it restarts on its sibling failure.
+// TestResilience throws some curveballs at the supervisor - either programming
+// errors or high load. It then ensures that another runnable is running, and
+// that it restarts on its sibling failure.
func TestResilience(t *testing.T) {
// request/response channel for testing liveness of the 'one' runnable
req := make(chan chan struct{})
@@ -443,7 +448,8 @@
timeout.Stop()
}
- // A nasty runnable that calls Signal with the wrong context (this is a programming error)
+ // A nasty runnable that calls Signal with the wrong context (this is a
+ // programming error)
two := func(ctx context.Context) error {
Signal(context.TODO(), SignalHealthy)
return nil