Skip to content

Commit c7c3ab1

Browse files
authored
[Feat] runtime metrics & [Chore] update dependencies (#48)
* [Feat] runtime metrics * [Chore] update dependencies * [Fix] sort cargo
1 parent 17019a4 commit c7c3ab1

File tree

12 files changed

+379
-259
lines changed

12 files changed

+379
-259
lines changed

Cargo.lock

+168-147
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+11-9
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ path = "benches/concurrent_insert/mod.rs"
2626
anyhow = "1.0"
2727
log = "0.4"
2828
toml = "0.7.3"
29-
prometheus-client = "0.20"
29+
prometheus-client = "0.21"
30+
tokio = { version = "1", features = ["full"] }
3031

3132
[dependencies]
3233
anyhow = { workspace = true }
3334
byteorder = "1.2"
34-
bytes = "0.4"
35+
bytes = "1.4"
3536
chrono = "0.4"
3637
crossbeam = "0.8.2"
3738
futures = "0.1"
@@ -49,22 +50,23 @@ reqwest = { version = "0.11.13", default-features = false, features = ["rustls-t
4950
rust-crypto = "0.2"
5051
scheduled-thread-pool = "0.2"
5152
serde = "1.0"
52-
serde_bytes = "0.10"
53+
serde_bytes = "0.11"
5354
serde_derive = "1.0"
5455
serde_json = "1.0"
55-
spin = "0.5.0"
56-
tokio-codec = "0.1"
56+
spin = "0.9"
57+
tokio = { workspace = true }
58+
tokio-util = "0.7"
5759
uuid = { version = "1.3.0", default-features = false, features = ["v4", "fast-rng", "macro-diagnostics"] }
58-
zstd = "0.11"
60+
zstd = "0.12"
5961

6062
[dev-dependencies]
6163
env_logger = "0.10"
6264
scoped_threadpool = "0.1"
63-
serial_test = "0.2"
64-
serial_test_derive = "0.2"
65+
serial_test = "2.0"
66+
serial_test_derive = "2.0"
6567
tempfile = "3.0"
6668
test-log = "0.2"
67-
time = "0.1"
69+
time = "0.3"
6870

6971
[profile.release]
7072
debug = true

src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extern crate mysql;
2323
#[macro_use]
2424
extern crate serde;
2525
extern crate serde_bytes;
26-
extern crate tokio_codec;
26+
extern crate tokio_util;
2727
#[macro_use]
2828
extern crate serde_derive;
2929
#[macro_use]
@@ -51,6 +51,7 @@ pub mod error;
5151
mod location;
5252
pub mod monitors;
5353
mod rpc;
54+
mod runtime;
5455
pub mod serde_obkv;
5556
mod util;
5657
pub use self::{

src/monitors/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ pub mod client_metrics;
1919
pub mod prometheus;
2020
pub mod proxy_metrics;
2121
pub mod rpc_metrics;
22+
pub mod runtime_metrics;

src/monitors/runtime_metrics.rs

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*-
2+
* #%L
3+
* OBKV Table Client Framework
4+
* %%
5+
* Copyright (C) 2021 OceanBase
6+
* %%
7+
* OBKV Table Client Framework is licensed under Mulan PSL v2.
8+
* You can use this software according to the terms and conditions of the
9+
* Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at:
10+
* http://license.coscl.org.cn/MulanPSL2
11+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
12+
* KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
13+
* NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
14+
* See the Mulan PSL v2 for more details.
15+
* #L%
16+
*/
17+
18+
use prometheus_client::{
19+
encoding::{EncodeLabelSet, EncodeLabelValue},
20+
metrics::{family::Family, gauge},
21+
registry::Registry,
22+
};
23+
24+
#[derive(Clone, Debug, Hash, PartialEq, Eq, EncodeLabelValue)]
25+
pub enum ObClientRuntimeGaugeType {
26+
Default = 0,
27+
ConnWriter = 1,
28+
ConnReader = 2,
29+
}
30+
31+
#[derive(Clone, Debug, Hash, PartialEq, Eq, EncodeLabelSet)]
32+
pub struct RuntimeThreadLabels {
33+
pub rt_type: ObClientRuntimeGaugeType,
34+
}
35+
36+
#[derive(Default)]
37+
pub struct RuntimeGaugeMetrics {
38+
runtime_thread_alive_gauges: Family<RuntimeThreadLabels, gauge::Gauge>,
39+
runtime_thread_idle_gauges: Family<RuntimeThreadLabels, gauge::Gauge>,
40+
}
41+
42+
impl RuntimeGaugeMetrics {
43+
pub fn register(&self, registry: &mut Registry) {
44+
let sub_registry = registry.sub_registry_with_prefix("runtime");
45+
sub_registry.register(
46+
"Runtime Alive Threads Gauges ",
47+
"Client alive threads num.",
48+
self.runtime_thread_alive_gauges.clone(),
49+
);
50+
sub_registry.register(
51+
"Runtime Idle Threads Gauges ",
52+
"Client idle threads num.",
53+
self.runtime_thread_idle_gauges.clone(),
54+
);
55+
}
56+
57+
pub fn on_thread_start(&self, rt_type: ObClientRuntimeGaugeType) {
58+
self.runtime_thread_alive_gauges
59+
.get_or_create(&RuntimeThreadLabels { rt_type })
60+
.inc();
61+
}
62+
63+
pub fn on_thread_stop(&self, rt_type: ObClientRuntimeGaugeType) {
64+
self.runtime_thread_alive_gauges
65+
.get_or_create(&RuntimeThreadLabels { rt_type })
66+
.dec();
67+
}
68+
69+
pub fn on_thread_park(&self, rt_type: ObClientRuntimeGaugeType) {
70+
self.runtime_thread_alive_gauges
71+
.get_or_create(&RuntimeThreadLabels { rt_type })
72+
.inc();
73+
}
74+
75+
pub fn on_thread_unpark(&self, rt_type: ObClientRuntimeGaugeType) {
76+
self.runtime_thread_alive_gauges
77+
.get_or_create(&RuntimeThreadLabels { rt_type })
78+
.dec();
79+
}
80+
81+
pub fn get_runtime_thread_alive_gauges(&self) -> &Family<RuntimeThreadLabels, gauge::Gauge> {
82+
&self.runtime_thread_alive_gauges
83+
}
84+
85+
pub fn get_runtime_thread_idle_gauges(&self) -> &Family<RuntimeThreadLabels, gauge::Gauge> {
86+
&self.runtime_thread_idle_gauges
87+
}
88+
}

src/rpc/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use byteorder::{BigEndian, ByteOrder};
3838
use bytes::BytesMut;
3939
use crossbeam::channel::{bounded, unbounded, Receiver, Sender};
4040
use net2::{TcpBuilder, TcpStreamExt};
41-
use tokio_codec::{Decoder, Encoder};
41+
use tokio_util::codec::{Decoder, Encoder};
4242
use uuid::Uuid;
4343

4444
use self::protocol::{

0 commit comments

Comments
 (0)