m/pkg/event: make type-safe

This is a fairly large change which makes use of Go type parameters
(“generics”) to make the event library (and its memory/etcd
implementations) type safe.

Since we now have the event.Value interface strongly typed, we also move
options which were implementation-specific (like BacklogOnly)
to be part of that interface, instead of the previously type-asserted
specific implementations. Use of options that are not handled by a
particular implementation is a runtime error. Expressing this in the
type system is probably not worth the effort.

We also implement Filter to allow offloading some of the functionality previously implemented in type assertion wrappers into the library itself.

In the end, this ends up removing a bunch of type assertion code, at
the cost of a fairly sweeping change. Unfortunately, some of this is due
to IntelliJ suddenly deciding to reformat comments.

Change-Id: I1ca6d93db1b5c4055a21af3fb9e5e3d425c0d86e
Reviewed-on: https://review.monogon.dev/c/monogon/+/1322
Tested-by: Jenkins CI
Reviewed-by: Leopold Schabel <leo@monogon.tech>
diff --git a/metropolis/node/core/consensus/consensus.go b/metropolis/node/core/consensus/consensus.go
index b570c69..5daa02f 100644
--- a/metropolis/node/core/consensus/consensus.go
+++ b/metropolis/node/core/consensus/consensus.go
@@ -99,6 +99,7 @@
 
 	"source.monogon.dev/metropolis/node/core/consensus/client"
 	"source.monogon.dev/metropolis/node/core/identity"
+	"source.monogon.dev/metropolis/pkg/event"
 	"source.monogon.dev/metropolis/pkg/event/memory"
 	"source.monogon.dev/metropolis/pkg/logtree/unraw"
 	"source.monogon.dev/metropolis/pkg/pki"
@@ -144,7 +145,7 @@
 type Service struct {
 	config *Config
 
-	value memory.Value
+	value memory.Value[*Status]
 	ca    *pki.Certificate
 }
 
@@ -454,7 +455,7 @@
 		}
 	}
 
-	w := s.Watch()
+	w := s.value.Watch()
 	for {
 		st, err := w.Get(ctx)
 		if err != nil {
@@ -473,6 +474,10 @@
 	}
 }
 
+func (s *Service) Watch() event.Watcher[*Status] {
+	return s.value.Watch()
+}
+
 // selfupdater is a runnable that performs a one-shot (once per Service Run,
 // thus once for each configuration) update of the node's Peer URL in etcd. This
 // is currently only really needed because the first node in the cluster
@@ -482,7 +487,7 @@
 // more robust.
 func (s *Service) selfupdater(ctx context.Context) error {
 	supervisor.Signal(ctx, supervisor.SignalHealthy)
-	w := s.Watch()
+	w := s.value.Watch()
 	for {
 		st, err := w.Get(ctx)
 		if err != nil {