From 5f24a0dd94d72ce7755b19ee134b10f83b8b517d Mon Sep 17 00:00:00 2001 From: ilbertt Date: Sat, 19 Oct 2024 18:12:00 +0200 Subject: [PATCH 1/6] feat: logger impl first iteration --- Cargo.lock | 1184 +++++++++++++++++++-- Cargo.toml | 3 + scripts/scrape-logs.sh | 3 + src/backend/external_canisters/Cargo.toml | 2 +- src/backend/impl/Cargo.toml | 2 +- src/backend/logs/Cargo.toml | 29 + src/backend/logs/src/actor.rs | 42 + src/backend/logs/src/backend.rs | 842 +++++++++++++++ src/backend/logs/src/main.rs | 168 +++ 9 files changed, 2201 insertions(+), 74 deletions(-) create mode 100755 scripts/scrape-logs.sh create mode 100644 src/backend/logs/Cargo.toml create mode 100644 src/backend/logs/src/actor.rs create mode 100644 src/backend/logs/src/backend.rs create mode 100644 src/backend/logs/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 7c555417..ff9126c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,21 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + [[package]] name = "ahash" version = "0.7.8" @@ -13,6 +28,18 @@ dependencies = [ "version_check", ] +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "aho-corasick" version = "1.1.2" @@ -22,6 +49,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "allocator-api2" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" + [[package]] name = "android-tzdata" version = "0.1.1" @@ -37,12 +70,55 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "0.6.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + [[package]] name = "anstyle" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" +[[package]] +name = "anstyle-parse" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + [[package]] name = "anyhow" version = "1.0.79" @@ -150,7 +226,7 @@ checksum = "1ca33f4bc4ed1babef42cad36cc1f51fa88be00420404e5b1e80ab1b18f7678c" dependencies = [ "concurrent-queue", "event-listener 4.0.3", - "event-listener-strategy", + "event-listener-strategy 0.4.0", "futures-core", "pin-project-lite", ] @@ -161,7 +237,7 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17ae5ebefcc48e7452b4987947920dac9450be1110cadf34d1b8c116bdbaf97c" dependencies = [ - "async-lock 3.2.0", + "async-lock 3.4.0", "async-task", "concurrent-queue", "fastrand 2.0.1", @@ -178,7 +254,7 @@ dependencies = [ "async-channel 2.1.1", "async-executor", "async-io 2.2.2", - "async-lock 3.2.0", + "async-lock 3.4.0", "blocking", "futures-lite 2.2.0", "once_cell", @@ -200,7 +276,7 @@ dependencies = [ "polling 2.8.0", "rustix 0.37.27", "slab", - "socket2", + "socket2 0.4.10", "waker-fn", ] @@ -210,7 +286,7 @@ version = "2.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6afaa937395a620e33dc6a742c593c01aced20aa376ffb0f628121198578ccc7" dependencies = [ - "async-lock 3.2.0", + "async-lock 3.4.0", "cfg-if", "concurrent-queue", "futures-io", @@ -234,12 +310,12 @@ dependencies = [ [[package]] name = "async-lock" -version = "3.2.0" +version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7125e42787d53db9dd54261812ef17e937c95a51e4d291373b670342fa44310c" +checksum = "ff6e472cdea888a4bd64f342f09b3f50e1886d32afe8df3d663c01140b811b18" dependencies = [ - "event-listener 4.0.3", - "event-listener-strategy", + "event-listener 5.3.1", + "event-listener-strategy 0.5.2", "pin-project-lite", ] @@ -348,6 +424,51 @@ dependencies = [ "uuid", ] +[[package]] +name = "backend_logs" +version = "0.1.0" +dependencies = [ + "anyhow", + "base64 0.22.0", + "candid", + "chrono", + "clap 4.5.13", + "ic-agent", + "ic-cdk", + "opentelemetry", + "opentelemetry-otlp", + "opentelemetry_sdk", + "serde", + "serde_bytes", + "tokio", +] + +[[package]] +name = "backoff" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b62ddb9cb1ec0a098ad4bbf9344d0713fa193ae1a80af55febcff2627b6a00c1" +dependencies = [ + "getrandom 0.2.11", + "instant", + "rand", +] + +[[package]] +name = "backtrace" +version = "0.3.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + [[package]] name = "base16ct" version = "0.2.0" @@ -480,7 +601,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a37913e8dc4ddcc604f0c6d3bf2887c995153af3611de9e23c352b44c1b9118" dependencies = [ "async-channel 2.1.1", - "async-lock 3.2.0", + "async-lock 3.4.0", "async-task", "fastrand 2.0.1", "futures-io", @@ -640,6 +761,19 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cached" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8466736fe5dbcaf8b8ee24f9bbefe43c884dc3e9ff7178da70f55bffca1133c" +dependencies = [ + "ahash 0.8.11", + "hashbrown 0.14.3", + "instant", + "once_cell", + "thiserror", +] + [[package]] name = "camino" version = "1.1.6" @@ -727,11 +861,11 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.83" +version = "1.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +checksum = "c2e7962b54006dcfcc61cb72735f4d89bb97061dd6a7ed882ec6b8ee53714c6f" dependencies = [ - "libc", + "shlex", ] [[package]] @@ -794,28 +928,62 @@ checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" dependencies = [ "atty", "bitflags 1.3.2", - "clap_derive", - "clap_lex", + "clap_derive 3.2.25", + "clap_lex 0.2.4", "indexmap 1.9.3", "once_cell", - "strsim", + "strsim 0.10.0", "termcolor", "textwrap", ] +[[package]] +name = "clap" +version = "4.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fbb260a053428790f3de475e304ff84cdbc4face759ea7a3e64c1edd938a7fc" +dependencies = [ + "clap_builder", + "clap_derive 4.5.13", +] + +[[package]] +name = "clap_builder" +version = "4.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64b17d7ea74e9f833c7dbf2cbe4fb12ff26783eda4782a8975b72f895c9b4d99" +dependencies = [ + "anstream", + "anstyle", + "clap_lex 0.7.2", + "strsim 0.11.1", +] + [[package]] name = "clap_derive" version = "3.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae6371b8bdc8b7d3959e9cf7b22d4435ef3e79e138688421ec654acf8c81b008" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro-error", "proc-macro2", "quote", "syn 1.0.109", ] +[[package]] +name = "clap_derive" +version = "4.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" +dependencies = [ + "heck 0.5.0", + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "clap_lex" version = "0.2.4" @@ -825,6 +993,12 @@ dependencies = [ "os_str_bytes", ] +[[package]] +name = "clap_lex" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" + [[package]] name = "codespan-reporting" version = "0.11.1" @@ -835,6 +1009,12 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "colorchoice" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" + [[package]] name = "comparable" version = "0.5.4" @@ -1041,7 +1221,7 @@ dependencies = [ "icrc-ledger-types", "lazy_static", "on_wire", - "prost", + "prost 0.12.4", "rand", "serde", "serde_cbor", @@ -1069,7 +1249,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "strsim", + "strsim 0.10.0", "syn 1.0.109", ] @@ -1198,7 +1378,7 @@ version = "0.9.0" source = "git+https://github.com/dfinity/ic?tag=release-2024-02-21_23-01#2e921c9adfc71f3edc96a9eb5d85fc742e7d8a9f" dependencies = [ "on_wire", - "prost", + "prost 0.12.4", ] [[package]] @@ -1384,6 +1564,17 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "event-listener" +version = "5.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6032be9bd27023a771701cc49f9f053c751055f71efb2e0ae5c15809093675ba" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + [[package]] name = "event-listener-strategy" version = "0.4.0" @@ -1394,6 +1585,16 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "event-listener-strategy" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f214dc438f977e6d4e3500aaa277f5ad94ca83fbbd9b1a15713ce2344ccc5a1" +dependencies = [ + "event-listener 5.3.1", + "pin-project-lite", +] + [[package]] name = "external_canisters" version = "0.1.0" @@ -1651,6 +1852,12 @@ dependencies = [ "wasi 0.11.0+wasi-snapshot-preview1", ] +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + [[package]] name = "glob" version = "0.3.1" @@ -1713,7 +1920,7 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" dependencies = [ - "ahash", + "ahash 0.7.8", ] [[package]] @@ -1721,6 +1928,10 @@ name = "hashbrown" version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +dependencies = [ + "ahash 0.8.11", + "allocator-api2", +] [[package]] name = "heck" @@ -1728,6 +1939,12 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -1739,9 +1956,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.3.3" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] name = "hex" @@ -1778,6 +1995,103 @@ dependencies = [ "itoa", ] +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http 1.1.0", +] + +[[package]] +name = "http-body-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http 1.1.0", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" + +[[package]] +name = "hyper" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbbff0a806a4728c99295b254c8838933b5b082d75e3cb70c8dab21fdfbcfa9a" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http 1.1.0", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" +dependencies = [ + "futures-util", + "http 1.1.0", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", + "webpki-roots", +] + +[[package]] +name = "hyper-util" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cde7055719c54e36e95e8719f95883f22072a48ede39db7fc17a4e1d5281e9b9" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http 1.1.0", + "http-body", + "hyper", + "pin-project-lite", + "socket2 0.5.7", + "tokio", + "tower", + "tower-service", + "tracing", +] + [[package]] name = "iana-time-zone" version = "0.1.60" @@ -1801,6 +2115,50 @@ dependencies = [ "cc", ] +[[package]] +name = "ic-agent" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0783cc46e082dc4b016ff693a45207db55e552e8e6f5e3e2552514761a285f6d" +dependencies = [ + "async-lock 3.4.0", + "async-trait", + "backoff", + "cached 0.52.0", + "candid", + "der", + "ecdsa", + "ed25519-consensus", + "elliptic-curve", + "futures-util", + "hex", + "http 1.1.0", + "http-body", + "ic-certification 2.6.0", + "ic-transport-types", + "ic-verify-bls-signature", + "k256", + "leb128", + "p256", + "pem 3.0.4", + "pkcs8", + "rand", + "rangemap", + "reqwest", + "sec1", + "serde", + "serde_bytes", + "serde_cbor", + "serde_repr", + "sha2 0.10.8", + "simple_asn1", + "thiserror", + "time", + "tokio", + "tower-service", + "url", +] + [[package]] name = "ic-base-types" version = "0.9.0" @@ -1814,7 +2172,7 @@ dependencies = [ "ic-protobuf", "ic-stable-structures", "phantom_newtype", - "prost", + "prost 0.12.4", "serde", ] @@ -1935,6 +2293,18 @@ dependencies = [ "sha2 0.10.8", ] +[[package]] +name = "ic-certification" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e64ee3d8b6e81b51f245716d3e0badb63c283c00f3c9fb5d5219afc30b5bf821" +dependencies = [ + "hex", + "serde", + "serde_bytes", + "sha2 0.10.8", +] + [[package]] name = "ic-certified-map" version = "0.3.4" @@ -1959,7 +2329,7 @@ dependencies = [ "k256", "lazy_static", "num-bigint", - "pem", + "pem 1.1.1", "rand", "simple_asn1", "zeroize", @@ -2012,10 +2382,10 @@ version = "0.9.0" source = "git+https://github.com/dfinity/ic?tag=release-2024-02-21_23-01#2e921c9adfc71f3edc96a9eb5d85fc742e7d8a9f" dependencies = [ "hex", - "ic_bls12_381", + "ic_bls12_381 0.8.0", "itertools 0.12.1", "lazy_static", - "pairing", + "pairing 0.22.0", "paste", "rand", "rand_chacha", @@ -2078,7 +2448,7 @@ version = "0.9.0" source = "git+https://github.com/dfinity/ic?tag=release-2024-02-21_23-01#2e921c9adfc71f3edc96a9eb5d85fc742e7d8a9f" dependencies = [ "base64 0.13.1", - "cached", + "cached 0.41.0", "hex", "ic-crypto-internal-bls12-381-type", "ic-crypto-internal-seed", @@ -2266,8 +2636,8 @@ version = "2.5.0" source = "git+https://github.com/dfinity/response-verification#600b3d5339381bbfe3454ce870a04afa79005c3d" dependencies = [ "candid", - "http", - "ic-certification", + "http 0.2.12", + "ic-certification 2.5.0", "ic-representation-independent-hash", "serde", "thiserror", @@ -2504,7 +2874,7 @@ dependencies = [ "mockall 0.11.4", "num-traits", "priority-queue", - "prost", + "prost 0.12.4", "rust_decimal", "serde", "serde_json", @@ -2547,7 +2917,7 @@ dependencies = [ "candid", "comparable", "ic-base-types", - "prost", + "prost 0.12.4", "serde", ] @@ -2626,7 +2996,7 @@ dependencies = [ "lazy_static", "num-traits", "on_wire", - "prost", + "prost 0.12.4", "serde", "sha2 0.9.9", ] @@ -2689,7 +3059,7 @@ dependencies = [ "num-traits", "on_wire", "pretty_assertions", - "prost", + "prost 0.12.4", "rand", "rand_chacha", "registry-canister", @@ -2730,7 +3100,7 @@ dependencies = [ "candid", "erased-serde", "maplit", - "prost", + "prost 0.12.4", "serde", "serde_json", "slog", @@ -2790,7 +3160,7 @@ dependencies = [ "candid", "ic-base-types", "ic-protobuf", - "prost", + "prost 0.12.4", "serde", ] @@ -2813,7 +3183,7 @@ dependencies = [ "build-info", "build-info-build", "candid", - "clap", + "clap 3.2.25", "comparable", "dfn_candid", "dfn_core", @@ -2846,7 +3216,7 @@ dependencies = [ "lazy_static", "maplit", "num-traits", - "prost", + "prost 0.12.4", "prost-build", "rand", "rand_chacha", @@ -2920,7 +3290,7 @@ dependencies = [ "isocountry", "lazy_static", "maplit", - "prost", + "prost 0.12.4", "serde", "serde_yaml", ] @@ -2950,7 +3320,7 @@ dependencies = [ "ic-nervous-system-runtime", "ic-sns-swap", "icrc-ledger-types", - "prost", + "prost 0.12.4", "serde", ] @@ -2984,7 +3354,7 @@ dependencies = [ "itertools 0.12.1", "lazy_static", "maplit", - "prost", + "prost 0.12.4", "rust_decimal", "serde", ] @@ -2998,7 +3368,7 @@ dependencies = [ "comparable", "ic-base-types", "ic-nervous-system-proto", - "prost", + "prost 0.12.4", "serde", ] @@ -3031,7 +3401,7 @@ dependencies = [ "ic-types", "icrc-ledger-types", "maplit", - "prost", + "prost 0.12.4", "serde", "serde_json", ] @@ -3046,18 +3416,36 @@ dependencies = [ ] [[package]] -name = "ic-types" -version = "0.9.0" -source = "git+https://github.com/dfinity/ic?tag=release-2024-02-21_23-01#2e921c9adfc71f3edc96a9eb5d85fc742e7d8a9f" +name = "ic-transport-types" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90400f5f1371fda054a07e23717d38813f15093e193b8f21a36fd3e2c62a7179" dependencies = [ - "base64 0.13.1", - "bincode", "candid", - "chrono", - "derive_more 0.99.8-alpha.0", "hex", - "ic-base-types", - "ic-btc-types-internal", + "ic-certification 2.6.0", + "leb128", + "serde", + "serde_bytes", + "serde_cbor", + "serde_repr", + "sha2 0.10.8", + "thiserror", +] + +[[package]] +name = "ic-types" +version = "0.9.0" +source = "git+https://github.com/dfinity/ic?tag=release-2024-02-21_23-01#2e921c9adfc71f3edc96a9eb5d85fc742e7d8a9f" +dependencies = [ + "base64 0.13.1", + "bincode", + "candid", + "chrono", + "derive_more 0.99.8-alpha.0", + "hex", + "ic-base-types", + "ic-btc-types-internal", "ic-constants", "ic-crypto-internal-types", "ic-crypto-sha2", @@ -3069,7 +3457,7 @@ dependencies = [ "maplit", "once_cell", "phantom_newtype", - "prost", + "prost 0.12.4", "serde", "serde_bytes", "serde_cbor", @@ -3087,11 +3475,25 @@ version = "0.9.0" source = "git+https://github.com/dfinity/ic?tag=release-2024-02-21_23-01#2e921c9adfc71f3edc96a9eb5d85fc742e7d8a9f" dependencies = [ "hex", - "prost", + "prost 0.12.4", "scoped_threadpool", "serde", ] +[[package]] +name = "ic-verify-bls-signature" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d420b25c0091059f6c3c23a21427a81915e6e0aca3b79e0d403ed767f286a3b9" +dependencies = [ + "hex", + "ic_bls12_381 0.10.0", + "lazy_static", + "pairing 0.23.0", + "rand", + "sha2 0.10.8", +] + [[package]] name = "ic-xrc-types" version = "1.2.0" @@ -3123,12 +3525,26 @@ dependencies = [ "digest 0.9.0", "ff 0.12.1", "group 0.12.1", - "pairing", + "pairing 0.22.0", "rand_core 0.6.4", "subtle", "zeroize", ] +[[package]] +name = "ic_bls12_381" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22c65787944f32af084dffd0c68c1e544237b76e215654ddea8cd9f527dd8b69" +dependencies = [ + "digest 0.10.7", + "ff 0.13.0", + "group 0.13.0", + "pairing 0.23.0", + "rand_core 0.6.4", + "subtle", +] + [[package]] name = "ic_principal" version = "0.1.1" @@ -3164,8 +3580,8 @@ dependencies = [ "lazy_static", "num-traits", "on_wire", - "prost", - "prost-derive", + "prost 0.12.4", + "prost-derive 0.12.4", "serde", "serde_bytes", "serde_cbor", @@ -3251,7 +3667,7 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ - "hermit-abi 0.3.3", + "hermit-abi 0.3.9", "libc", "windows-sys 0.48.0", ] @@ -3268,11 +3684,17 @@ version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bad00257d07be169d870ab665980b06cdb366d792ad690bf2e76876dc503455" dependencies = [ - "hermit-abi 0.3.3", + "hermit-abi 0.3.9", "rustix 0.38.28", "windows-sys 0.52.0", ] +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + [[package]] name = "isocountry" version = "0.3.2" @@ -3338,15 +3760,16 @@ dependencies = [ [[package]] name = "k256" -version = "0.13.3" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" +checksum = "f6e3919bbaa2945715f0bb6d3934a173d1e9a59ac23767fbaaef277265a7411b" dependencies = [ "cfg-if", "ecdsa", "elliptic-curve", "once_cell", "sha2 0.10.8", + "signature", ] [[package]] @@ -3396,7 +3819,7 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" dependencies = [ - "spin", + "spin 0.5.2", ] [[package]] @@ -3514,12 +3937,39 @@ version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + [[package]] name = "minimal-lexical" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" +dependencies = [ + "hermit-abi 0.3.9", + "libc", + "wasi 0.11.0+wasi-snapshot-preview1", + "windows-sys 0.52.0", +] + [[package]] name = "mockall" version = "0.11.4" @@ -3667,6 +4117,15 @@ dependencies = [ "autocfg", ] +[[package]] +name = "object" +version = "0.36.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" +dependencies = [ + "memchr", +] + [[package]] name = "oid-registry" version = "0.6.1" @@ -3693,6 +4152,87 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" +[[package]] +name = "opentelemetry" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "570074cc999d1a58184080966e5bd3bf3a9a4af650c3b05047c2621e7405cd17" +dependencies = [ + "futures-core", + "futures-sink", + "js-sys", + "once_cell", + "pin-project-lite", + "thiserror", +] + +[[package]] +name = "opentelemetry-http" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6351496aeaa49d7c267fb480678d85d1cd30c5edb20b497c48c56f62a8c14b99" +dependencies = [ + "async-trait", + "bytes", + "http 1.1.0", + "opentelemetry", + "reqwest", +] + +[[package]] +name = "opentelemetry-otlp" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29e1f9c8b032d4f635c730c0efcf731d5e2530ea13fa8bef7939ddc8420696bd" +dependencies = [ + "async-trait", + "futures-core", + "http 1.1.0", + "opentelemetry", + "opentelemetry-http", + "opentelemetry-proto", + "opentelemetry_sdk", + "prost 0.13.3", + "reqwest", + "serde_json", + "thiserror", +] + +[[package]] +name = "opentelemetry-proto" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9d3968ce3aefdcca5c27e3c4ea4391b37547726a70893aab52d3de95d5f8b34" +dependencies = [ + "hex", + "opentelemetry", + "opentelemetry_sdk", + "prost 0.13.3", + "serde", + "tonic", +] + +[[package]] +name = "opentelemetry_sdk" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2c627d9f4c9cdc1f21a29ee4bfbd6028fcb8bcf2a857b43f3abdf72c9c862f3" +dependencies = [ + "async-trait", + "futures-channel", + "futures-executor", + "futures-util", + "glob", + "once_cell", + "opentelemetry", + "percent-encoding", + "rand", + "serde_json", + "thiserror", + "tokio", + "tokio-stream", +] + [[package]] name = "os_str_bytes" version = "6.6.1" @@ -3720,6 +4260,15 @@ dependencies = [ "group 0.12.1", ] +[[package]] +name = "pairing" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" +dependencies = [ + "group 0.13.0", +] + [[package]] name = "parking" version = "2.2.0" @@ -3764,6 +4313,16 @@ dependencies = [ "base64 0.13.1", ] +[[package]] +name = "pem" +version = "3.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e459365e590736a54c3fa561947c84837534b8e9af6fc5bf781307e82658fae" +dependencies = [ + "base64 0.22.0", + "serde", +] + [[package]] name = "pem-rfc7468" version = "0.7.0" @@ -3859,6 +4418,26 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5be167a7af36ee22fe3115051bc51f6e6c7054c9348e28deb4f49bd6f705a315" +[[package]] +name = "pin-project" +version = "1.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf123a161dde1e524adf36f90bc5d8d3462824a9c43553ad07a8183161189ec" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4502d8515ca9f32f1fb543d987f63d95a14934883db45bdb48060b6b69257f8" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "pin-project-lite" version = "0.2.13" @@ -4092,7 +4671,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0f5d036824e4761737860779c906171497f6d55681139d8312388f8fe398922" dependencies = [ "bytes", - "prost-derive", + "prost-derive 0.12.4", +] + +[[package]] +name = "prost" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b0487d90e047de87f984913713b85c601c05609aad5b0df4b4573fbf69aa13f" +dependencies = [ + "bytes", + "prost-derive 0.13.3", ] [[package]] @@ -4102,14 +4691,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80b776a1b2dc779f5ee0641f8ade0125bc1298dd41a9a0c16d8bd57b42d222b1" dependencies = [ "bytes", - "heck", - "itertools 0.11.0", + "heck 0.5.0", + "itertools 0.12.1", "log", "multimap", "once_cell", "petgraph", "prettyplease", - "prost", + "prost 0.12.4", "prost-types", "regex", "syn 2.0.48", @@ -4123,7 +4712,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19de2de2a00075bf566bee3bd4db014b11587e84184d3f7a791bc17f1a8e9e48" dependencies = [ "anyhow", - "itertools 0.11.0", + "itertools 0.12.1", + "proc-macro2", + "quote", + "syn 2.0.48", +] + +[[package]] +name = "prost-derive" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9552f850d5f0964a4e4d0bf306459ac29323ddfbae05e35a7c0d35cb0803cc5" +dependencies = [ + "anyhow", + "itertools 0.12.1", "proc-macro2", "quote", "syn 2.0.48", @@ -4135,7 +4737,7 @@ version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3235c33eb02c1f1e212abdbe34c78b264b038fb58ca612664343271e36e55ffe" dependencies = [ - "prost", + "prost 0.12.4", ] [[package]] @@ -4167,6 +4769,54 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2 0.5.7", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2 0.5.7", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.35" @@ -4221,6 +4871,12 @@ dependencies = [ "getrandom 0.2.11", ] +[[package]] +name = "rangemap" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f60fcc7d6849342eff22c4350c8b9a989ee8ceabc4b481253e8946b9fe83d684" + [[package]] name = "redox_syscall" version = "0.4.1" @@ -4319,7 +4975,7 @@ dependencies = [ "lazy_static", "leb128", "on_wire", - "prost", + "prost 0.12.4", "serde", "url", ] @@ -4339,6 +4995,51 @@ dependencies = [ "bytecheck", ] +[[package]] +name = "reqwest" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7d6d2a27d57148378eb5e111173f4276ad26340ecc5c49a4a2152167a2d6a37" +dependencies = [ + "base64 0.22.0", + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "http 1.1.0", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "once_cell", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls", + "rustls-pemfile", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tokio-rustls", + "tokio-util", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-streams", + "web-sys", + "webpki-roots", + "winreg", +] + [[package]] name = "rfc6979" version = "0.4.0" @@ -4349,6 +5050,21 @@ dependencies = [ "subtle", ] +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.11", + "libc", + "spin 0.9.8", + "untrusted", + "windows-sys 0.52.0", +] + [[package]] name = "rkyv" version = "0.7.44" @@ -4433,6 +5149,18 @@ dependencies = [ "rust_decimal", ] +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustc-hash" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" + [[package]] name = "rustc_version" version = "0.4.0" @@ -4478,6 +5206,46 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rustls" +version = "0.23.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fbb44d7acc4e873d613422379f69f237a1b141928c02f6bc6ccfddddc2d7993" +dependencies = [ + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16f1201b3c9a7ee8039bcadc17b7e605e2945b27eee7631788c1bd2b0643674b" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + [[package]] name = "rustversion" version = "1.0.14" @@ -4581,6 +5349,17 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_repr" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "serde_tokenstream" version = "0.1.7" @@ -4592,6 +5371,18 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + [[package]] name = "serde_with" version = "1.14.0" @@ -4651,6 +5442,21 @@ dependencies = [ "digest 0.10.7", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + [[package]] name = "signature" version = "2.2.0" @@ -4714,9 +5520,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "socket2" @@ -4728,12 +5534,28 @@ dependencies = [ "winapi", ] +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "spin" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + [[package]] name = "spki" version = "0.7.3" @@ -4776,6 +5598,12 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "strum" version = "0.25.0" @@ -4791,7 +5619,7 @@ version = "0.25.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro2", "quote", "rustversion", @@ -4844,6 +5672,12 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" + [[package]] name = "synstructure" version = "0.12.6" @@ -4988,6 +5822,70 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" +[[package]] +name = "tokio" +version = "1.40.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2 0.5.7", + "tokio-macros", + "windows-sys 0.52.0", +] + +[[package]] +name = "tokio-macros" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + [[package]] name = "toml_datetime" version = "0.6.5" @@ -5005,6 +5903,54 @@ dependencies = [ "winnow", ] +[[package]] +name = "tonic" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877c5b330756d856ffcc4553ab34a5684481ade925ecc54bcd1bf02b1d0d4d52" +dependencies = [ + "async-trait", + "base64 0.22.0", + "bytes", + "http 1.1.0", + "http-body", + "http-body-util", + "percent-encoding", + "pin-project", + "prost 0.13.3", + "tokio-stream", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + [[package]] name = "tracing" version = "0.1.40" @@ -5012,14 +5958,35 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ "pin-project-lite", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "tracing-core" version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "typed-arena" @@ -5084,6 +6051,12 @@ version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + [[package]] name = "url" version = "2.5.0" @@ -5107,6 +6080,12 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86bd8d4e895da8537e5315b8254664e6b769c4ff3db18321b297a1e7004392e3" +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "uuid" version = "1.6.1" @@ -5134,6 +6113,15 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3c4517f54858c779bbcbf228f4fca63d121bf85fbecb2dc578cdf4a39395690" +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + [[package]] name = "wasi" version = "0.9.0+wasi-snapshot-preview1" @@ -5212,6 +6200,19 @@ version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" +[[package]] +name = "wasm-streams" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e072d4e72f700fb3443d8fe94a39315df013eef1104903cdb0a2abd322bbecd" +dependencies = [ + "futures-util", + "js-sys", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + [[package]] name = "web-sys" version = "0.3.66" @@ -5222,6 +6223,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "winapi" version = "0.3.9" @@ -5403,6 +6413,16 @@ dependencies = [ "memchr", ] +[[package]] +name = "winreg" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a277a57398d4bfa075df44f501a17cfdf8542d224f0d36095a2adc7aee4ef0a5" +dependencies = [ + "cfg-if", + "windows-sys 0.48.0", +] + [[package]] name = "wyz" version = "0.5.1" @@ -5445,6 +6465,26 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "zeroize" version = "1.7.0" diff --git a/Cargo.toml b/Cargo.toml index 6e938b38..7a607694 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ members = [ "src/backend/api", "src/backend/impl", "src/backend/external_canisters", + "src/backend/logs", ] [profile.release] @@ -24,6 +25,8 @@ candid = "0.10" candid_parser = "0.1" serde = "1.0" uuid = "1.6" +serde_bytes = "0.11" +chrono = { version = "0.4", default-features = false, features = ["std"] } mockall = "0.12" rstest = "0.18" diff --git a/scripts/scrape-logs.sh b/scripts/scrape-logs.sh new file mode 100755 index 00000000..d55c2609 --- /dev/null +++ b/scripts/scrape-logs.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +cargo run --package backend_logs --bin backend_logs -- --identity-pem data/codegov-website-logger-identity.pem --loki-endpoint https://logs-prod-eu-west-0.grafana.net/loki/api/v1/push --loki-username 152321 --loki-password $LOKI_PASSWORD --backend-canister-id nijcm-2qaaa-aaaal-qcx2a-cai diff --git a/src/backend/external_canisters/Cargo.toml b/src/backend/external_canisters/Cargo.toml index ba0d6ef6..f5c314f5 100644 --- a/src/backend/external_canisters/Cargo.toml +++ b/src/backend/external_canisters/Cargo.toml @@ -9,4 +9,4 @@ ic-nns-governance.workspace = true candid.workspace = true serde.workspace = true -serde_bytes = "0.11" +serde_bytes.workspace = true diff --git a/src/backend/impl/Cargo.toml b/src/backend/impl/Cargo.toml index e96f938a..c88c4930 100644 --- a/src/backend/impl/Cargo.toml +++ b/src/backend/impl/Cargo.toml @@ -29,7 +29,7 @@ serde.workspace = true serde_cbor = "0.11" uuid = { workspace = true, features = ["serde"] } -chrono = { version = "0.4", default-features = false, features = ["std"] } +chrono.workspace = true hex = "0.4" lazy_static = "1.4" base64 = "0.22" diff --git a/src/backend/logs/Cargo.toml b/src/backend/logs/Cargo.toml new file mode 100644 index 00000000..8369931c --- /dev/null +++ b/src/backend/logs/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "backend_logs" +version = "0.1.0" +edition = "2021" + +[[bin]] +name = "backend_logs" +path = "src/main.rs" + +[dependencies] +ic-cdk.workspace = true +ic-agent = "0.39" + +candid.workspace = true +serde.workspace = true +serde_bytes.workspace = true + +clap = { version = "4.5", features = ["derive"] } +opentelemetry = "0.26" +opentelemetry-otlp = { version = "0.26", features = [ + "logs", + "http-json", + "reqwest-client", +], default-features = false } +opentelemetry_sdk = { version = "0.26", features = ["logs", "rt-tokio"] } +tokio = { version = "1.40", features = ["full"] } +anyhow = "1.0" +base64 = "0.22" +chrono.workspace = true diff --git a/src/backend/logs/src/actor.rs b/src/backend/logs/src/actor.rs new file mode 100644 index 00000000..4a15ddb5 --- /dev/null +++ b/src/backend/logs/src/actor.rs @@ -0,0 +1,42 @@ +use std::path::PathBuf; + +use candid::{Decode, Encode, Principal}; +use ic_agent::{identity::Secp256k1Identity, Agent}; + +use crate::backend::{ListLogsResponse, LogsFilterRequest}; + +pub struct BackendActor { + agent: Agent, + canister_id: Principal, +} + +impl BackendActor { + pub fn new(identity_pem: PathBuf, canister_id: Principal) -> anyhow::Result { + let identity = Secp256k1Identity::from_pem_file(identity_pem)?; + let agent = Agent::builder() + .with_identity(identity) + .with_url("https://icp-api.io") + .build()?; + Ok(Self { agent, canister_id }) + } + + pub async fn list_logs( + &self, + after_timestamp_ms: Option, + ) -> Result { + let request = LogsFilterRequest { + after_timestamp_ms, + before_timestamp_ms: None, + context_contains_any: None, + level: None, + message_contains_any: None, + }; + let response = self + .agent + .query(&self.canister_id, "list_logs") + .with_arg(Encode!(&request)?) + .await?; + let result = Decode!(&response, ListLogsResponse)?; + Ok(result) + } +} diff --git a/src/backend/logs/src/backend.rs b/src/backend/logs/src/backend.rs new file mode 100644 index 00000000..005b4dc1 --- /dev/null +++ b/src/backend/logs/src/backend.rs @@ -0,0 +1,842 @@ +// This is an experimental feature to generate Rust binding from Candid. +// You may want to manually adjust some of the types. +#![allow(dead_code, unused_imports)] +use candid::{self, CandidType, Deserialize, Principal}; +use ic_cdk::api::call::CallResult as Result; + +#[derive(CandidType, Deserialize)] +pub enum SocialLinkPlatform { + #[serde(rename="x")] + X, + #[serde(rename="taggr")] + Taggr, + #[serde(rename="dfinityforum")] + Dfinityforum, + #[serde(rename="website")] + Website, + #[serde(rename="discord")] + Discord, + #[serde(rename="dscvr")] + Dscvr, + #[serde(rename="github")] + Github, + #[serde(rename="openchat")] + Openchat, +} +#[derive(CandidType, Deserialize)] +pub struct SocialLink { pub username: String, pub platform: SocialLinkPlatform } +#[derive(CandidType, Deserialize)] +pub enum UserConfig { + #[serde(rename="admin")] + Admin{ bio: String }, + #[serde(rename="anonymous")] + Anonymous, + #[serde(rename="reviewer")] + Reviewer{ + bio: String, + wallet_address: String, + social_links: Vec, + neuron_id: u64, + }, +} +#[derive(CandidType, Deserialize)] +pub struct Err { pub code: u16, pub message: String } +#[derive(CandidType, Deserialize)] +pub enum CreateMyUserProfileResponse { + #[serde(rename="ok")] + Ok{ id: String, username: String, config: UserConfig }, + #[serde(rename="err")] + Err(Err), +} +#[derive(CandidType, Deserialize)] +pub struct CreateProposalReviewRequest { + pub review_duration_mins: Option, + pub summary: Option, + pub proposal_id: String, + pub build_reproduced: Option, +} +#[derive(CandidType, Deserialize)] +pub enum ProposalReviewStatus { + #[serde(rename="published")] + Published, + #[serde(rename="draft")] + Draft, +} +#[derive(CandidType, Deserialize)] +pub enum ReviewCommitState { + #[serde(rename="not_reviewed")] + NotReviewed, + #[serde(rename="reviewed")] + Reviewed{ + highlights: Vec, + comment: Option, + matches_description: Option, + }, +} +#[derive(CandidType, Deserialize)] +pub struct ProposalReviewCommit { + pub proposal_review_id: String, + pub created_at: String, + pub user_id: String, + pub state: ReviewCommitState, + pub last_updated_at: Option, + pub commit_sha: String, +} +#[derive(CandidType, Deserialize)] +pub struct ProposalReviewCommitWithId { + pub id: String, + pub proposal_review_commit: ProposalReviewCommit, +} +#[derive(CandidType, Deserialize)] +pub struct ProposalReview { + pub status: ProposalReviewStatus, + pub proposal_review_commits: Vec, + pub created_at: String, + pub user_id: String, + pub review_duration_mins: Option, + pub summary: Option, + pub images_paths: Vec, + pub last_updated_at: Option, + pub proposal_id: String, + pub build_reproduced: Option, +} +#[derive(CandidType, Deserialize)] +pub struct ProposalReviewWithId { + pub id: String, + pub proposal_review: ProposalReview, +} +#[derive(CandidType, Deserialize)] +pub enum CreateProposalReviewResponse { + #[serde(rename="ok")] + Ok(ProposalReviewWithId), + #[serde(rename="err")] + Err(Err), +} +#[derive(CandidType, Deserialize)] +pub struct CreateProposalReviewCommitRequest { + pub proposal_review_id: String, + pub state: ReviewCommitState, + pub commit_sha: String, +} +#[derive(CandidType, Deserialize)] +pub enum CreateProposalReviewCommitResponse { + #[serde(rename="ok")] + Ok(ProposalReviewCommitWithId), + #[serde(rename="err")] + Err(Err), +} +#[derive(CandidType, Deserialize)] +pub struct CreateProposalReviewImageRequest { + pub content_type: String, + pub content_bytes: serde_bytes::ByteBuf, + pub proposal_id: String, +} +#[derive(CandidType, Deserialize)] +pub enum CreateProposalReviewImageResponse { + #[serde(rename="ok")] + Ok{ path: String }, + #[serde(rename="err")] + Err(Err), +} +#[derive(CandidType, Deserialize)] +pub struct DeleteProposalReviewCommitRequest { pub id: String } +#[derive(CandidType, Deserialize)] +pub enum DeleteProposalReviewCommitResponse { + #[serde(rename="ok")] + Ok, + #[serde(rename="err")] + Err(Err), +} +#[derive(CandidType, Deserialize)] +pub struct DeleteProposalReviewImageRequest { + pub image_path: String, + pub proposal_id: String, +} +#[derive(CandidType, Deserialize)] +pub enum DeleteProposalReviewImageResponse { + #[serde(rename="ok")] + Ok, + #[serde(rename="err")] + Err(Err), +} +#[derive(CandidType, Deserialize)] +pub struct GetMyProposalReviewRequest { pub proposal_id: String } +#[derive(CandidType, Deserialize)] +pub enum GetMyProposalReviewResponse { + #[serde(rename="ok")] + Ok(ProposalReviewWithId), + #[serde(rename="err")] + Err(Err), +} +#[derive(CandidType, Deserialize)] +pub enum GetMyUserProfileResponse { + #[serde(rename="ok")] + Ok{ id: String, username: String, config: UserConfig }, + #[serde(rename="err")] + Err(Err), +} +#[derive(CandidType, Deserialize)] +pub enum HistoryAction { + #[serde(rename="restore")] + Restore, + #[serde(rename="delete")] + Delete, + #[serde(rename="create")] + Create, + #[serde(rename="update")] + Update, +} +#[derive(CandidType, Deserialize)] +pub struct UserProfileHistoryEntry { + pub username: String, + pub config: UserConfig, +} +#[derive(CandidType, Deserialize)] +pub struct GetMyUserProfileHistoryResponseOkHistoryItem { + pub action: HistoryAction, + pub data: UserProfileHistoryEntry, + pub date_time: String, + pub user: Principal, +} +#[derive(CandidType, Deserialize)] +pub enum GetMyUserProfileHistoryResponse { + #[serde(rename="ok")] + Ok{ history: Vec }, + #[serde(rename="err")] + Err(Err), +} +#[derive(CandidType, Deserialize)] +pub struct GetProposalReviewRequest { pub proposal_review_id: String } +#[derive(CandidType, Deserialize)] +pub enum GetProposalReviewResponse { + #[serde(rename="ok")] + Ok(ProposalReviewWithId), + #[serde(rename="err")] + Err(Err), +} +#[derive(CandidType, Deserialize)] +pub struct HeaderField (pub String,pub String,); +#[derive(CandidType, Deserialize)] +pub struct HttpRequest { + pub url: String, + pub method: String, + pub body: serde_bytes::ByteBuf, + pub headers: Vec, + pub certificate_version: Option, +} +#[derive(CandidType, Deserialize)] +pub struct HttpResponse { + pub body: serde_bytes::ByteBuf, + pub headers: Vec, + pub status_code: u16, +} +#[derive(CandidType, Deserialize)] +pub enum LogLevel { + #[serde(rename="info")] + Info, + #[serde(rename="warn")] + Warn, + #[serde(rename="error")] + Error, +} +#[derive(CandidType, Deserialize)] +pub struct LogsFilterRequest { + pub context_contains_any: Option>, + pub level: Option, + pub message_contains_any: Option>, + pub after_timestamp_ms: Option, + pub before_timestamp_ms: Option, +} +#[derive(CandidType, Deserialize)] +pub struct LogEntry { + pub context: Option, + pub date_time: String, + pub level: LogLevel, + pub message: String, +} +#[derive(CandidType, Deserialize)] +pub enum ListLogsResponse { + #[serde(rename="ok")] + Ok{ logs: Vec }, + #[serde(rename="err")] + Err(Err), +} +#[derive(CandidType, Deserialize)] +pub struct ListProposalReviewsRequest { + pub user_id: Option, + pub proposal_id: Option, +} +#[derive(CandidType, Deserialize)] +pub enum ListProposalReviewsResponse { + #[serde(rename="ok")] + Ok{ proposal_reviews: Vec }, + #[serde(rename="err")] + Err(Err), +} +#[derive(CandidType, Deserialize)] +pub enum ReviewPeriodStateKey { + #[serde(rename="in_progress")] + InProgress, + #[serde(rename="completed")] + Completed, +} +#[derive(CandidType, Deserialize)] +pub struct ListProposalsRequest { pub state: Option } +#[derive(CandidType, Deserialize)] +pub enum ReviewPeriodState { + #[serde(rename="in_progress")] + InProgress, + #[serde(rename="completed")] + Completed{ completed_at: String }, +} +#[derive(CandidType, Deserialize)] +pub struct NeuronId { pub id: u64 } +#[derive(CandidType, Deserialize)] +pub struct GovernanceError { pub error_message: String, pub error_type: i32 } +#[derive(CandidType, Deserialize)] +pub struct Ballot { pub vote: i32, pub voting_power: u64 } +#[derive(CandidType, Deserialize)] +pub struct CanisterStatusResultV2 { + pub status: Option, + pub freezing_threshold: Option, + pub controllers: Vec, + pub memory_size: Option, + pub cycles: Option, + pub idle_cycles_burned_per_day: Option, + pub module_hash: serde_bytes::ByteBuf, +} +#[derive(CandidType, Deserialize)] +pub struct CanisterSummary { + pub status: Option, + pub canister_id: Option, +} +#[derive(CandidType, Deserialize)] +pub struct SwapBackgroundInformation { + pub ledger_index_canister_summary: Option, + pub fallback_controller_principal_ids: Vec, + pub ledger_archive_canister_summaries: Vec, + pub ledger_canister_summary: Option, + pub swap_canister_summary: Option, + pub governance_canister_summary: Option, + pub root_canister_summary: Option, + pub dapp_canister_summaries: Vec, +} +#[derive(CandidType, Deserialize)] +pub struct DerivedProposalInformation { + pub swap_background_information: Option, +} +#[derive(CandidType, Deserialize)] +pub struct Tally { + pub no: u64, + pub yes: u64, + pub total: u64, + pub timestamp_seconds: u64, +} +#[derive(CandidType, Deserialize)] +pub struct KnownNeuronData { pub name: String, pub description: Option } +#[derive(CandidType, Deserialize)] +pub struct KnownNeuron { + pub id: Option, + pub known_neuron_data: Option, +} +#[derive(CandidType, Deserialize)] +pub struct Spawn { + pub percentage_to_spawn: Option, + pub new_controller: Option, + pub nonce: Option, +} +#[derive(CandidType, Deserialize)] +pub struct Split { pub amount_e8s: u64 } +#[derive(CandidType, Deserialize)] +pub struct Follow { pub topic: i32, pub followees: Vec } +#[derive(CandidType, Deserialize)] +pub struct ClaimOrRefreshNeuronFromAccount { + pub controller: Option, + pub memo: u64, +} +#[derive(CandidType, Deserialize)] +pub enum By { + NeuronIdOrSubaccount{}, + MemoAndController(ClaimOrRefreshNeuronFromAccount), + Memo(u64), +} +#[derive(CandidType, Deserialize)] +pub struct ClaimOrRefresh { pub by: Option } +#[derive(CandidType, Deserialize)] +pub struct RemoveHotKey { pub hot_key_to_remove: Option } +#[derive(CandidType, Deserialize)] +pub struct AddHotKey { pub new_hot_key: Option } +#[derive(CandidType, Deserialize)] +pub struct ChangeAutoStakeMaturity { + pub requested_setting_for_auto_stake_maturity: bool, +} +#[derive(CandidType, Deserialize)] +pub struct IncreaseDissolveDelay { pub additional_dissolve_delay_seconds: u32 } +#[derive(CandidType, Deserialize)] +pub struct SetDissolveTimestamp { pub dissolve_timestamp_seconds: u64 } +#[derive(CandidType, Deserialize)] +pub enum Operation { + RemoveHotKey(RemoveHotKey), + AddHotKey(AddHotKey), + ChangeAutoStakeMaturity(ChangeAutoStakeMaturity), + StopDissolving{}, + StartDissolving{}, + IncreaseDissolveDelay(IncreaseDissolveDelay), + JoinCommunityFund{}, + LeaveCommunityFund{}, + SetDissolveTimestamp(SetDissolveTimestamp), +} +#[derive(CandidType, Deserialize)] +pub struct Configure { pub operation: Option } +#[derive(CandidType, Deserialize)] +pub struct RegisterVote { pub vote: i32, pub proposal: Option } +#[derive(CandidType, Deserialize)] +pub struct Merge { pub source_neuron_id: Option } +#[derive(CandidType, Deserialize)] +pub struct DisburseToNeuron { + pub dissolve_delay_seconds: u64, + pub kyc_verified: bool, + pub amount_e8s: u64, + pub new_controller: Option, + pub nonce: u64, +} +#[derive(CandidType, Deserialize)] +pub struct StakeMaturity { pub percentage_to_stake: Option } +#[derive(CandidType, Deserialize)] +pub struct MergeMaturity { pub percentage_to_merge: u32 } +#[derive(CandidType, Deserialize)] +pub struct AccountIdentifier { pub hash: serde_bytes::ByteBuf } +#[derive(CandidType, Deserialize)] +pub struct Amount { pub e8s: u64 } +#[derive(CandidType, Deserialize)] +pub struct Disburse { + pub to_account: Option, + pub amount: Option, +} +#[derive(CandidType, Deserialize)] +pub enum Command { + Spawn(Spawn), + Split(Split), + Follow(Follow), + ClaimOrRefresh(ClaimOrRefresh), + Configure(Configure), + RegisterVote(RegisterVote), + Merge(Merge), + DisburseToNeuron(DisburseToNeuron), + MakeProposal(Box), + StakeMaturity(StakeMaturity), + MergeMaturity(MergeMaturity), + Disburse(Disburse), +} +#[derive(CandidType, Deserialize)] +pub enum NeuronIdOrSubaccount { + Subaccount(serde_bytes::ByteBuf), + NeuronId(NeuronId), +} +#[derive(CandidType, Deserialize)] +pub struct ManageNeuron { + pub id: Option, + pub command: Option, + pub neuron_id_or_subaccount: Option, +} +#[derive(CandidType, Deserialize)] +pub struct Percentage { pub basis_points: Option } +#[derive(CandidType, Deserialize)] +pub struct Duration { pub seconds: Option } +#[derive(CandidType, Deserialize)] +pub struct Tokens { pub e8s: Option } +#[derive(CandidType, Deserialize)] +pub struct VotingRewardParameters { + pub reward_rate_transition_duration: Option, + pub initial_reward_rate: Option, + pub final_reward_rate: Option, +} +#[derive(CandidType, Deserialize)] +pub struct GovernanceParameters { + pub neuron_maximum_dissolve_delay_bonus: Option, + pub neuron_maximum_age_for_age_bonus: Option, + pub neuron_maximum_dissolve_delay: Option, + pub neuron_minimum_dissolve_delay_to_vote: Option, + pub neuron_maximum_age_bonus: Option, + pub neuron_minimum_stake: Option, + pub proposal_wait_for_quiet_deadline_increase: Option, + pub proposal_initial_voting_period: Option, + pub proposal_rejection_fee: Option, + pub voting_reward_parameters: Option, +} +#[derive(CandidType, Deserialize)] +pub struct Image { pub base64_encoding: Option } +#[derive(CandidType, Deserialize)] +pub struct LedgerParameters { + pub transaction_fee: Option, + pub token_symbol: Option, + pub token_logo: Option, + pub token_name: Option, +} +#[derive(CandidType, Deserialize)] +pub struct Canister { pub id: Option } +#[derive(CandidType, Deserialize)] +pub struct NeuronBasketConstructionParameters { + pub dissolve_delay_interval: Option, + pub count: Option, +} +#[derive(CandidType, Deserialize)] +pub struct GlobalTimeOfDay { pub seconds_after_utc_midnight: Option } +#[derive(CandidType, Deserialize)] +pub struct Countries { pub iso_codes: Vec } +#[derive(CandidType, Deserialize)] +pub struct SwapParameters { + pub minimum_participants: Option, + pub neurons_fund_participation: Option, + pub duration: Option, + pub neuron_basket_construction_parameters: Option< + NeuronBasketConstructionParameters + >, + pub confirmation_text: Option, + pub maximum_participant_icp: Option, + pub minimum_icp: Option, + pub minimum_direct_participation_icp: Option, + pub minimum_participant_icp: Option, + pub start_time: Option, + pub maximum_direct_participation_icp: Option, + pub maximum_icp: Option, + pub neurons_fund_investment_icp: Option, + pub restricted_countries: Option, +} +#[derive(CandidType, Deserialize)] +pub struct SwapDistribution { pub total: Option } +#[derive(CandidType, Deserialize)] +pub struct NeuronDistribution { + pub controller: Option, + pub dissolve_delay: Option, + pub memo: Option, + pub vesting_period: Option, + pub stake: Option, +} +#[derive(CandidType, Deserialize)] +pub struct DeveloperDistribution { + pub developer_neurons: Vec, +} +#[derive(CandidType, Deserialize)] +pub struct InitialTokenDistribution { + pub treasury_distribution: Option, + pub developer_distribution: Option, + pub swap_distribution: Option, +} +#[derive(CandidType, Deserialize)] +pub struct CreateServiceNervousSystem { + pub url: Option, + pub governance_parameters: Option, + pub fallback_controller_principal_ids: Vec, + pub logo: Option, + pub name: Option, + pub ledger_parameters: Option, + pub description: Option, + pub dapp_canisters: Vec, + pub swap_parameters: Option, + pub initial_token_distribution: Option, +} +#[derive(CandidType, Deserialize)] +pub struct ExecuteNnsFunction { + pub nns_function: i32, + pub payload: serde_bytes::ByteBuf, +} +#[derive(CandidType, Deserialize)] +pub struct NodeProvider { + pub id: Option, + pub reward_account: Option, +} +#[derive(CandidType, Deserialize)] +pub struct RewardToNeuron { pub dissolve_delay_seconds: u64 } +#[derive(CandidType, Deserialize)] +pub struct RewardToAccount { pub to_account: Option } +#[derive(CandidType, Deserialize)] +pub enum RewardMode { + RewardToNeuron(RewardToNeuron), + RewardToAccount(RewardToAccount), +} +#[derive(CandidType, Deserialize)] +pub struct RewardNodeProvider { + pub node_provider: Option, + pub reward_mode: Option, + pub amount_e8s: u64, +} +#[derive(CandidType, Deserialize)] +pub struct NeuronBasketConstructionParameters1 { + pub dissolve_delay_interval_seconds: u64, + pub count: u64, +} +#[derive(CandidType, Deserialize)] +pub struct Params { + pub min_participant_icp_e8s: u64, + pub neuron_basket_construction_parameters: Option< + NeuronBasketConstructionParameters1 + >, + pub max_icp_e8s: u64, + pub swap_due_timestamp_seconds: u64, + pub min_participants: u32, + pub sns_token_e8s: u64, + pub sale_delay_seconds: Option, + pub max_participant_icp_e8s: u64, + pub min_direct_participation_icp_e8s: Option, + pub min_icp_e8s: u64, + pub max_direct_participation_icp_e8s: Option, +} +#[derive(CandidType, Deserialize)] +pub struct OpenSnsTokenSwap { + pub community_fund_investment_e8s: Option, + pub target_swap_canister_id: Option, + pub params: Option, +} +#[derive(CandidType, Deserialize)] +pub struct TimeWindow { + pub start_timestamp_seconds: u64, + pub end_timestamp_seconds: u64, +} +#[derive(CandidType, Deserialize)] +pub struct SetOpenTimeWindowRequest { pub open_time_window: Option } +#[derive(CandidType, Deserialize)] +pub struct SetSnsTokenSwapOpenTimeWindow { + pub request: Option, + pub swap_canister_id: Option, +} +#[derive(CandidType, Deserialize)] +pub struct Followees { pub followees: Vec } +#[derive(CandidType, Deserialize)] +pub struct SetDefaultFollowees { pub default_followees: Vec<(i32,Followees,)> } +#[derive(CandidType, Deserialize)] +pub struct RewardNodeProviders { + pub use_registry_derived_rewards: Option, + pub rewards: Vec, +} +#[derive(CandidType, Deserialize)] +pub struct NetworkEconomics { + pub neuron_minimum_stake_e8s: u64, + pub max_proposals_to_keep_per_topic: u32, + pub neuron_management_fee_per_proposal_e8s: u64, + pub reject_cost_e8s: u64, + pub transaction_fee_e8s: u64, + pub neuron_spawn_dissolve_delay_seconds: u64, + pub minimum_icp_xdr_rate: u64, + pub maximum_node_provider_rewards_e8s: u64, +} +#[derive(CandidType, Deserialize)] +pub struct ApproveGenesisKyc { pub principals: Vec } +#[derive(CandidType, Deserialize)] +pub enum Change { ToRemove(NodeProvider), ToAdd(NodeProvider) } +#[derive(CandidType, Deserialize)] +pub struct AddOrRemoveNodeProvider { pub change: Option } +#[derive(CandidType, Deserialize)] +pub struct Motion { pub motion_text: String } +#[derive(CandidType, Deserialize)] +pub enum Action { + RegisterKnownNeuron(KnownNeuron), + ManageNeuron(ManageNeuron), + CreateServiceNervousSystem(CreateServiceNervousSystem), + ExecuteNnsFunction(ExecuteNnsFunction), + RewardNodeProvider(RewardNodeProvider), + OpenSnsTokenSwap(OpenSnsTokenSwap), + SetSnsTokenSwapOpenTimeWindow(SetSnsTokenSwapOpenTimeWindow), + SetDefaultFollowees(SetDefaultFollowees), + RewardNodeProviders(RewardNodeProviders), + ManageNetworkEconomics(NetworkEconomics), + ApproveGenesisKyc(ApproveGenesisKyc), + AddOrRemoveNodeProvider(AddOrRemoveNodeProvider), + Motion(Motion), +} +#[derive(CandidType, Deserialize)] +pub struct Proposal { + pub url: String, + pub title: Option, + pub action: Option, + pub summary: String, +} +#[derive(CandidType, Deserialize)] +pub struct ProposalInfo { + pub id: Option, + pub status: i32, + pub topic: i32, + pub failure_reason: Option, + pub ballots: Vec<(u64,Ballot,)>, + pub proposal_timestamp_seconds: u64, + pub reward_event_round: u64, + pub deadline_timestamp_seconds: Option, + pub failed_timestamp_seconds: u64, + pub reject_cost_e8s: u64, + pub derived_proposal_information: Option, + pub latest_tally: Option, + pub reward_status: i32, + pub decided_timestamp_seconds: u64, + pub proposal: Option>, + pub proposer: Option, + pub executed_timestamp_seconds: u64, +} +#[derive(CandidType, Deserialize)] +pub enum NervousSystem { + #[serde(rename="network")] + Network{ id: u64, proposal_info: ProposalInfo }, +} +#[derive(CandidType, Deserialize)] +pub struct BackendProposal { + pub state: ReviewPeriodState, + pub synced_at: String, + pub nervous_system: NervousSystem, + pub proposed_at: String, +} +#[derive(CandidType, Deserialize)] +pub struct ProposalResponse { pub id: String, pub proposal: BackendProposal } +#[derive(CandidType, Deserialize)] +pub enum ListProposalsResponse { + #[serde(rename="ok")] + Ok{ proposals: Vec }, + #[serde(rename="err")] + Err(Err), +} +#[derive(CandidType, Deserialize)] +pub enum SyncProposalsResponse { + #[serde(rename="ok")] + Ok{ synced_proposals_count: u64, completed_proposals_count: u64 }, + #[serde(rename="err")] + Err(Err), +} +#[derive(CandidType, Deserialize)] +pub enum MyUserConfigUpdate { + #[serde(rename="admin")] + Admin{ bio: Option }, + #[serde(rename="anonymous")] + Anonymous, + #[serde(rename="reviewer")] + Reviewer{ + bio: Option, + wallet_address: Option, + social_links: Option>, + }, +} +#[derive(CandidType, Deserialize)] +pub struct UpdateMyUserProfileRequest { + pub username: Option, + pub config: Option, +} +#[derive(CandidType, Deserialize)] +pub enum UpdateMyUserProfileResponse { + #[serde(rename="ok")] + Ok, + #[serde(rename="err")] + Err(Err), +} +#[derive(CandidType, Deserialize)] +pub struct UpdateProposalReviewRequest { + pub status: Option, + pub review_duration_mins: Option, + pub summary: Option, + pub proposal_id: String, + pub build_reproduced: Option, +} +#[derive(CandidType, Deserialize)] +pub enum UpdateProposalReviewResponse { + #[serde(rename="ok")] + Ok, + #[serde(rename="err")] + Err(Err), +} +#[derive(CandidType, Deserialize)] +pub struct UpdateProposalReviewCommitRequest { + pub id: String, + pub state: ReviewCommitState, +} +#[derive(CandidType, Deserialize)] +pub enum UpdateProposalReviewCommitResponse { + #[serde(rename="ok")] + Ok, + #[serde(rename="err")] + Err(Err), +} +#[derive(CandidType, Deserialize)] +pub enum UserConfigUpdate { + #[serde(rename="admin")] + Admin{ bio: Option }, + #[serde(rename="anonymous")] + Anonymous, + #[serde(rename="reviewer")] + Reviewer{ + bio: Option, + wallet_address: Option, + social_links: Option>, + neuron_id: Option, + }, +} +#[derive(CandidType, Deserialize)] +pub struct UpdateUserProfileRequest { + pub username: Option, + pub user_id: String, + pub config: Option, +} +#[derive(CandidType, Deserialize)] +pub enum UpdateUserProfileResponse { + #[serde(rename="ok")] + Ok, + #[serde(rename="err")] + Err(Err), +} + +pub struct Service(pub Principal); +impl Service { + pub async fn create_my_user_profile(&self) -> Result<(CreateMyUserProfileResponse,)> { + ic_cdk::call(self.0, "create_my_user_profile", ()).await + } + pub async fn create_proposal_review(&self, arg0: CreateProposalReviewRequest) -> Result<(CreateProposalReviewResponse,)> { + ic_cdk::call(self.0, "create_proposal_review", (arg0,)).await + } + pub async fn create_proposal_review_commit(&self, arg0: CreateProposalReviewCommitRequest) -> Result<(CreateProposalReviewCommitResponse,)> { + ic_cdk::call(self.0, "create_proposal_review_commit", (arg0,)).await + } + pub async fn create_proposal_review_image(&self, arg0: CreateProposalReviewImageRequest) -> Result<(CreateProposalReviewImageResponse,)> { + ic_cdk::call(self.0, "create_proposal_review_image", (arg0,)).await + } + pub async fn delete_proposal_review_commit(&self, arg0: DeleteProposalReviewCommitRequest) -> Result<(DeleteProposalReviewCommitResponse,)> { + ic_cdk::call(self.0, "delete_proposal_review_commit", (arg0,)).await + } + pub async fn delete_proposal_review_image(&self, arg0: DeleteProposalReviewImageRequest) -> Result<(DeleteProposalReviewImageResponse,)> { + ic_cdk::call(self.0, "delete_proposal_review_image", (arg0,)).await + } + pub async fn get_my_proposal_review(&self, arg0: GetMyProposalReviewRequest) -> Result<(GetMyProposalReviewResponse,)> { + ic_cdk::call(self.0, "get_my_proposal_review", (arg0,)).await + } + pub async fn get_my_user_profile(&self) -> Result<(GetMyUserProfileResponse,)> { + ic_cdk::call(self.0, "get_my_user_profile", ()).await + } + pub async fn get_my_user_profile_history(&self) -> Result<(GetMyUserProfileHistoryResponse,)> { + ic_cdk::call(self.0, "get_my_user_profile_history", ()).await + } + pub async fn get_proposal_review(&self, arg0: GetProposalReviewRequest) -> Result<(GetProposalReviewResponse,)> { + ic_cdk::call(self.0, "get_proposal_review", (arg0,)).await + } + pub async fn http_request(&self, arg0: HttpRequest) -> Result<(HttpResponse,)> { + ic_cdk::call(self.0, "http_request", (arg0,)).await + } + pub async fn list_logs(&self, arg0: LogsFilterRequest) -> Result<(ListLogsResponse,)> { + ic_cdk::call(self.0, "list_logs", (arg0,)).await + } + pub async fn list_proposal_reviews(&self, arg0: ListProposalReviewsRequest) -> Result<(ListProposalReviewsResponse,)> { + ic_cdk::call(self.0, "list_proposal_reviews", (arg0,)).await + } + pub async fn list_proposals(&self, arg0: ListProposalsRequest) -> Result<(ListProposalsResponse,)> { + ic_cdk::call(self.0, "list_proposals", (arg0,)).await + } + pub async fn sync_proposals(&self) -> Result<(SyncProposalsResponse,)> { + ic_cdk::call(self.0, "sync_proposals", ()).await + } + pub async fn update_my_user_profile(&self, arg0: UpdateMyUserProfileRequest) -> Result<(UpdateMyUserProfileResponse,)> { + ic_cdk::call(self.0, "update_my_user_profile", (arg0,)).await + } + pub async fn update_proposal_review(&self, arg0: UpdateProposalReviewRequest) -> Result<(UpdateProposalReviewResponse,)> { + ic_cdk::call(self.0, "update_proposal_review", (arg0,)).await + } + pub async fn update_proposal_review_commit(&self, arg0: UpdateProposalReviewCommitRequest) -> Result<(UpdateProposalReviewCommitResponse,)> { + ic_cdk::call(self.0, "update_proposal_review_commit", (arg0,)).await + } + pub async fn update_user_profile(&self, arg0: UpdateUserProfileRequest) -> Result<(UpdateUserProfileResponse,)> { + ic_cdk::call(self.0, "update_user_profile", (arg0,)).await + } +} + diff --git a/src/backend/logs/src/main.rs b/src/backend/logs/src/main.rs new file mode 100644 index 00000000..8f0d0a86 --- /dev/null +++ b/src/backend/logs/src/main.rs @@ -0,0 +1,168 @@ +use base64::{engine::general_purpose::STANDARD as BASE64, Engine}; +use candid::Principal; +use clap::Parser; +use opentelemetry::logs::{AnyValue, Logger as _, LoggerProvider as _, Severity}; +use opentelemetry_otlp::WithExportConfig; +use opentelemetry_sdk::logs::{Logger, LoggerProvider}; +use std::collections::HashMap; +use std::{ + fs::{File, OpenOptions}, + io::{Read, Write}, + path::PathBuf, + time::{SystemTime, UNIX_EPOCH}, +}; + +mod actor; +mod backend; + +use actor::BackendActor; +use backend::{ListLogsResponse, LogEntry, LogLevel}; + +fn now() -> SystemTime { + SystemTime::now() +} + +fn now_timestamp_ms() -> u64 { + now().duration_since(UNIX_EPOCH).unwrap().as_millis() as u64 +} + +fn loki_headers(username: String, password: String) -> HashMap { + let mut headers = HashMap::new(); + let auth_header = format!( + "Basic {}", + BASE64.encode(format!("{}:{}", username, password)) + ); + headers.insert("Authorization".to_string(), auth_header.parse().unwrap()); + headers +} + +fn init_telemetry( + endpoint: String, + username: String, + password: String, +) -> anyhow::Result { + let headers = loki_headers(username, password); + let exporter = opentelemetry_otlp::new_exporter() + .http() + .with_endpoint(endpoint) + .with_headers(headers) + .build_log_exporter()?; + + let logger_provider = LoggerProvider::builder() + .with_simple_exporter(exporter) + .build(); + + Ok(logger_provider) +} + +fn build_logger(provider: &LoggerProvider) -> Logger { + provider.logger_builder("backend_canister_logger").build() +} + +struct LogFetcher { + last_fetch_timestamp: Option, + file: File, + actor: BackendActor, +} + +impl LogFetcher { + fn new(identity_pem: PathBuf, backend_canister_id: String) -> anyhow::Result { + let path = "last_fetch_timestamp.txt"; + let mut file = OpenOptions::new() + .create(true) + .read(true) + .write(true) + .open(path)?; + let mut last_fetch_timestamp = String::new(); + file.read_to_string(&mut last_fetch_timestamp)?; + + let actor = BackendActor::new(identity_pem, Principal::from_text(&backend_canister_id)?)?; + + Ok(Self { + file, + last_fetch_timestamp: last_fetch_timestamp.trim().parse().ok(), + actor, + }) + } + + async fn fetch_logs(&mut self) -> anyhow::Result> { + let logs = self.actor.list_logs(self.last_fetch_timestamp).await?; + let now = now_timestamp_ms(); + self.update_last_fetch_timestamp(now); + match logs { + ListLogsResponse::Ok { logs } => Ok(logs), + ListLogsResponse::Err(err) => Err(anyhow::anyhow!(err.message)), + } + } + + fn update_last_fetch_timestamp(&mut self, timestamp: u64) { + self.last_fetch_timestamp = Some(timestamp); + self.file.set_len(0).unwrap(); + self.file + .write_all(timestamp.to_string().as_bytes()) + .unwrap(); + self.file.flush().unwrap(); + } +} + +#[derive(Parser, Debug)] +#[command(author, version, about, long_about = None)] +struct Args { + /// Path to the identity PEM file + #[arg(long, value_name = "FILE")] + identity_pem: PathBuf, + + /// Loki endpoint URL + #[arg(long, value_name = "URL")] + loki_endpoint: String, + + /// Loki username + #[arg(long)] + loki_username: String, + + /// Loki password + #[arg(long)] + loki_password: String, + + /// Backend canister ID + #[arg(long, value_name = "CANISTER_ID")] + backend_canister_id: String, +} + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + let args = Args::parse(); + + // we need to keep the logger provider in memory because the drop implementation shuts down the processors + let logger_provider = + init_telemetry(args.loki_endpoint, args.loki_username, args.loki_password)?; + let logger = build_logger(&logger_provider); + + let mut log_fetcher = LogFetcher::new(args.identity_pem, args.backend_canister_id)?; + let logs = log_fetcher.fetch_logs().await?; + + println!("Sending {} logs to Loki...", logs.len()); + + for log in logs { + let mut log_record = logger.create_log_record(); + log_record.timestamp = Some(chrono::DateTime::parse_from_rfc3339(&log.date_time)?.into()); + log_record.observed_timestamp = Some(now()); + log_record.severity_number = Some(match log.level { + LogLevel::Info => Severity::Info, + LogLevel::Warn => Severity::Warn, + LogLevel::Error => Severity::Error, + }); + let mut body = HashMap::new(); + body.insert("message".into(), log.message.into()); + if let Some(context) = log.context { + body.insert("context".into(), context.into()); + } + log_record.body = Some(AnyValue::Map(Box::new(body))); + + logger.emit(log_record); + } + + println!("Logs sent to Loki"); + + Ok(()) +} From e12e1e451dcb3083b623eec15b709ccb1de3cab7 Mon Sep 17 00:00:00 2001 From: ilbertt Date: Sat, 19 Oct 2024 20:24:53 +0200 Subject: [PATCH 2/6] fix: overwrite last timestamp file content properly --- src/backend/logs/src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/backend/logs/src/main.rs b/src/backend/logs/src/main.rs index 8f0d0a86..5a479e9a 100644 --- a/src/backend/logs/src/main.rs +++ b/src/backend/logs/src/main.rs @@ -7,7 +7,7 @@ use opentelemetry_sdk::logs::{Logger, LoggerProvider}; use std::collections::HashMap; use std::{ fs::{File, OpenOptions}, - io::{Read, Write}, + io::{Read, Seek, Write}, path::PathBuf, time::{SystemTime, UNIX_EPOCH}, }; @@ -67,7 +67,7 @@ struct LogFetcher { impl LogFetcher { fn new(identity_pem: PathBuf, backend_canister_id: String) -> anyhow::Result { - let path = "last_fetch_timestamp.txt"; + let path = "data/last-fetch-timestamp.txt"; let mut file = OpenOptions::new() .create(true) .read(true) @@ -98,10 +98,10 @@ impl LogFetcher { fn update_last_fetch_timestamp(&mut self, timestamp: u64) { self.last_fetch_timestamp = Some(timestamp); self.file.set_len(0).unwrap(); + self.file.rewind().unwrap(); self.file .write_all(timestamp.to_string().as_bytes()) .unwrap(); - self.file.flush().unwrap(); } } From e678162246d4ba63814d1963e740b1f8f43f9481 Mon Sep 17 00:00:00 2001 From: ilbertt Date: Sat, 19 Oct 2024 21:26:24 +0200 Subject: [PATCH 3/6] refactor: use backend_api crate and reorganize code --- Cargo.lock | 8 + Cargo.toml | 1 + scripts/scrape-logs.sh | 10 +- src/backend/impl/Cargo.toml | 2 +- src/backend/logs/Cargo.toml | 11 +- src/backend/logs/src/actor.rs | 42 -- src/backend/logs/src/backend.rs | 842 -------------------------------- src/backend/logs/src/fetcher.rs | 94 ++++ src/backend/logs/src/main.rs | 160 +++--- src/backend/logs/src/utils.rs | 9 + 10 files changed, 188 insertions(+), 991 deletions(-) delete mode 100644 src/backend/logs/src/actor.rs delete mode 100644 src/backend/logs/src/backend.rs create mode 100644 src/backend/logs/src/fetcher.rs create mode 100644 src/backend/logs/src/utils.rs diff --git a/Cargo.lock b/Cargo.lock index ff9126c9..fdae3838 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -429,6 +429,7 @@ name = "backend_logs" version = "0.1.0" dependencies = [ "anyhow", + "backend_api", "base64 0.22.0", "candid", "chrono", @@ -437,6 +438,7 @@ dependencies = [ "ic-cdk", "opentelemetry", "opentelemetry-otlp", + "opentelemetry-semantic-conventions", "opentelemetry_sdk", "serde", "serde_bytes", @@ -4212,6 +4214,12 @@ dependencies = [ "tonic", ] +[[package]] +name = "opentelemetry-semantic-conventions" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db945c1eaea8ac6a9677185357480d215bb6999faa9f691d0c4d4d641eab7a09" + [[package]] name = "opentelemetry_sdk" version = "0.26.0" diff --git a/Cargo.toml b/Cargo.toml index 7a607694..ec17faaf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,6 +27,7 @@ serde = "1.0" uuid = "1.6" serde_bytes = "0.11" chrono = { version = "0.4", default-features = false, features = ["std"] } +base64 = "0.22" mockall = "0.12" rstest = "0.18" diff --git a/scripts/scrape-logs.sh b/scripts/scrape-logs.sh index d55c2609..5c58403e 100755 --- a/scripts/scrape-logs.sh +++ b/scripts/scrape-logs.sh @@ -1,3 +1,11 @@ #!/bin/bash -cargo run --package backend_logs --bin backend_logs -- --identity-pem data/codegov-website-logger-identity.pem --loki-endpoint https://logs-prod-eu-west-0.grafana.net/loki/api/v1/push --loki-username 152321 --loki-password $LOKI_PASSWORD --backend-canister-id nijcm-2qaaa-aaaal-qcx2a-cai +cargo run \ + --package backend_logs \ + --bin backend_logs \ + -- \ + --identity-pem data/codegov-website-logger-identity.pem \ + --loki-endpoint https://logs-prod-eu-west-0.grafana.net \ + --loki-username 152321 \ + --loki-password $LOKI_PASSWORD \ + --backend-canister-id nijcm-2qaaa-aaaal-qcx2a-cai diff --git a/src/backend/impl/Cargo.toml b/src/backend/impl/Cargo.toml index c88c4930..6e7db6a2 100644 --- a/src/backend/impl/Cargo.toml +++ b/src/backend/impl/Cargo.toml @@ -32,7 +32,7 @@ uuid = { workspace = true, features = ["serde"] } chrono.workspace = true hex = "0.4" lazy_static = "1.4" -base64 = "0.22" +base64.workspace = true rand = { version = "0.8", default-features = false } rand_chacha = { version = "0.3", default-features = false } diff --git a/src/backend/logs/Cargo.toml b/src/backend/logs/Cargo.toml index 8369931c..a6353e05 100644 --- a/src/backend/logs/Cargo.toml +++ b/src/backend/logs/Cargo.toml @@ -8,6 +8,8 @@ name = "backend_logs" path = "src/main.rs" [dependencies] +backend_api = { path = "../api" } + ic-cdk.workspace = true ic-agent = "0.39" @@ -18,12 +20,13 @@ serde_bytes.workspace = true clap = { version = "4.5", features = ["derive"] } opentelemetry = "0.26" opentelemetry-otlp = { version = "0.26", features = [ - "logs", - "http-json", - "reqwest-client", + "logs", + "http-json", + "reqwest-client", ], default-features = false } opentelemetry_sdk = { version = "0.26", features = ["logs", "rt-tokio"] } +opentelemetry-semantic-conventions = "0.26" tokio = { version = "1.40", features = ["full"] } anyhow = "1.0" -base64 = "0.22" +base64.workspace = true chrono.workspace = true diff --git a/src/backend/logs/src/actor.rs b/src/backend/logs/src/actor.rs deleted file mode 100644 index 4a15ddb5..00000000 --- a/src/backend/logs/src/actor.rs +++ /dev/null @@ -1,42 +0,0 @@ -use std::path::PathBuf; - -use candid::{Decode, Encode, Principal}; -use ic_agent::{identity::Secp256k1Identity, Agent}; - -use crate::backend::{ListLogsResponse, LogsFilterRequest}; - -pub struct BackendActor { - agent: Agent, - canister_id: Principal, -} - -impl BackendActor { - pub fn new(identity_pem: PathBuf, canister_id: Principal) -> anyhow::Result { - let identity = Secp256k1Identity::from_pem_file(identity_pem)?; - let agent = Agent::builder() - .with_identity(identity) - .with_url("https://icp-api.io") - .build()?; - Ok(Self { agent, canister_id }) - } - - pub async fn list_logs( - &self, - after_timestamp_ms: Option, - ) -> Result { - let request = LogsFilterRequest { - after_timestamp_ms, - before_timestamp_ms: None, - context_contains_any: None, - level: None, - message_contains_any: None, - }; - let response = self - .agent - .query(&self.canister_id, "list_logs") - .with_arg(Encode!(&request)?) - .await?; - let result = Decode!(&response, ListLogsResponse)?; - Ok(result) - } -} diff --git a/src/backend/logs/src/backend.rs b/src/backend/logs/src/backend.rs deleted file mode 100644 index 005b4dc1..00000000 --- a/src/backend/logs/src/backend.rs +++ /dev/null @@ -1,842 +0,0 @@ -// This is an experimental feature to generate Rust binding from Candid. -// You may want to manually adjust some of the types. -#![allow(dead_code, unused_imports)] -use candid::{self, CandidType, Deserialize, Principal}; -use ic_cdk::api::call::CallResult as Result; - -#[derive(CandidType, Deserialize)] -pub enum SocialLinkPlatform { - #[serde(rename="x")] - X, - #[serde(rename="taggr")] - Taggr, - #[serde(rename="dfinityforum")] - Dfinityforum, - #[serde(rename="website")] - Website, - #[serde(rename="discord")] - Discord, - #[serde(rename="dscvr")] - Dscvr, - #[serde(rename="github")] - Github, - #[serde(rename="openchat")] - Openchat, -} -#[derive(CandidType, Deserialize)] -pub struct SocialLink { pub username: String, pub platform: SocialLinkPlatform } -#[derive(CandidType, Deserialize)] -pub enum UserConfig { - #[serde(rename="admin")] - Admin{ bio: String }, - #[serde(rename="anonymous")] - Anonymous, - #[serde(rename="reviewer")] - Reviewer{ - bio: String, - wallet_address: String, - social_links: Vec, - neuron_id: u64, - }, -} -#[derive(CandidType, Deserialize)] -pub struct Err { pub code: u16, pub message: String } -#[derive(CandidType, Deserialize)] -pub enum CreateMyUserProfileResponse { - #[serde(rename="ok")] - Ok{ id: String, username: String, config: UserConfig }, - #[serde(rename="err")] - Err(Err), -} -#[derive(CandidType, Deserialize)] -pub struct CreateProposalReviewRequest { - pub review_duration_mins: Option, - pub summary: Option, - pub proposal_id: String, - pub build_reproduced: Option, -} -#[derive(CandidType, Deserialize)] -pub enum ProposalReviewStatus { - #[serde(rename="published")] - Published, - #[serde(rename="draft")] - Draft, -} -#[derive(CandidType, Deserialize)] -pub enum ReviewCommitState { - #[serde(rename="not_reviewed")] - NotReviewed, - #[serde(rename="reviewed")] - Reviewed{ - highlights: Vec, - comment: Option, - matches_description: Option, - }, -} -#[derive(CandidType, Deserialize)] -pub struct ProposalReviewCommit { - pub proposal_review_id: String, - pub created_at: String, - pub user_id: String, - pub state: ReviewCommitState, - pub last_updated_at: Option, - pub commit_sha: String, -} -#[derive(CandidType, Deserialize)] -pub struct ProposalReviewCommitWithId { - pub id: String, - pub proposal_review_commit: ProposalReviewCommit, -} -#[derive(CandidType, Deserialize)] -pub struct ProposalReview { - pub status: ProposalReviewStatus, - pub proposal_review_commits: Vec, - pub created_at: String, - pub user_id: String, - pub review_duration_mins: Option, - pub summary: Option, - pub images_paths: Vec, - pub last_updated_at: Option, - pub proposal_id: String, - pub build_reproduced: Option, -} -#[derive(CandidType, Deserialize)] -pub struct ProposalReviewWithId { - pub id: String, - pub proposal_review: ProposalReview, -} -#[derive(CandidType, Deserialize)] -pub enum CreateProposalReviewResponse { - #[serde(rename="ok")] - Ok(ProposalReviewWithId), - #[serde(rename="err")] - Err(Err), -} -#[derive(CandidType, Deserialize)] -pub struct CreateProposalReviewCommitRequest { - pub proposal_review_id: String, - pub state: ReviewCommitState, - pub commit_sha: String, -} -#[derive(CandidType, Deserialize)] -pub enum CreateProposalReviewCommitResponse { - #[serde(rename="ok")] - Ok(ProposalReviewCommitWithId), - #[serde(rename="err")] - Err(Err), -} -#[derive(CandidType, Deserialize)] -pub struct CreateProposalReviewImageRequest { - pub content_type: String, - pub content_bytes: serde_bytes::ByteBuf, - pub proposal_id: String, -} -#[derive(CandidType, Deserialize)] -pub enum CreateProposalReviewImageResponse { - #[serde(rename="ok")] - Ok{ path: String }, - #[serde(rename="err")] - Err(Err), -} -#[derive(CandidType, Deserialize)] -pub struct DeleteProposalReviewCommitRequest { pub id: String } -#[derive(CandidType, Deserialize)] -pub enum DeleteProposalReviewCommitResponse { - #[serde(rename="ok")] - Ok, - #[serde(rename="err")] - Err(Err), -} -#[derive(CandidType, Deserialize)] -pub struct DeleteProposalReviewImageRequest { - pub image_path: String, - pub proposal_id: String, -} -#[derive(CandidType, Deserialize)] -pub enum DeleteProposalReviewImageResponse { - #[serde(rename="ok")] - Ok, - #[serde(rename="err")] - Err(Err), -} -#[derive(CandidType, Deserialize)] -pub struct GetMyProposalReviewRequest { pub proposal_id: String } -#[derive(CandidType, Deserialize)] -pub enum GetMyProposalReviewResponse { - #[serde(rename="ok")] - Ok(ProposalReviewWithId), - #[serde(rename="err")] - Err(Err), -} -#[derive(CandidType, Deserialize)] -pub enum GetMyUserProfileResponse { - #[serde(rename="ok")] - Ok{ id: String, username: String, config: UserConfig }, - #[serde(rename="err")] - Err(Err), -} -#[derive(CandidType, Deserialize)] -pub enum HistoryAction { - #[serde(rename="restore")] - Restore, - #[serde(rename="delete")] - Delete, - #[serde(rename="create")] - Create, - #[serde(rename="update")] - Update, -} -#[derive(CandidType, Deserialize)] -pub struct UserProfileHistoryEntry { - pub username: String, - pub config: UserConfig, -} -#[derive(CandidType, Deserialize)] -pub struct GetMyUserProfileHistoryResponseOkHistoryItem { - pub action: HistoryAction, - pub data: UserProfileHistoryEntry, - pub date_time: String, - pub user: Principal, -} -#[derive(CandidType, Deserialize)] -pub enum GetMyUserProfileHistoryResponse { - #[serde(rename="ok")] - Ok{ history: Vec }, - #[serde(rename="err")] - Err(Err), -} -#[derive(CandidType, Deserialize)] -pub struct GetProposalReviewRequest { pub proposal_review_id: String } -#[derive(CandidType, Deserialize)] -pub enum GetProposalReviewResponse { - #[serde(rename="ok")] - Ok(ProposalReviewWithId), - #[serde(rename="err")] - Err(Err), -} -#[derive(CandidType, Deserialize)] -pub struct HeaderField (pub String,pub String,); -#[derive(CandidType, Deserialize)] -pub struct HttpRequest { - pub url: String, - pub method: String, - pub body: serde_bytes::ByteBuf, - pub headers: Vec, - pub certificate_version: Option, -} -#[derive(CandidType, Deserialize)] -pub struct HttpResponse { - pub body: serde_bytes::ByteBuf, - pub headers: Vec, - pub status_code: u16, -} -#[derive(CandidType, Deserialize)] -pub enum LogLevel { - #[serde(rename="info")] - Info, - #[serde(rename="warn")] - Warn, - #[serde(rename="error")] - Error, -} -#[derive(CandidType, Deserialize)] -pub struct LogsFilterRequest { - pub context_contains_any: Option>, - pub level: Option, - pub message_contains_any: Option>, - pub after_timestamp_ms: Option, - pub before_timestamp_ms: Option, -} -#[derive(CandidType, Deserialize)] -pub struct LogEntry { - pub context: Option, - pub date_time: String, - pub level: LogLevel, - pub message: String, -} -#[derive(CandidType, Deserialize)] -pub enum ListLogsResponse { - #[serde(rename="ok")] - Ok{ logs: Vec }, - #[serde(rename="err")] - Err(Err), -} -#[derive(CandidType, Deserialize)] -pub struct ListProposalReviewsRequest { - pub user_id: Option, - pub proposal_id: Option, -} -#[derive(CandidType, Deserialize)] -pub enum ListProposalReviewsResponse { - #[serde(rename="ok")] - Ok{ proposal_reviews: Vec }, - #[serde(rename="err")] - Err(Err), -} -#[derive(CandidType, Deserialize)] -pub enum ReviewPeriodStateKey { - #[serde(rename="in_progress")] - InProgress, - #[serde(rename="completed")] - Completed, -} -#[derive(CandidType, Deserialize)] -pub struct ListProposalsRequest { pub state: Option } -#[derive(CandidType, Deserialize)] -pub enum ReviewPeriodState { - #[serde(rename="in_progress")] - InProgress, - #[serde(rename="completed")] - Completed{ completed_at: String }, -} -#[derive(CandidType, Deserialize)] -pub struct NeuronId { pub id: u64 } -#[derive(CandidType, Deserialize)] -pub struct GovernanceError { pub error_message: String, pub error_type: i32 } -#[derive(CandidType, Deserialize)] -pub struct Ballot { pub vote: i32, pub voting_power: u64 } -#[derive(CandidType, Deserialize)] -pub struct CanisterStatusResultV2 { - pub status: Option, - pub freezing_threshold: Option, - pub controllers: Vec, - pub memory_size: Option, - pub cycles: Option, - pub idle_cycles_burned_per_day: Option, - pub module_hash: serde_bytes::ByteBuf, -} -#[derive(CandidType, Deserialize)] -pub struct CanisterSummary { - pub status: Option, - pub canister_id: Option, -} -#[derive(CandidType, Deserialize)] -pub struct SwapBackgroundInformation { - pub ledger_index_canister_summary: Option, - pub fallback_controller_principal_ids: Vec, - pub ledger_archive_canister_summaries: Vec, - pub ledger_canister_summary: Option, - pub swap_canister_summary: Option, - pub governance_canister_summary: Option, - pub root_canister_summary: Option, - pub dapp_canister_summaries: Vec, -} -#[derive(CandidType, Deserialize)] -pub struct DerivedProposalInformation { - pub swap_background_information: Option, -} -#[derive(CandidType, Deserialize)] -pub struct Tally { - pub no: u64, - pub yes: u64, - pub total: u64, - pub timestamp_seconds: u64, -} -#[derive(CandidType, Deserialize)] -pub struct KnownNeuronData { pub name: String, pub description: Option } -#[derive(CandidType, Deserialize)] -pub struct KnownNeuron { - pub id: Option, - pub known_neuron_data: Option, -} -#[derive(CandidType, Deserialize)] -pub struct Spawn { - pub percentage_to_spawn: Option, - pub new_controller: Option, - pub nonce: Option, -} -#[derive(CandidType, Deserialize)] -pub struct Split { pub amount_e8s: u64 } -#[derive(CandidType, Deserialize)] -pub struct Follow { pub topic: i32, pub followees: Vec } -#[derive(CandidType, Deserialize)] -pub struct ClaimOrRefreshNeuronFromAccount { - pub controller: Option, - pub memo: u64, -} -#[derive(CandidType, Deserialize)] -pub enum By { - NeuronIdOrSubaccount{}, - MemoAndController(ClaimOrRefreshNeuronFromAccount), - Memo(u64), -} -#[derive(CandidType, Deserialize)] -pub struct ClaimOrRefresh { pub by: Option } -#[derive(CandidType, Deserialize)] -pub struct RemoveHotKey { pub hot_key_to_remove: Option } -#[derive(CandidType, Deserialize)] -pub struct AddHotKey { pub new_hot_key: Option } -#[derive(CandidType, Deserialize)] -pub struct ChangeAutoStakeMaturity { - pub requested_setting_for_auto_stake_maturity: bool, -} -#[derive(CandidType, Deserialize)] -pub struct IncreaseDissolveDelay { pub additional_dissolve_delay_seconds: u32 } -#[derive(CandidType, Deserialize)] -pub struct SetDissolveTimestamp { pub dissolve_timestamp_seconds: u64 } -#[derive(CandidType, Deserialize)] -pub enum Operation { - RemoveHotKey(RemoveHotKey), - AddHotKey(AddHotKey), - ChangeAutoStakeMaturity(ChangeAutoStakeMaturity), - StopDissolving{}, - StartDissolving{}, - IncreaseDissolveDelay(IncreaseDissolveDelay), - JoinCommunityFund{}, - LeaveCommunityFund{}, - SetDissolveTimestamp(SetDissolveTimestamp), -} -#[derive(CandidType, Deserialize)] -pub struct Configure { pub operation: Option } -#[derive(CandidType, Deserialize)] -pub struct RegisterVote { pub vote: i32, pub proposal: Option } -#[derive(CandidType, Deserialize)] -pub struct Merge { pub source_neuron_id: Option } -#[derive(CandidType, Deserialize)] -pub struct DisburseToNeuron { - pub dissolve_delay_seconds: u64, - pub kyc_verified: bool, - pub amount_e8s: u64, - pub new_controller: Option, - pub nonce: u64, -} -#[derive(CandidType, Deserialize)] -pub struct StakeMaturity { pub percentage_to_stake: Option } -#[derive(CandidType, Deserialize)] -pub struct MergeMaturity { pub percentage_to_merge: u32 } -#[derive(CandidType, Deserialize)] -pub struct AccountIdentifier { pub hash: serde_bytes::ByteBuf } -#[derive(CandidType, Deserialize)] -pub struct Amount { pub e8s: u64 } -#[derive(CandidType, Deserialize)] -pub struct Disburse { - pub to_account: Option, - pub amount: Option, -} -#[derive(CandidType, Deserialize)] -pub enum Command { - Spawn(Spawn), - Split(Split), - Follow(Follow), - ClaimOrRefresh(ClaimOrRefresh), - Configure(Configure), - RegisterVote(RegisterVote), - Merge(Merge), - DisburseToNeuron(DisburseToNeuron), - MakeProposal(Box), - StakeMaturity(StakeMaturity), - MergeMaturity(MergeMaturity), - Disburse(Disburse), -} -#[derive(CandidType, Deserialize)] -pub enum NeuronIdOrSubaccount { - Subaccount(serde_bytes::ByteBuf), - NeuronId(NeuronId), -} -#[derive(CandidType, Deserialize)] -pub struct ManageNeuron { - pub id: Option, - pub command: Option, - pub neuron_id_or_subaccount: Option, -} -#[derive(CandidType, Deserialize)] -pub struct Percentage { pub basis_points: Option } -#[derive(CandidType, Deserialize)] -pub struct Duration { pub seconds: Option } -#[derive(CandidType, Deserialize)] -pub struct Tokens { pub e8s: Option } -#[derive(CandidType, Deserialize)] -pub struct VotingRewardParameters { - pub reward_rate_transition_duration: Option, - pub initial_reward_rate: Option, - pub final_reward_rate: Option, -} -#[derive(CandidType, Deserialize)] -pub struct GovernanceParameters { - pub neuron_maximum_dissolve_delay_bonus: Option, - pub neuron_maximum_age_for_age_bonus: Option, - pub neuron_maximum_dissolve_delay: Option, - pub neuron_minimum_dissolve_delay_to_vote: Option, - pub neuron_maximum_age_bonus: Option, - pub neuron_minimum_stake: Option, - pub proposal_wait_for_quiet_deadline_increase: Option, - pub proposal_initial_voting_period: Option, - pub proposal_rejection_fee: Option, - pub voting_reward_parameters: Option, -} -#[derive(CandidType, Deserialize)] -pub struct Image { pub base64_encoding: Option } -#[derive(CandidType, Deserialize)] -pub struct LedgerParameters { - pub transaction_fee: Option, - pub token_symbol: Option, - pub token_logo: Option, - pub token_name: Option, -} -#[derive(CandidType, Deserialize)] -pub struct Canister { pub id: Option } -#[derive(CandidType, Deserialize)] -pub struct NeuronBasketConstructionParameters { - pub dissolve_delay_interval: Option, - pub count: Option, -} -#[derive(CandidType, Deserialize)] -pub struct GlobalTimeOfDay { pub seconds_after_utc_midnight: Option } -#[derive(CandidType, Deserialize)] -pub struct Countries { pub iso_codes: Vec } -#[derive(CandidType, Deserialize)] -pub struct SwapParameters { - pub minimum_participants: Option, - pub neurons_fund_participation: Option, - pub duration: Option, - pub neuron_basket_construction_parameters: Option< - NeuronBasketConstructionParameters - >, - pub confirmation_text: Option, - pub maximum_participant_icp: Option, - pub minimum_icp: Option, - pub minimum_direct_participation_icp: Option, - pub minimum_participant_icp: Option, - pub start_time: Option, - pub maximum_direct_participation_icp: Option, - pub maximum_icp: Option, - pub neurons_fund_investment_icp: Option, - pub restricted_countries: Option, -} -#[derive(CandidType, Deserialize)] -pub struct SwapDistribution { pub total: Option } -#[derive(CandidType, Deserialize)] -pub struct NeuronDistribution { - pub controller: Option, - pub dissolve_delay: Option, - pub memo: Option, - pub vesting_period: Option, - pub stake: Option, -} -#[derive(CandidType, Deserialize)] -pub struct DeveloperDistribution { - pub developer_neurons: Vec, -} -#[derive(CandidType, Deserialize)] -pub struct InitialTokenDistribution { - pub treasury_distribution: Option, - pub developer_distribution: Option, - pub swap_distribution: Option, -} -#[derive(CandidType, Deserialize)] -pub struct CreateServiceNervousSystem { - pub url: Option, - pub governance_parameters: Option, - pub fallback_controller_principal_ids: Vec, - pub logo: Option, - pub name: Option, - pub ledger_parameters: Option, - pub description: Option, - pub dapp_canisters: Vec, - pub swap_parameters: Option, - pub initial_token_distribution: Option, -} -#[derive(CandidType, Deserialize)] -pub struct ExecuteNnsFunction { - pub nns_function: i32, - pub payload: serde_bytes::ByteBuf, -} -#[derive(CandidType, Deserialize)] -pub struct NodeProvider { - pub id: Option, - pub reward_account: Option, -} -#[derive(CandidType, Deserialize)] -pub struct RewardToNeuron { pub dissolve_delay_seconds: u64 } -#[derive(CandidType, Deserialize)] -pub struct RewardToAccount { pub to_account: Option } -#[derive(CandidType, Deserialize)] -pub enum RewardMode { - RewardToNeuron(RewardToNeuron), - RewardToAccount(RewardToAccount), -} -#[derive(CandidType, Deserialize)] -pub struct RewardNodeProvider { - pub node_provider: Option, - pub reward_mode: Option, - pub amount_e8s: u64, -} -#[derive(CandidType, Deserialize)] -pub struct NeuronBasketConstructionParameters1 { - pub dissolve_delay_interval_seconds: u64, - pub count: u64, -} -#[derive(CandidType, Deserialize)] -pub struct Params { - pub min_participant_icp_e8s: u64, - pub neuron_basket_construction_parameters: Option< - NeuronBasketConstructionParameters1 - >, - pub max_icp_e8s: u64, - pub swap_due_timestamp_seconds: u64, - pub min_participants: u32, - pub sns_token_e8s: u64, - pub sale_delay_seconds: Option, - pub max_participant_icp_e8s: u64, - pub min_direct_participation_icp_e8s: Option, - pub min_icp_e8s: u64, - pub max_direct_participation_icp_e8s: Option, -} -#[derive(CandidType, Deserialize)] -pub struct OpenSnsTokenSwap { - pub community_fund_investment_e8s: Option, - pub target_swap_canister_id: Option, - pub params: Option, -} -#[derive(CandidType, Deserialize)] -pub struct TimeWindow { - pub start_timestamp_seconds: u64, - pub end_timestamp_seconds: u64, -} -#[derive(CandidType, Deserialize)] -pub struct SetOpenTimeWindowRequest { pub open_time_window: Option } -#[derive(CandidType, Deserialize)] -pub struct SetSnsTokenSwapOpenTimeWindow { - pub request: Option, - pub swap_canister_id: Option, -} -#[derive(CandidType, Deserialize)] -pub struct Followees { pub followees: Vec } -#[derive(CandidType, Deserialize)] -pub struct SetDefaultFollowees { pub default_followees: Vec<(i32,Followees,)> } -#[derive(CandidType, Deserialize)] -pub struct RewardNodeProviders { - pub use_registry_derived_rewards: Option, - pub rewards: Vec, -} -#[derive(CandidType, Deserialize)] -pub struct NetworkEconomics { - pub neuron_minimum_stake_e8s: u64, - pub max_proposals_to_keep_per_topic: u32, - pub neuron_management_fee_per_proposal_e8s: u64, - pub reject_cost_e8s: u64, - pub transaction_fee_e8s: u64, - pub neuron_spawn_dissolve_delay_seconds: u64, - pub minimum_icp_xdr_rate: u64, - pub maximum_node_provider_rewards_e8s: u64, -} -#[derive(CandidType, Deserialize)] -pub struct ApproveGenesisKyc { pub principals: Vec } -#[derive(CandidType, Deserialize)] -pub enum Change { ToRemove(NodeProvider), ToAdd(NodeProvider) } -#[derive(CandidType, Deserialize)] -pub struct AddOrRemoveNodeProvider { pub change: Option } -#[derive(CandidType, Deserialize)] -pub struct Motion { pub motion_text: String } -#[derive(CandidType, Deserialize)] -pub enum Action { - RegisterKnownNeuron(KnownNeuron), - ManageNeuron(ManageNeuron), - CreateServiceNervousSystem(CreateServiceNervousSystem), - ExecuteNnsFunction(ExecuteNnsFunction), - RewardNodeProvider(RewardNodeProvider), - OpenSnsTokenSwap(OpenSnsTokenSwap), - SetSnsTokenSwapOpenTimeWindow(SetSnsTokenSwapOpenTimeWindow), - SetDefaultFollowees(SetDefaultFollowees), - RewardNodeProviders(RewardNodeProviders), - ManageNetworkEconomics(NetworkEconomics), - ApproveGenesisKyc(ApproveGenesisKyc), - AddOrRemoveNodeProvider(AddOrRemoveNodeProvider), - Motion(Motion), -} -#[derive(CandidType, Deserialize)] -pub struct Proposal { - pub url: String, - pub title: Option, - pub action: Option, - pub summary: String, -} -#[derive(CandidType, Deserialize)] -pub struct ProposalInfo { - pub id: Option, - pub status: i32, - pub topic: i32, - pub failure_reason: Option, - pub ballots: Vec<(u64,Ballot,)>, - pub proposal_timestamp_seconds: u64, - pub reward_event_round: u64, - pub deadline_timestamp_seconds: Option, - pub failed_timestamp_seconds: u64, - pub reject_cost_e8s: u64, - pub derived_proposal_information: Option, - pub latest_tally: Option, - pub reward_status: i32, - pub decided_timestamp_seconds: u64, - pub proposal: Option>, - pub proposer: Option, - pub executed_timestamp_seconds: u64, -} -#[derive(CandidType, Deserialize)] -pub enum NervousSystem { - #[serde(rename="network")] - Network{ id: u64, proposal_info: ProposalInfo }, -} -#[derive(CandidType, Deserialize)] -pub struct BackendProposal { - pub state: ReviewPeriodState, - pub synced_at: String, - pub nervous_system: NervousSystem, - pub proposed_at: String, -} -#[derive(CandidType, Deserialize)] -pub struct ProposalResponse { pub id: String, pub proposal: BackendProposal } -#[derive(CandidType, Deserialize)] -pub enum ListProposalsResponse { - #[serde(rename="ok")] - Ok{ proposals: Vec }, - #[serde(rename="err")] - Err(Err), -} -#[derive(CandidType, Deserialize)] -pub enum SyncProposalsResponse { - #[serde(rename="ok")] - Ok{ synced_proposals_count: u64, completed_proposals_count: u64 }, - #[serde(rename="err")] - Err(Err), -} -#[derive(CandidType, Deserialize)] -pub enum MyUserConfigUpdate { - #[serde(rename="admin")] - Admin{ bio: Option }, - #[serde(rename="anonymous")] - Anonymous, - #[serde(rename="reviewer")] - Reviewer{ - bio: Option, - wallet_address: Option, - social_links: Option>, - }, -} -#[derive(CandidType, Deserialize)] -pub struct UpdateMyUserProfileRequest { - pub username: Option, - pub config: Option, -} -#[derive(CandidType, Deserialize)] -pub enum UpdateMyUserProfileResponse { - #[serde(rename="ok")] - Ok, - #[serde(rename="err")] - Err(Err), -} -#[derive(CandidType, Deserialize)] -pub struct UpdateProposalReviewRequest { - pub status: Option, - pub review_duration_mins: Option, - pub summary: Option, - pub proposal_id: String, - pub build_reproduced: Option, -} -#[derive(CandidType, Deserialize)] -pub enum UpdateProposalReviewResponse { - #[serde(rename="ok")] - Ok, - #[serde(rename="err")] - Err(Err), -} -#[derive(CandidType, Deserialize)] -pub struct UpdateProposalReviewCommitRequest { - pub id: String, - pub state: ReviewCommitState, -} -#[derive(CandidType, Deserialize)] -pub enum UpdateProposalReviewCommitResponse { - #[serde(rename="ok")] - Ok, - #[serde(rename="err")] - Err(Err), -} -#[derive(CandidType, Deserialize)] -pub enum UserConfigUpdate { - #[serde(rename="admin")] - Admin{ bio: Option }, - #[serde(rename="anonymous")] - Anonymous, - #[serde(rename="reviewer")] - Reviewer{ - bio: Option, - wallet_address: Option, - social_links: Option>, - neuron_id: Option, - }, -} -#[derive(CandidType, Deserialize)] -pub struct UpdateUserProfileRequest { - pub username: Option, - pub user_id: String, - pub config: Option, -} -#[derive(CandidType, Deserialize)] -pub enum UpdateUserProfileResponse { - #[serde(rename="ok")] - Ok, - #[serde(rename="err")] - Err(Err), -} - -pub struct Service(pub Principal); -impl Service { - pub async fn create_my_user_profile(&self) -> Result<(CreateMyUserProfileResponse,)> { - ic_cdk::call(self.0, "create_my_user_profile", ()).await - } - pub async fn create_proposal_review(&self, arg0: CreateProposalReviewRequest) -> Result<(CreateProposalReviewResponse,)> { - ic_cdk::call(self.0, "create_proposal_review", (arg0,)).await - } - pub async fn create_proposal_review_commit(&self, arg0: CreateProposalReviewCommitRequest) -> Result<(CreateProposalReviewCommitResponse,)> { - ic_cdk::call(self.0, "create_proposal_review_commit", (arg0,)).await - } - pub async fn create_proposal_review_image(&self, arg0: CreateProposalReviewImageRequest) -> Result<(CreateProposalReviewImageResponse,)> { - ic_cdk::call(self.0, "create_proposal_review_image", (arg0,)).await - } - pub async fn delete_proposal_review_commit(&self, arg0: DeleteProposalReviewCommitRequest) -> Result<(DeleteProposalReviewCommitResponse,)> { - ic_cdk::call(self.0, "delete_proposal_review_commit", (arg0,)).await - } - pub async fn delete_proposal_review_image(&self, arg0: DeleteProposalReviewImageRequest) -> Result<(DeleteProposalReviewImageResponse,)> { - ic_cdk::call(self.0, "delete_proposal_review_image", (arg0,)).await - } - pub async fn get_my_proposal_review(&self, arg0: GetMyProposalReviewRequest) -> Result<(GetMyProposalReviewResponse,)> { - ic_cdk::call(self.0, "get_my_proposal_review", (arg0,)).await - } - pub async fn get_my_user_profile(&self) -> Result<(GetMyUserProfileResponse,)> { - ic_cdk::call(self.0, "get_my_user_profile", ()).await - } - pub async fn get_my_user_profile_history(&self) -> Result<(GetMyUserProfileHistoryResponse,)> { - ic_cdk::call(self.0, "get_my_user_profile_history", ()).await - } - pub async fn get_proposal_review(&self, arg0: GetProposalReviewRequest) -> Result<(GetProposalReviewResponse,)> { - ic_cdk::call(self.0, "get_proposal_review", (arg0,)).await - } - pub async fn http_request(&self, arg0: HttpRequest) -> Result<(HttpResponse,)> { - ic_cdk::call(self.0, "http_request", (arg0,)).await - } - pub async fn list_logs(&self, arg0: LogsFilterRequest) -> Result<(ListLogsResponse,)> { - ic_cdk::call(self.0, "list_logs", (arg0,)).await - } - pub async fn list_proposal_reviews(&self, arg0: ListProposalReviewsRequest) -> Result<(ListProposalReviewsResponse,)> { - ic_cdk::call(self.0, "list_proposal_reviews", (arg0,)).await - } - pub async fn list_proposals(&self, arg0: ListProposalsRequest) -> Result<(ListProposalsResponse,)> { - ic_cdk::call(self.0, "list_proposals", (arg0,)).await - } - pub async fn sync_proposals(&self) -> Result<(SyncProposalsResponse,)> { - ic_cdk::call(self.0, "sync_proposals", ()).await - } - pub async fn update_my_user_profile(&self, arg0: UpdateMyUserProfileRequest) -> Result<(UpdateMyUserProfileResponse,)> { - ic_cdk::call(self.0, "update_my_user_profile", (arg0,)).await - } - pub async fn update_proposal_review(&self, arg0: UpdateProposalReviewRequest) -> Result<(UpdateProposalReviewResponse,)> { - ic_cdk::call(self.0, "update_proposal_review", (arg0,)).await - } - pub async fn update_proposal_review_commit(&self, arg0: UpdateProposalReviewCommitRequest) -> Result<(UpdateProposalReviewCommitResponse,)> { - ic_cdk::call(self.0, "update_proposal_review_commit", (arg0,)).await - } - pub async fn update_user_profile(&self, arg0: UpdateUserProfileRequest) -> Result<(UpdateUserProfileResponse,)> { - ic_cdk::call(self.0, "update_user_profile", (arg0,)).await - } -} - diff --git a/src/backend/logs/src/fetcher.rs b/src/backend/logs/src/fetcher.rs new file mode 100644 index 00000000..7440f8fe --- /dev/null +++ b/src/backend/logs/src/fetcher.rs @@ -0,0 +1,94 @@ +use std::{ + fs::{File, OpenOptions}, + io::{Read, Seek, Write}, + path::PathBuf, +}; + +use candid::{Decode, Encode, Principal}; +use ic_agent::{identity::Secp256k1Identity, Agent}; + +use backend_api::{ApiResult, ListLogsResponse, LogEntry, LogsFilterRequest}; + +use crate::utils::now_timestamp_ms; + +struct BackendActor { + agent: Agent, + canister_id: Principal, +} + +impl BackendActor { + pub fn new(identity_pem: PathBuf, canister_id: Principal) -> anyhow::Result { + let identity = Secp256k1Identity::from_pem_file(identity_pem)?; + let agent = Agent::builder() + .with_identity(identity) + .with_url("https://icp-api.io") + .build()?; + Ok(Self { agent, canister_id }) + } + + pub async fn list_logs( + &self, + after_timestamp_ms: Option, + ) -> Result { + let request = LogsFilterRequest { + after_timestamp_ms, + before_timestamp_ms: None, + context_contains_any: None, + level: None, + message_contains_any: None, + }; + let response = self + .agent + .query(&self.canister_id, "list_logs") + .with_arg(Encode!(&request)?) + .await?; + let result = Decode!(&response, ApiResult)?; + match result { + ApiResult::Ok(ok) => Ok(ok), + ApiResult::Err(err) => Err(anyhow::anyhow!(err)), + } + } +} + +pub struct LogFetcher { + last_fetch_timestamp: Option, + file: File, + actor: BackendActor, +} + +impl LogFetcher { + pub fn new(identity_pem: PathBuf, backend_canister_id: String) -> anyhow::Result { + let path = "data/last-fetch-timestamp.txt"; + let mut file = OpenOptions::new() + .create(true) + .read(true) + .write(true) + .open(path)?; + let mut last_fetch_timestamp = String::new(); + file.read_to_string(&mut last_fetch_timestamp)?; + + let actor = BackendActor::new(identity_pem, Principal::from_text(backend_canister_id)?)?; + + Ok(Self { + file, + last_fetch_timestamp: last_fetch_timestamp.trim().parse().ok(), + actor, + }) + } + + pub async fn fetch_logs(&mut self) -> anyhow::Result> { + let logs = self.actor.list_logs(self.last_fetch_timestamp).await?; + let now = now_timestamp_ms(); + self.update_last_fetch_timestamp(now); + Ok(logs.logs) + } + + fn update_last_fetch_timestamp(&mut self, timestamp: u64) { + self.last_fetch_timestamp = Some(timestamp); + self.file.set_len(0).unwrap(); + self.file.rewind().unwrap(); + self.file + .write_all(timestamp.to_string().as_bytes()) + .unwrap(); + } +} diff --git a/src/backend/logs/src/main.rs b/src/backend/logs/src/main.rs index 5a479e9a..12811d32 100644 --- a/src/backend/logs/src/main.rs +++ b/src/backend/logs/src/main.rs @@ -1,55 +1,50 @@ +use backend_api::{LogEntry, LogLevel}; use base64::{engine::general_purpose::STANDARD as BASE64, Engine}; -use candid::Principal; use clap::Parser; -use opentelemetry::logs::{AnyValue, Logger as _, LoggerProvider as _, Severity}; +use opentelemetry::{ + logs::{AnyValue, Logger as _, LoggerProvider as _, Severity}, + KeyValue, +}; use opentelemetry_otlp::WithExportConfig; -use opentelemetry_sdk::logs::{Logger, LoggerProvider}; -use std::collections::HashMap; -use std::{ - fs::{File, OpenOptions}, - io::{Read, Seek, Write}, - path::PathBuf, - time::{SystemTime, UNIX_EPOCH}, +use opentelemetry_sdk::{ + logs::{LogRecord, Logger, LoggerProvider}, + Resource, }; - -mod actor; -mod backend; - -use actor::BackendActor; -use backend::{ListLogsResponse, LogEntry, LogLevel}; - -fn now() -> SystemTime { - SystemTime::now() -} - -fn now_timestamp_ms() -> u64 { - now().duration_since(UNIX_EPOCH).unwrap().as_millis() as u64 -} - -fn loki_headers(username: String, password: String) -> HashMap { - let mut headers = HashMap::new(); - let auth_header = format!( - "Basic {}", - BASE64.encode(format!("{}:{}", username, password)) - ); - headers.insert("Authorization".to_string(), auth_header.parse().unwrap()); - headers -} - -fn init_telemetry( - endpoint: String, - username: String, - password: String, -) -> anyhow::Result { - let headers = loki_headers(username, password); +use std::{collections::HashMap, path::PathBuf}; + +mod fetcher; +mod utils; + +use fetcher::LogFetcher; +use utils::now; + +fn init_telemetry(args: &Args) -> anyhow::Result { + let headers = { + let mut headers = HashMap::new(); + let auth_header = format!( + "Basic {}", + BASE64.encode(format!("{}:{}", args.loki_username, args.loki_password)) + ); + headers.insert("Authorization".to_string(), auth_header.parse().unwrap()); + headers + }; + // from https://grafana.com/docs/loki/latest/reference/loki-http-api/#ingest-logs-using-otlp + let loki_endpoint = format!("{}/otlp/v1/logs", args.loki_endpoint); let exporter = opentelemetry_otlp::new_exporter() .http() - .with_endpoint(endpoint) + .with_endpoint(loki_endpoint) .with_headers(headers) .build_log_exporter()?; let logger_provider = LoggerProvider::builder() .with_simple_exporter(exporter) + .with_resource(Resource::new(vec![ + KeyValue::new( + opentelemetry_semantic_conventions::resource::SERVICE_NAME, + "backend_canister", + ), + KeyValue::new("canister_id", args.backend_canister_id.clone()), + ])) .build(); Ok(logger_provider) @@ -59,49 +54,29 @@ fn build_logger(provider: &LoggerProvider) -> Logger { provider.logger_builder("backend_canister_logger").build() } -struct LogFetcher { - last_fetch_timestamp: Option, - file: File, - actor: BackendActor, -} +struct LogEntryAdapter(LogEntry); -impl LogFetcher { - fn new(identity_pem: PathBuf, backend_canister_id: String) -> anyhow::Result { - let path = "data/last-fetch-timestamp.txt"; - let mut file = OpenOptions::new() - .create(true) - .read(true) - .write(true) - .open(path)?; - let mut last_fetch_timestamp = String::new(); - file.read_to_string(&mut last_fetch_timestamp)?; - - let actor = BackendActor::new(identity_pem, Principal::from_text(&backend_canister_id)?)?; - - Ok(Self { - file, - last_fetch_timestamp: last_fetch_timestamp.trim().parse().ok(), - actor, - }) - } +impl TryInto for LogEntryAdapter { + type Error = anyhow::Error; - async fn fetch_logs(&mut self) -> anyhow::Result> { - let logs = self.actor.list_logs(self.last_fetch_timestamp).await?; - let now = now_timestamp_ms(); - self.update_last_fetch_timestamp(now); - match logs { - ListLogsResponse::Ok { logs } => Ok(logs), - ListLogsResponse::Err(err) => Err(anyhow::anyhow!(err.message)), + fn try_into(self) -> Result { + let mut log_record = LogRecord::default(); + log_record.timestamp = + Some(chrono::DateTime::parse_from_rfc3339(&self.0.date_time)?.into()); + log_record.observed_timestamp = Some(now()); + log_record.severity_number = Some(match self.0.level { + LogLevel::Info => Severity::Info, + LogLevel::Warn => Severity::Warn, + LogLevel::Error => Severity::Error, + }); + let mut body = HashMap::new(); + body.insert("message".into(), self.0.message.into()); + if let Some(context) = self.0.context { + body.insert("context".into(), context.into()); } - } + log_record.body = Some(AnyValue::Map(Box::new(body))); - fn update_last_fetch_timestamp(&mut self, timestamp: u64) { - self.last_fetch_timestamp = Some(timestamp); - self.file.set_len(0).unwrap(); - self.file.rewind().unwrap(); - self.file - .write_all(timestamp.to_string().as_bytes()) - .unwrap(); + Ok(log_record) } } @@ -134,34 +109,17 @@ async fn main() -> anyhow::Result<()> { let args = Args::parse(); // we need to keep the logger provider in memory because the drop implementation shuts down the processors - let logger_provider = - init_telemetry(args.loki_endpoint, args.loki_username, args.loki_password)?; + let logger_provider = init_telemetry(&args)?; let logger = build_logger(&logger_provider); let mut log_fetcher = LogFetcher::new(args.identity_pem, args.backend_canister_id)?; - let logs = log_fetcher.fetch_logs().await?; + let logs = log_fetcher.fetch_logs().await?; println!("Sending {} logs to Loki...", logs.len()); - for log in logs { - let mut log_record = logger.create_log_record(); - log_record.timestamp = Some(chrono::DateTime::parse_from_rfc3339(&log.date_time)?.into()); - log_record.observed_timestamp = Some(now()); - log_record.severity_number = Some(match log.level { - LogLevel::Info => Severity::Info, - LogLevel::Warn => Severity::Warn, - LogLevel::Error => Severity::Error, - }); - let mut body = HashMap::new(); - body.insert("message".into(), log.message.into()); - if let Some(context) = log.context { - body.insert("context".into(), context.into()); - } - log_record.body = Some(AnyValue::Map(Box::new(body))); - - logger.emit(log_record); + let log_entry = LogEntryAdapter(log); + logger.emit(log_entry.try_into()?); } - println!("Logs sent to Loki"); Ok(()) diff --git a/src/backend/logs/src/utils.rs b/src/backend/logs/src/utils.rs new file mode 100644 index 00000000..a4d1ac0e --- /dev/null +++ b/src/backend/logs/src/utils.rs @@ -0,0 +1,9 @@ +use std::time::{SystemTime, UNIX_EPOCH}; + +pub fn now() -> SystemTime { + SystemTime::now() +} + +pub fn now_timestamp_ms() -> u64 { + now().duration_since(UNIX_EPOCH).unwrap().as_millis() as u64 +} From c9e4eb4b8e960748ff2edc2d85850ed3b3d49b07 Mon Sep 17 00:00:00 2001 From: ilbertt Date: Sat, 19 Oct 2024 21:31:05 +0200 Subject: [PATCH 4/6] refactor: reorganize imports --- src/backend/logs/src/fetcher.rs | 7 +++---- src/backend/logs/src/main.rs | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/backend/logs/src/fetcher.rs b/src/backend/logs/src/fetcher.rs index 7440f8fe..7476ad11 100644 --- a/src/backend/logs/src/fetcher.rs +++ b/src/backend/logs/src/fetcher.rs @@ -4,11 +4,10 @@ use std::{ path::PathBuf, }; +use backend_api::{ApiResult, ListLogsResponse, LogEntry, LogsFilterRequest}; use candid::{Decode, Encode, Principal}; use ic_agent::{identity::Secp256k1Identity, Agent}; -use backend_api::{ApiResult, ListLogsResponse, LogEntry, LogsFilterRequest}; - use crate::utils::now_timestamp_ms; struct BackendActor { @@ -17,7 +16,7 @@ struct BackendActor { } impl BackendActor { - pub fn new(identity_pem: PathBuf, canister_id: Principal) -> anyhow::Result { + fn new(identity_pem: PathBuf, canister_id: Principal) -> anyhow::Result { let identity = Secp256k1Identity::from_pem_file(identity_pem)?; let agent = Agent::builder() .with_identity(identity) @@ -26,7 +25,7 @@ impl BackendActor { Ok(Self { agent, canister_id }) } - pub async fn list_logs( + async fn list_logs( &self, after_timestamp_ms: Option, ) -> Result { diff --git a/src/backend/logs/src/main.rs b/src/backend/logs/src/main.rs index 12811d32..be6c3560 100644 --- a/src/backend/logs/src/main.rs +++ b/src/backend/logs/src/main.rs @@ -1,3 +1,5 @@ +use std::{collections::HashMap, path::PathBuf}; + use backend_api::{LogEntry, LogLevel}; use base64::{engine::general_purpose::STANDARD as BASE64, Engine}; use clap::Parser; @@ -10,7 +12,6 @@ use opentelemetry_sdk::{ logs::{LogRecord, Logger, LoggerProvider}, Resource, }; -use std::{collections::HashMap, path::PathBuf}; mod fetcher; mod utils; From 92fc66216eb9e4e1f16b2fafa66a419db8d7f5fe Mon Sep 17 00:00:00 2001 From: ilbertt Date: Fri, 25 Oct 2024 14:52:44 +0200 Subject: [PATCH 5/6] refactor: use batch exporter for logs --- src/backend/logs/src/main.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/backend/logs/src/main.rs b/src/backend/logs/src/main.rs index be6c3560..2b8bf084 100644 --- a/src/backend/logs/src/main.rs +++ b/src/backend/logs/src/main.rs @@ -9,7 +9,8 @@ use opentelemetry::{ }; use opentelemetry_otlp::WithExportConfig; use opentelemetry_sdk::{ - logs::{LogRecord, Logger, LoggerProvider}, + logs::{BatchConfigBuilder, BatchLogProcessor, LogRecord, Logger, LoggerProvider}, + runtime::Tokio, Resource, }; @@ -37,8 +38,16 @@ fn init_telemetry(args: &Args) -> anyhow::Result { .with_headers(headers) .build_log_exporter()?; + let processor = BatchLogProcessor::builder(exporter, Tokio) + .with_batch_config( + BatchConfigBuilder::default() + .with_max_queue_size(2_048 * 4) + .build(), + ) + .build(); + let logger_provider = LoggerProvider::builder() - .with_simple_exporter(exporter) + .with_log_processor(processor) .with_resource(Resource::new(vec![ KeyValue::new( opentelemetry_semantic_conventions::resource::SERVICE_NAME, From a622ba295400cf6df3cedca9f2f854e897219986 Mon Sep 17 00:00:00 2001 From: ilbertt Date: Fri, 25 Oct 2024 15:59:53 +0200 Subject: [PATCH 6/6] refactor: use constant --- src/backend/logs/src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/backend/logs/src/main.rs b/src/backend/logs/src/main.rs index 2b8bf084..d23a9d2d 100644 --- a/src/backend/logs/src/main.rs +++ b/src/backend/logs/src/main.rs @@ -20,6 +20,10 @@ mod utils; use fetcher::LogFetcher; use utils::now; +/// `2048` is the default batch size for the OTLP logs batch processor. +/// We use `2048 * 4` to accommodate cases where we fetch a lot of logs at once. +const LOGS_PROCESSOR_MAX_QUEUE_SIZE_DEFAULT: usize = 2_048 * 4; + fn init_telemetry(args: &Args) -> anyhow::Result { let headers = { let mut headers = HashMap::new(); @@ -41,7 +45,7 @@ fn init_telemetry(args: &Args) -> anyhow::Result { let processor = BatchLogProcessor::builder(exporter, Tokio) .with_batch_config( BatchConfigBuilder::default() - .with_max_queue_size(2_048 * 4) + .with_max_queue_size(LOGS_PROCESSOR_MAX_QUEUE_SIZE_DEFAULT) .build(), ) .build();