Skip to content

Commit 6d6baef

Browse files
authored
feat: introduce agent-control health-check configuration (#1334)
1 parent 2ec3df8 commit 6d6baef

File tree

8 files changed

+44
-22
lines changed

8 files changed

+44
-22
lines changed

agent-control/src/agent_control.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1+
pub mod agent_id;
12
pub mod config;
23
pub mod config_storer;
4+
pub mod config_validator;
35
pub mod defaults;
46
pub mod error;
5-
pub(super) mod event_handler;
6-
pub use agent_control::*;
7-
#[allow(clippy::module_inception)]
8-
mod agent_control;
9-
pub mod agent_id;
10-
pub mod config_validator;
117
pub mod http_server;
128
pub mod pid_cache;
139
pub mod resource_cleaner;
1410
pub mod run;
1511
pub mod uptime_report;
1612
pub mod version_updater;
13+
14+
pub(super) mod event_handler;
15+
16+
mod health_checker;
17+
18+
pub use agent_control::*;
19+
#[allow(clippy::module_inception)]
20+
mod agent_control;

agent-control/src/agent_control/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use super::agent_id::AgentID;
22
use super::http_server::config::ServerConfig;
33
use super::uptime_report::UptimeReportConfig;
4+
use crate::agent_control::health_checker::AgentControlHealthCheckerConfig;
45
use crate::http::config::ProxyConfig;
56
use crate::instrumentation::config::logs::config::LoggingConfig;
67
use crate::opamp::auth::config::AuthConfig;
@@ -51,6 +52,9 @@ pub struct AgentControlConfig {
5152

5253
#[serde(default)]
5354
pub uptime_report: UptimeReportConfig,
55+
56+
#[serde(default)]
57+
pub health_check: AgentControlHealthCheckerConfig,
5458
}
5559

5660
#[derive(Error, Debug)]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use serde::Deserialize;
2+
3+
use crate::health::health_checker::HealthCheckInterval;
4+
5+
/// Holds the Agent Control configuration fields for setting up the health-check.
6+
#[derive(Debug, Default, Clone, PartialEq, Deserialize)]
7+
pub struct AgentControlHealthCheckerConfig {
8+
interval: HealthCheckInterval,
9+
}

agent-control/src/agent_type/runtime_config.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,9 @@ pub mod templateable_value;
1313
use super::definition::Variables;
1414
use super::error::AgentTypeError;
1515
use super::templates::Templateable;
16-
use duration_str::deserialize_duration;
1716
use k8s::K8s;
1817
use onhost::OnHost;
1918
use serde::Deserialize;
20-
use std::time::Duration;
21-
use wrapper_with_default::WrapperWithDefault;
22-
23-
const DEFAULT_HEALTH_CHECK_INTERVAL: Duration = Duration::from_secs(60);
2419

2520
/// Strict structure that describes how to start a given agent with all needed binaries, arguments, env, etc.
2621
#[derive(Debug, Deserialize, Clone, PartialEq)]
@@ -107,10 +102,6 @@ impl Templateable for Runtime {
107102
}
108103
}
109104

110-
#[derive(Debug, Deserialize, Clone, Copy, PartialEq, WrapperWithDefault)]
111-
#[wrapper_default_value(DEFAULT_HEALTH_CHECK_INTERVAL)]
112-
pub struct HealthCheckInterval(#[serde(deserialize_with = "deserialize_duration")] Duration);
113-
114105
#[cfg(test)]
115106
mod tests {
116107
use super::*;

agent-control/src/agent_type/runtime_config/health_config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use wrapper_with_default::WrapperWithDefault;
55

66
use crate::agent_type::definition::Variables;
77
use crate::agent_type::error::AgentTypeError;
8-
use crate::agent_type::runtime_config::HealthCheckInterval;
98
use crate::agent_type::templates::Templateable;
9+
use crate::health::health_checker::HealthCheckInterval;
1010

1111
use super::templateable_value::TemplateableValue;
1212

agent-control/src/agent_type/runtime_config/k8s.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::agent_type::definition::Variables;
22
use crate::agent_type::error::AgentTypeError;
3-
use crate::agent_type::runtime_config::HealthCheckInterval;
43
use crate::agent_type::templates::Templateable;
4+
use crate::health::health_checker::HealthCheckInterval;
55
use serde::Deserialize;
66
use std::collections::{BTreeMap, HashMap};
77

agent-control/src/health/health_checker.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
1-
use super::with_start_time::StartTime;
21
use crate::agent_control::agent_id::AgentID;
3-
use crate::agent_type::runtime_config::HealthCheckInterval;
42
use crate::event::SubAgentInternalEvent;
53
use crate::event::cancellation::CancellationMessage;
64
use crate::event::channel::{EventConsumer, EventPublisher};
7-
8-
use crate::health::with_start_time::HealthWithStartTime;
5+
use crate::health::with_start_time::{HealthWithStartTime, StartTime};
96
use crate::k8s;
107
use crate::sub_agent::identity::ID_ATTRIBUTE_NAME;
118
use crate::sub_agent::supervisor::starter::SupervisorStarterError;
129
use crate::utils::thread_context::{NotStartedThreadContext, StartedThreadContext};
10+
use duration_str::deserialize_duration;
11+
use serde::Deserialize;
1312
use std::thread::sleep;
1413
use std::time::{Duration, SystemTime, SystemTimeError};
1514
use tracing::{debug, error, info_span};
15+
use wrapper_with_default::WrapperWithDefault;
1616

1717
const HEALTH_CHECKER_THREAD_NAME: &str = "health_checker";
1818

19+
const DEFAULT_HEALTH_CHECK_INTERVAL: Duration = Duration::from_secs(60);
20+
1921
pub type StatusTime = SystemTime;
2022

23+
#[derive(Debug, Deserialize, Clone, Copy, PartialEq, WrapperWithDefault)]
24+
#[wrapper_default_value(DEFAULT_HEALTH_CHECK_INTERVAL)]
25+
pub struct HealthCheckInterval(#[serde(deserialize_with = "deserialize_duration")] Duration);
26+
2127
#[derive(Clone, Debug, PartialEq)]
2228
pub enum Health {
2329
Healthy(Healthy),
@@ -278,7 +284,6 @@ where
278284
break;
279285
}
280286
};
281-
282287
NotStartedThreadContext::new(HEALTH_CHECKER_THREAD_NAME, callback).start()
283288
}
284289

docs/CONFIG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ server:
9292
enabled: true # The status server is enabled by default
9393
```
9494

95+
### health_check
96+
97+
Configuration fields to set-up Agent Control health-check
98+
99+
```yaml
100+
health_check:
101+
interval: 120s # Defaults to 60s
102+
```
103+
95104
### self_instrumentation
96105

97106
Agent Control can be configured to instrument itself and report traces, logs and metrics through OpenTelemetry. If proxy is configured globally it will also apply to self-instrumentation.

0 commit comments

Comments
 (0)