Skip to content

Commit

Permalink
chore: add calculated value to rcu (#22)
Browse files Browse the repository at this point in the history
* chore: add calculated value to rcu

* chore: fix license

* chore: fix cr
  • Loading branch information
shuiyisong authored Jan 25, 2024
1 parent abbd357 commit 9984cee
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 19 deletions.
2 changes: 1 addition & 1 deletion meter-core/src/collect.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Greptime Team
// Copyright 2024 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
12 changes: 11 additions & 1 deletion meter-core/src/data.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Greptime Team
// Copyright 2024 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -22,6 +22,11 @@ pub struct WriteRecord {

/// Volume of data written in byte.
pub byte_count: u32,

/// The calculated value of this read record.
///
/// If present, other fields will be ignored.
pub calculated_value: Option<u64>,
}

/// The ReadRecord records some data about data query.
Expand All @@ -46,4 +51,9 @@ pub struct ReadRecord {
///
/// Unit is byte.
pub network_egress: u64,

/// The calculated value of this read record.
///
/// If present, other fields will be ignored.
pub calculated_value: Option<u64>,
}
2 changes: 1 addition & 1 deletion meter-core/src/global.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Greptime Team
// Copyright 2024 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion meter-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Greptime Team
// Copyright 2024 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion meter-core/src/registry.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Greptime Team
// Copyright 2024 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion meter-core/src/write_calc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Greptime Team
// Copyright 2024 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
15 changes: 11 additions & 4 deletions meter-example/examples/simple.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Greptime Team
// Copyright 2024 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -70,6 +70,8 @@ async fn do_some_record() {

read_meter!("greptime", "db2", 100000, 100000, 100000);

read_meter!("greptime", "db3", calculated_value: 100000);

tokio::time::sleep(Duration::from_secs(1)).await;
}
}
Expand All @@ -85,10 +87,15 @@ fn rcu_calc(r_info: &ReadRecord) -> u32 {
cpu_time,
table_scan,
network_egress,
calculated_value,
..
} = r_info;

(*cpu_time / 3 + table_scan / 4096 + network_egress / 4096)
.try_into()
.unwrap()
if let Some(calculated_value) = calculated_value {
(*calculated_value).try_into().unwrap()
} else {
(*cpu_time / 3 + table_scan / 4096 + network_egress / 4096)
.try_into()
.unwrap()
}
}
6 changes: 3 additions & 3 deletions meter-example/src/collector.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Greptime Team
// Copyright 2024 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -94,7 +94,7 @@ where
schema: record.schema.clone(),
};

let mut entry = self.read_data.entry(schema_id).or_insert_with(Vec::new);
let mut entry = self.read_data.entry(schema_id).or_default();

entry.push(record)
}
Expand All @@ -105,7 +105,7 @@ where
schema: record.schema.clone(),
};

let mut entry = self.write_data.entry(schema_id).or_insert_with(Vec::new);
let mut entry = self.write_data.entry(schema_id).or_default();

entry.push(record)
}
Expand Down
2 changes: 1 addition & 1 deletion meter-example/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Greptime Team
// Copyright 2024 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion meter-example/src/reporter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Greptime Team
// Copyright 2024 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion meter-macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Greptime Team
// Copyright 2024 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
22 changes: 21 additions & 1 deletion meter-macros/src/read_meter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Greptime Team
// Copyright 2024 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,9 @@
#[cfg(feature = "noop")]
#[macro_export]
macro_rules! read_meter {
($catalog: expr, $schema: expr, calculated_value: $calculated_value: expr) => {
let _ = ($catalog, $schema, $calculated_value);
};
($catalog: expr, $schema: expr, cpu_time: $cpu_time: expr) => {
let _ = ($catalog, $schema, $cpu_time);
};
Expand Down Expand Up @@ -55,6 +58,19 @@ macro_rules! read_meter {
#[cfg(not(feature = "noop"))]
#[macro_export]
macro_rules! read_meter {
($catalog: expr, $schema: expr, calculated_value: $calculated_value: expr) => {
let record = meter_core::data::ReadRecord {
catalog: $catalog.into(),
schema: $schema.into(),
table: None,
region_num: None,
cpu_time: 0,
table_scan: 0,
network_egress: 0,
calculated_value: Some($calculated_value),
};
meter_core::global::global_registry().record_read(record);
};
($catalog: expr, $schema: expr, cpu_time: $cpu_time: expr) => {
let record = meter_core::data::ReadRecord {
catalog: $catalog.into(),
Expand All @@ -64,6 +80,7 @@ macro_rules! read_meter {
cpu_time: $cpu_time,
table_scan: 0,
network_egress: 0,
calculated_value: None,
};
meter_core::global::global_registry().record_read(record);
};
Expand All @@ -76,6 +93,7 @@ macro_rules! read_meter {
cpu_time: 0,
table_scan: $table_scan,
network_egress: 0,
calculated_value: None,
};
meter_core::global::global_registry().record_read(record);
};
Expand All @@ -88,6 +106,7 @@ macro_rules! read_meter {
cpu_time: 0,
table_scan: 0,
network_egress: $network_egress,
calculated_value: None,
};
meter_core::global::global_registry().record_read(record);
};
Expand All @@ -100,6 +119,7 @@ macro_rules! read_meter {
cpu_time: $cpu_time,
table_scan: $table_scan,
network_egress: $network_egress,
calculated_value: None,
};
meter_core::global::global_registry().record_read(record);
};
Expand Down
4 changes: 2 additions & 2 deletions meter-macros/src/write_meter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Greptime Team
// Copyright 2024 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -57,7 +57,6 @@ macro_rules! write_meter {
///
/// write_meter!("greptime", "public", MockInsert);
/// ```
#[cfg(not(feature = "noop"))]
#[macro_export]
macro_rules! write_meter {
Expand All @@ -73,6 +72,7 @@ macro_rules! write_meter {
table: None,
region_num: None,
byte_count,
calculated_value: None,
};

r.record_write(record);
Expand Down

0 comments on commit 9984cee

Please sign in to comment.