m/p/supervisor: implement sub-loggers

This permits logging from a runnable into a logtree sub-DN that is not
backed by an actualy child runnable. For example, 'root.foo' can request
a SubLogger with name 'bar' to emit logs into 'root.foo.bar'.

This is in preparation for logging RPC calls within supervised
runnables, but can also come in handy in other situations where we'd
like to log to separete 'topics' within a single runnable.

This breaks 1:1 correspondence between logtree DNs and supervisor DNs.
An alternative would be to introduce extra 'tags'/'topics' eg
root.foo:bar, but that would require encoding extra logic to the
logtree. However, that would perhaps allow us to introduce higher
cardinality child loggers, with a logger per RPC. We'll have to consider
this at some later point.

Let's see where this takes us, there's a chance we'll roll this
back if it's too confusing from an UX point of view.

Change-Id: Ibdee5c2b400bb8fce76b0a4f781914748793db0e
Reviewed-on: https://review.monogon.dev/c/monogon/+/536
Reviewed-by: Leopold Schabel <leo@nexantic.com>
diff --git a/metropolis/pkg/supervisor/supervisor_node.go b/metropolis/pkg/supervisor/supervisor_node.go
index a3bf5e4..4fb2ddb 100644
--- a/metropolis/pkg/supervisor/supervisor_node.go
+++ b/metropolis/pkg/supervisor/supervisor_node.go
@@ -43,6 +43,10 @@
 	// Children of this tree. This is represented by a map keyed from child
 	// node names, for easy access.
 	children map[string]*node
+	// Reserved nodes that may not be used as child names. This is currently
+	// used by sub-loggers (see SubLogger function), preventing a sub-logger
+	// name from colliding with a node name.
+	reserved map[string]bool
 	// 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
@@ -199,6 +203,7 @@
 	// Clear children and state
 	n.state = nodeStateNew
 	n.children = make(map[string]*node)
+	n.reserved = make(map[string]bool)
 	n.groups = nil
 
 	// The node is now ready to be scheduled.
@@ -244,6 +249,9 @@
 		if _, ok := n.children[name]; ok {
 			return fmt.Errorf("runnable %q already exists", name)
 		}
+		if _, ok := n.reserved[name]; ok {
+			return fmt.Errorf("runnable %q would shadow reserved name (eg. sub-logger)", name)
+		}
 	}
 
 	// Create child nodes.