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

[ExeUnit] Limit the subset of SGX metrics #735

Merged
merged 3 commits into from
Nov 16, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions exe-unit/src/runtime/process.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use crate::error::Error;
use crate::message::{ExecuteCommand, SetRuntimeMode, SetTaskPackagePath, Shutdown};
use crate::output::{forward_output, vec_to_string};
use crate::process::kill;
use crate::process::ProcessTree;
use crate::process::SystemError;
use crate::process::{kill, ProcessTree, SystemError};
use crate::runtime::event::EventMonitor;
use crate::runtime::{Runtime, RuntimeArgs, RuntimeMode};
use crate::ExeUnitContext;
Expand Down
86 changes: 56 additions & 30 deletions exe-unit/src/service/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,68 @@ impl MetricsService {
backlog_limit: Option<usize>,
supervise_caps: bool,
) -> Result<Self, MetricError> {
let caps = move |ctx: &ExeUnitContext, id| match supervise_caps {
let caps = move |ctx: &ExeUnitContext, id: &str| match supervise_caps {
true => ctx.agreement.usage_limits.get(id).cloned(),
_ => None,
};
let metrics: HashMap<String, MetricProvider> = vec![
let metrics = Self::metrics(&ctx, backlog_limit, caps);

if let Some(e) = ctx
.agreement
.usage_vector
.iter()
.find(|e| !metrics.contains_key(*e))
{
return Err(MetricError::Unsupported(e.to_string()));
}

Ok(MetricsService {
usage_vector: ctx.agreement.usage_vector.clone(),
metrics,
})
}

#[cfg(feature = "sgx")]
pub fn usage_vector() -> Vec<String> {
vec![TimeMetric::ID.to_string()]
}

#[cfg(feature = "sgx")]
fn metrics<F: Fn(&ExeUnitContext, &str) -> Option<f64>>(
ctx: &ExeUnitContext,
backlog_limit: Option<usize>,
caps: F,
) -> HashMap<String, MetricProvider> {
vec![(
TimeMetric::ID.to_string(),
MetricProvider::new(TimeMetric::default(), Some(1), caps(ctx, TimeMetric::ID)),
)]
.into_iter()
.collect()
}

#[cfg(not(feature = "sgx"))]
pub fn usage_vector() -> Vec<String> {
vec![
TimeMetric::ID.to_string(),
CpuMetric::ID.to_string(),
MemMetric::ID.to_string(),
StorageMetric::ID.to_string(),
]
}

#[cfg(not(feature = "sgx"))]
fn metrics<F: Fn(&ExeUnitContext, &str) -> Option<f64>>(
ctx: &ExeUnitContext,
backlog_limit: Option<usize>,
caps: F,
) -> HashMap<String, MetricProvider> {
vec![
(
CpuMetric::ID.to_string(),
MetricProvider::new(
CpuMetric::default(),
backlog_limit.clone(),
backlog_limit,
caps(ctx, CpuMetric::ID),
),
),
Expand All @@ -59,32 +111,7 @@ impl MetricsService {
),
]
.into_iter()
.collect();

if let Some(e) = ctx
.agreement
.usage_vector
.iter()
.find(|e| !metrics.contains_key(*e))
{
return Err(MetricError::Unsupported(e.to_string()));
}

Ok(MetricsService {
usage_vector: ctx.agreement.usage_vector.clone(),
metrics,
})
}

pub fn usage_vector() -> Vec<String> {
// TODO: sgx
[
TimeMetric::ID.to_string(),
CpuMetric::ID.to_string(),
MemMetric::ID.to_string(),
StorageMetric::ID.to_string(),
]
.to_vec()
.collect()
}
}

Expand All @@ -107,7 +134,6 @@ impl Handler<GetMetrics> for MetricsService {
fn handle(&mut self, _: GetMetrics, _: &mut Self::Context) -> Self::Result {
let mut metrics = vec![0f64; self.usage_vector.len()];

#[cfg(not(feature = "sgx"))]
for (i, name) in self.usage_vector.iter().enumerate() {
let metric = self
.metrics
Expand Down