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

change: metric data save in data-layer #185

Merged
merged 17 commits into from
Nov 3, 2023
Merged

Conversation

Ari-suhyeon
Copy link
Contributor

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • DevOps process (non-breaking change which improves efficiency and reliability for CI/CD)
  • Documentation only

What this PR does / why we need it:

Metric data save in memory (daya-layer)

  • As-Is: metric data save in database
  • default buffer: 500MB
  • SourceMetrics add item: create_dt
  • add error logs

Which issue/s this PR fixes

fixes #183

How Has This Been Tested?

  • moon run tested - check the buffer size of stored data
  • Unit Test has been tested.

Checklist:

@Ari-suhyeon Ari-suhyeon added this to the v0.0.15 milestone Oct 24, 2023
@Ari-suhyeon Ari-suhyeon self-assigned this Oct 24, 2023
@Ari-suhyeon Ari-suhyeon linked an issue Oct 24, 2023 that may be closed by this pull request
core/data-layer/src/data_layer.rs Outdated Show resolved Hide resolved
Comment on lines 769 to 783
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;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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]);
}

remove_target_data
.iter()
.for_each(|(metric_id, ulid, size)| {
let Some(metric_id_data) = source_metrics.get_mut(metric_id) else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 Show resolved Hide resolved
core/data-layer/src/data_layer.rs Outdated Show resolved Hide resolved
core/data-layer/src/data_layer.rs Outdated Show resolved Hide resolved
core/data-layer/src/data_layer.rs Show resolved Hide resolved
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 {
Copy link
Member

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

};
subtract_total_size -= front_source_metrics_metadata.2; // oldest metadata size
remove_target_data.append(&mut vec![front_source_metrics_metadata]);
continue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove continue;

Comment on lines 159 to 164
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)
}),
);
Copy link
Member

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: .....

@pueding pueding merged commit c96666c into main Nov 3, 2023
1 check passed
@pueding pueding deleted the 183-metric-data-save-in-memory branch November 3, 2023 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Metric data save in memory (data-layer)
2 participants