Skip to content

Commit

Permalink
[PR Feedback] Rename health_check duration field to execution
Browse files Browse the repository at this point in the history
More self-describing this way.

Signed-off-by: Christopher Maier <cmaier@chef.io>
  • Loading branch information
christophermaier committed May 15, 2019
1 parent 9002dcb commit 2e11c8f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
3 changes: 1 addition & 2 deletions components/sup/protocols/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ message ServiceStoppedEvent {
message HealthCheckEvent {
EventMetadata event_metadata = 1;
ServiceMetadata service_metadata = 2;
// The result of the health check execution
HealthCheck result = 3;
// If the service has a health check hook script, how long it took
// to execute.
google.protobuf.Duration duration = 4;
google.protobuf.Duration execution = 4;
}
6 changes: 4 additions & 2 deletions components/sup/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,15 @@ pub fn service_stopped(service: &Service) {
}
}

pub fn health_check(service: &Service, check_result: HealthCheck, duration: Option<Duration>) {
/// `execution` will be `Some` if the service had a hook to run, and
/// records how long it took that hook to execute completely.
pub fn health_check(service: &Service, check_result: HealthCheck, execution: Option<Duration>) {
if stream_initialized() {
let check_result: types::HealthCheck = check_result.into();
publish(HealthCheckEvent { service_metadata: Some(service.to_service_metadata()),
event_metadata: None,
result: i32::from(check_result),
duration: duration.map(Into::into), });
execution: execution.map(Into::into), });
}
}

Expand Down
6 changes: 3 additions & 3 deletions components/sup/src/manager/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -936,14 +936,14 @@ impl Service {
// Additionally, we'll only send the time with the health
// check event if there's actually a hook that runs. We'll
// default to there not being a hook, though.
let mut event_duration = None;
let mut execution_duration = None;

let check_result = if let Some(ref hook) = self.hooks.health_check {
let event_start = Instant::now();
let result = hook.run(&self.service_group,
&self.pkg,
self.svc_encrypted_password.as_ref());
event_duration = Some(event_start.elapsed());
execution_duration = Some(event_start.elapsed());
result
} else {
match self.supervisor.status() {
Expand All @@ -966,7 +966,7 @@ impl Service {
self.schedule_special_health_check();
}
self.health_check = check_result;
event::health_check(&self, check_result, event_duration);
event::health_check(&self, check_result, execution_duration);
self.cache_health_check(check_result);
}

Expand Down

0 comments on commit 2e11c8f

Please sign in to comment.