Add progenitor client #3

Merged
dln merged 2 commits from dln/push-oxxyxtkwlqov into main 2024-12-15 15:31:07 +01:00
11 changed files with 1016 additions and 39 deletions
Showing only changes of commit b07d037a7d - Show all commits

958
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -36,9 +36,11 @@ opentelemetry-otlp = { version = "0.27.0", features = ["grpc-tonic", "trace"] }
opentelemetry_sdk = { version = "0.27.1", features = ["metrics", "rt-tokio"] }
opentelemetry-semantic-conventions = "0.27.0"
opentelemetry-stdout = "0.27.0"
progenitor = "0.8.0"
reqwest = { version = "0.12.9", features = ["json", "stream", "rustls-tls"] }
schemars = "0.8.21"
semver = "1.0.23"
serde = "1.0.215"
serde = { version = "1.0.215", features = ["derive"] }
slog = "2.7.0"
slog-async = "2.8.0"
tokio = { version = "1.41.1", features = ["full"] }
@ -53,3 +55,4 @@ tracing-subscriber = { version = "0.3.18", default-features = false, features =
"env-filter",
"fmt",
] }
uuid = { version = "1", features = [ "serde", "v4" ] }

View file

@ -7,10 +7,14 @@ license = "MPL-2.0"
[dependencies]
anyhow.workspace = true
clap.workspace = true
progenitor.workspace = true
reqwest.workspace = true
schemars.workspace = true
serde.workspace = true
tokio.workspace = true
tracing.workspace = true
tracing-chrome.workspace = true
tracing-subscriber.workspace = true
tracing.workspace = true
[[bin]]
name = "patagia-agent"

View file

@ -3,6 +3,8 @@ use clap::Parser;
use tokio::time::{sleep, Duration};
use tracing_subscriber::prelude::*;
mod patagia_api;
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Cli {}
@ -19,6 +21,10 @@ async fn main() -> Result<()> {
tracing::info!("Patagia Agent");
let client = patagia_api::Client::new("http://localhost:9474");
let result = client.version().await?;
tracing::info!("Result: {:?}", result);
sleep(Duration::from_secs(3)).await;
Ok(())
}

3
agent/src/patagia_api.rs Normal file
View file

@ -0,0 +1,3 @@
use progenitor::generate_api;
generate_api!(spec = "../api.json", derives = [schemars::JsonSchema]);

View file

@ -8,7 +8,7 @@
"/version": {
"get": {
"summary": "Fetch version info.",
"operationId": "api_version",
"operationId": "version",
"responses": {
"200": {
"description": "successful operation",

View file

@ -28,7 +28,7 @@ tracing-opentelemetry.workspace = true
tracing-slog.workspace = true
tracing-subscriber.workspace = true
tracing.workspace = true
[[bin]]
name = "patagia-controller"
doc = false
#
# [[bin]]
# name = "patagia-controller"
# doc = false

View file

@ -10,6 +10,6 @@ type ControllerApiDescription = ApiDescription<Arc<ControllerContext>>;
pub fn api() -> Result<ControllerApiDescription> {
let mut api = ControllerApiDescription::new();
api.register(version::api_version)?;
api.register(version::version)?;
Ok(api)
}

View file

@ -29,7 +29,7 @@ struct VersionInfo {
),
err(Debug),
)]
pub async fn api_version(
pub(crate) async fn version(
rqctx: RequestContext<Arc<ControllerContext>>,
) -> Result<HttpResponseOk<VersionInfo>, HttpError> {
let ver = VersionInfo {

View file

@ -49,29 +49,24 @@
nativeBuildInputs = with pkgs; [
clang_18
mold
pkg-config
];
sourceAndFixtures = path: type: (craneLib.filterCargoSources path type);
jsonFilter = path: _type: builtins.match ".*json$" path != null;
sourceAndFixtures = path: type:
(jsonFilter path type) || (craneLib.filterCargoSources path type);
src = pkgs.lib.cleanSourceWith {
src = ./.;
filter = sourceAndFixtures;
};
treefmtEval = treefmt-nix.lib.evalModule pkgs {
projectRootFile = "flake.nix";
programs = {
nixfmt.enable = true;
Review

A comment after the fact...

A comment after the fact...
nixfmt.package = pkgs.nixfmt-rfc-style;
shfmt.enable = true;
rustfmt.enable = true;
};
settings.formatter.rustfmt.command = pkgs.lib.mkForce "${pkgs.rust-toolchain}/bin/rustfmt";
};
commonArgs = {
inherit src stdenv nativeBuildInputs;
strictDeps = true;
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
buildInputs = with pkgs; [
openssl
];
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
@ -123,6 +118,18 @@
src = fileSetForCrate ./xtask;
}
);
treefmtEval = treefmt-nix.lib.evalModule pkgs {
projectRootFile = "flake.nix";
programs = {
nixfmt.enable = true;
nixfmt.package = pkgs.nixfmt-rfc-style;
shfmt.enable = true;
rustfmt.enable = true;
};
settings.formatter.rustfmt.command = pkgs.lib.mkForce "${pkgs.rust-toolchain}/bin/rustfmt";
};
in
{
# `nix build`
@ -142,7 +149,7 @@
}
);
fmt = craneLib.cargoFmt (commonArgs // { inherit src; });
# fmt = craneLib.cargoFmt (commonArgs // { inherit src; });
audit = craneLib.cargoAudit (commonArgs // { inherit src advisory-db; });
@ -156,11 +163,17 @@
);
openapi =
pkgs.runCommand "openapi" (commonArgs // {
src = fileSetForCrate ./xtask;
}) ''
${self.packages.${system}.xtask}/bin/xtask open-api | ${pkgs.diffutils}/bin/diff -u $src/api.json - | tee $out
'';
pkgs.runCommand "openapi"
(
commonArgs
// {
inherit cargoArtifacts;
src = fileSetForCrate ./xtask;
}
)
''
${self.packages.${system}.xtask}/bin/xtask open-api | ${pkgs.diffutils}/bin/diff -u $src/api.json - | tee $out
'';
};
# For `nix fmt`
@ -178,14 +191,16 @@
cargo-nextest
cargo-watch
hyperfine
openssl
just
rust-dev-toolchain
watchexec
];
RUST_BACKTRACE = 1;
RUST_SRC_PATH = pkgs.rustPlatform.rustLibSrc; # Required for rust-analyzer
shellHook = ''
export RUST_SRC_PATH=${pkgs.rustPlatform.rustLibSrc} # Required for rust-analyzer
echo
echo " Welcome to the Patagia development environment! "
echo "🛠 Welcome to the Patagia development environment 🛠"
echo "Run 'just' to see available commands."
echo
'';

View file

@ -12,6 +12,14 @@ run-controller $RUST_LOG="debug,h2=info,hyper_util=info,tower=info":
dev-controller:
watchexec --clear --restart --stop-signal INT --debounce 300ms -- just run-controller
# Run agent
run-agent $RUST_LOG="debug,h2=info,hyper_util=info,tower=info":
cargo run --package patagia-agent
# Run agent local development
dev-agent:
watchexec --clear --restart --stop-signal INT --debounce 300ms -- just run-agent
# Lint all source code
lint:
cargo clippy