m/pkg/combinectx: implement
This implements combinectx, a Go library for combining two contexts into
a single one. We need this for the new curator logic (where we want to
cancel RPC calls both when the incoming request gets canceled but also
when leadership status changes), and this functionality has been
factored out as a reusable, generic library.
Prior art:
1) https://github.com/golang/go/issues/36503
Proposal to add Merge() to context stdlib package. Unimplemented.
2) https://github.com/teivah/onecontext
Complex reflect-based logic for arbitrary amount of contexts to join,
no functionality to detect which context caused the joined context to
be canceled.
3) https://github.com/LK4D4/joincontext
No functionality to detect which context caused the joined context to
be canceled.
Change-Id: I774607da38b06c192ff0fee133eb258abd500864
Reviewed-on: https://review.monogon.dev/c/monogon/+/123
Reviewed-by: Leopold Schabel <leo@nexantic.com>
diff --git a/metropolis/pkg/combinectx/BUILD.bazel b/metropolis/pkg/combinectx/BUILD.bazel
new file mode 100644
index 0000000..d467c47
--- /dev/null
+++ b/metropolis/pkg/combinectx/BUILD.bazel
@@ -0,0 +1,17 @@
+load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
+
+go_library(
+ name = "go_default_library",
+ srcs = ["combinectx.go"],
+ importpath = "source.monogon.dev/metropolis/pkg/combinectx",
+ visibility = ["//visibility:public"],
+)
+
+go_test(
+ name = "go_default_test",
+ srcs = [
+ "combinectx_test.go",
+ "example_test.go",
+ ],
+ embed = [":go_default_library"],
+)