diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0e7aed2..8df8207 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -39,7 +39,7 @@ jobs: matrix: # Only the go_binary targets support cross-compilation at the moment: target: - - //cdpi_agent/cmd/agent + - //agent/cmd/agent - //tools/nbictl/cmd/nbictl - //tools/generate_jwt os: [linux, windows, darwin] @@ -64,14 +64,14 @@ jobs: path: | bazel-bin/tools/nbictl/cmd/nbictl/nbictl_/nbictl bazel-bin/tools/nbictl/cmd/nbictl/nbictl_/nbictl.exe - - name: Upload cdpi_agent binary + - name: Upload agent binary uses: actions/upload-artifact@v3 - if: matrix.target == '//cdpi_agent/cmd/agent' + if: matrix.target == '//agent/cmd/agent' with: - name: cdpi_agent-${{ matrix.os }}-${{ matrix.arch }} + name: agent-${{ matrix.os }}-${{ matrix.arch }} path: | - bazel-bin/cdpi_agent/cmd/agent/agent_/agent - bazel-bin/cdpi_agent/cmd/agent/agent_/agent.exe + bazel-bin/agent/cmd/agent/agent_/agent + bazel-bin/agent/cmd/agent/agent_/agent.exe - name: Upload generate_jwt binary uses: actions/upload-artifact@v3 if: matrix.target == '//tools/generate_jwt' diff --git a/README.md b/README.md index f081a67..7e3b73c 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ This site contains: ## Repo Contents In this repo, you will find the following directories: - [api](/api): The [gRPC](https://grpc.io/) and [Protocol Buffers](https://protobuf.dev/) definitions of the API. -- [cdpi_agent](/cdpi_agent): A Go implementation of a CDPI agent. +- [agent](/agent): A Go implementation of an SBI agent. - [contrib](/contrib): An open-source directory of real hardware that has been modeled in Spacetime and used in real networks. Contributions are welcome! ## Contributing diff --git a/cdpi_agent/BUILD b/agent/BUILD similarity index 86% rename from cdpi_agent/BUILD rename to agent/BUILD index 2442886..f783b87 100644 --- a/cdpi_agent/BUILD +++ b/agent/BUILD @@ -20,7 +20,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") package(default_visibility = ["//visibility:public"]) go_library( - name = "cdpi_agent", + name = "agent", srcs = [ "agent.go", "enactment_service.go", @@ -28,16 +28,16 @@ go_library( "telemetry_service.go", "timing.go", ], - importpath = "aalyria.com/spacetime/cdpi_agent", + importpath = "aalyria.com/spacetime/agent", deps = [ + "//agent/enactment", + "//agent/internal/channels", + "//agent/internal/loggable", + "//agent/internal/task", + "//agent/telemetry", "//api/cdpi/v1alpha:cdpi_go_grpc", "//api/common:common_go_proto", "//api/scheduling/v1alpha:scheduling_go_grpc", - "//cdpi_agent/enactment", - "//cdpi_agent/internal/channels", - "//cdpi_agent/internal/loggable", - "//cdpi_agent/internal/task", - "//cdpi_agent/telemetry", "@com_github_google_uuid//:uuid", "@com_github_jonboulle_clockwork//:clockwork", "@com_github_rs_zerolog//:zerolog", @@ -52,7 +52,7 @@ go_library( ) go_test( - name = "cdpi_agent_test", + name = "agent_test", size = "small", srcs = [ "agent_test.go", @@ -61,13 +61,13 @@ go_test( "telemetry_test.go", "timing_test.go", ], - embed = [":cdpi_agent"], + embed = [":agent"], deps = [ + "//agent/internal/channels", + "//agent/internal/task", "//api/cdpi/v1alpha:cdpi_go_grpc", "//api/common:common_go_proto", "//api/scheduling/v1alpha:scheduling_go_grpc", - "//cdpi_agent/internal/channels", - "//cdpi_agent/internal/task", "@com_github_google_go_cmp//cmp", "@com_github_jonboulle_clockwork//:clockwork", "@com_github_rs_zerolog//:zerolog", diff --git a/cdpi_agent/README.md b/agent/README.md similarity index 69% rename from cdpi_agent/README.md rename to agent/README.md index d013b40..846de8a 100644 --- a/cdpi_agent/README.md +++ b/agent/README.md @@ -11,14 +11,14 @@ sophisticated features. This directory provides two important pieces for interacting with the Spacetime CDPI: -- The `agent` (`//cdpi_agent/cmd/agent`), a Go binary that handle the CDPI protocol and +- The `agent` (`//agent/cmd/agent`), a Go binary that handle the CDPI protocol and authentication details while delegating the actual implementation of enactments to a user-configured external process. While the details of the CDPI protocol are still subject to change, the command line interface for these binaries is intended to be significantly more stable and provide an easy to develop against abstraction that insulates platform integrators from the majority of those changes. -- The `cdpi_agent` library (`//cdpi_agent`), a Go package that provides a growing set of +- The `agent` library (`//agent`), a Go package that provides a growing set of abstractions for writing a new CDPI agent. This library is subject to change alongside the CDPI protocol, so platform integrators are encouraged to use the `agent` binary until the underlying APIs reach a stable milestone. @@ -26,13 +26,13 @@ This directory provides two important pieces for interacting with the Spacetime ## Building This repo uses the [bazel](https://bazel.build/) build system. Once you have a copy of `bazel` in -your `$PATH`, running `bazel build //cdpi_agent/cmd/agent` will build the Go binary. Similarly, -running `bazel build //cdpi_agent` will build the Go library. +your `$PATH`, running `bazel build //agent/cmd/agent` will build the Go binary. Similarly, +running `bazel build //agent` will build the Go library. For a full list of available build targets, you can use `bazel query`: ```bash -bazel query //cdpi_agent/...:all +bazel query //agent/...:all ``` ## Getting started with the `agent` binary @@ -40,7 +40,7 @@ bazel query //cdpi_agent/...:all ### Configuration The `agent` binary accepts configuration in the form of a protobuf message, documented in -[config.proto](cdpi_agent/cmd/agent/config.proto). The message can be encoded in +[config.proto](agent/cmd/agent/config.proto). The message can be encoded in [prototext format](https://protobuf.dev/reference/protobuf/textformat-spec/) (human readable and writable), [json](https://protobuf.dev/programming-guides/proto3/#json), or the [binary proto format](https://protobuf.dev/programming-guides/encoding/). Most users will find the @@ -50,37 +50,34 @@ More details for each aspect of the configuration are provided below, but a simp file might look like this: ```textproto -connection_params: { - # TODO: change to point to the domain of your spacetime instance - cdpi_endpoint: "dns:///my_instance.spacetime.aalyria.com" +# each network_node is configured with a stanza like so: +network_nodes: { + id: "node-a" + enactment_backend: { + connection_params: { + # TODO: change to point to the domain of your spacetime instance + endpoint_uri: "dns:///scheduling.my_instance.spacetime.aalyria.com" - transport_security: { - system_cert_pool: {} - } + transport_security: { + system_cert_pool: {} + } - auth_strategy: { - jwt: { - # TODO: change to the domain of your spacetime instance - audience: "my_instance.spacetime.aalyria.com" - # TODO: use the email your Aalyria representative will share with you - email: "my-cdpi-agent@example.com" - # TODO: use the private key ID your Aalyria representative will share with you - private_key_id: "BADDB0BACAFE" - signing_strategy: { - # TODO: change to the path of your PEM-encoded RSA private key - private_key_file: "/path/to/agent/private/key.pem" + auth_strategy: { + jwt: { + # TODO: change to the domain of your spacetime instance + audience: "scheduling.my_instance.spacetime.aalyria.com" + # TODO: use the email your Aalyria representative will share with you + email: "my-cdpi-agent@example.com" + # TODO: use the private key ID your Aalyria representative will share with you + private_key_id: "BADDB0BACAFE" + signing_strategy: { + # TODO: change to the path of your PEM-encoded RSA private key + private_key_file: "/path/to/agent/private/key.pem" + } + } } } - } -} -# each network_node is configured with a stanza like so: -network_nodes: { - id: "node-a" - state_backend: { - static_initial_state: {} - } - enactment_backend: { external_command: { # while each command invocation will receive a node ID as part of the # enactment request, you can also pass additional arguments here to help @@ -98,10 +95,31 @@ network_nodes: { network_nodes: { id: "node-b" - state_backend: { - static_initial_state: {} - } enactment_backend: { + connection_params: { + # TODO: change to point to the domain of your spacetime instance + endpoint_uri: "dns:///scheduling.my_instance.spacetime.aalyria.com" + + transport_security: { + system_cert_pool: {} + } + + auth_strategy: { + jwt: { + # TODO: change to the domain of your spacetime instance + audience: "scheduling.my_instance.spacetime.aalyria.com" + # TODO: use the email your Aalyria representative will share with you + email: "my-cdpi-agent@example.com" + # TODO: use the private key ID your Aalyria representative will share with you + private_key_id: "BADDB0BACAFE" + signing_strategy: { + # TODO: change to the path of your PEM-encoded RSA private key + private_key_file: "/path/to/agent/private/key.pem" + } + } + } + } + external_command: { args: "/usr/local/bin/some_other_enactment_cmd" # Use the protobuf binary format for encoding both stdin and stdout messages. @@ -111,20 +129,20 @@ network_nodes: { } ``` -See the documentation in [config.proto](cdpi_agent/cmd/agent/config.proto) for more details on the +See the documentation in [config.proto](agent/cmd/agent/config.proto) for more details on the available options. You can use the `--dry-run` flag to check that your configuration is valid: ```bash -bazel run //cdpi_agent/cmd/agent -- --log-level trace --config "$PWD/config.textproto" --dry-run +bazel run //agent/cmd/agent -- --log-level trace --config "$PWD/config.textproto" --dry-run INFO: Invocation ID: d8a4b02f-1e01-47cb-bd26-5366704165af -INFO: Analyzed target //cdpi_agent/cmd/agent:agent (0 packages loaded, 0 targets configured). +INFO: Analyzed target //agent/cmd/agent:agent (0 packages loaded, 0 targets configured). INFO: Found 1 target... -Target //cdpi_agent/cmd/agent:agent up-to-date: - bazel-bin/cdpi_agent/cmd/agent/agent_/agent +Target //agent/cmd/agent:agent up-to-date: + bazel-bin/agent/cmd/agent/agent_/agent INFO: Elapsed time: 1.768s, Critical Path: 1.56s INFO: 3 processes: 1 internal, 2 linux-sandbox. INFO: Build completed successfully, 3 total actions -INFO: Running command line: bazel-bin/cdpi_agent/cmd/agent/agent_/agent --log-level trace --config /path/to/config.textproto --format text --dry-run +INFO: Running command line: bazel-bin/agent/cmd/agent/agent_/agent --log-level trace --config /path/to/config.textproto --format text --dry-run 2023-04-19 11:57:01AM INF config is valid ``` @@ -153,7 +171,7 @@ Assuming you've saved your configuration in a file called `config.textproto`, yo following command to start the agent: ```bash -bazel run //cdpi_agent/cmd/agent -- --config "$PWD/my_config.textproto" --log-level debug +bazel run //agent/cmd/agent -- --config "$PWD/my_config.textproto" --log-level debug ``` NOTE: `bazel run` changes the working directory of the process, so you'll need diff --git a/cdpi_agent/agent.go b/agent/agent.go similarity index 97% rename from cdpi_agent/agent.go rename to agent/agent.go index 6bd720f..0615512 100644 --- a/cdpi_agent/agent.go +++ b/agent/agent.go @@ -22,9 +22,9 @@ import ( "fmt" "sync" - "aalyria.com/spacetime/cdpi_agent/enactment" - "aalyria.com/spacetime/cdpi_agent/internal/task" - "aalyria.com/spacetime/cdpi_agent/telemetry" + "aalyria.com/spacetime/agent/enactment" + "aalyria.com/spacetime/agent/internal/task" + "aalyria.com/spacetime/agent/telemetry" "github.com/jonboulle/clockwork" "github.com/rs/zerolog" diff --git a/cdpi_agent/agent_test.go b/agent/agent_test.go similarity index 100% rename from cdpi_agent/agent_test.go rename to agent/agent_test.go diff --git a/cdpi_agent/cmd/agent/BUILD b/agent/cmd/agent/BUILD similarity index 87% rename from cdpi_agent/cmd/agent/BUILD rename to agent/cmd/agent/BUILD index ded58fd..b38d1df 100644 --- a/cdpi_agent/cmd/agent/BUILD +++ b/agent/cmd/agent/BUILD @@ -26,6 +26,6 @@ go_binary( go_library( name = "agent_lib", srcs = ["agent.go"], - importpath = "aalyria.com/spacetime/cdpi_agent/cmd/agent", - deps = ["//cdpi_agent/internal/agentcli:agentcli_lib"], + importpath = "aalyria.com/spacetime/agent/cmd/agent", + deps = ["//agent/internal/agentcli:agentcli_lib"], ) diff --git a/cdpi_agent/cmd/agent/agent.go b/agent/cmd/agent/agent.go similarity index 95% rename from cdpi_agent/cmd/agent/agent.go rename to agent/cmd/agent/agent.go index ecbd7a2..c16267d 100644 --- a/cdpi_agent/cmd/agent/agent.go +++ b/agent/cmd/agent/agent.go @@ -21,7 +21,7 @@ import ( "fmt" "os" - "aalyria.com/spacetime/cdpi_agent/internal/agentcli" + "aalyria.com/spacetime/agent/internal/agentcli" ) func main() { diff --git a/cdpi_agent/cmd/prom2spacetime/BUILD b/agent/cmd/prom2spacetime/BUILD similarity index 91% rename from cdpi_agent/cmd/prom2spacetime/BUILD rename to agent/cmd/prom2spacetime/BUILD index 377eb68..d99cd7d 100644 --- a/cdpi_agent/cmd/prom2spacetime/BUILD +++ b/agent/cmd/prom2spacetime/BUILD @@ -19,10 +19,10 @@ package(default_visibility = ["//visibility:public"]) go_library( name = "prom2spacetime_lib", srcs = ["prom2spacetime.go"], - importpath = "aalyria.com/spacetime/cdpi_agent/cmd/prom2spacetime", + importpath = "aalyria.com/spacetime/agent/cmd/prom2spacetime", deps = [ + "//agent/telemetry/prometheus", "//api/common:common_go_proto", - "//cdpi_agent/telemetry/prometheus", "@org_golang_google_protobuf//encoding/protojson", "@org_golang_google_protobuf//encoding/prototext", "@org_golang_google_protobuf//encoding/protowire", diff --git a/cdpi_agent/cmd/prom2spacetime/prom2spacetime.go b/agent/cmd/prom2spacetime/prom2spacetime.go similarity index 98% rename from cdpi_agent/cmd/prom2spacetime/prom2spacetime.go rename to agent/cmd/prom2spacetime/prom2spacetime.go index bc2a3f4..2d7c652 100644 --- a/cdpi_agent/cmd/prom2spacetime/prom2spacetime.go +++ b/agent/cmd/prom2spacetime/prom2spacetime.go @@ -24,7 +24,7 @@ import ( "time" apipb "aalyria.com/spacetime/api/common" - "aalyria.com/spacetime/cdpi_agent/telemetry/prometheus" + "aalyria.com/spacetime/agent/telemetry/prometheus" "google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/encoding/prototext" diff --git a/cdpi_agent/common_test.go b/agent/common_test.go similarity index 100% rename from cdpi_agent/common_test.go rename to agent/common_test.go diff --git a/cdpi_agent/enactment/BUILD b/agent/enactment/BUILD similarity index 93% rename from cdpi_agent/enactment/BUILD rename to agent/enactment/BUILD index 945af84..bac7e72 100644 --- a/cdpi_agent/enactment/BUILD +++ b/agent/enactment/BUILD @@ -19,6 +19,6 @@ package(default_visibility = ["//visibility:public"]) go_library( name = "enactment", srcs = ["enactment.go"], - importpath = "aalyria.com/spacetime/cdpi_agent/enactment", + importpath = "aalyria.com/spacetime/agent/enactment", deps = ["//api/scheduling/v1alpha:scheduling_go_grpc"], ) diff --git a/cdpi_agent/enactment/enactment.go b/agent/enactment/enactment.go similarity index 100% rename from cdpi_agent/enactment/enactment.go rename to agent/enactment/enactment.go diff --git a/cdpi_agent/enactment/extproc/BUILD b/agent/enactment/extproc/BUILD similarity index 82% rename from cdpi_agent/enactment/extproc/BUILD rename to agent/enactment/extproc/BUILD index e1cff45..5ab569f 100644 --- a/cdpi_agent/enactment/extproc/BUILD +++ b/agent/enactment/extproc/BUILD @@ -19,12 +19,12 @@ package(default_visibility = ["//visibility:public"]) go_library( name = "extproc", srcs = ["extproc.go"], - importpath = "aalyria.com/spacetime/cdpi_agent/enactment/extproc", + importpath = "aalyria.com/spacetime/agent/enactment/extproc", deps = [ + "//agent/enactment", + "//agent/internal/extprocs", + "//agent/internal/protofmt", "//api/scheduling/v1alpha:scheduling_go_grpc", - "//cdpi_agent/enactment", - "//cdpi_agent/internal/extprocs", - "//cdpi_agent/internal/protofmt", "@com_github_rs_zerolog//:zerolog", ], ) @@ -34,7 +34,7 @@ go_test( srcs = ["extproc_test.go"], embed = [":extproc"], deps = [ + "//agent/internal/protofmt", "//api/scheduling/v1alpha:scheduling_go_grpc", - "//cdpi_agent/internal/protofmt", ], ) diff --git a/cdpi_agent/enactment/extproc/extproc.go b/agent/enactment/extproc/extproc.go similarity index 94% rename from cdpi_agent/enactment/extproc/extproc.go rename to agent/enactment/extproc/extproc.go index 3384fdf..d90226f 100644 --- a/cdpi_agent/enactment/extproc/extproc.go +++ b/agent/enactment/extproc/extproc.go @@ -32,9 +32,9 @@ import ( "os/exec" schedpb "aalyria.com/spacetime/api/scheduling/v1alpha" - "aalyria.com/spacetime/cdpi_agent/enactment" - "aalyria.com/spacetime/cdpi_agent/internal/extprocs" - "aalyria.com/spacetime/cdpi_agent/internal/protofmt" + "aalyria.com/spacetime/agent/enactment" + "aalyria.com/spacetime/agent/internal/extprocs" + "aalyria.com/spacetime/agent/internal/protofmt" "github.com/rs/zerolog" ) diff --git a/cdpi_agent/enactment/extproc/extproc_test.go b/agent/enactment/extproc/extproc_test.go similarity index 95% rename from cdpi_agent/enactment/extproc/extproc_test.go rename to agent/enactment/extproc/extproc_test.go index 1eb065e..d59448c 100644 --- a/cdpi_agent/enactment/extproc/extproc_test.go +++ b/agent/enactment/extproc/extproc_test.go @@ -19,7 +19,7 @@ import ( "testing" schedpb "aalyria.com/spacetime/api/scheduling/v1alpha" - "aalyria.com/spacetime/cdpi_agent/internal/protofmt" + "aalyria.com/spacetime/agent/internal/protofmt" ) func TestDispatchEmptyOutput(t *testing.T) { diff --git a/cdpi_agent/enactment/netlink/BUILD b/agent/enactment/netlink/BUILD similarity index 96% rename from cdpi_agent/enactment/netlink/BUILD rename to agent/enactment/netlink/BUILD index e063f3c..8462d04 100644 --- a/cdpi_agent/enactment/netlink/BUILD +++ b/agent/enactment/netlink/BUILD @@ -24,7 +24,7 @@ go_library( "errors.go", "netlink.go", ], - importpath = "aalyria.com/spacetime/cdpi_agent/enactment/netlink", + importpath = "aalyria.com/spacetime/agent/enactment/netlink", deps = [ "//api/common:common_go_proto", "//api/scheduling/v1alpha:scheduling_go_grpc", diff --git a/cdpi_agent/enactment/netlink/container_test/BUILD b/agent/enactment/netlink/container_test/BUILD similarity index 93% rename from cdpi_agent/enactment/netlink/container_test/BUILD rename to agent/enactment/netlink/container_test/BUILD index c9e43d8..df47640 100644 --- a/cdpi_agent/enactment/netlink/container_test/BUILD +++ b/agent/enactment/netlink/container_test/BUILD @@ -31,10 +31,10 @@ go_binary( go_library( name = "netlink_exercise_lib", srcs = ["netlink_exercise.go"], - importpath = "aalyria.com/spacetime/cdpi_agent/enactment/netlink/container_test", + importpath = "aalyria.com/spacetime/agent/enactment/netlink/container_test", deps = [ + "//agent/enactment/netlink", "//api/common:common_go_proto", - "//cdpi_agent/enactment/netlink", "@com_github_jonboulle_clockwork//:clockwork", "@com_github_vishvananda_netlink//:netlink", "@org_golang_google_protobuf//proto", diff --git a/cdpi_agent/enactment/netlink/container_test/debug.sh b/agent/enactment/netlink/container_test/debug.sh similarity index 100% rename from cdpi_agent/enactment/netlink/container_test/debug.sh rename to agent/enactment/netlink/container_test/debug.sh diff --git a/cdpi_agent/enactment/netlink/container_test/netlink_exercise.go b/agent/enactment/netlink/container_test/netlink_exercise.go similarity index 98% rename from cdpi_agent/enactment/netlink/container_test/netlink_exercise.go rename to agent/enactment/netlink/container_test/netlink_exercise.go index c328170..673bbf7 100644 --- a/cdpi_agent/enactment/netlink/container_test/netlink_exercise.go +++ b/agent/enactment/netlink/container_test/netlink_exercise.go @@ -27,7 +27,7 @@ import ( "google.golang.org/protobuf/proto" apipb "aalyria.com/spacetime/api/common" - "aalyria.com/spacetime/cdpi_agent/enactment/netlink" + "aalyria.com/spacetime/agent/enactment/netlink" "github.com/jonboulle/clockwork" vnl "github.com/vishvananda/netlink" @@ -252,7 +252,7 @@ func main() { return } - fmt.Printf("\nImplement zulu3 FlowRuleID for destination 104.198.75.23. Without syncing, cdpi_agent would think this is already implemented, and the route ADD would be skipped, leaving us without a route\n") + fmt.Printf("\nImplement zulu3 FlowRuleID for destination 104.198.75.23. Without syncing, agent would think this is already implemented, and the route ADD would be skipped, leaving us without a route\n") updateId = "64288bc4-d401-428a-b7be-926bebb5f832" newState, err = eb.Apply(ctx, &apipb.ScheduledControlUpdate{ diff --git a/cdpi_agent/enactment/netlink/container_test/netlink_exercise_tests.yaml b/agent/enactment/netlink/container_test/netlink_exercise_tests.yaml similarity index 100% rename from cdpi_agent/enactment/netlink/container_test/netlink_exercise_tests.yaml rename to agent/enactment/netlink/container_test/netlink_exercise_tests.yaml diff --git a/cdpi_agent/enactment/netlink/errors.go b/agent/enactment/netlink/errors.go similarity index 100% rename from cdpi_agent/enactment/netlink/errors.go rename to agent/enactment/netlink/errors.go diff --git a/cdpi_agent/enactment/netlink/netlink.go b/agent/enactment/netlink/netlink.go similarity index 99% rename from cdpi_agent/enactment/netlink/netlink.go rename to agent/enactment/netlink/netlink.go index 8d0ee1e..2ca3d63 100644 --- a/cdpi_agent/enactment/netlink/netlink.go +++ b/agent/enactment/netlink/netlink.go @@ -323,7 +323,7 @@ func (b *Driver) buildStateProtoUnlocked(installedRouteProvider func() ([]vnl.Ro defer b.mu.Unlock() // TODO: this is simply a brute force matching. If and when we have - // `cdpi_agent`s with large volumes of routes, we may want to use a more + // `agent`s with large volumes of routes, we may want to use a more // intelligent matching algorithm. for _, rt := range b.routesToRuleIDs { for ruleID, flowRulePB := range rt.ruleIDs { diff --git a/cdpi_agent/enactment/netlink/netlink_test.go b/agent/enactment/netlink/netlink_test.go similarity index 100% rename from cdpi_agent/enactment/netlink/netlink_test.go rename to agent/enactment/netlink/netlink_test.go diff --git a/cdpi_agent/enactment_service.go b/agent/enactment_service.go similarity index 91% rename from cdpi_agent/enactment_service.go rename to agent/enactment_service.go index ef21fe3..3817f8a 100644 --- a/cdpi_agent/enactment_service.go +++ b/agent/enactment_service.go @@ -29,10 +29,10 @@ import ( apipb "aalyria.com/spacetime/api/common" schedpb "aalyria.com/spacetime/api/scheduling/v1alpha" - "aalyria.com/spacetime/cdpi_agent/enactment" - "aalyria.com/spacetime/cdpi_agent/internal/channels" - "aalyria.com/spacetime/cdpi_agent/internal/loggable" - "aalyria.com/spacetime/cdpi_agent/internal/task" + "aalyria.com/spacetime/agent/enactment" + "aalyria.com/spacetime/agent/internal/channels" + "aalyria.com/spacetime/agent/internal/loggable" + "aalyria.com/spacetime/agent/internal/task" ) // we keep already attempted enactments in memory for this long to help resolve @@ -155,7 +155,6 @@ func (sm *scheduleManager) recordResult(result *enactmentResult) { entry.Error = result.err entry.EndTime = result.tStamp - // TODO: log (will want ctx here) if entry.DeletePending { // A DeleteEntryRequest arrived after the request had @@ -286,6 +285,10 @@ func (es *enactmentService) mainScheduleLoop(ctx context.Context) error { req = pendingRequests[0] seqno := mustSeqno(req) if seqno > nextSeqno { + zerolog.Ctx(ctx).Info(). + Uint64("seqno.this", seqno). + Uint64("seqno.nextExpected", nextSeqno). + Msg("seqno greater than next expected; delaying scheduling") break } status := es.handleSchedulingRequest(ctx, req) @@ -305,6 +308,14 @@ func (es *enactmentService) mainScheduleLoop(ctx context.Context) error { // Likely a DeleteEntry() racing with the Timer firing. continue } + if entry.StartTime.After(entry.EndTime) { + zerolog.Ctx(ctx).Warn().Object("req", loggable.Proto(entry.Req)).Msg("Dispatch already in progress") + continue + } + if entry.EndTime.After(entry.StartTime) { + zerolog.Ctx(ctx).Warn().Object("req", loggable.Proto(entry.Req)).Msg("Dispatch already completed") + continue + } entry.StartTime = es.clock.Now() go func() { result := &enactmentResult{ @@ -321,6 +332,11 @@ func (es *enactmentService) mainScheduleLoop(ctx context.Context) error { }() // [3] Note the return code (and other results) from a backend call. case result := <-es.enactmentResults: + zerolog.Ctx(ctx).Debug(). + Str("result.id", result.id). + AnErr("result.err", result.err). + Time("result.tStamp", result.tStamp). + Msg("recv'd Dispatch result") es.schedMgr.recordResult(result) } } @@ -338,6 +354,7 @@ func (es *enactmentService) sendResponse(ctx context.Context, id int64, status * case <-ctx.Done(): return context.Cause(ctx) case es.rspsToController <- resp: + zerolog.Ctx(ctx).Debug().Object("response", loggable.Proto(resp)).Msg("sending response") return nil } } @@ -346,6 +363,11 @@ func (es *enactmentService) handleSchedulingRequest(ctx context.Context, req *sc switch req.Request.(type) { case *schedpb.ReceiveRequestsMessageFromController_CreateEntry: id := req.GetCreateEntry().Id + if _, ok := es.schedMgr.Entries[id]; ok { + // Ignore repeated scheduling of the same entry ID. + zerolog.Ctx(ctx).Debug().Str("entry ID", id).Msg("ignoring scheduling attempt of duplicate entry") + return OK() + } delay := req.GetCreateEntry().Time.AsTime().Sub(es.clock.Now()) timer := es.clock.AfterFunc(delay, func() { select { diff --git a/cdpi_agent/enactment_test.go b/agent/enactment_test.go similarity index 99% rename from cdpi_agent/enactment_test.go rename to agent/enactment_test.go index 07ea588..a6091e8 100644 --- a/cdpi_agent/enactment_test.go +++ b/agent/enactment_test.go @@ -26,8 +26,8 @@ import ( afpb "aalyria.com/spacetime/api/cdpi/v1alpha" apipb "aalyria.com/spacetime/api/common" schedpb "aalyria.com/spacetime/api/scheduling/v1alpha" - "aalyria.com/spacetime/cdpi_agent/internal/channels" - "aalyria.com/spacetime/cdpi_agent/internal/task" + "aalyria.com/spacetime/agent/internal/channels" + "aalyria.com/spacetime/agent/internal/task" "github.com/google/go-cmp/cmp" "github.com/jonboulle/clockwork" diff --git a/cdpi_agent/examples/enact_flow_forward_updates.py b/agent/examples/enact_flow_forward_updates.py similarity index 100% rename from cdpi_agent/examples/enact_flow_forward_updates.py rename to agent/examples/enact_flow_forward_updates.py diff --git a/cdpi_agent/examples/flow_update_request.json b/agent/examples/flow_update_request.json similarity index 100% rename from cdpi_agent/examples/flow_update_request.json rename to agent/examples/flow_update_request.json diff --git a/cdpi_agent/internal/agentcli/BUILD b/agent/internal/agentcli/BUILD similarity index 79% rename from cdpi_agent/internal/agentcli/BUILD rename to agent/internal/agentcli/BUILD index a1d9929..38cccde 100644 --- a/cdpi_agent/internal/agentcli/BUILD +++ b/agent/internal/agentcli/BUILD @@ -23,17 +23,17 @@ go_library( "netlink_linux.go", "netlink_other.go", ], - importpath = "aalyria.com/spacetime/cdpi_agent/internal/agentcli", + importpath = "aalyria.com/spacetime/agent/internal/agentcli", deps = [ + "//agent", + "//agent/enactment", + "//agent/enactment/extproc", + "//agent/internal/configpb:configpb_go_proto", + "//agent/internal/protofmt", + "//agent/internal/task", + "//agent/telemetry", + "//agent/telemetry/extproc", "//auth", - "//cdpi_agent", - "//cdpi_agent/enactment", - "//cdpi_agent/enactment/extproc", - "//cdpi_agent/internal/configpb:configpb_go_proto", - "//cdpi_agent/internal/protofmt", - "//cdpi_agent/internal/task", - "//cdpi_agent/telemetry", - "//cdpi_agent/telemetry/extproc", "@com_github_jonboulle_clockwork//:clockwork", "@com_github_rs_zerolog//:zerolog", "@io_opentelemetry_go_contrib_instrumentation_google_golang_org_grpc_otelgrpc//:otelgrpc", @@ -54,13 +54,13 @@ go_library( "@org_golang_x_sync//errgroup", ] + select({ "@rules_go//go/platform:android": [ - "//cdpi_agent/enactment/netlink", - "//cdpi_agent/telemetry/netlink", + "//agent/enactment/netlink", + "//agent/telemetry/netlink", "@com_github_vishvananda_netlink//:netlink", ], "@rules_go//go/platform:linux": [ - "//cdpi_agent/enactment/netlink", - "//cdpi_agent/telemetry/netlink", + "//agent/enactment/netlink", + "//agent/telemetry/netlink", "@com_github_vishvananda_netlink//:netlink", ], "//conditions:default": [], diff --git a/cdpi_agent/internal/agentcli/agentcli.go b/agent/internal/agentcli/agentcli.go similarity index 97% rename from cdpi_agent/internal/agentcli/agentcli.go rename to agent/internal/agentcli/agentcli.go index 63460ba..8f74ee6 100644 --- a/cdpi_agent/internal/agentcli/agentcli.go +++ b/agent/internal/agentcli/agentcli.go @@ -51,14 +51,14 @@ import ( "google.golang.org/protobuf/types/known/anypb" "aalyria.com/spacetime/auth" - agent "aalyria.com/spacetime/cdpi_agent" - "aalyria.com/spacetime/cdpi_agent/enactment" - enact_extproc "aalyria.com/spacetime/cdpi_agent/enactment/extproc" - "aalyria.com/spacetime/cdpi_agent/internal/configpb" - "aalyria.com/spacetime/cdpi_agent/internal/protofmt" - "aalyria.com/spacetime/cdpi_agent/internal/task" - "aalyria.com/spacetime/cdpi_agent/telemetry" - telemetry_extproc "aalyria.com/spacetime/cdpi_agent/telemetry/extproc" + agent "aalyria.com/spacetime/agent" + "aalyria.com/spacetime/agent/enactment" + enact_extproc "aalyria.com/spacetime/agent/enactment/extproc" + "aalyria.com/spacetime/agent/internal/configpb" + "aalyria.com/spacetime/agent/internal/protofmt" + "aalyria.com/spacetime/agent/internal/task" + "aalyria.com/spacetime/agent/telemetry" + telemetry_extproc "aalyria.com/spacetime/agent/telemetry/extproc" ) // Handles are abstractions over impure, external resources like time and stdio diff --git a/cdpi_agent/internal/agentcli/netlink_linux.go b/agent/internal/agentcli/netlink_linux.go similarity index 86% rename from cdpi_agent/internal/agentcli/netlink_linux.go rename to agent/internal/agentcli/netlink_linux.go index 700d0bc..c55a363 100644 --- a/cdpi_agent/internal/agentcli/netlink_linux.go +++ b/agent/internal/agentcli/netlink_linux.go @@ -20,11 +20,11 @@ import ( "context" "fmt" - "aalyria.com/spacetime/cdpi_agent/enactment" - enact_netlink "aalyria.com/spacetime/cdpi_agent/enactment/netlink" - "aalyria.com/spacetime/cdpi_agent/internal/configpb" - "aalyria.com/spacetime/cdpi_agent/telemetry" - telemetry_netlink "aalyria.com/spacetime/cdpi_agent/telemetry/netlink" + "aalyria.com/spacetime/agent/enactment" + enact_netlink "aalyria.com/spacetime/agent/enactment/netlink" + "aalyria.com/spacetime/agent/internal/configpb" + "aalyria.com/spacetime/agent/telemetry" + telemetry_netlink "aalyria.com/spacetime/agent/telemetry/netlink" "github.com/jonboulle/clockwork" vnl "github.com/vishvananda/netlink" diff --git a/cdpi_agent/internal/agentcli/netlink_other.go b/agent/internal/agentcli/netlink_other.go similarity index 89% rename from cdpi_agent/internal/agentcli/netlink_other.go rename to agent/internal/agentcli/netlink_other.go index 1df520f..1684ee7 100644 --- a/cdpi_agent/internal/agentcli/netlink_other.go +++ b/agent/internal/agentcli/netlink_other.go @@ -20,9 +20,9 @@ import ( "context" "fmt" - "aalyria.com/spacetime/cdpi_agent/enactment" - "aalyria.com/spacetime/cdpi_agent/internal/configpb" - "aalyria.com/spacetime/cdpi_agent/telemetry" + "aalyria.com/spacetime/agent/enactment" + "aalyria.com/spacetime/agent/internal/configpb" + "aalyria.com/spacetime/agent/telemetry" "github.com/jonboulle/clockwork" ) diff --git a/cdpi_agent/internal/channels/BUILD b/agent/internal/channels/BUILD similarity index 88% rename from cdpi_agent/internal/channels/BUILD rename to agent/internal/channels/BUILD index f323baf..eecc102 100644 --- a/cdpi_agent/internal/channels/BUILD +++ b/agent/internal/channels/BUILD @@ -19,9 +19,9 @@ package(default_visibility = ["//visibility:public"]) go_library( name = "channels", srcs = ["channels.go"], - importpath = "aalyria.com/spacetime/cdpi_agent/internal/channels", + importpath = "aalyria.com/spacetime/agent/internal/channels", deps = [ - "//cdpi_agent/internal/task", + "//agent/internal/task", "@com_github_rs_zerolog//:zerolog", ], ) diff --git a/cdpi_agent/internal/channels/channels.go b/agent/internal/channels/channels.go similarity index 98% rename from cdpi_agent/internal/channels/channels.go rename to agent/internal/channels/channels.go index 8d59b6b..a04726a 100644 --- a/cdpi_agent/internal/channels/channels.go +++ b/agent/internal/channels/channels.go @@ -19,7 +19,7 @@ package channels import ( "context" - "aalyria.com/spacetime/cdpi_agent/internal/task" + "aalyria.com/spacetime/agent/internal/task" "github.com/rs/zerolog" ) diff --git a/cdpi_agent/internal/configpb/BUILD b/agent/internal/configpb/BUILD similarity index 94% rename from cdpi_agent/internal/configpb/BUILD rename to agent/internal/configpb/BUILD index 2cc8aba..080f149 100644 --- a/cdpi_agent/internal/configpb/BUILD +++ b/agent/internal/configpb/BUILD @@ -30,7 +30,7 @@ proto_library( go_proto_library( name = "configpb_go_proto", - importpath = "aalyria.com/spacetime/cdpi_agent/internal/configpb", + importpath = "aalyria.com/spacetime/agent/internal/configpb", proto = ":configpb_proto", deps = [ "//api/common:common_go_proto", diff --git a/cdpi_agent/internal/configpb/config.proto b/agent/internal/configpb/config.proto similarity index 98% rename from cdpi_agent/internal/configpb/config.proto rename to agent/internal/configpb/config.proto index 0cf8b16..acb0d0f 100644 --- a/cdpi_agent/internal/configpb/config.proto +++ b/agent/internal/configpb/config.proto @@ -16,14 +16,14 @@ syntax = "proto3"; -package aalyria.spacetime.cdpi_agent.cmd.agent; +package aalyria.spacetime.agent.cmd.agent; import "google/protobuf/duration.proto"; import "google/protobuf/empty.proto"; import "google/protobuf/any.proto"; import "api/common/control.proto"; -option go_package = "aalyria.com/spacetime/cdpi_agent/internal/configpb"; +option go_package = "aalyria.com/spacetime/agent/internal/configpb"; // A strategy for signing a JWT. message SigningStrategy { diff --git a/cdpi_agent/internal/extprocs/BUILD b/agent/internal/extprocs/BUILD similarity index 93% rename from cdpi_agent/internal/extprocs/BUILD rename to agent/internal/extprocs/BUILD index 2605ce1..ad4bda0 100644 --- a/cdpi_agent/internal/extprocs/BUILD +++ b/agent/internal/extprocs/BUILD @@ -19,7 +19,7 @@ package(default_visibility = ["//visibility:public"]) go_library( name = "extprocs", srcs = ["extprocs.go"], - importpath = "aalyria.com/spacetime/cdpi_agent/internal/extprocs", + importpath = "aalyria.com/spacetime/agent/internal/extprocs", deps = [ "@org_golang_google_grpc//codes", "@org_golang_google_grpc//status", diff --git a/cdpi_agent/internal/extprocs/extprocs.go b/agent/internal/extprocs/extprocs.go similarity index 100% rename from cdpi_agent/internal/extprocs/extprocs.go rename to agent/internal/extprocs/extprocs.go diff --git a/cdpi_agent/internal/extprocs/extprocs_test.go b/agent/internal/extprocs/extprocs_test.go similarity index 100% rename from cdpi_agent/internal/extprocs/extprocs_test.go rename to agent/internal/extprocs/extprocs_test.go diff --git a/cdpi_agent/internal/loggable/BUILD b/agent/internal/loggable/BUILD similarity index 94% rename from cdpi_agent/internal/loggable/BUILD rename to agent/internal/loggable/BUILD index 1e21783..d1622a7 100644 --- a/cdpi_agent/internal/loggable/BUILD +++ b/agent/internal/loggable/BUILD @@ -19,7 +19,7 @@ package(default_visibility = ["//visibility:public"]) go_library( name = "loggable", srcs = ["loggable.go"], - importpath = "aalyria.com/spacetime/cdpi_agent/internal/loggable", + importpath = "aalyria.com/spacetime/agent/internal/loggable", deps = [ "@com_github_rs_zerolog//:zerolog", "@org_golang_google_protobuf//proto", diff --git a/cdpi_agent/internal/loggable/loggable.go b/agent/internal/loggable/loggable.go similarity index 100% rename from cdpi_agent/internal/loggable/loggable.go rename to agent/internal/loggable/loggable.go diff --git a/cdpi_agent/internal/loggable/loggable_test.go b/agent/internal/loggable/loggable_test.go similarity index 100% rename from cdpi_agent/internal/loggable/loggable_test.go rename to agent/internal/loggable/loggable_test.go diff --git a/cdpi_agent/internal/protofmt/BUILD b/agent/internal/protofmt/BUILD similarity index 93% rename from cdpi_agent/internal/protofmt/BUILD rename to agent/internal/protofmt/BUILD index a28d201..295aa0b 100644 --- a/cdpi_agent/internal/protofmt/BUILD +++ b/agent/internal/protofmt/BUILD @@ -19,7 +19,7 @@ package(default_visibility = ["//visibility:public"]) go_library( name = "protofmt", srcs = ["protofmt.go"], - importpath = "aalyria.com/spacetime/cdpi_agent/internal/protofmt", + importpath = "aalyria.com/spacetime/agent/internal/protofmt", deps = [ "@org_golang_google_protobuf//encoding/protojson", "@org_golang_google_protobuf//encoding/prototext", diff --git a/cdpi_agent/internal/protofmt/protofmt.go b/agent/internal/protofmt/protofmt.go similarity index 100% rename from cdpi_agent/internal/protofmt/protofmt.go rename to agent/internal/protofmt/protofmt.go diff --git a/cdpi_agent/internal/protofmt/protofmt_test.go b/agent/internal/protofmt/protofmt_test.go similarity index 100% rename from cdpi_agent/internal/protofmt/protofmt_test.go rename to agent/internal/protofmt/protofmt_test.go diff --git a/cdpi_agent/internal/task/BUILD b/agent/internal/task/BUILD similarity index 95% rename from cdpi_agent/internal/task/BUILD rename to agent/internal/task/BUILD index bc1a42a..5e9c1ae 100644 --- a/cdpi_agent/internal/task/BUILD +++ b/agent/internal/task/BUILD @@ -19,7 +19,7 @@ package(default_visibility = ["//visibility:public"]) go_library( name = "task", srcs = ["task.go"], - importpath = "aalyria.com/spacetime/cdpi_agent/internal/task", + importpath = "aalyria.com/spacetime/agent/internal/task", deps = [ "@com_github_jonboulle_clockwork//:clockwork", "@com_github_rs_zerolog//:zerolog", diff --git a/cdpi_agent/internal/task/task.go b/agent/internal/task/task.go similarity index 100% rename from cdpi_agent/internal/task/task.go rename to agent/internal/task/task.go diff --git a/cdpi_agent/internal/task/task_test.go b/agent/internal/task/task_test.go similarity index 100% rename from cdpi_agent/internal/task/task_test.go rename to agent/internal/task/task_test.go diff --git a/cdpi_agent/internal/worker/BUILD b/agent/internal/worker/BUILD similarity index 94% rename from cdpi_agent/internal/worker/BUILD rename to agent/internal/worker/BUILD index b73d2e2..04eb787 100644 --- a/cdpi_agent/internal/worker/BUILD +++ b/agent/internal/worker/BUILD @@ -19,7 +19,7 @@ package(default_visibility = ["//visibility:public"]) go_library( name = "worker", srcs = ["worker.go"], - importpath = "aalyria.com/spacetime/cdpi_agent/internal/worker", + importpath = "aalyria.com/spacetime/agent/internal/worker", ) go_test( diff --git a/cdpi_agent/internal/worker/worker.go b/agent/internal/worker/worker.go similarity index 100% rename from cdpi_agent/internal/worker/worker.go rename to agent/internal/worker/worker.go diff --git a/cdpi_agent/internal/worker/worker_test.go b/agent/internal/worker/worker_test.go similarity index 100% rename from cdpi_agent/internal/worker/worker_test.go rename to agent/internal/worker/worker_test.go diff --git a/cdpi_agent/node_controller.go b/agent/node_controller.go similarity index 98% rename from cdpi_agent/node_controller.go rename to agent/node_controller.go index c22e7b4..7218945 100644 --- a/cdpi_agent/node_controller.go +++ b/agent/node_controller.go @@ -23,7 +23,7 @@ import ( afpb "aalyria.com/spacetime/api/cdpi/v1alpha" apipb "aalyria.com/spacetime/api/common" schedpb "aalyria.com/spacetime/api/scheduling/v1alpha" - "aalyria.com/spacetime/cdpi_agent/internal/task" + "aalyria.com/spacetime/agent/internal/task" "github.com/google/uuid" "github.com/jonboulle/clockwork" diff --git a/cdpi_agent/telemetry/BUILD b/agent/telemetry/BUILD similarity index 92% rename from cdpi_agent/telemetry/BUILD rename to agent/telemetry/BUILD index df12a90..ca9e313 100644 --- a/cdpi_agent/telemetry/BUILD +++ b/agent/telemetry/BUILD @@ -19,6 +19,6 @@ package(default_visibility = ["//visibility:public"]) go_library( name = "telemetry", srcs = ["telemetry.go"], - importpath = "aalyria.com/spacetime/cdpi_agent/telemetry", + importpath = "aalyria.com/spacetime/agent/telemetry", deps = ["//api/common:common_go_proto"], ) diff --git a/cdpi_agent/telemetry/extproc/BUILD b/agent/telemetry/extproc/BUILD similarity index 79% rename from cdpi_agent/telemetry/extproc/BUILD rename to agent/telemetry/extproc/BUILD index d843361..af2d8a1 100644 --- a/cdpi_agent/telemetry/extproc/BUILD +++ b/agent/telemetry/extproc/BUILD @@ -19,13 +19,13 @@ package(default_visibility = ["//visibility:public"]) go_library( name = "extproc", srcs = ["extproc.go"], - importpath = "aalyria.com/spacetime/cdpi_agent/telemetry/extproc", + importpath = "aalyria.com/spacetime/agent/telemetry/extproc", deps = [ + "//agent/internal/extprocs", + "//agent/internal/loggable", + "//agent/internal/protofmt", + "//agent/telemetry", "//api/common:common_go_proto", - "//cdpi_agent/internal/extprocs", - "//cdpi_agent/internal/loggable", - "//cdpi_agent/internal/protofmt", - "//cdpi_agent/telemetry", "@com_github_rs_zerolog//:zerolog", ], ) diff --git a/cdpi_agent/telemetry/extproc/extproc.go b/agent/telemetry/extproc/extproc.go similarity index 91% rename from cdpi_agent/telemetry/extproc/extproc.go rename to agent/telemetry/extproc/extproc.go index 2c9a140..0ebfe1b 100644 --- a/cdpi_agent/telemetry/extproc/extproc.go +++ b/agent/telemetry/extproc/extproc.go @@ -23,10 +23,10 @@ import ( "os/exec" apipb "aalyria.com/spacetime/api/common" - "aalyria.com/spacetime/cdpi_agent/internal/extprocs" - "aalyria.com/spacetime/cdpi_agent/internal/loggable" - "aalyria.com/spacetime/cdpi_agent/internal/protofmt" - "aalyria.com/spacetime/cdpi_agent/telemetry" + "aalyria.com/spacetime/agent/internal/extprocs" + "aalyria.com/spacetime/agent/internal/loggable" + "aalyria.com/spacetime/agent/internal/protofmt" + "aalyria.com/spacetime/agent/telemetry" "github.com/rs/zerolog" ) diff --git a/cdpi_agent/telemetry/netlink/BUILD b/agent/telemetry/netlink/BUILD similarity index 90% rename from cdpi_agent/telemetry/netlink/BUILD rename to agent/telemetry/netlink/BUILD index 2eb96a8..48c12a4 100644 --- a/cdpi_agent/telemetry/netlink/BUILD +++ b/agent/telemetry/netlink/BUILD @@ -19,10 +19,10 @@ package(default_visibility = ["//visibility:public"]) go_library( name = "netlink", srcs = ["netlink.go"], - importpath = "aalyria.com/spacetime/cdpi_agent/telemetry/netlink", + importpath = "aalyria.com/spacetime/agent/telemetry/netlink", deps = [ + "//agent/telemetry", "//api/common:common_go_proto", - "//cdpi_agent/telemetry", "@com_github_jonboulle_clockwork//:clockwork", "@com_github_rs_zerolog//:zerolog", "@com_github_vishvananda_netlink//:netlink", diff --git a/cdpi_agent/telemetry/netlink/netlink.go b/agent/telemetry/netlink/netlink.go similarity index 98% rename from cdpi_agent/telemetry/netlink/netlink.go rename to agent/telemetry/netlink/netlink.go index 8b17cc0..94b2261 100644 --- a/cdpi_agent/telemetry/netlink/netlink.go +++ b/agent/telemetry/netlink/netlink.go @@ -19,7 +19,7 @@ import ( "errors" apipb "aalyria.com/spacetime/api/common" - "aalyria.com/spacetime/cdpi_agent/telemetry" + "aalyria.com/spacetime/agent/telemetry" "github.com/jonboulle/clockwork" "github.com/rs/zerolog" diff --git a/cdpi_agent/telemetry/prometheus/BUILD b/agent/telemetry/prometheus/BUILD similarity index 95% rename from cdpi_agent/telemetry/prometheus/BUILD rename to agent/telemetry/prometheus/BUILD index fec7c21..93e3073 100644 --- a/cdpi_agent/telemetry/prometheus/BUILD +++ b/agent/telemetry/prometheus/BUILD @@ -19,7 +19,7 @@ package(default_visibility = ["//visibility:public"]) go_library( name = "prometheus", srcs = ["scraper.go"], - importpath = "aalyria.com/spacetime/cdpi_agent/telemetry/prometheus", + importpath = "aalyria.com/spacetime/agent/telemetry/prometheus", deps = [ "//api/common:common_go_proto", "@com_github_jonboulle_clockwork//:clockwork", diff --git a/cdpi_agent/telemetry/prometheus/node_exporter_metrics_testdata.txt b/agent/telemetry/prometheus/node_exporter_metrics_testdata.txt similarity index 100% rename from cdpi_agent/telemetry/prometheus/node_exporter_metrics_testdata.txt rename to agent/telemetry/prometheus/node_exporter_metrics_testdata.txt diff --git a/cdpi_agent/telemetry/prometheus/scraper.go b/agent/telemetry/prometheus/scraper.go similarity index 100% rename from cdpi_agent/telemetry/prometheus/scraper.go rename to agent/telemetry/prometheus/scraper.go diff --git a/cdpi_agent/telemetry/prometheus/scraper_test.go b/agent/telemetry/prometheus/scraper_test.go similarity index 100% rename from cdpi_agent/telemetry/prometheus/scraper_test.go rename to agent/telemetry/prometheus/scraper_test.go diff --git a/cdpi_agent/telemetry/telemetry.go b/agent/telemetry/telemetry.go similarity index 100% rename from cdpi_agent/telemetry/telemetry.go rename to agent/telemetry/telemetry.go diff --git a/cdpi_agent/telemetry_service.go b/agent/telemetry_service.go similarity index 97% rename from cdpi_agent/telemetry_service.go rename to agent/telemetry_service.go index 1db67ba..128b849 100644 --- a/cdpi_agent/telemetry_service.go +++ b/agent/telemetry_service.go @@ -20,10 +20,10 @@ import ( afpb "aalyria.com/spacetime/api/cdpi/v1alpha" apipb "aalyria.com/spacetime/api/common" - "aalyria.com/spacetime/cdpi_agent/internal/channels" - "aalyria.com/spacetime/cdpi_agent/internal/loggable" - "aalyria.com/spacetime/cdpi_agent/internal/task" - "aalyria.com/spacetime/cdpi_agent/telemetry" + "aalyria.com/spacetime/agent/internal/channels" + "aalyria.com/spacetime/agent/internal/loggable" + "aalyria.com/spacetime/agent/internal/task" + "aalyria.com/spacetime/agent/telemetry" "github.com/rs/zerolog" "go.opentelemetry.io/otel/attribute" diff --git a/cdpi_agent/telemetry_test.go b/agent/telemetry_test.go similarity index 99% rename from cdpi_agent/telemetry_test.go rename to agent/telemetry_test.go index 20f8d1c..00eab5f 100644 --- a/cdpi_agent/telemetry_test.go +++ b/agent/telemetry_test.go @@ -25,7 +25,7 @@ import ( afpb "aalyria.com/spacetime/api/cdpi/v1alpha" apipb "aalyria.com/spacetime/api/common" - "aalyria.com/spacetime/cdpi_agent/internal/channels" + "aalyria.com/spacetime/agent/internal/channels" "github.com/jonboulle/clockwork" "golang.org/x/sync/errgroup" diff --git a/cdpi_agent/timing.go b/agent/timing.go similarity index 100% rename from cdpi_agent/timing.go rename to agent/timing.go diff --git a/cdpi_agent/timing_test.go b/agent/timing_test.go similarity index 100% rename from cdpi_agent/timing_test.go rename to agent/timing_test.go diff --git a/tools/nbictl/README.md b/tools/nbictl/README.md index 1df5472..a2211f3 100644 --- a/tools/nbictl/README.md +++ b/tools/nbictl/README.md @@ -119,6 +119,14 @@ Generate RSA keys to use for authentication with the Spacetime APIs. **--state**="": State of certificate. +## list-configs + +List all configuration profiles (ignores any `--context` flag) + +## get-config + +Prints the NBI connection settings associated with the configuration profile given by the `--context` flag (defaults to "DEFAULT"). + ## set-config Sets or updates a configuration profile that contains NBI connection settings. You can create multiple configs by specifying the name of the configuration using the `--context` flag (defaults to "DEFAULT"). diff --git a/tools/nbictl/config.go b/tools/nbictl/config.go index 66ef133..ffaec41 100644 --- a/tools/nbictl/config.go +++ b/tools/nbictl/config.go @@ -43,8 +43,8 @@ func getAppConfDir(appCtx *cli.Context) (string, error) { return filepath.Join(confDir, appCtx.App.Name), nil } -func readConfig(context, confDir string) (*nbictlpb.Config, error) { - confs, err := readConfigs(confDir) +func readConfig(context, confFilePath string) (*nbictlpb.Config, error) { + confs, err := readConfigs(confFilePath) if err != nil { return nil, fmt.Errorf("unable to get config contexts: %w", err) } @@ -86,6 +86,61 @@ func readConfigs(confFilePath string) (*nbictlpb.AppConfig, error) { return confProto, nil } +func getConfFileForContext(appCtx *cli.Context) (string, error) { + confDir, err := getAppConfDir(appCtx) + if err != nil { + return "", fmt.Errorf("unable to obtain the default config directory: %w", err) + } + + return filepath.Join(confDir, confFileName), nil +} + +func ListConfigs(appCtx *cli.Context) error { + confFile, err := getConfFileForContext(appCtx) + if err != nil { + return err + } + confProto, err := readConfigs(confFile) + if err != nil { + return err + } + + for _, profile := range confProto.GetConfigs() { + fmt.Fprintln(appCtx.App.Writer, profile.GetName()) + } + + return nil +} + +func GetConfig(appCtx *cli.Context) error { + confFile, err := getConfFileForContext(appCtx) + if err != nil { + return err + } + confProto, err := readConfigs(confFile) + if err != nil { + return err + } + + confName := "DEFAULT" + if appCtx.IsSet("context") { + confName = appCtx.String("context") + } + + for _, profile := range confProto.GetConfigs() { + if profile.GetName() == confName { + protoMessage, err := prototext.MarshalOptions{Multiline: true}.Marshal(profile) + if err != nil { + return err + } + fmt.Fprint(appCtx.App.Writer, string(protoMessage)) + return nil + } + } + + return fmt.Errorf("unable to find config %q in file %q.", confName, confFile) +} + func SetConfig(appCtx *cli.Context) error { confName := "DEFAULT" if appCtx.IsSet("context") { @@ -97,11 +152,10 @@ func SetConfig(appCtx *cli.Context) error { url := appCtx.String("url") transportSecurity := appCtx.String("transport_security") - confDir, err := getAppConfDir(appCtx) + confPath, err := getConfFileForContext(appCtx) if err != nil { - return fmt.Errorf("unable to obtain the default config directory: %w", err) + return err } - confPath := filepath.Join(confDir, confFileName) var transportSecurityPb *nbictlpb.Config_TransportSecurity @@ -193,6 +247,6 @@ func setConfig(outWriter, errWriter io.Writer, confToCreate *nbictlpb.Config, co return fmt.Errorf("unable to convert the nbictl context into textproto format: %w", err) } fmt.Fprintf(errWriter, "configuration successfully updated; the configuration file is stored under: %s\n", confFile) - fmt.Println(outWriter, string(protoMessage)) + fmt.Fprint(outWriter, string(protoMessage)) return nil } diff --git a/tools/nbictl/nbictl.go b/tools/nbictl/nbictl.go index ff2c953..195c735 100644 --- a/tools/nbictl/nbictl.go +++ b/tools/nbictl/nbictl.go @@ -355,6 +355,18 @@ func App() *cli.App { }, Action: GenerateKeys, }, + { + Name: "list-configs", + Usage: "List all configuration profiles (ignores any `--context` flag)", + Category: "configuration", + Action: ListConfigs, + }, + { + Name: "get-config", + Usage: "Prints the NBI connection settings associated with the configuration profile given by the `--context` flag (defaults to \"DEFAULT\").", + Category: "configuration", + Action: GetConfig, + }, { Name: "set-config", Usage: "Sets or updates a configuration profile that contains NBI connection settings. You can create multiple configs by specifying the name of the configuration using the `--context` flag (defaults to \"DEFAULT\").", @@ -777,7 +789,7 @@ func GetLinkBudget(appCtx *cli.Context) error { } if !appCtx.IsSet("output_file") { - fmt.Println(string(spResProto)) + fmt.Fprintln(appCtx.App.Writer, string(spResProto)) } else { outPath := appCtx.Path("output_file") // Creates the output file, if necessary, with read and write permissions. @@ -785,7 +797,7 @@ func GetLinkBudget(appCtx *cli.Context) error { return fmt.Errorf("writing to output file %s: %w", outPath, err) } } - fmt.Fprintln(os.Stderr, "successfully retrieved link budget.") + fmt.Fprintln(appCtx.App.ErrWriter, "successfully retrieved link budget.") return nil }