Skip to content

Commit

Permalink
fix conficts from dependabot
Browse files Browse the repository at this point in the history
  • Loading branch information
Forsworns committed Nov 26, 2021
1 parent 52778c4 commit e04b05a
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 18 deletions.
1 change: 1 addition & 0 deletions .mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pull_request_rules:
conditions:
- author~=^dependabot(|-preview)\[bot\]$
- check-success=CI
- check-success=Platforms
actions:
merge:
method: squash
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ fmt:
unit: unit_single unit_parallel

unit_single:
cargo test -- --ignored --test-threads=1
cargo test -- --ignored --test-threads=1 --nocapture

unit_parallel:
cargo test
cargo test -- --nocapture

.PHONY: clean clippy doc fmt unit unit_single unit_parallel check
2 changes: 1 addition & 1 deletion sentinel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ cfg-if = "1.0.0"
# enum
enum-map = "1.1.0"
# num_enum = "0.5.2"
time = "0.3.5"
time = { version = "0.3.5", features = ["formatting", "macros"] }
# serialize/deserialize
serde = { version = "1.0.126", features = ["derive"] }
serde_json = "1.0.64"
Expand Down
2 changes: 0 additions & 2 deletions sentinel/src/core/hotspot/param_metric.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use time::PreciseTime;

use super::*;
use crate::base::ParamKey;
use std::any::Any;
Expand Down
12 changes: 9 additions & 3 deletions sentinel/src/core/stat/base/leap_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,8 @@ impl<T: MetricTrait> LeapArray<T> {

#[cfg(test)]
pub(self) fn get_valid_head(&self) -> Result<Arc<BucketWrap<T>>> {
println!("bucket_len_ms: {}", self.bucket_len_ms);
println!("curr time: {}", curr_time_millis());
let idx = self.time2idx(curr_time_millis() + (self.bucket_len_ms as u64)) as usize;
println!("idx: {}", idx);
let bucket = self.array[idx].clone();
println!("{:?}", bucket);
if bucket.is_deprecated(curr_time_millis(), self.interval_ms as u64) {
Expand Down Expand Up @@ -308,17 +306,25 @@ mod test {
#[ignore]
fn valid_head() {
let sample_count = 10;
let interval_ms = 1000;
cfg_if::cfg_if! {
if #[cfg(any(windows, target_os = "macos"))]{
let interval_ms = 10000;
}else{
let interval_ms = 1000;
}
}
let bucket_len_ms = (interval_ms / sample_count) as u64;
let mut arr = LeapArrayAtomicU64::new(sample_count, interval_ms).unwrap();

let window = time::Duration::from_millis(bucket_len_ms);
for i in 1..=(sample_count as u64) {
thread::sleep(window);
println!("{}: curr time: {}", i, curr_time_millis());
arr.current_bucket()
.unwrap()
.value()
.store(i, Ordering::SeqCst);
println!("{}: {:?}", i, arr.current_bucket());
}
thread::sleep(window);
let head = arr.get_valid_head().unwrap();
Expand Down
5 changes: 4 additions & 1 deletion sentinel/src/core/system_metric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ pub fn init_cpu_collector(cpu_interval: u32) {
*CURRENT_CPU.lock().unwrap() = cpu_percent;
utils::sleep_for_ms(cpu_interval as u64);
});
})
});
// Windows needs more time to start the collector thread
#[cfg(windows)]
utils::sleep_for_ms(400);
}

#[inline]
Expand Down
20 changes: 11 additions & 9 deletions sentinel/src/utils/time.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
use lazy_static::lazy_static;
use time::{Duration, OffsetDateTime};
use time::{macros::format_description, Duration, OffsetDateTime};

lazy_static! {
static ref UNIX_TIME_UNIT_OFFSET: i128 =
(Duration::millisecond() / Duration::nanosecond()) as i128;
static ref UNIX_TIME_UNIT_OFFSET: i128 = (Duration::MILLISECOND / Duration::NANOSECOND) as i128;
}

const TIME_FORMAT: &str = "%F %T";
const DATE_FORMAT: &str = "%F";

#[inline]
pub fn unix_time_unit_offset() -> u64 {
*UNIX_TIME_UNIT_OFFSET as u64
Expand All @@ -32,19 +28,25 @@ fn cal_curr_time_millis() -> u64 {
#[inline]
pub fn format_time_millis(ts_millis: u64) -> String {
OffsetDateTime::from_unix_timestamp_nanos(milli2nano(ts_millis))
.format(time::Format::Custom(TIME_FORMAT.into()))
.unwrap()
.format(format_description!("[hour]:[minute]:[second]"))
.unwrap()
}

#[inline]
pub fn format_date(ts_millis: u64) -> String {
OffsetDateTime::from_unix_timestamp_nanos(milli2nano(ts_millis))
.format(time::Format::Custom(DATE_FORMAT.into()))
.unwrap()
.format(format_description!("[hour]:[minute]:[second]"))
.unwrap()
}

#[inline]
pub fn format_time_nanos_curr() -> String {
OffsetDateTime::from_unix_timestamp_nanos(curr_time_nanos())
.format(time::Format::Custom(TIME_FORMAT.into()))
.unwrap()
.format(format_description!("[hour]:[minute]:[second]"))
.unwrap()
}

pub fn curr_time_millis() -> u64 {
Expand Down

0 comments on commit e04b05a

Please sign in to comment.