-
Notifications
You must be signed in to change notification settings - Fork 2
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
change: metric data save in data-layer #185
Conversation
…TCLab-Inc/wave-autoscale into 183-metric-data-save-in-memory
core/data-layer/src/data_layer.rs
Outdated
loop { | ||
// check size :: buffersize - total size < 0 (None) => remove target data | ||
if metric_buffer_size_kb | ||
.checked_sub(subtract_total_size as u64) | ||
.is_none() | ||
{ | ||
let Some(front_source_metrics_metadata) = source_metrics_metadata.pop_front() else { | ||
break; | ||
}; | ||
subtract_total_size -= front_source_metrics_metadata.2; // oldest metadata size | ||
remove_target_data.append(&mut vec![front_source_metrics_metadata]); | ||
continue; | ||
} | ||
break; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
loop { | |
// check size :: buffersize - total size < 0 (None) => remove target data | |
if metric_buffer_size_kb | |
.checked_sub(subtract_total_size as u64) | |
.is_none() | |
{ | |
let Some(front_source_metrics_metadata) = source_metrics_metadata.pop_front() else { | |
break; | |
}; | |
subtract_total_size -= front_source_metrics_metadata.2; // oldest metadata size | |
remove_target_data.append(&mut vec![front_source_metrics_metadata]); | |
continue; | |
} | |
break; | |
} | |
loop { | |
// check size :: buffersize - total size < 0 (None) => remove target data | |
if metric_buffer_size_kb | |
.checked_sub(subtract_total_size as u64) | |
.is_some() { | |
break; | |
} | |
let Some(front_source_metrics_metadata) = source_metrics_metadata.pop_front() else { | |
break; | |
}; | |
subtract_total_size -= front_source_metrics_metadata.2; // oldest metadata size | |
remove_target_data.append(&mut vec![front_source_metrics_metadata]); | |
} |
core/data-layer/src/data_layer.rs
Outdated
remove_target_data | ||
.iter() | ||
.for_each(|(metric_id, ulid, size)| { | ||
let Some(metric_id_data) = source_metrics.get_mut(metric_id) else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let Some(metric_id_data) = source_metrics.get_mut(metric_id) else { | |
let Some(source_metrics_map) = source_metrics.get_mut(metric_id) else { |
to match variable names as shown below (source_metrics_map)
core/data-layer/src/data_layer.rs
Outdated
let source_metrics_data = SOURCE_METRICS_DATA.clone(); | ||
let Ok(mut source_metrics_data) = source_metrics_data.write() else { | ||
error!("[DataLayer::new()] Failed to get the lock of source_metrics_data and try to create a new one"); | ||
return DataLayer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should do panic here because it cannot get the static variable
core/data-layer/src/data_layer.rs
Outdated
}; | ||
subtract_total_size -= front_source_metrics_metadata.2; // oldest metadata size | ||
remove_target_data.append(&mut vec![front_source_metrics_metadata]); | ||
continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove continue;
let _ = ctx.globals().set( | ||
"get", | ||
rquickjs::prelude::Func::new("get", move |args: rquickjs::Object| -> Result<f64, rquickjs::Error> { | ||
let metric_id = args.get::<String, String>("metric_id".to_string()).map_err(|_| rquickjs::Error::Exception)?; | ||
let name = args.get::<String, String>("name".to_string()).map_err(|_| rquickjs::Error::Exception)?; | ||
let tags = args.get::<String, HashMap<String, String>>("tags".to_string()); | ||
let tags = match tags { | ||
Ok(tags) => tags, | ||
Err(_) => HashMap::new() | ||
}; | ||
let stats = args.get::<String, String>("stats".to_string()).map_err(|_| rquickjs::Error::Exception)?; | ||
let period_sec = args.get::<String, u64>("period_sec".to_string()).map_err(|_| rquickjs::Error::Exception)?; | ||
context_global_get_func(metric_id, name, tags, stats, period_sec, metric_ids_values.clone()) | ||
get_in_js(args) | ||
}), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we do not need to have the closure function move |args: .....
Types of changes
What this PR does / why we need it:
Metric data save in memory (daya-layer)
Which issue/s this PR fixes
fixes #183
How Has This Been Tested?
Checklist: