diff --git a/Cargo.lock b/Cargo.lock index 2cfbeaa..41b42d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -52,6 +52,164 @@ version = "1.0.42" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "595d3cfa7a60d4555cb5067b99f07142a08ea778de5cf993f7b75c7d8fabc486" +[[package]] +name = "async-attributes" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3203e79f4dd9bdda415ed03cf14dae5a2bf775c683a00f94e9cd1faf0f596e5" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "async-channel" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2114d64672151c0c5eaa5e131ec84a74f06e1e559830dabba01ca30605d66319" +dependencies = [ + "concurrent-queue", + "event-listener", + "futures-core", +] + +[[package]] +name = "async-executor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "871f9bb5e0a22eeb7e8cf16641feb87c9dc67032ccf8ff49e772eb9941d3a965" +dependencies = [ + "async-task", + "concurrent-queue", + "fastrand", + "futures-lite", + "once_cell", + "slab", +] + +[[package]] +name = "async-global-executor" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9586ec52317f36de58453159d48351bc244bc24ced3effc1fce22f3d48664af6" +dependencies = [ + "async-channel", + "async-executor", + "async-io", + "async-mutex", + "blocking", + "futures-lite", + "num_cpus", + "once_cell", + "tokio", +] + +[[package]] +name = "async-io" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a811e6a479f2439f0c04038796b5cfb3d2ad56c230e0f2d3f7b04d68cfee607b" +dependencies = [ + "concurrent-queue", + "futures-lite", + "libc", + "log", + "once_cell", + "parking", + "polling", + "slab", + "socket2", + "waker-fn", + "winapi", +] + +[[package]] +name = "async-lock" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6a8ea61bf9947a1007c5cada31e647dbc77b103c679858150003ba697ea798b" +dependencies = [ + "event-listener", +] + +[[package]] +name = "async-mutex" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479db852db25d9dbf6204e6cb6253698f175c15726470f78af0d918e99d6156e" +dependencies = [ + "event-listener", +] + +[[package]] +name = "async-process" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f38756dd9ac84671c428afbf7c9f7495feff9ec5b0710f17100098e5b354ac" +dependencies = [ + "async-io", + "blocking", + "cfg-if 1.0.0", + "event-listener", + "futures-lite", + "libc", + "once_cell", + "signal-hook", + "winapi", +] + +[[package]] +name = "async-std" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9f06685bad74e0570f5213741bea82158279a4103d988e57bfada11ad230341" +dependencies = [ + "async-attributes", + "async-channel", + "async-global-executor", + "async-io", + "async-lock", + "async-process", + "crossbeam-utils 0.8.5", + "futures-channel", + "futures-core", + "futures-io", + "futures-lite", + "gloo-timers", + "kv-log-macro", + "log", + "memchr", + "num_cpus", + "once_cell", + "pin-project-lite", + "pin-utils", + "slab", + "wasm-bindgen-futures", +] + +[[package]] +name = "async-task" +version = "4.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91831deabf0d6d7ec49552e489aed63b7456a7a3c46cff62adad428110b0af0" + +[[package]] +name = "async-trait" +version = "0.1.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b98e84bbb4cbcdd97da190ba0c58a1bb0de2c1fdf67d159e192ed766aeca722" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "atomic-waker" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a" + [[package]] name = "autocfg" version = "1.0.1" @@ -73,30 +231,11 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "bagua-core-c" -version = "0.1.2" -dependencies = [ - "anyhow", - "bagua-core-internal", - "cc", - "cmd_lib", - "color-eyre", - "cpp_build", - "numpy", - "openssl-sys", - "parking_lot", - "pyo3", - "shadow-rs", - "tracing", - "tracing-subscriber", - "which", -] - [[package]] name = "bagua-core-internal" version = "0.1.2" dependencies = [ + "bagua-opentelemetry", "base64", "cc", "cmake", @@ -113,6 +252,7 @@ dependencies = [ "num-traits", "once_cell", "oneshot", + "opentelemetry", "parking_lot", "pyo3", "scheduled-thread-pool", @@ -150,6 +290,23 @@ dependencies = [ "which", ] +[[package]] +name = "bagua-opentelemetry" +version = "0.1.0" +dependencies = [ + "async-std", + "async-trait", + "futures", + "hyper", + "opentelemetry", + "reqwest", + "serde", + "serde_json", + "tokio", + "tokio-stream", + "tracing", +] + [[package]] name = "base64" version = "0.13.0" @@ -162,6 +319,20 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +[[package]] +name = "blocking" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5e170dbede1f740736619b776d7251cb1b9095c435c34d8ca9f57fcd2f335e9" +dependencies = [ + "async-channel", + "async-task", + "atomic-waker", + "fastrand", + "futures-lite", + "once_cell", +] + [[package]] name = "bumpalo" version = "3.7.0" @@ -174,6 +345,18 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +[[package]] +name = "bytes" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" + +[[package]] +name = "cache-padded" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba" + [[package]] name = "cc" version = "1.0.69" @@ -275,6 +458,31 @@ dependencies = [ "tracing-error", ] +[[package]] +name = "concurrent-queue" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30ed07550be01594c6026cff2a1d7fe9c8f683caa798e12b68694ac9e88286a3" +dependencies = [ + "cache-padded", +] + +[[package]] +name = "core-foundation" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a89e2ae426ea83155dccf10c0fa6b1463ef6d5fcb44cee0b224a408fa640a62" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" + [[package]] name = "cpp" version = "0.5.6" @@ -326,6 +534,16 @@ dependencies = [ "syn", ] +[[package]] +name = "crossbeam-channel" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-utils 0.8.5", +] + [[package]] name = "crossbeam-queue" version = "0.2.3" @@ -333,7 +551,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "774ba60a54c213d409d5353bda12d49cd68d14e45036a285234c8d6f91f92570" dependencies = [ "cfg-if 0.1.10", - "crossbeam-utils", + "crossbeam-utils 0.7.2", "maybe-uninit", ] @@ -348,6 +566,36 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "crossbeam-utils" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" +dependencies = [ + "cfg-if 1.0.0", + "lazy_static", +] + +[[package]] +name = "ctor" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e98e2ad1a782e33928b96fc3948e7c355e5af34ba4de7670fe8bac2a3b2006d" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "dashmap" +version = "4.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e77a43b28d0668df09411cb0bc9a8c2adc40f9a048afe863e05fd43251e8e39c" +dependencies = [ + "cfg-if 1.0.0", + "num_cpus", +] + [[package]] name = "derivative" version = "2.2.0" @@ -380,6 +628,21 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" +[[package]] +name = "encoding_rs" +version = "0.8.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80df024fbc5ac80f87dfef0d9f5209a252f2a497f7f42944cff24d8253cac065" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "event-listener" +version = "2.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7531096570974c3a9dcf9e4b8e1cede1ec26cf5046219fb3b9d897503b9be59" + [[package]] name = "eyre" version = "0.6.5" @@ -401,6 +664,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "fastrand" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b394ed3d285a429378d3b384b9eb1285267e7df4b166df24b7a6939a04dc392e" +dependencies = [ + "instant", +] + [[package]] name = "fixedbitset" version = "0.2.0" @@ -420,6 +692,27 @@ dependencies = [ "spinning_top", ] +[[package]] +name = "fnv" +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.0.1" @@ -430,18 +723,115 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "futures" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e7e43a803dae2fa37c1f6a8fe121e1f7bf9548b4dfc0522a42f34145dadfc27" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e682a68b29a882df0545c143dc3646daefe80ba479bcdede94d5a703de2871e2" +dependencies = [ + "futures-core", + "futures-sink", +] + [[package]] name = "futures-core" version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0402f765d8a89a26043b889b26ce3c4679d268fa6bb22cd7c6aad98340e179d1" +[[package]] +name = "futures-executor" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "badaa6a909fac9e7236d0620a2f57f7664640c56575b71a7552fbd68deafab79" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acc499defb3b348f8d8f3f66415835a9131856ff7714bf10dadfc4ec4bdb29a1" + +[[package]] +name = "futures-lite" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7694489acd39452c77daa48516b894c153f192c3578d5a839b62c58099fcbf48" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "memchr", + "parking", + "pin-project-lite", + "waker-fn", +] + +[[package]] +name = "futures-macro" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4c40298486cdf52cc00cd6d6987892ba502c7656a16a4192a9992b1ccedd121" +dependencies = [ + "autocfg", + "proc-macro-hack", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "futures-sink" version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a57bead0ceff0d6dde8f465ecd96c9338121bb7717d3e7b108059531870c4282" +[[package]] +name = "futures-task" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a16bef9fc1a4dddb5bee51c989e3fbba26569cbb0e31f5b303c184e3dd33dae" + +[[package]] +name = "futures-util" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "feb5c238d27e2bf94ffdfd27b2c29e3df4a68c4193bb6427384259e2bf191967" +dependencies = [ + "autocfg", + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "proc-macro-hack", + "proc-macro-nested", + "slab", +] + [[package]] name = "generator" version = "0.6.25" @@ -487,6 +877,38 @@ dependencies = [ "url", ] +[[package]] +name = "gloo-timers" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47204a46aaff920a1ea58b11d03dec6f704287d27561724a4631e450654a891f" +dependencies = [ + "futures-channel", + "futures-core", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "h2" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "825343c4eef0b63f541f8903f395dc5beb362a979b5799a84062527ef1e37726" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "hashbrown" version = "0.9.1" @@ -502,6 +924,86 @@ dependencies = [ "ahash", ] +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "http" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "527e8c9ac747e28542699a951517aa9a6945af506cd1f2e1b53a576c17b6cc11" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60daa14be0e0786db0f03a9e57cb404c9d756eed2b6c62b9ea98ec5743ec75a9" +dependencies = [ + "bytes", + "http", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3a87b616e37e93c22fb19bcd386f02f3af5ea98a25670ad0fce773de23c5e68" + +[[package]] +name = "httpdate" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6456b8a6c8f33fee7d958fcd1b60d55b11940a79e63ae87013e6d22e26034440" + +[[package]] +name = "hyper" +version = "0.14.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b61cf2d1aebcf6e6352c97b81dc2244ca29194be1b276f5d8ad5c6330fffb11" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper", + "native-tls", + "tokio", + "tokio-native-tls", +] + [[package]] name = "idna" version = "0.2.3" @@ -567,6 +1069,12 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "ipnet" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68f2d64f2edebec4ce84ad108148e67e1064789bee435edc5b60ad398714a3a9" + [[package]] name = "itertools" version = "0.10.1" @@ -600,6 +1108,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "kv-log-macro" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" +dependencies = [ + "log", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -652,6 +1169,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ "cfg-if 1.0.0", + "value-bag", ] [[package]] @@ -701,6 +1219,12 @@ version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" +[[package]] +name = "mime" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" + [[package]] name = "miniz_oxide" version = "0.4.4" @@ -711,6 +1235,28 @@ dependencies = [ "autocfg", ] +[[package]] +name = "mio" +version = "0.7.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c2bdb6314ec10835cd3293dd268473a835c02b7b352e788be788b3c6ca6bb16" +dependencies = [ + "libc", + "log", + "miow", + "ntapi", + "winapi", +] + +[[package]] +name = "miow" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" +dependencies = [ + "winapi", +] + [[package]] name = "nanorand" version = "0.5.2" @@ -720,6 +1266,24 @@ dependencies = [ "getrandom", ] +[[package]] +name = "native-tls" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8d96b2e1c8da3957d58100b09f102c6d9cfdfced01b7ec5a8974044bb09dbd4" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + [[package]] name = "ndarray" version = "0.15.3" @@ -733,6 +1297,15 @@ dependencies = [ "rawpointer", ] +[[package]] +name = "ntapi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" +dependencies = [ + "winapi", +] + [[package]] name = "num-complex" version = "0.4.0" @@ -764,12 +1337,22 @@ dependencies = [ ] [[package]] -name = "num-traits" -version = "0.2.14" +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" dependencies = [ - "autocfg", + "hermit-abi", + "libc", ] [[package]] @@ -810,6 +1393,26 @@ dependencies = [ "loom", ] +[[package]] +name = "openssl" +version = "0.10.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "549430950c79ae24e6d02e0b7404534ecf311d94cc9f861e9e4020187d13d885" +dependencies = [ + "bitflags", + "cfg-if 1.0.0", + "foreign-types", + "libc", + "once_cell", + "openssl-sys", +] + +[[package]] +name = "openssl-probe" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28988d872ab76095a6e6ac88d99b54fd267702734fd7ffe610ca27f533ddb95a" + [[package]] name = "openssl-src" version = "111.15.0+1.1.1k" @@ -833,6 +1436,27 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "opentelemetry" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff27b33e30432e7b9854936693ca103d8591b0501f7ae9f633de48cda3bf2a67" +dependencies = [ + "async-std", + "async-trait", + "crossbeam-channel", + "dashmap", + "fnv", + "futures", + "js-sys", + "lazy_static", + "percent-encoding", + "pin-project", + "rand", + "serde", + "thiserror", +] + [[package]] name = "os_pipe" version = "0.9.2" @@ -849,6 +1473,12 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2386b4ebe91c2f7f51082d4cefa145d030e33a1842a96b12e4885cc3c01f7a55" +[[package]] +name = "parking" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" + [[package]] name = "parking_lot" version = "0.11.1" @@ -938,12 +1568,37 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + [[package]] name = "pkg-config" version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" +[[package]] +name = "polling" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92341d779fa34ea8437ef4d82d440d5e1ce3f3ff7f824aa64424cd481f9a1f25" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "log", + "wepoll-ffi", + "winapi", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" + [[package]] name = "proc-macro-error" version = "1.0.4" @@ -974,6 +1629,12 @@ version = "0.5.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" +[[package]] +name = "proc-macro-nested" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" + [[package]] name = "proc-macro2" version = "1.0.27" @@ -1040,6 +1701,46 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", + "rand_hc", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_hc" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" +dependencies = [ + "rand_core", +] + [[package]] name = "rawpointer" version = "0.2.1" @@ -1087,6 +1788,50 @@ version = "0.6.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi", +] + +[[package]] +name = "reqwest" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "246e9f61b9bb77df069a947682be06e31ac43ea37862e244a69f177694ea6d22" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "http", + "http-body", + "hyper", + "hyper-tls", + "ipnet", + "js-sys", + "lazy_static", + "log", + "mime", + "native-tls", + "percent-encoding", + "pin-project-lite", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-native-tls", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + [[package]] name = "ring" version = "0.16.20" @@ -1133,6 +1878,16 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" +[[package]] +name = "schannel" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" +dependencies = [ + "lazy_static", + "winapi", +] + [[package]] name = "scheduled-thread-pool" version = "0.2.5" @@ -1164,6 +1919,29 @@ dependencies = [ "untrusted", ] +[[package]] +name = "security-framework" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23a2ac85147a3a11d77ecf1bc7166ec0b92febfa4461c37944e180f319ece467" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e4effb91b4b8b6fb7732e670b6cee160278ff8e6bf485c7805d9e319d76e284" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "serde" version = "1.0.126" @@ -1195,6 +1973,18 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_urlencoded" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + [[package]] name = "shadow-rs" version = "0.6.2" @@ -1214,6 +2004,25 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "signal-hook" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "470c5a6397076fae0094aaf06a08e6ba6f37acb77d3b1b91ea92b4d6c8650c39" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" +dependencies = [ + "libc", +] + [[package]] name = "sized-object-pool" version = "0.2.2" @@ -1225,12 +2034,28 @@ dependencies = [ "tracing", ] +[[package]] +name = "slab" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f173ac3d1a7e3b28003f40de0b5ce7fe2710f9b9dc3fc38664cebee46b3b6527" + [[package]] name = "smallvec" version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" +[[package]] +name = "socket2" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e3dfc207c526015c632472a77be09cf1b6e46866581aecae5cc38fb4235dea2" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "spin" version = "0.5.2" @@ -1257,6 +2082,20 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "tempfile" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "rand", + "redox_syscall 0.2.9", + "remove_dir_all", + "winapi", +] + [[package]] name = "thiserror" version = "1.0.26" @@ -1322,6 +2161,78 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" +[[package]] +name = "tokio" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2602b8af3767c285202012822834005f596c811042315fa7e9f5b12b2a43207" +dependencies = [ + "autocfg", + "bytes", + "libc", + "memchr", + "mio", + "num_cpus", + "once_cell", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "tokio-macros", + "winapi", +] + +[[package]] +name = "tokio-macros" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54473be61f4ebe4efd09cec9bd5d16fa51d70ea0192213d754d2d500457db110" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b2f3f698253f03119ac0102beaa64f67a67e08074d03a22d18784104543727f" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1caa0b0c8d94a049db56b5acf8cba99dc0623aab1b26d5b5f5e2d945846b3592" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "log", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" + [[package]] name = "tracing" version = "0.1.26" @@ -1407,6 +2318,12 @@ dependencies = [ "tracing-serde", ] +[[package]] +name = "try-lock" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" + [[package]] name = "unicode-bidi" version = "0.3.5" @@ -1471,6 +2388,16 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "value-bag" +version = "1.0.0-alpha.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd320e1520f94261153e96f7534476ad869c14022aee1e59af7c778075d840ae" +dependencies = [ + "ctor", + "version_check", +] + [[package]] name = "vcpkg" version = "0.2.15" @@ -1483,6 +2410,22 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" +[[package]] +name = "waker-fn" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" + +[[package]] +name = "want" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +dependencies = [ + "log", + "try-lock", +] + [[package]] name = "wasi" version = "0.10.2+wasi-snapshot-preview1" @@ -1496,6 +2439,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d54ee1d4ed486f78874278e63e4069fc1ab9f6a18ca492076ffb90c5eb2997fd" dependencies = [ "cfg-if 1.0.0", + "serde", + "serde_json", "wasm-bindgen-macro", ] @@ -1514,6 +2459,18 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fba7978c679d53ce2d0ac80c8c175840feb849a161664365d1287b41f2e67f1" +dependencies = [ + "cfg-if 1.0.0", + "js-sys", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.74" @@ -1572,6 +2529,15 @@ dependencies = [ "webpki", ] +[[package]] +name = "wepoll-ffi" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d743fdedc5c64377b5fc2bc036b01c7fd642205a0d96356034ae3404d49eb7fb" +dependencies = [ + "cc", +] + [[package]] name = "which" version = "4.1.0" @@ -1603,3 +2569,12 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "winreg" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" +dependencies = [ + "winapi", +] diff --git a/Cargo.toml b/Cargo.toml index d2e0623..e3e33dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1 +1,5 @@ -workspace = {members = ["bagua-core-internal", "bagua-core-py", "bagua-core-c"],exclude = []} +workspace = { members = [ + "bagua-core-internal", + "bagua-core-py", + "bagua-opentelemetry", +], exclude = [] } diff --git a/bagua-core-internal/Cargo.toml b/bagua-core-internal/Cargo.toml index a6a3870..6c11fa8 100644 --- a/bagua-core-internal/Cargo.toml +++ b/bagua-core-internal/Cargo.toml @@ -29,6 +29,8 @@ ureq = "2.1" num-traits = "0.2" num-derive = "0.3" display_utils = "0.4.0" +opentelemetry = { version = "0.15", features = ["serialize", "metrics"] } +bagua-opentelemetry = { path = "../bagua-opentelemetry" } [dependencies.pyo3] version = "0.14.1" diff --git a/bagua-core-internal/src/datatypes/mod.rs b/bagua-core-internal/src/datatypes/mod.rs index 350a8f7..e87ef15 100644 --- a/bagua-core-internal/src/datatypes/mod.rs +++ b/bagua-core-internal/src/datatypes/mod.rs @@ -8,7 +8,6 @@ use crate::comm_ops::python_ffi_op::PythonFFIOp; use crate::comm_ops::CommOpTrait; use crate::communicators::{BaguaCommunicator, BaguaSingleCommunicator}; use crate::resource_pool::{CudaMemory, CUDA_DEVICE_MEMORY_POOL}; -use crate::telemetry::TELEMETRY; use crate::torch_ffi::root::c10::{DeviceType, StorageImpl, TensorImpl}; use crate::{kernels, BaguaCoreError}; use itertools::Itertools; @@ -769,12 +768,6 @@ impl BaguaTensor { if cuda_event_ptr == 0 { tracing::info!("mark comm ready with an event 0, ignoring event"); } - match TELEMETRY.as_ref() { - None => {} - Some(ref x) => { - x.lock().new_tensor_ready(self.inner.read().name.as_str()); - } - } let mut guard = self.inner.write(); guard.ready_for_comm = true; guard.ready_cuda_event_ptr = cuda_event_ptr; diff --git a/bagua-core-internal/src/lib.rs b/bagua-core-internal/src/lib.rs index e56408f..caead44 100644 --- a/bagua-core-internal/src/lib.rs +++ b/bagua-core-internal/src/lib.rs @@ -10,16 +10,20 @@ pub mod datatypes; pub mod events; pub mod kernels; pub mod resource_pool; -pub mod telemetry; mod torch_ffi; use crate::comm_ops::CommOpTrait; -use crate::telemetry::{SCHEDULED_THREAD_POOL, TELEMETRY}; +use bagua_opentelemetry; use cpp::cpp; use datatypes::{BaguaBucket, BaguaTensor}; use events::BaguaEventChannel; use flume::RecvTimeoutError; use hashbrown::{HashMap, HashSet}; +use opentelemetry::{ + global, + trace::{Span, Tracer}, + KeyValue, +}; use std::collections::VecDeque; use std::fmt::Debug; use std::sync::Arc; @@ -167,6 +171,8 @@ impl BaguaCommBackend { } } +static TELEMETRY_INIT_ONCE: std::sync::Once = std::sync::Once::new(); + impl BaguaCommBackend { pub fn new(schedule_channel_cap: usize, device_id: usize) -> BaguaCommBackend { unsafe { @@ -181,6 +187,20 @@ impl BaguaCommBackend { let (monitor_op_finish_channel_sender, monitor_op_finish_channel_receiver) = flume::unbounded(); + TELEMETRY_INIT_ONCE.call_once(|| { + match std::env::var("AUTO_TUNE_SERVER_ADDR") { + Ok(server_addr) => { + tracing::info!("detected auto tuning server, connecting"); + bagua_opentelemetry::init_tracer(&server_addr); + } + Err(_) => { + tracing::warn!( + "auto tuning server not detected, may experience degraded performance" + ); + } + }; + }); + BaguaCommBackend { ordered_buckets: Default::default(), bucket_mapping: Default::default(), @@ -282,6 +302,10 @@ impl BaguaCommBackend { tensor: &BaguaTensor, ready_cuda_event_ptr: u64, ) -> Result<(), BaguaCoreError> { + let tracer = global::tracer("bagua-core"); + let mut span = tracer.start("tensor_ready"); + span.set_attribute(KeyValue::new("tensor_name", tensor.name())); + tensor.mark_comm_ready(ready_cuda_event_ptr); while self.should_schedule()? { let bucket = self.ordered_buckets.pop_front().unwrap(); @@ -311,27 +335,4 @@ impl BaguaCommBackend { } } } - - pub fn start_upload_telemetry(&self, skip: bool) -> Result<(), BaguaCoreError> { - SCHEDULED_THREAD_POOL.execute(move || match TELEMETRY.as_ref() { - None => {} - Some(x) => { - let mut guard = x.lock(); - match skip { - true => { - guard.clear(); - } - false => { - match guard.push_payload_and_clear() { - Ok(_) => {} - Err(x) => { - tracing::error!("{:?}", x) - } - }; - } - } - } - }); - Ok(()) - } } diff --git a/bagua-core-internal/src/telemetry/mod.rs b/bagua-core-internal/src/telemetry/mod.rs deleted file mode 100644 index 32e8a6c..0000000 --- a/bagua-core-internal/src/telemetry/mod.rs +++ /dev/null @@ -1,82 +0,0 @@ -use crate::BaguaCoreError; -use once_cell::sync::Lazy; -use parking_lot::Mutex; -use scheduled_thread_pool::ScheduledThreadPool; -use serde::{Deserialize, Serialize}; - -#[allow(dead_code)] -pub static SCHEDULED_THREAD_POOL: Lazy = - Lazy::new(|| ScheduledThreadPool::with_name("bagua_scheduled_thread_pool", 1)); - -pub static TELEMETRY: Lazy>> = - Lazy::new(|| match std::env::var("AUTO_TUNE_SERVER_ADDR") { - Ok(x) => { - tracing::info!("detected auto tuning server, connecting"); - Some(Mutex::new(BaguaCommCoreTelemetry::new(x.as_str()))) - } - Err(_) => { - tracing::warn!("auto tuning server not detected, may experience degraded performance"); - None - } - }); - -pub struct BaguaCommCoreTelemetry { - server_addr: String, - current_payload: TelemetryPayload, -} - -#[derive(Debug, Serialize, Deserialize)] -pub struct TelemetryPayload { - tensor_ready_order: Vec, - communication_time_ms: u64, -} - -impl TelemetryPayload { - pub fn clear(&mut self) { - self.tensor_ready_order.clear(); - self.communication_time_ms = 0; - } -} - -impl Default for TelemetryPayload { - fn default() -> Self { - Self { - tensor_ready_order: vec![], - communication_time_ms: 0, - } - } -} - -impl BaguaCommCoreTelemetry { - pub fn new(server_addr: &str) -> Self { - Self { - server_addr: server_addr.to_string(), - current_payload: TelemetryPayload::default(), - } - } - - pub fn new_tensor_ready(&mut self, tensor_name: &str) { - self.current_payload - .tensor_ready_order - .push(tensor_name.to_string()); - } - - pub fn push_payload_and_clear(&mut self) -> Result<(), BaguaCoreError> { - let payload_string = serde_json::to_string(&self.current_payload)?; - if ureq::post(format!("{}/api/v1/bagua_backend_metrics", self.server_addr).as_str()) - .send_string(payload_string.as_str())? - .status() - != 200 - { - return Err(BaguaCoreError::TelemetryError( - "post TELEMETRY payload failed".into(), - )); - } - self.clear(); - Ok(()) - } - - pub fn clear(&mut self) { - self.current_payload.clear(); - } -} diff --git a/bagua-core-py/src/lib.rs b/bagua-core-py/src/lib.rs index 353539f..22c737b 100644 --- a/bagua-core-py/src/lib.rs +++ b/bagua-core-py/src/lib.rs @@ -339,11 +339,6 @@ impl BaguaCommBackendPy { py.allow_threads(|| self.inner.wait_pending_comm_ops()) .map_err(|e| PyRuntimeError::new_err(format!("{:?}", e))) } - - pub fn start_upload_telemetry(&self, skip: bool, py: Python) -> PyResult<()> { - py.allow_threads(|| self.inner.start_upload_telemetry(skip)) - .map_err(|e| PyRuntimeError::new_err(format!("{:?}", e))) - } } #[pyclass(dict)] diff --git a/bagua-opentelemetry/Cargo.toml b/bagua-opentelemetry/Cargo.toml new file mode 100644 index 0000000..ec8fb12 --- /dev/null +++ b/bagua-opentelemetry/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "bagua-opentelemetry" +version = "0.1.0" +edition = "2018" +publish = ["private"] + +[dependencies] +tracing = "0.1" +async-std = { version = "1.6", features = ["attributes", "tokio1"] } +async-trait = { version = "0.1" } +hyper = { version = "0.14", features = ["full"] } +opentelemetry = { version = "0.15", default-features = false, features = [ + "trace", + "rt-async-std", +] } +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +reqwest = { version = "0.11", features = ["json"] } +tokio = { version = "1", features = ["full"] } +futures = { version = "0.3" } + +tokio-stream = { version = "0.1" } diff --git a/bagua-opentelemetry/src/exporter/agent.rs b/bagua-opentelemetry/src/exporter/agent.rs new file mode 100644 index 0000000..9d11c9f --- /dev/null +++ b/bagua-opentelemetry/src/exporter/agent.rs @@ -0,0 +1,44 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Clone, Debug, Hash)] +pub struct BaguaSpan { + pub trace_id: u128, + pub action: String, + pub tensor_name: String, + pub start_time: u128, + pub end_time: u128, +} + +#[derive(Serialize, Deserialize, Clone, Debug, Hash)] +pub struct BaguaBatch { + pub spans: Vec, +} + +#[derive(Debug)] +pub struct AgentAsyncClientHTTP { + server_addr: String, + client: reqwest::Client, +} + +impl AgentAsyncClientHTTP { + pub fn new(server_addr: String) -> AgentAsyncClientHTTP { + Self { + server_addr: server_addr, + client: reqwest::Client::new(), + } + } + + pub async fn emit_batch( + &mut self, + batch: BaguaBatch, + ) -> Result { + let uri = format!( + "http://{}/api/v1/report_tensor_execution_order", + self.server_addr + ); + + let resp = self.client.post(uri).json(&batch).send().await?; + + Ok(resp) + } +} diff --git a/bagua-opentelemetry/src/exporter/mod.rs b/bagua-opentelemetry/src/exporter/mod.rs new file mode 100644 index 0000000..2b59511 --- /dev/null +++ b/bagua-opentelemetry/src/exporter/mod.rs @@ -0,0 +1,62 @@ +pub mod agent; + +use crate::exporter::agent::{AgentAsyncClientHTTP, BaguaBatch, BaguaSpan}; +use async_trait::async_trait; +use opentelemetry::{sdk::export::trace, Key}; +use reqwest::StatusCode; +use std::time::UNIX_EPOCH; + +#[derive(Debug)] +pub struct Exporter { + pub uploader: AgentAsyncClientHTTP, +} + +#[async_trait] +impl trace::SpanExporter for Exporter { + async fn export(&mut self, batch: Vec) -> trace::ExportResult { + let mut bagua_spans = Vec::new(); + for span in batch { + let bagua_span = BaguaSpan { + trace_id: span.span_context.trace_id().to_u128(), + action: span.name.into_owned(), + tensor_name: span + .attributes + .get(&Key::new("tensor_name")) + .unwrap() + .as_str() + .to_string(), + start_time: span + .start_time + .duration_since(UNIX_EPOCH) + .unwrap() + .as_millis(), + end_time: span + .end_time + .duration_since(UNIX_EPOCH) + .unwrap() + .as_millis(), + }; + + bagua_spans.push(bagua_span); + } + + let resp = self + .uploader + .emit_batch(BaguaBatch { spans: bagua_spans }) + .await; + match resp { + Ok(resp) => { + if resp.status() != StatusCode::OK { + tracing::warn!("upload bagua span failed, resp={:?}", resp); + } + } + Err(err) => { + tracing::warn!("upload bagua span failed, err={:?}", err); + } + } + + Ok(()) + } + + fn shutdown(&mut self) {} +} diff --git a/bagua-opentelemetry/src/lib.rs b/bagua-opentelemetry/src/lib.rs new file mode 100644 index 0000000..740e11a --- /dev/null +++ b/bagua-opentelemetry/src/lib.rs @@ -0,0 +1,21 @@ +pub mod exporter; + +use crate::exporter::agent::AgentAsyncClientHTTP; +use crate::exporter::Exporter; +use opentelemetry; +use opentelemetry::{global, sdk, trace::Tracer, trace::TracerProvider}; + +pub fn init_tracer(autotune_server_addr: &str) -> impl Tracer { + let exporter = Exporter { + uploader: AgentAsyncClientHTTP::new(autotune_server_addr.to_string()), + }; + + let builder = sdk::trace::TracerProvider::builder() + .with_batch_exporter(exporter, opentelemetry::runtime::AsyncStd); + + let tracer_provider = builder.build(); + let tracer = tracer_provider.get_tracer("bagua-opentelemetry", Some(env!("CARGO_PKG_VERSION"))); + let _ = global::set_tracer_provider(tracer_provider); + + tracer +} diff --git a/setup.py b/setup.py index 404c46a..42f10cf 100644 --- a/setup.py +++ b/setup.py @@ -194,6 +194,9 @@ def install_dependency_library(): ], author="Kuaishou AI Platform & DS3 Lab", author_email="admin@mail.xrlian.com", - install_requires=[], + install_requires=[ + "setuptools_rust", + "colorama", + ], zip_safe=False, )