Compare commits

...

7 commits

Author SHA1 Message Date
add9df8f87
feat(agent): use varlink to communicate with systemd 2025-01-10 23:17:35 +01:00
c460e4b992
chore: typo
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
2025-01-09 00:41:26 +01:00
3ccfb881b5
feat(telemetry): add resource detection and better default
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
2025-01-08 21:53:32 +01:00
e297e16cfb
feat(direnv): opentelemetry env vars for development
Some checks failed
ci/woodpecker/push/ci Pipeline failed
2025-01-08 18:55:43 +01:00
7333ced376
feat(controller): use env in clap to allow env var config
Some checks failed
ci/woodpecker/push/ci Pipeline failed
2025-01-08 16:41:58 +01:00
a9a4c513f5
feat(controller): add listen-address flag 2025-01-08 16:40:07 +01:00
abd6748703
chore(just): remove unnecessary dev-postgres-reset recipe
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
2025-01-08 14:16:03 +01:00
15 changed files with 640 additions and 105 deletions

View file

@ -1,4 +1,8 @@
nix_direnv_manual_reload
use flake
export DATABASE_URL=postgresql://patagia:swordfish@/patagia?host=$XDG_RUNTIME_DIR/patagia-postgres
export DATABASE_URL=postgresql://patagia:swordfish@patagia?host=$XDG_RUNTIME_DIR/patagia-postgres
export OTEL_EXPORTER_OTLP_TRACES_PROTOCOL="http/protobuf"
export OTEL_RESOURCE_ATTRIBUTES=host.name=$HOSTNAME
export OTEL_SERVICE_NAME=$USER.patagia-control
export OTEL_TRACES_SAMPLER=always_on
dotenv_if_exists

275
Cargo.lock generated
View file

@ -23,7 +23,7 @@ version = "0.8.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"once_cell",
"version_check",
"zerocopy",
@ -59,6 +59,15 @@ dependencies = [
"libc",
]
[[package]]
name = "ansi_term"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
dependencies = [
"winapi",
]
[[package]]
name = "anstream"
version = "0.6.18"
@ -133,7 +142,7 @@ checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.95",
]
[[package]]
@ -144,7 +153,7 @@ checksum = "1b1244b10dcd56c92219da4e14caa97e312079e185f04ba3eea25061561dc0a0"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.95",
]
[[package]]
@ -213,7 +222,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a"
dependencies = [
"addr2line",
"cfg-if",
"cfg-if 1.0.0",
"libc",
"miniz_oxide",
"object",
@ -280,6 +289,12 @@ dependencies = [
"shlex",
]
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "cfg-if"
version = "1.0.0"
@ -292,6 +307,12 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
[[package]]
name = "chainerror"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ce1bb7fb0c258a6600d699950da347a7a9dad66c3ce815769b5f11cf8fce78e"
[[package]]
name = "chrono"
version = "0.4.39"
@ -337,7 +358,7 @@ dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
"syn 2.0.95",
]
[[package]]
@ -393,7 +414,7 @@ version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
]
[[package]]
@ -452,7 +473,7 @@ version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"dirs-sys-next",
]
@ -475,7 +496,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.95",
]
[[package]]
@ -540,7 +561,7 @@ dependencies = [
"semver",
"serde",
"serde_tokenstream",
"syn",
"syn 2.0.95",
]
[[package]]
@ -561,7 +582,7 @@ version = "0.8.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
]
[[package]]
@ -682,7 +703,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.95",
]
[[package]]
@ -725,13 +746,22 @@ dependencies = [
"version_check",
]
[[package]]
name = "getopts"
version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5"
dependencies = [
"unicode-width",
]
[[package]]
name = "getrandom"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"js-sys",
"libc",
"wasi",
@ -820,7 +850,7 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9c7c7c8ac16c798734b8a24560c1362120597c40d5e1459f09498f8f6c8f2ba"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"libc",
"windows",
]
@ -1096,7 +1126,7 @@ checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.95",
]
[[package]]
@ -1143,13 +1173,15 @@ dependencies = [
[[package]]
name = "instrumentation"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"anyhow",
"http",
"once_cell",
"opentelemetry",
"opentelemetry-appender-tracing",
"opentelemetry-otlp",
"opentelemetry-resource-detectors",
"opentelemetry-semantic-conventions",
"opentelemetry_sdk",
"tonic",
@ -1291,6 +1323,15 @@ version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
name = "memoffset"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a"
dependencies = [
"autocfg",
]
[[package]]
name = "mime"
version = "0.3.17"
@ -1418,7 +1459,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6174bc48f102d208783c2c84bf931bb75927a617866870de8a4ea85597f871f5"
dependencies = [
"bitflags",
"cfg-if",
"cfg-if 1.0.0",
"foreign-types",
"libc",
"once_cell",
@ -1434,7 +1475,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.95",
]
[[package]]
@ -1469,6 +1510,20 @@ dependencies = [
"tracing",
]
[[package]]
name = "opentelemetry-appender-tracing"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5feffc321035ad94088a7e5333abb4d84a8726e54a802e736ce9dd7237e85b"
dependencies = [
"log",
"opentelemetry",
"tracing",
"tracing-core",
"tracing-log",
"tracing-subscriber",
]
[[package]]
name = "opentelemetry-otlp"
version = "0.27.0"
@ -1500,6 +1555,17 @@ dependencies = [
"tonic",
]
[[package]]
name = "opentelemetry-resource-detectors"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf6e83d3dca8fe93cfac95cd07313721c9e6e9f8655e7b06d061d4924df1a0cd"
dependencies = [
"opentelemetry",
"opentelemetry-semantic-conventions",
"opentelemetry_sdk",
]
[[package]]
name = "opentelemetry-semantic-conventions"
version = "0.27.0"
@ -1549,7 +1615,7 @@ version = "0.9.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"libc",
"redox_syscall",
"smallvec",
@ -1564,7 +1630,7 @@ checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
[[package]]
name = "patagia-agent"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"anyhow",
"clap",
@ -1573,13 +1639,16 @@ dependencies = [
"reqwest",
"schemars",
"serde",
"serde_derive",
"tokio",
"tracing",
"varlink",
"varlink_generator",
]
[[package]]
name = "patagia-controller"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"anyhow",
"clap",
@ -1596,6 +1665,33 @@ dependencies = [
"tracing-slog",
]
[[package]]
name = "peg"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f76678828272f177ac33b7e2ac2e3e73cc6c1cd1e3e387928aa69562fa51367"
dependencies = [
"peg-macros",
"peg-runtime",
]
[[package]]
name = "peg-macros"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "636d60acf97633e48d266d7415a9355d4389cea327a193f87df395d88cd2b14d"
dependencies = [
"peg-runtime",
"proc-macro2",
"quote",
]
[[package]]
name = "peg-runtime"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9555b1514d2d99d78150d3c799d4c357a3e2c2a8062cd108e93a06d9057629c5"
[[package]]
name = "percent-encoding"
version = "2.3.1"
@ -1619,7 +1715,7 @@ checksum = "3c0f5fad0874fc7abcd4d750e76917eaebbecaa2c20bde22e1dbeeba8beb758c"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.95",
]
[[package]]
@ -1706,7 +1802,7 @@ dependencies = [
"schemars",
"serde",
"serde_json",
"syn",
"syn 2.0.95",
"thiserror 1.0.69",
"typify",
"unicode-ident",
@ -1727,7 +1823,7 @@ dependencies = [
"serde_json",
"serde_tokenstream",
"serde_yaml",
"syn",
"syn 2.0.95",
]
[[package]]
@ -1750,7 +1846,7 @@ dependencies = [
"itertools",
"proc-macro2",
"quote",
"syn",
"syn 2.0.95",
]
[[package]]
@ -1976,7 +2072,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d"
dependencies = [
"cc",
"cfg-if",
"cfg-if 1.0.0",
"getrandom",
"libc",
"spin",
@ -2123,7 +2219,7 @@ dependencies = [
"proc-macro2",
"quote",
"serde_derive_internals",
"syn",
"syn 2.0.95",
]
[[package]]
@ -2194,7 +2290,7 @@ checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.95",
]
[[package]]
@ -2205,7 +2301,7 @@ checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.95",
]
[[package]]
@ -2248,7 +2344,7 @@ dependencies = [
"proc-macro2",
"quote",
"serde",
"syn",
"syn 2.0.95",
]
[[package]]
@ -2282,7 +2378,7 @@ version = "0.10.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"cpufeatures",
"digest",
]
@ -2415,6 +2511,17 @@ version = "2.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]]
name = "syn"
version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "syn"
version = "2.0.95"
@ -2443,7 +2550,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.95",
]
[[package]]
@ -2479,7 +2586,7 @@ version = "3.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a8a559c81686f576e8cd0290cd2a24a2a9ad80c98b3478856500fcbd7acd704"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"fastrand",
"getrandom",
"once_cell",
@ -2534,7 +2641,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.95",
]
[[package]]
@ -2545,7 +2652,7 @@ checksum = "7b50fa271071aae2e6ee85f842e2e28ba8cd2c5fb67f11fcb1fd70b276f9e7d4"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.95",
]
[[package]]
@ -2554,7 +2661,7 @@ version = "1.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"once_cell",
]
@ -2642,7 +2749,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.95",
]
[[package]]
@ -2818,13 +2925,13 @@ checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3"
[[package]]
name = "trace-request"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"dropshot",
"http",
"proc-macro2",
"quote",
"syn",
"syn 2.0.95",
"tracing",
]
@ -2847,7 +2954,7 @@ checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.95",
]
[[package]]
@ -2951,7 +3058,7 @@ dependencies = [
"semver",
"serde",
"serde_json",
"syn",
"syn 2.0.95",
"thiserror 1.0.69",
"unicode-ident",
]
@ -2969,16 +3076,43 @@ dependencies = [
"serde",
"serde_json",
"serde_tokenstream",
"syn",
"syn 2.0.95",
"typify-impl",
]
[[package]]
name = "uds_windows"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89daebc3e6fd160ac4aa9fc8b3bf71e1f74fbf92367ae71fb83a037e8bf164b9"
dependencies = [
"memoffset",
"tempfile",
"winapi",
]
[[package]]
name = "unicode-ident"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
[[package]]
name = "unicode-width"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
[[package]]
name = "unix_socket"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6aa2700417c405c38f5e6902d699345241c28c0b7ade4abaad71e35a87eb1564"
dependencies = [
"cfg-if 0.1.10",
"libc",
]
[[package]]
name = "unsafe-libyaml"
version = "0.2.11"
@ -3036,6 +3170,47 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]]
name = "varlink"
version = "11.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "409e275987d74665c23610c0959c133360cafd761c1a6ddb1ca6d0685c8cef5d"
dependencies = [
"libc",
"serde",
"serde_derive",
"serde_json",
"tempfile",
"uds_windows",
"unix_socket",
"winapi",
]
[[package]]
name = "varlink_generator"
version = "10.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d8ff746c5b65d4bfb3a50f630b85cfb6a9d59f18720126e3ebd6bc98527fa51"
dependencies = [
"chainerror",
"getopts",
"proc-macro2",
"quote",
"syn 1.0.109",
"varlink_parser",
]
[[package]]
name = "varlink_parser"
version = "4.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35fb9f3c1e8ccb33cdb6c84a4477ef3f3884ce6f4b70514ef1fbf7686eae921e"
dependencies = [
"ansi_term",
"chainerror",
"peg",
]
[[package]]
name = "vcpkg"
version = "0.2.15"
@ -3078,7 +3253,7 @@ version = "0.2.99"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a474f6281d1d70c17ae7aa6a613c87fce69a127e2624002df63dcb39d6cf6396"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"once_cell",
"wasm-bindgen-macro",
]
@ -3093,7 +3268,7 @@ dependencies = [
"log",
"proc-macro2",
"quote",
"syn",
"syn 2.0.95",
"wasm-bindgen-shared",
]
@ -3103,7 +3278,7 @@ version = "0.4.49"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38176d9b44ea84e9184eff0bc34cc167ed044f816accfe5922e54d84cf48eca2"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"js-sys",
"once_cell",
"wasm-bindgen",
@ -3128,7 +3303,7 @@ checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.95",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
@ -3357,7 +3532,7 @@ checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51"
[[package]]
name = "xtask"
version = "0.0.0"
version = "0.2.0"
dependencies = [
"anyhow",
"clap",
@ -3385,7 +3560,7 @@ checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.95",
"synstructure",
]
@ -3407,7 +3582,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.95",
]
[[package]]
@ -3427,7 +3602,7 @@ checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.95",
"synstructure",
]
@ -3456,7 +3631,7 @@ checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.95",
]
[[package]]

View file

@ -27,18 +27,13 @@ anyhow = "1.0.95"
clap = { version = "4.5.23", features = [
"derive",
"deprecated",
"env",
"wrap_help",
"string",
] }
dropshot = "0.15.1"
http = "1.2.0"
once_cell = "1.20.2"
opentelemetry = "0.27.1"
opentelemetry-appender-tracing = { version = "0.27.0", features = ["log", "experimental_metadata_attributes"] }
opentelemetry-otlp = { version = "0.27.0", features = ["grpc-tonic", "gzip-tonic", "zstd-tonic", "tls", "tls-roots", "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.12", features = ["json", "stream", "rustls-tls"] }
schemars = "0.8.21"
@ -47,16 +42,8 @@ serde = { version = "1.0.217", features = ["derive"] }
slog = "2.7.0"
slog-async = "2.8.0"
tokio = { version = "1.42.0", features = ["full"] }
tonic = "0.12.3"
tracing = "0.1.41"
tracing-core = "0.1.33"
tracing-chrome = "0.7.2"
tracing-opentelemetry = "0.28.0"
tracing-slog = { git = "https://github.com/oxidecomputer/tracing-slog", default-features = false }
tracing-subscriber = { version = "0.3.19", default-features = false, features = [
"std",
"ansi",
"env-filter",
"fmt",
] }
uuid = { version = "1", features = [ "serde", "v4" ] }

View file

@ -1,8 +1,8 @@
[package]
name = "patagia-agent"
version = "0.1.0"
edition = "2021"
license = "MPL-2.0"
version.workspace = true
[dependencies]
anyhow.workspace = true
@ -12,8 +12,13 @@ progenitor.workspace = true
reqwest.workspace = true
schemars.workspace = true
serde.workspace = true
serde_derive = "1.0.217"
tokio.workspace = true
tracing.workspace = true
varlink = "11.0.1"
[build-dependencies]
varlink_generator = "10.1.0"
[package.metadata.cargo-machete]
ignored = ["reqwest", "serde"]

5
agent/build.rs Normal file
View file

@ -0,0 +1,5 @@
extern crate varlink_generator;
fn main() {
varlink_generator::cargo_build_tosource("src/io.systemd.Hostname.varlink", true);
}

View file

@ -0,0 +1,32 @@
interface io.systemd.Hostname
method Describe() -> (
Hostname: string,
StaticHostname: ?string,
PrettyHostname: ?string,
DefaultHostname: ?string,
HostnameSource: string,
IconName: ?string,
Chassis: ?string,
Deployment: ?string,
Location: ?string,
KernelName: string,
KernelRelease: string,
KernelVersion: string,
OperatingSystemPrettyName: ?string,
OperatingSystemCPEName: ?string,
OperatingSystemHomeURL: ?string,
OperatingSystemSupportEnd: ?int,
OperatingSystemReleaseData: ?[]string,
MachineInformationData: ?[]string,
HardwareVendor: ?string,
HardwareModel: ?string,
HardwareSerial: ?string,
FirmwareVersion: ?string,
FirmwareVendor: ?string,
FirmwareDate: ?int,
MachineID: string,
BootID: string,
ProductUUID: ?string,
VSockCID: ?int
)

View file

@ -0,0 +1,295 @@
#![doc = "This file was automatically generated by the varlink rust generator"]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
use serde_derive::{Deserialize, Serialize};
use std::io::BufRead;
use std::sync::{Arc, RwLock};
use varlink::{self, CallTrait};
#[allow(dead_code)]
#[derive(Clone, PartialEq, Debug)]
#[allow(clippy::enum_variant_names)]
pub enum ErrorKind {
Varlink_Error,
VarlinkReply_Error,
}
impl ::std::fmt::Display for ErrorKind {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
match self {
ErrorKind::Varlink_Error => write!(f, "Varlink Error"),
ErrorKind::VarlinkReply_Error => write!(f, "Varlink error reply"),
}
}
}
pub struct Error(
pub ErrorKind,
pub Option<Box<dyn std::error::Error + 'static + Send + Sync>>,
pub Option<&'static str>,
);
impl Error {
#[allow(dead_code)]
pub fn kind(&self) -> &ErrorKind {
&self.0
}
}
impl From<ErrorKind> for Error {
fn from(e: ErrorKind) -> Self {
Error(e, None, None)
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
self.1
.as_ref()
.map(|e| e.as_ref() as &(dyn std::error::Error + 'static))
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
std::fmt::Display::fmt(&self.0, f)
}
}
impl std::fmt::Debug for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
use std::error::Error as StdError;
if let Some(ref o) = self.2 {
std::fmt::Display::fmt(o, f)?;
}
std::fmt::Debug::fmt(&self.0, f)?;
if let Some(e) = self.source() {
std::fmt::Display::fmt("\nCaused by:\n", f)?;
std::fmt::Debug::fmt(&e, f)?;
}
Ok(())
}
}
#[allow(dead_code)]
pub type Result<T> = std::result::Result<T, Error>;
impl From<varlink::Error> for Error {
fn from(e: varlink::Error) -> Self {
match e.kind() {
varlink::ErrorKind::VarlinkErrorReply(r) => Error(
ErrorKind::from(r),
Some(Box::from(e)),
Some(concat!(file!(), ":", line!(), ": ")),
),
_ => Error(
ErrorKind::Varlink_Error,
Some(Box::from(e)),
Some(concat!(file!(), ":", line!(), ": ")),
),
}
}
}
#[allow(dead_code)]
impl Error {
pub fn source_varlink_kind(&self) -> Option<&varlink::ErrorKind> {
use std::error::Error as StdError;
let mut s: &dyn StdError = self;
while let Some(c) = s.source() {
let k = self
.source()
.and_then(|e| e.downcast_ref::<varlink::Error>())
.map(|e| e.kind());
if k.is_some() {
return k;
}
s = c;
}
None
}
}
impl From<&varlink::Reply> for ErrorKind {
#[allow(unused_variables)]
fn from(e: &varlink::Reply) -> Self {
match e {
_ => ErrorKind::VarlinkReply_Error,
}
}
}
pub trait VarlinkCallError: varlink::CallTrait {}
impl<'a> VarlinkCallError for varlink::Call<'a> {}
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
pub struct Describe_Reply {
pub r#Hostname: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub r#StaticHostname: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub r#PrettyHostname: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub r#DefaultHostname: Option<String>,
pub r#HostnameSource: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub r#IconName: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub r#Chassis: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub r#Deployment: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub r#Location: Option<String>,
pub r#KernelName: String,
pub r#KernelRelease: String,
pub r#KernelVersion: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub r#OperatingSystemPrettyName: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub r#OperatingSystemCPEName: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub r#OperatingSystemHomeURL: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub r#OperatingSystemSupportEnd: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub r#OperatingSystemReleaseData: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub r#MachineInformationData: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub r#HardwareVendor: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub r#HardwareModel: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub r#HardwareSerial: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub r#FirmwareVersion: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub r#FirmwareVendor: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub r#FirmwareDate: Option<i64>,
pub r#MachineID: String,
pub r#BootID: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub r#ProductUUID: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub r#VSockCID: Option<i64>,
}
impl varlink::VarlinkReply for Describe_Reply {}
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
pub struct Describe_Args {}
pub trait Call_Describe: VarlinkCallError {
fn reply(
&mut self,
r#Hostname: String,
r#StaticHostname: Option<String>,
r#PrettyHostname: Option<String>,
r#DefaultHostname: Option<String>,
r#HostnameSource: String,
r#IconName: Option<String>,
r#Chassis: Option<String>,
r#Deployment: Option<String>,
r#Location: Option<String>,
r#KernelName: String,
r#KernelRelease: String,
r#KernelVersion: String,
r#OperatingSystemPrettyName: Option<String>,
r#OperatingSystemCPEName: Option<String>,
r#OperatingSystemHomeURL: Option<String>,
r#OperatingSystemSupportEnd: Option<i64>,
r#OperatingSystemReleaseData: Option<Vec<String>>,
r#MachineInformationData: Option<Vec<String>>,
r#HardwareVendor: Option<String>,
r#HardwareModel: Option<String>,
r#HardwareSerial: Option<String>,
r#FirmwareVersion: Option<String>,
r#FirmwareVendor: Option<String>,
r#FirmwareDate: Option<i64>,
r#MachineID: String,
r#BootID: String,
r#ProductUUID: Option<String>,
r#VSockCID: Option<i64>,
) -> varlink::Result<()> {
self.reply_struct(
Describe_Reply {
r#Hostname,
r#StaticHostname,
r#PrettyHostname,
r#DefaultHostname,
r#HostnameSource,
r#IconName,
r#Chassis,
r#Deployment,
r#Location,
r#KernelName,
r#KernelRelease,
r#KernelVersion,
r#OperatingSystemPrettyName,
r#OperatingSystemCPEName,
r#OperatingSystemHomeURL,
r#OperatingSystemSupportEnd,
r#OperatingSystemReleaseData,
r#MachineInformationData,
r#HardwareVendor,
r#HardwareModel,
r#HardwareSerial,
r#FirmwareVersion,
r#FirmwareVendor,
r#FirmwareDate,
r#MachineID,
r#BootID,
r#ProductUUID,
r#VSockCID,
}
.into(),
)
}
}
impl<'a> Call_Describe for varlink::Call<'a> {}
pub trait VarlinkInterface {
fn describe(&self, call: &mut dyn Call_Describe) -> varlink::Result<()>;
fn call_upgraded(
&self,
_call: &mut varlink::Call,
_bufreader: &mut dyn BufRead,
) -> varlink::Result<Vec<u8>> {
Ok(Vec::new())
}
}
pub trait VarlinkClientInterface {
fn describe(&mut self) -> varlink::MethodCall<Describe_Args, Describe_Reply, Error>;
}
#[allow(dead_code)]
pub struct VarlinkClient {
connection: Arc<RwLock<varlink::Connection>>,
}
impl VarlinkClient {
#[allow(dead_code)]
pub fn new(connection: Arc<RwLock<varlink::Connection>>) -> Self {
VarlinkClient { connection }
}
}
impl VarlinkClientInterface for VarlinkClient {
fn describe(&mut self) -> varlink::MethodCall<Describe_Args, Describe_Reply, Error> {
varlink::MethodCall::<Describe_Args, Describe_Reply, Error>::new(
self.connection.clone(),
"io.systemd.Hostname.Describe",
Describe_Args {},
)
}
}
#[allow(dead_code)]
pub struct VarlinkInterfaceProxy {
inner: Box<dyn VarlinkInterface + Send + Sync>,
}
#[allow(dead_code)]
pub fn new(inner: Box<dyn VarlinkInterface + Send + Sync>) -> VarlinkInterfaceProxy {
VarlinkInterfaceProxy { inner }
}
impl varlink::Interface for VarlinkInterfaceProxy {
fn get_description(&self) -> &'static str {
"interface io.systemd.Hostname\n\nmethod Describe() -> (\n\tHostname: string,\n\tStaticHostname: ?string,\n\tPrettyHostname: ?string,\n\tDefaultHostname: ?string,\n\tHostnameSource: string,\n\tIconName: ?string,\n\tChassis: ?string,\n\tDeployment: ?string,\n\tLocation: ?string,\n\tKernelName: string,\n\tKernelRelease: string,\n\tKernelVersion: string,\n\tOperatingSystemPrettyName: ?string,\n\tOperatingSystemCPEName: ?string,\n\tOperatingSystemHomeURL: ?string,\n\tOperatingSystemSupportEnd: ?int,\n\tOperatingSystemReleaseData: ?[]string,\n\tMachineInformationData: ?[]string,\n\tHardwareVendor: ?string,\n\tHardwareModel: ?string,\n\tHardwareSerial: ?string,\n\tFirmwareVersion: ?string,\n\tFirmwareVendor: ?string,\n\tFirmwareDate: ?int,\n\tMachineID: string,\n\tBootID: string,\n\tProductUUID: ?string,\n\tVSockCID: ?int\n)\n"
}
fn get_name(&self) -> &'static str {
"io.systemd.Hostname"
}
fn call_upgraded(
&self,
call: &mut varlink::Call,
bufreader: &mut dyn BufRead,
) -> varlink::Result<Vec<u8>> {
self.inner.call_upgraded(call, bufreader)
}
fn call(&self, call: &mut varlink::Call) -> varlink::Result<()> {
let req = call.request.unwrap();
match req.method.as_ref() {
"io.systemd.Hostname.Describe" => self.inner.describe(call as &mut dyn Call_Describe),
m => call.reply_method_not_found(String::from(m)),
}
}
}

View file

@ -1,7 +1,10 @@
use crate::io_systemd_Hostname::VarlinkClientInterface;
use anyhow::Result;
use clap::Parser;
use tokio::time::{sleep, Duration};
use varlink::Connection;
mod io_systemd_Hostname;
mod patagia_api;
#[derive(Parser, Debug)]
@ -30,9 +33,19 @@ async fn main() -> Result<()> {
tracing::info!("Patagia Agent");
let conn = Connection::with_address("unix://run/systemd/io.systemd.Hostname")?;
let mut systemd_hostname_iface = io_systemd_Hostname::VarlinkClient::new(conn);
let desc = systemd_hostname_iface.describe().call()?;
println!(
"Welcome {} (Machine ID: {})!",
desc.Hostname, desc.MachineID
);
let client = patagia_api::Client::new("http://localhost:9474");
let result = client.version().await?;
tracing::info!("Result: {:?}", result);
tracing::info!("Patagia Agent finished");
sleep(Duration::from_secs(3)).await;
Ok(())

View file

@ -1,9 +1,9 @@
[package]
name = "patagia-controller"
description = "Patagia controller server"
version = "0.1.0"
description = "Patagia control plane server"
edition = "2021"
license = "MPL-2.0"
version.workspace = true
[dependencies]
anyhow.workspace = true

View file

@ -18,7 +18,7 @@ struct Cli {
#[arg(
long = "telemetry-otlp-endpoint",
default_value = "http://localhost:4317",
value_name = "OTEL_EXPORTER_OTLP_ENDPOINT"
env = "OTEL_EXPORTER_OTLP_ENDPOINT"
)]
otlp_endpoint: Option<String>,
@ -26,9 +26,16 @@ struct Cli {
long = "log-stderr",
short = 'v',
default_value = "false",
value_name = "LOG_TO_STDERR"
env = "LOG_TO_STDERR"
)]
log_stderr: bool,
#[arg(
long = "listen-address",
default_value = "0.0.0.0:9474",
env = "LISTEN_ADDRESS"
)]
listen_address: String,
}
#[tokio::main]
@ -39,7 +46,7 @@ async fn main() -> Result<()> {
tracing::info!("Patagia Controller");
let config = ConfigDropshot {
bind_address: SocketAddr::from_str("0.0.0.0:9474").unwrap(),
bind_address: SocketAddr::from_str(&args.listen_address).unwrap(),
..Default::default()
};

View file

@ -1,17 +1,24 @@
[package]
name = "instrumentation"
version = "0.1.0"
edition = "2021"
license = "MPL-2.0"
version.workspace = true
[dependencies]
anyhow.workspace = true
http.workspace = true
once_cell.workspace = true
opentelemetry-otlp.workspace = true
opentelemetry_sdk.workspace = true
opentelemetry-semantic-conventions.workspace = true
opentelemetry.workspace = true
tonic.workspace = true
tracing-opentelemetry.workspace = true
tracing-subscriber.workspace = true
opentelemetry-otlp = { version = "0.27.0", features = ["grpc-tonic", "gzip-tonic", "zstd-tonic", "tls", "tls-roots", "trace"] }
opentelemetry_sdk = { version = "0.27.1", features = ["metrics", "rt-tokio"] }
opentelemetry-semantic-conventions = "0.27.0"
opentelemetry-appender-tracing = { version = "0.27.0", features = ["log", "experimental_metadata_attributes"] }
opentelemetry-resource-detectors = { version = "0.6.0" }
opentelemetry = "0.27.1"
tonic = "0.12.3"
tracing-opentelemetry = "0.28.0"
tracing-subscriber = { version = "0.3.19", default-features = false, features = [
"std",
"ansi",
"env-filter",
"fmt",
] }

View file

@ -1,5 +1,4 @@
use anyhow::{anyhow, Result};
use once_cell::sync::Lazy;
use opentelemetry::{trace::TracerProvider as _, KeyValue};
use opentelemetry_otlp::{WithExportConfig, WithTonicConfig};
use opentelemetry_sdk::{
@ -9,25 +8,15 @@ use opentelemetry_sdk::{
trace::{RandomIdGenerator, Sampler, TracerProvider},
Resource,
};
use opentelemetry_semantic_conventions as semcov;
use tracing_opentelemetry::{MetricsLayer, OpenTelemetryLayer};
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
static RESOURCE: Lazy<Resource> = Lazy::new(|| {
Resource::new(vec![
KeyValue::new(
opentelemetry_semantic_conventions::resource::SERVICE_NAME,
env!("CARGO_PKG_NAME"),
),
KeyValue::new(
opentelemetry_semantic_conventions::resource::SERVICE_VERSION,
env!("CARGO_PKG_VERSION"),
),
])
});
use std::time::Duration;
// Construct MeterProvider for MetricsLayer
fn init_meter_provider(otel_endpoint: &String) -> Result<SdkMeterProvider> {
fn init_meter_provider(otel_endpoint: &String, resource: Resource) -> Result<SdkMeterProvider> {
let exporter = opentelemetry_otlp::MetricExporter::builder()
.with_tonic()
.with_endpoint(otel_endpoint)
@ -38,7 +27,7 @@ fn init_meter_provider(otel_endpoint: &String) -> Result<SdkMeterProvider> {
.map_err(|e| anyhow!("Error creating OTLP metric exporter: {:?}", e))?;
let meter_provider = MeterProviderBuilder::default()
.with_resource(RESOURCE.clone())
.with_resource(resource)
.with_reader(
PeriodicReader::builder(exporter, runtime::Tokio)
.with_interval(std::time::Duration::from_secs(10))
@ -52,7 +41,7 @@ fn init_meter_provider(otel_endpoint: &String) -> Result<SdkMeterProvider> {
}
// Construct TracerProvider for OpenTelemetryLayer
fn init_tracer_provider(otel_endpoint: &String) -> Result<TracerProvider> {
fn init_tracer_provider(otel_endpoint: &String, resource: Resource) -> Result<TracerProvider> {
let exporter = opentelemetry_otlp::SpanExporter::builder()
.with_tonic()
.with_tls_config(tonic::transport::ClientTlsConfig::new().with_native_roots())
@ -65,7 +54,7 @@ fn init_tracer_provider(otel_endpoint: &String) -> Result<TracerProvider> {
.with_sampler(Sampler::ParentBased(Box::new(Sampler::TraceIdRatioBased(
1.0,
))))
.with_resource(RESOURCE.clone())
.with_resource(resource)
.with_id_generator(RandomIdGenerator::default())
.with_batch_exporter(exporter, opentelemetry_sdk::runtime::Tokio)
.build();
@ -75,6 +64,25 @@ fn init_tracer_provider(otel_endpoint: &String) -> Result<TracerProvider> {
// Initialize tracing-subscriber and return TracingGuard for opentelemetry-related termination processing
pub fn init_tracing(otel_endpoint: Option<&String>, log_stderr: bool) -> Result<TracingGuard> {
let resource = {
let r = Resource::new([KeyValue::new(
semcov::resource::SERVICE_VERSION,
env!("CARGO_PKG_VERSION"),
)]);
let detected = Resource::from_detectors(
Duration::from_secs(5),
vec![
Box::new(opentelemetry_sdk::resource::SdkProvidedResourceDetector),
Box::new(opentelemetry_sdk::resource::EnvResourceDetector::new()),
Box::new(opentelemetry_resource_detectors::OsResourceDetector),
Box::new(opentelemetry_resource_detectors::ProcessResourceDetector),
Box::new(opentelemetry_sdk::resource::TelemetryResourceDetector),
],
);
r.merge(&detected)
};
let env_filter = tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new(""));
@ -84,7 +92,7 @@ pub fn init_tracing(otel_endpoint: Option<&String>, log_stderr: bool) -> Result<
};
let meter_provider = match otel_endpoint {
Some(endpoint) => Some(init_meter_provider(endpoint)?),
Some(endpoint) => Some(init_meter_provider(endpoint, resource.clone())?),
None => None,
};
@ -94,7 +102,7 @@ pub fn init_tracing(otel_endpoint: Option<&String>, log_stderr: bool) -> Result<
};
let tracer_provider = match otel_endpoint {
Some(endpoint) => Some(init_tracer_provider(endpoint)?),
Some(endpoint) => Some(init_tracer_provider(endpoint, resource)?),
None => None,
};

View file

@ -57,7 +57,7 @@ check-nix:
# Run PostgreSQL for development and testing
dev-postgres:
mkdir -p "$XDG_RUNTIME_DIR/patagia-postgres"
mkdir -p "${XDG_RUNTIME_DIR}/patagia-postgres"
podman volume exists patagia-postgres || podman volume create patagia-postgres
podman run \
--detach \
@ -67,12 +67,9 @@ dev-postgres:
--env POSTGRES_USER=patagia \
--env POSTGRES_PASSWORD=swordfish \
--volume patagia-postgres:/var/lib/postgresql/data \
--volume "$XDG_RUNTIME_DIR/patagia-postgres:/var/run/postgresql" \
--volume "${XDG_RUNTIME_DIR}/patagia-postgres:/var/run/postgresql" \
docker.io/postgres:17
# Reset PostgreSQL data and start
dev-postgres-reset: dev-postgres-clean dev-postgres
# Clean up PostgreSQL data
dev-postgres-clean:
podman rm -f patagia-postgres || true

View file

@ -1,8 +1,8 @@
[package]
name = "trace-request"
version = "0.1.0"
edition = "2021"
license = "MPL-2.0"
version.workspace = true
[lib]
proc-macro = true

View file

@ -1,7 +1,7 @@
[package]
name = "xtask"
version = "0.0.0"
edition = "2021"
version.workspace = true
[[bin]]
name = "xtask"