Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add traffic source to meter record #24

Merged
merged 6 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
[workspace.package]
edition = "2021"
license = "Apache-2.0"

[workspace]
members = ["meter-core", "meter-example", "meter-macros"]
resolver = "2"
2 changes: 2 additions & 0 deletions meter-core/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ impl ReadItem {
}

#[derive(Debug)]
#[non_exhaustive]
pub struct MeterRecord {
pub catalog: String,
pub schema: String,
pub value: u64,
pub source: u8,
}
5 changes: 3 additions & 2 deletions meter-example/examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async fn setup_global_registry() {
async fn do_some_record() {
for _i in 0..20 {
let insert_req = "String insert req".to_string();
let w = write_meter!("greptime", "db1", insert_req);
let w = write_meter!("greptime", "db1", insert_req, 0);
info!("w: {}", w);

let r = read_meter!(
Expand All @@ -76,7 +76,8 @@ async fn do_some_record() {
ReadItem {
cpu_time: 100000,
table_scan: 100000,
}
},
0
);
info!("r: {}", r);

Expand Down
9 changes: 5 additions & 4 deletions meter-macros/src/read_meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#[cfg(feature = "noop")]
#[macro_export]
macro_rules! read_meter {
($catalog: expr, $schema: expr, $item: expr) => {{
let _ = ($catalog, $schema, $item);
($catalog: expr, $schema: expr, $item: expr, $source: expr) => {{
let _ = ($catalog, $schema, $item, $source);
0 as u64
}};
}
Expand Down Expand Up @@ -57,12 +57,12 @@ macro_rules! read_meter {
/// read_meter!("greptime", "public", ReadItem {
/// cpu_time: cpu_time_ns,
/// table_scan: table_scan_bytes,
/// });
/// }, 0);
/// ```
#[cfg(not(feature = "noop"))]
#[macro_export]
macro_rules! read_meter {
($catalog: expr, $schema: expr, $item: expr) => {{
($catalog: expr, $schema: expr, $item: expr, $source: expr) => {{
let r = meter_core::global::global_registry();
let mut value = 0;
if let Some(calc) = r.get_calculator() {
Expand All @@ -71,6 +71,7 @@ macro_rules! read_meter {
catalog: $catalog.into(),
schema: $schema.into(),
value: value,
source: source,
};
meter_core::global::global_registry().record_read(record);
}
Expand Down
9 changes: 5 additions & 4 deletions meter-macros/src/write_meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#[cfg(feature = "noop")]
#[macro_export]
macro_rules! write_meter {
($catalog: expr, $schema: expr, $write_calc: expr) => {{
let _ = ($catalog, $schema, &$write_calc);
($catalog: expr, $schema: expr, $write_calc: expr, $source: expr) => {{
let _ = ($catalog, $schema, &$write_calc, $source);
0 as u64
}};
}
Expand Down Expand Up @@ -50,12 +50,12 @@ macro_rules! write_meter {
/// let registry = global_registry();
/// registry.register_calculator(Arc::new(MockInsertCalculator));
///
/// write_meter!("greptime", "public", MockInsert);
/// write_meter!("greptime", "public", MockInsert, 0);
/// ```
#[cfg(not(feature = "noop"))]
#[macro_export]
macro_rules! write_meter {
($catalog: expr, $schema: expr, $req_item: expr) => {{
($catalog: expr, $schema: expr, $req_item: expr, $source: expr) => {{
let r = meter_core::global::global_registry();
let mut value = 0;
if let Some(calc) = r.get_calculator() {
Expand All @@ -65,6 +65,7 @@ macro_rules! write_meter {
catalog: $catalog.into(),
schema: $schema.into(),
value: value,
source: source,
};

r.record_write(record);
Expand Down
Loading