WIP: Add progenitor client
Some checks failed
ci/woodpecker/pr/ci Pipeline failed

This commit is contained in:
Daniel Lundin 2024-12-14 22:47:40 +01:00
parent a5e3170d37
commit f1122e8e5d
Signed by: dln
SSH key fingerprint: SHA256:dQy1Xj3UiqJYpKR5ggQ2bxgz4jCH8IF+k3AB8o0kmdI
11 changed files with 1012 additions and 22 deletions

967
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -2,11 +2,13 @@
resolver = "2"
members = [
"agent",
"client",
"controller",
"xtask",
]
default-members = [
"agent",
"client",
"controller",
"xtask",
]
@ -36,9 +38,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 +57,4 @@ tracing-subscriber = { version = "0.3.18", default-features = false, features =
"env-filter",
"fmt",
] }
uuid = { version = "1", features = [ "serde", "v4" ] }

View file

@ -7,6 +7,7 @@ license = "MPL-2.0"
[dependencies]
anyhow.workspace = true
clap.workspace = true
patagia-client = { path = "../client" }
tokio.workspace = true
tracing.workspace = true
tracing-chrome.workspace = true

View file

@ -19,6 +19,10 @@ async fn main() -> Result<()> {
tracing::info!("Patagia Agent");
let client = patagia_client::Client::new("http://localhost:9474");
let result = client.version().await?;
tracing::info!("Result: {:?}", result);
sleep(Duration::from_secs(3)).await;
Ok(())
}

View file

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

13
client/Cargo.toml Normal file
View file

@ -0,0 +1,13 @@
[package]
name = "patagia-client"
version = "0.0.1"
license = "MPL-2.0"
edition = "2021"
[dependencies]
anyhow.workspace = true
chrono = { version = "0.4.0", default-features = false, features = ["serde"] }
progenitor.workspace = true
reqwest.workspace = true
schemars.workspace = true
serde.workspace = true

4
client/src/lib.rs Normal file
View file

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

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,6 +49,7 @@
nativeBuildInputs = with pkgs; [
clang_18
mold
openssl
];
sourceAndFixtures = path: type: (craneLib.filterCargoSources path type);
@ -142,7 +143,7 @@
}
);
fmt = craneLib.cargoFmt (commonArgs // { inherit src; });
# fmt = craneLib.cargoFmt (commonArgs // { inherit src; });
audit = craneLib.cargoAudit (commonArgs // { inherit src advisory-db; });
@ -156,11 +157,16 @@
);
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
// {
src = fileSetForCrate ./xtask;
}
)
''
${self.packages.${system}.xtask}/bin/xtask open-api | ${pkgs.diffutils}/bin/diff -u $src/api.json - | tee $out
'';
};
# For `nix fmt`
@ -179,13 +185,15 @@
cargo-watch
hyperfine
just
pkg-config
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