diff --git a/Cargo.lock b/Cargo.lock index ba94907..b4cb412 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -38,6 +38,18 @@ dependencies = [ "cpufeatures", ] +[[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" @@ -197,6 +209,12 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +[[package]] +name = "base64" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51" + [[package]] name = "base64ct" version = "1.6.0" @@ -209,6 +227,26 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" +[[package]] +name = "bindgen" +version = "0.69.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" +dependencies = [ + "bitflags 2.4.2", + "cexpr", + "clang-sys", + "itertools", + "lazy_static", + "lazycell", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn 2.0.52", +] + [[package]] name = "bit-set" version = "0.5.3" @@ -357,6 +395,15 @@ dependencies = [ "libc", ] +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -373,6 +420,8 @@ dependencies = [ "ethers", "eyre", "log", + "metrics-exporter-prometheus", + "metrics-process", "rpassword", "tokio", "warp", @@ -392,6 +441,7 @@ dependencies = [ "hex-literal", "lazy_static", "log", + "metrics", "mockall", "prometheus", "tokio", @@ -422,6 +472,17 @@ dependencies = [ "inout", ] +[[package]] +name = "clang-sys" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67523a3b4be3ce1989d607a828d036249522dd9c1c8de7f4dd2dae43a37369d1" +dependencies = [ + "glob", + "libc", + "libloading", +] + [[package]] name = "clap" version = "4.5.2" @@ -1104,7 +1165,7 @@ dependencies = [ "futures-timer", "futures-util", "hashers", - "http", + "http 0.2.12", "instant", "jsonwebtoken", "once_cell", @@ -1235,6 +1296,21 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "form_urlencoded" version = "1.2.1" @@ -1452,7 +1528,26 @@ dependencies = [ "futures-core", "futures-sink", "futures-util", - "http", + "http 0.2.12", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "h2" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "816ec7294445779408f36fe57bc5b7fc1cf59664059096c65f905c1c61f58069" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http 1.1.0", "indexmap", "slab", "tokio", @@ -1465,6 +1560,9 @@ name = "hashbrown" version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +dependencies = [ + "ahash", +] [[package]] name = "hashers" @@ -1484,7 +1582,7 @@ dependencies = [ "base64 0.21.7", "bytes", "headers-core", - "http", + "http 0.2.12", "httpdate", "mime", "sha1", @@ -1496,7 +1594,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429" dependencies = [ - "http", + "http 0.2.12", ] [[package]] @@ -1552,6 +1650,17 @@ 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 = "0.4.6" @@ -1559,7 +1668,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" dependencies = [ "bytes", - "http", + "http 0.2.12", + "pin-project-lite", +] + +[[package]] +name = "http-body" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" +dependencies = [ + "bytes", + "http 1.1.0", +] + +[[package]] +name = "http-body-util" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0475f8b2ac86659c21b64320d5d653f9efe42acd2a4e560073ec61a155a34f1d" +dependencies = [ + "bytes", + "futures-core", + "http 1.1.0", + "http-body 1.0.0", "pin-project-lite", ] @@ -1591,9 +1723,9 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", - "h2", - "http", - "http-body", + "h2 0.3.26", + "http 0.2.12", + "http-body 0.4.6", "httparse", "httpdate", "itoa", @@ -1605,6 +1737,27 @@ dependencies = [ "want", ] +[[package]] +name = "hyper" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "186548d73ac615b32a73aafe38fb4f56c0d340e110e5a200bcadbaf2e199263a" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2 0.4.4", + "http 1.1.0", + "http-body 1.0.0", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + [[package]] name = "hyper-rustls" version = "0.24.2" @@ -1612,13 +1765,49 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" dependencies = [ "futures-util", - "http", - "hyper", + "http 0.2.12", + "hyper 0.14.28", "rustls", "tokio", "tokio-rustls", ] +[[package]] +name = "hyper-tls" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper 1.2.0", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http 1.1.0", + "http-body 1.0.0", + "hyper 1.2.0", + "pin-project-lite", + "socket2", + "tokio", + "tower", + "tower-service", + "tracing", +] + [[package]] name = "iana-time-zone" version = "0.1.60" @@ -1630,7 +1819,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -1847,18 +2036,45 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + [[package]] name = "libc" version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +[[package]] +name = "libloading" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" +dependencies = [ + "cfg-if", + "windows-targets 0.52.4", +] + [[package]] name = "libm" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +[[package]] +name = "libproc" +version = "0.14.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eb6497078a4c9c2aca63df56d8dce6eb4381d53a960f781a3a748f7ea97436d" +dependencies = [ + "bindgen", + "errno", + "libc", +] + [[package]] name = "libredox" version = "0.0.1" @@ -1898,6 +2114,15 @@ version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +[[package]] +name = "mach2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709" +dependencies = [ + "libc", +] + [[package]] name = "md-5" version = "0.10.6" @@ -1914,6 +2139,67 @@ version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" +[[package]] +name = "metrics" +version = "0.22.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2be3cbd384d4e955b231c895ce10685e3d8260c5ccffae898c96c723b0772835" +dependencies = [ + "ahash", + "portable-atomic", +] + +[[package]] +name = "metrics-exporter-prometheus" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d58e362dc7206e9456ddbcdbd53c71ba441020e62104703075a69151e38d85f" +dependencies = [ + "base64 0.22.0", + "http-body-util", + "hyper 1.2.0", + "hyper-tls", + "hyper-util", + "indexmap", + "ipnet", + "metrics", + "metrics-util", + "quanta", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "metrics-process" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f69c2a98ebe047f74b834c7eeaad0db5a9fd3604e129721d212e0ef9442e238a" +dependencies = [ + "libproc", + "mach2", + "metrics", + "once_cell", + "procfs 0.16.0", + "rlimit", + "windows", +] + +[[package]] +name = "metrics-util" +version = "0.16.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b07a5eb561b8cbc16be2d216faf7757f9baf3bfb94dbb0fae3df8387a5bb47f" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", + "hashbrown", + "metrics", + "num_cpus", + "quanta", + "sketches-ddsketch", +] + [[package]] name = "mime" version = "0.3.17" @@ -1930,6 +2216,12 @@ dependencies = [ "unicase", ] +[[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.2" @@ -1986,7 +2278,7 @@ dependencies = [ "bytes", "encoding_rs", "futures-util", - "http", + "http 0.2.12", "httparse", "log", "memchr", @@ -1995,12 +2287,40 @@ dependencies = [ "version_check", ] +[[package]] +name = "native-tls" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + [[package]] name = "new_debug_unreachable" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "num-bigint" version = "0.4.4" @@ -2108,6 +2428,50 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "openssl" +version = "0.10.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" +dependencies = [ + "bitflags 2.4.2", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.52", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c597637d56fbc83893a35eb0dd04b2b8e7a50c91e64e9493e398b5df4fb45fa2" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "option-ext" version = "0.2.0" @@ -2336,6 +2700,12 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "portable-atomic" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0" + [[package]] name = "powerfmt" version = "0.2.0" @@ -2454,6 +2824,29 @@ dependencies = [ "rustix 0.36.17", ] +[[package]] +name = "procfs" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "731e0d9356b0c25f16f33b5be79b1c57b562f141ebfcdb0ad8ac2c13a24293b4" +dependencies = [ + "bitflags 2.4.2", + "hex", + "lazy_static", + "procfs-core", + "rustix 0.38.31", +] + +[[package]] +name = "procfs-core" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d3554923a69f4ce04c4a754260c338f505ce22642d3830e049a399fc2059a29" +dependencies = [ + "bitflags 2.4.2", + "hex", +] + [[package]] name = "prometheus" version = "0.13.3" @@ -2466,7 +2859,7 @@ dependencies = [ "libc", "memchr", "parking_lot", - "procfs", + "procfs 0.14.2", "protobuf", "thiserror", ] @@ -2493,6 +2886,21 @@ version = "2.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94" +[[package]] +name = "quanta" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5167a477619228a0b284fac2674e3c388cba90631d7b7de620e6f1fcd08da5" +dependencies = [ + "crossbeam-utils", + "libc", + "once_cell", + "raw-cpuid", + "wasi", + "web-sys", + "winapi", +] + [[package]] name = "quote" version = "1.0.35" @@ -2547,6 +2955,15 @@ dependencies = [ "rand_core", ] +[[package]] +name = "raw-cpuid" +version = "11.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d86a7c4638d42c44551f4791a20e687dbb4c3de1f33c43dd71e355cd429def1" +dependencies = [ + "bitflags 2.4.2", +] + [[package]] name = "rayon" version = "1.9.0" @@ -2627,10 +3044,10 @@ dependencies = [ "encoding_rs", "futures-core", "futures-util", - "h2", - "http", - "http-body", - "hyper", + "h2 0.3.26", + "http 0.2.12", + "http-body 0.4.6", + "hyper 0.14.28", "hyper-rustls", "ipnet", "js-sys", @@ -2706,6 +3123,15 @@ dependencies = [ "digest", ] +[[package]] +name = "rlimit" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3560f70f30a0f16d11d01ed078a07740fe6b489667abc7c7b029155d9f21c3d8" +dependencies = [ + "libc", +] + [[package]] name = "rlp" version = "0.5.2" @@ -2755,6 +3181,12 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + [[package]] name = "rustc-hex" version = "2.1.0" @@ -2882,6 +3314,15 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "schannel" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "scoped-tls" version = "1.0.1" @@ -2930,6 +3371,29 @@ dependencies = [ "zeroize", ] +[[package]] +name = "security-framework" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "770452e37cad93e0a50d5abc3990d2bc351c36d0328f86cefec2f2fb206eaef6" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41f3cc463c0ef97e11c3461a9d3787412d30e8e7eb907c79180c4a57bf7c04ef" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "semver" version = "1.0.22" @@ -3035,6 +3499,12 @@ dependencies = [ "keccak", ] +[[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.1" @@ -3072,6 +3542,12 @@ version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" +[[package]] +name = "sketches-ddsketch" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85636c14b73d81f541e525f585c0a2109e6744e1565b5c1668e31c70c10ed65c" + [[package]] name = "slab" version = "0.4.9" @@ -3395,6 +3871,16 @@ dependencies = [ "syn 2.0.52", ] +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + [[package]] name = "tokio-rustls" version = "0.24.1" @@ -3512,6 +3998,28 @@ dependencies = [ "winnow 0.6.5", ] +[[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", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" + [[package]] name = "tower-service" version = "0.3.2" @@ -3575,7 +4083,7 @@ dependencies = [ "byteorder", "bytes", "data-encoding", - "http", + "http 0.2.12", "httparse", "log", "rand", @@ -3691,6 +4199,12 @@ dependencies = [ "serde", ] +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "version_check" version = "0.9.4" @@ -3726,8 +4240,8 @@ dependencies = [ "futures-channel", "futures-util", "headers", - "http", - "hyper", + "http 0.2.12", + "hyper 0.14.28", "log", "mime", "mime_guess", @@ -3866,6 +4380,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.54.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9252e5725dbed82865af151df558e754e4a3c2c30818359eb17465f1346a1b49" +dependencies = [ + "windows-core 0.54.0", + "windows-targets 0.52.4", +] + [[package]] name = "windows-core" version = "0.52.0" @@ -3875,6 +4399,25 @@ dependencies = [ "windows-targets 0.52.4", ] +[[package]] +name = "windows-core" +version = "0.54.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12661b9c89351d684a50a8a643ce5f608e20243b9fb84687800163429f161d65" +dependencies = [ + "windows-result", + "windows-targets 0.52.4", +] + +[[package]] +name = "windows-result" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd19df78e5168dfb0aedc343d1d1b8d422ab2db6756d2dc3fef75035402a3f64" +dependencies = [ + "windows-targets 0.52.4", +] + [[package]] name = "windows-sys" version = "0.45.0" @@ -4135,6 +4678,26 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" +[[package]] +name = "zerocopy" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.52", +] + [[package]] name = "zeroize" version = "1.7.0" diff --git a/Cargo.toml b/Cargo.toml index 4c6e417..e7d1d40 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,11 @@ chrono = "0.4.26" lazy_static = "1.4.0" async-trait = "0.1.73" warp = "0.3" +metrics-process = "1.2.1" +metrics-exporter-prometheus = { version = "0.14.0", features = [ + "http-listener", +] } +metrics = "0.22.3" [dependencies] challenger-lib.workspace = true @@ -32,6 +37,8 @@ log = { workspace = true, features = ["kv"] } eyre = { workspace = true } ethers = { workspace = true } warp = { workspace = true } +metrics-process = { workspace = true } +metrics-exporter-prometheus = { workspace = true } clap = { version = "4.3.21", features = ["derive", "env"] } rpassword = "7.2.0" diff --git a/challenger/Cargo.toml b/challenger/Cargo.toml index 80fed76..6107888 100644 --- a/challenger/Cargo.toml +++ b/challenger/Cargo.toml @@ -19,6 +19,7 @@ chrono = { workspace = true } lazy_static = { workspace = true } tokio-util = { workspace = true } async-trait = { workspace = true } +metrics = { workspace = true } prometheus = { version = "0.13.3", features = ["process"] } diff --git a/challenger/src/metrics.rs b/challenger/src/metrics.rs index 891caaa..f564123 100644 --- a/challenger/src/metrics.rs +++ b/challenger/src/metrics.rs @@ -1,94 +1,52 @@ use ethers::types::{Address, H256}; -use eyre::{Context, Result}; -use lazy_static::lazy_static; -use prometheus::{IntCounterVec, IntGaugeVec, Opts, Registry}; +use metrics::{counter, describe_counter, describe_gauge, gauge}; -lazy_static! { - pub static ref REGISTRY: Registry = - Registry::new_custom(Some(String::from("challenger")), None) - .expect("registry can be created"); - pub static ref ERRORS_COUNTER: IntCounterVec = IntCounterVec::new( - Opts::new("errors_total", "Challenger Errors Counter"), - &["address", "from", "error"] - ) - .expect("metric can be created"); - pub static ref CHALLENGE_COUNTER: IntCounterVec = IntCounterVec::new( - Opts::new("challenges_total", "Number of challenges made"), - &["address", "from", "tx"] - ) - .expect("metric can be created"); - pub static ref LAST_SCANNED_BLOCK_GAUGE: IntGaugeVec = IntGaugeVec::new( - Opts::new("last_scanned_block", "Last scanned block"), - &["address", "from"] - ) - .expect("metric can be created"); -} +const LAST_SCANNED_BLOCK_GAUGE: &'static str = "challenger_last_scanned_block"; +const ERRORS_COUNTER: &'static str = "challenger_errors_total"; +const CHALLENGE_COUNTER: &'static str = "challenger_challenges_total"; /// `set_last_scanned_block` sets the last scanned block for given `address` and `from` account. pub fn set_last_scanned_block(address: Address, from: Address, block: i64) { - LAST_SCANNED_BLOCK_GAUGE - .with_label_values(&[&format!("{:?}", address), &format!("{:?}", from)]) - .set(block); + let labels = [ + ("address", format!("{:?}", address)), + (("from"), format!("{:?}", from)), + ]; + gauge!(LAST_SCANNED_BLOCK_GAUGE, &labels).set(block as f64); } -/// `inc_challenges_counter` increments the errors counter for given `address`, `from` account +/// `inc_errors_counter` increments the errors counter for given `address`, `from` account pub fn inc_errors_counter(address: Address, from: Address, error: &str) { - ERRORS_COUNTER - .with_label_values(&[&format!("{:?}", address), &format!("{:?}", from), error]) - .inc(); + let labels = [ + ("address", format!("{:?}", address)), + ("from", format!("{:?}", from)), + ("error", String::from(error)), + ]; + counter!(ERRORS_COUNTER, &labels).increment(1); } -/// `inc_challenge_counter` increments the challenges counter for given `address`, `from` account and tx hash. +/// `inc_challenge_counter` increments the challenges counter for given `address`, `from` account and `tx` hash. pub fn inc_challenge_counter(address: Address, from: Address, tx: H256) { - CHALLENGE_COUNTER - .with_label_values(&[ - &format!("{:?}", address), - &format!("{:?}", from), - &format!("{:?}", tx), - ]) - .inc(); + let labels = [ + ("address", format!("{:?}", address)), + ("from", format!("{:?}", from)), + ("tx", format!("{:?}", tx)), + ]; + counter!(CHALLENGE_COUNTER, &labels).increment(1); } /// `register_custom_metrics` registers custom metrics to the registry. -/// It have to be called before you plan to serve `/metrics` route. -pub fn register_custom_metrics() { - REGISTRY - .register(Box::new(ERRORS_COUNTER.clone())) - .expect("collector can be registered"); - - REGISTRY - .register(Box::new(CHALLENGE_COUNTER.clone())) - .expect("collector can be registered"); - - REGISTRY - .register(Box::new(LAST_SCANNED_BLOCK_GAUGE.clone())) - .expect("collector can be registered"); -} - -pub fn as_encoded_string() -> Result { - use prometheus::Encoder; - let encoder = prometheus::TextEncoder::new(); - - // Collect and encode custom metrics from `REGISTRY` - let mut buffer = Vec::new(); - encoder - .encode(®ISTRY.gather(), &mut buffer) - .wrap_err("Failed to encode REGISTRY metrics")?; - - let mut res = String::from_utf8(buffer.clone()) - .wrap_err("Failed to convert REGISTRY metrics from utf8")?; - buffer.clear(); - - // Collect and encode prometheus metrics from `prometheus::gather()` - let mut buffer = Vec::new(); - encoder - .encode(&prometheus::gather(), &mut buffer) - .wrap_err("Failed to encode prometheus metrics")?; - - let res_custom = String::from_utf8(buffer.clone()) - .wrap_err("Failed to convert prometheus metrics from utf8")?; - buffer.clear(); - - res.push_str(&res_custom); - Ok(res) +/// It have to be called before you start processing & if you plans to serve `/metrics` route. +pub fn describe() { + describe_counter!( + ERRORS_COUNTER, + "Counts different errors in challenger process by given address" + ); + describe_counter!( + CHALLENGE_COUNTER, + "Counts happened challenges for given address and from account" + ); + describe_gauge!( + LAST_SCANNED_BLOCK_GAUGE, + "Keeps track of last scanned block for given address and from account" + ); } diff --git a/src/main.rs b/src/main.rs index 0660493..df22281 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,18 +23,20 @@ use ethers::{ }; use eyre::Result; use log::{error, info}; -use std::sync::Arc; -use std::{env, panic}; +use std::{env, panic, time::Duration}; +use std::{net::SocketAddr, sync::Arc}; mod wallet; use challenger_lib::{contract::HttpScribeOptimisticProvider, metrics, Challenger}; use tokio::signal; -use tokio::task::JoinSet; +use tokio::{task::JoinSet, time}; use wallet::{CustomWallet, KeystoreWallet, PrivateKeyWallet}; -use warp::{reject::Rejection, reply::Reply, Filter}; + +use metrics_exporter_prometheus::PrometheusBuilder; +use metrics_process::Collector; #[derive(Parser, Debug)] #[command(author, version, about)] @@ -131,6 +133,29 @@ async fn main() -> Result<()> { let mut addresses = args.addresses; addresses.dedup(); + // Register Prometheus metrics + let builder = PrometheusBuilder::new(); + + let port = env::var("HTTP_PORT") + .unwrap_or(String::from("9090")) + .parse::() + .unwrap(); + + let addr = SocketAddr::from(([0, 0, 0, 0], port)); + + builder + .with_http_listener(addr) + .install() + .expect("failed to install Prometheus recorder"); + + // Add challenger metrics description + metrics::describe(); + + let collector = Collector::new("challenger_"); + // Add Prometheus metrics help for process metrics + collector.describe(); + + // Start processing per address for address in &addresses { let address = address.parse::
()?; @@ -154,22 +179,14 @@ async fn main() -> Result<()> { }); } - // TODO: Start HTTP server for `:9090/metrics` + // Run metrics collector process set.spawn(async move { - metrics::register_custom_metrics(); + let mut interval = time::interval(Duration::from_millis(750)); - let metrics_route = warp::path!("metrics").and_then(metrics_handle); - let health_route = warp::path!("health").map(|| warp::reply::json(&"OK")); - - let port = env::var("HTTP_PORT") - .unwrap_or(String::from("9090")) - .parse::() - .unwrap(); - - info!("Starting HTTP server on port {}", port); - warp::serve(metrics_route.or(health_route)) - .run(([0, 0, 0, 0], port)) - .await; + loop { + collector.collect(); + interval.tick().await; + } }); tokio::select! { @@ -194,16 +211,6 @@ async fn main() -> Result<()> { Ok(()) } -async fn metrics_handle() -> Result { - match metrics::as_encoded_string() { - Ok(v) => Ok(v), - Err(e) => { - error!("Could not encode custom metrics: {}", e); - Ok(String::default()) - } - } -} - #[cfg(test)] mod tests { use std::path::PathBuf;