Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions charts/cmk-rustik/templates/metrics-cache/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ spec:
- --writer-allowlist={{ .Release.Namespace }}:{{ include "rustik.fullname" . }}-metrics-fetcher
- --cluster-name={{ required "clusterName is required (there is no safe default: it names every generated host)" .Values.clusterName }}
- --cluster-host-name={{ required "clusterHostName is required (it must exactly match the Checkmk host representing this cluster)" .Values.clusterHostName }}
- --kubelet-stats-cache-ttl={{ .Values.metricsCache.kubeletStatsCacheTtl }}
- --linux-agent-cache-ttl={{ .Values.metricsCache.linuxAgentCacheTtl }}
{{- if .Values.hostLabels.importAllAnnotations }}
{{- if .Values.hostLabels.importKeyPattern }}
{{ fail "hostLabels.importKeyPattern should not be set while hostLabels.importAllAnnotations is true" }}
Expand Down
8 changes: 8 additions & 0 deletions charts/cmk-rustik/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ metricsCache:
# Inherits top-level logLevel by default.
logLevel: ""

# kubeletStatsCacheTtl is how long (seconds) kubelet stats entries are
# persisted in the cache before expiring.
kubeletStatsCacheTtl: 120

# linuxAgentCacheTtl is how long (seconds) Linux agent entries are
# persisted in the cache before expiring.
linuxAgentCacheTtl: 120

# extraVolumes is volume definitions to add to the Pod in the Deployment.
extraVolumes: []
# extraVolumeMounts is volume mounts to mount in the metrics-cache container.
Expand Down
35 changes: 31 additions & 4 deletions metrics-cache/src/cli_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,21 @@ pub struct CliArgs {
)]
pub writer_allowlist: Vec<String>,

/// How long (seconds) entries are persisted in the cache
/// How long (seconds) kubelet stats entries are persisted in the cache
#[arg(
short = 't',
long = "cache-ttl",
long = "kubelet-stats-cache-ttl",
value_parser = parse_duration_secs,
default_value = "120"
)]
pub cache_ttl: Duration,
pub kubelet_stats_cache_ttl: Duration,

/// How long (seconds) Linux agent entries are persisted in the cache
#[arg(
long = "linux-agent-cache-ttl",
value_parser = parse_duration_secs,
default_value = "120"
)]
pub linux_agent_cache_ttl: Duration,

/// How verbose to log
#[arg(
Expand Down Expand Up @@ -398,6 +405,26 @@ mod tests {
}
}

#[test]
fn cache_ttls_have_expected_defaults() {
let args = parse(&[]).expect("minimal args should parse");
assert_eq!(args.kubelet_stats_cache_ttl, Duration::from_secs(120));
assert_eq!(args.linux_agent_cache_ttl, Duration::from_secs(120));
}

#[test]
fn cache_ttls_parse_from_flags() {
let args = parse(&[
"--kubelet-stats-cache-ttl",
"30",
"--linux-agent-cache-ttl",
"60",
])
.expect("cache TTL flags should parse");
assert_eq!(args.kubelet_stats_cache_ttl, Duration::from_secs(30));
assert_eq!(args.linux_agent_cache_ttl, Duration::from_secs(60));
}

#[test]
fn push_interval_parse_correctly() {
for interval in ["1", "80"] {
Expand Down
2 changes: 2 additions & 0 deletions metrics-cache/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ impl AppState<Client> {
reader_allowlist: args.reader_allowlist.clone(),
writer_allowlist: args.writer_allowlist.clone(),
kubelet_stats_summary_cache: Cache::builder()
.time_to_live(args.kubelet_stats_cache_ttl)
.max_capacity(MAX_SUPPORTED_KUBERNETES_NODES)
.build(),
system_agent_cache: Cache::builder()
.time_to_live(args.linux_agent_cache_ttl)
.max_capacity(MAX_SUPPORTED_KUBERNETES_NODES)
.build(),
host_settings: host_settings.into(),
Expand Down
Loading