Skip to content

feat: add linux agent data into metrics-cache - #24

Open
racicLuka wants to merge 4 commits into
masterfrom
CMK-36613-linux-agent-ingest
Open

feat: add linux agent data into metrics-cache#24
racicLuka wants to merge 4 commits into
masterfrom
CMK-36613-linux-agent-ingest

Conversation

@racicLuka

Copy link
Copy Markdown

CMK-36613

@racicLuka
racicLuka force-pushed the CMK-36613-linux-agent-ingest branch from 2783cc5 to fa04ca7 Compare July 31, 2026 08:07
@racicLuka
racicLuka requested a review from relrod July 31, 2026 08:26
Comment thread metrics-cache/src/state.rs Outdated
pub reader_allowlist: Vec<String>,
pub writer_allowlist: Vec<String>,
pub kubelet_stats_summary_cache: Cache<String, Arc<MetricsFetcherIngestion<StatsSummary>>>,
pub linux_agent_cache: Cache<String, Arc<String>>,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Consider Cache<String, Arc<MetricsFetcherIngestion<String>>

Or better, newtype the String and have Cache<String, MetricsFetcherIngestion<LinuxAgentOutput>>

You can follow the kubelet stats ingestion as an example - the advantage here is that we can inject the timestamp of the last received payload and use it for self-health reporting (for example, warn if we haven't gotten a agent payload in X minutes).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Actually (this goes with my comment below, about non-utf-8 output), I'd go even further here and use Bytes instead of String to be safe. Otherwise "verbatim" is questionable in the doc comment in ingest.rs 😅

Comment on lines +14 to +15
const AGENT_PATH: &str = "/usr/local/bin/check_mk_agent";
const AGENT_TIMEOUT: Duration = Duration::from_secs(5);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can be later, but maybe eventually we should take both of these from CLI args and drop them into the helm chart. Definitely the timeout.

The agent path I could be convinced either way, it ties this code to how our image is constructed but realistically if someone is using it, they will be using our image (and if they "fork" it and want to run a different agent, they could just overwrite /usr/local/bin/check_mk_agent in their custom image).

Comment thread metrics-fetcher/src/linux_agent.rs Outdated
Comment thread metrics-fetcher/src/linux_agent.rs Outdated
Comment thread metrics-fetcher/src/main.rs Outdated
let kubelet_scrape = tokio::spawn(kubelet_stats_summary_scraper.loop_push_scrape());
let _ = tokio::try_join!(kubelet_scrape);
let linux_agent_scrape = tokio::spawn(linux_agent_scraper.loop_push_scrape());
let _ = tokio::try_join!(kubelet_scrape, linux_agent_scrape);

@relrod relrod Aug 1, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would consider tokio::select! here (see metrics-cache/src/main.rs for an example).

Otherwise right now (also in the pre-existing code) we'll exit 0 with no useful output at all, if somehow we panic in either loop. I'd copy the select! + log + bail pattern from metrics-cache main().

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Nice little trick. Needed to inform myself about tokio::select!

Comment thread metrics-fetcher/src/payload.rs Outdated
Comment thread metrics-cache/src/handlers/ingest.rs Outdated
Comment thread metrics-cache/src/handlers/ingest.rs Outdated
Comment thread metrics-cache/src/handlers/ingest.rs Outdated
use crate::handlers::app;
use crate::state::tests::{MockValidator, test_app_state_with_validator};

fn no_pull_agent() -> PullAgentMiddlewareConfig {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If you wanted instead of this I'd also be okay with a (manual) Default instance for PullAgentMiddlewareConfig that sets auth_enabled: true, shared_secret: None (this way if the default ever somehow gets used in non-test code, it defaults closed).

Thoughts?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Makes perfect sense

Comment thread metrics-fetcher/src/payload.rs Outdated
fn content_type(&self) -> &'static str {
match self {
Self::KubeletStatsSummary(_) => "application/json",
Self::CheckmkLinuxAgent { .. } => "text/plain; charset=utf-8",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we know that it's utf-8? I wonder if there are cases (particularly I am thinking of "someone patches our image to add a plugin") where the agent might produce non-utf-8 output?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

You are right, we do not 100% know that it's utf-8. This should be safer.

Comment thread metrics-cache/src/state.rs Outdated
pub reader_allowlist: Vec<String>,
pub writer_allowlist: Vec<String>,
pub kubelet_stats_summary_cache: Cache<String, Arc<MetricsFetcherIngestion<StatsSummary>>>,
pub linux_agent_cache: Cache<String, Arc<String>>,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Actually (this goes with my comment below, about non-utf-8 output), I'd go even further here and use Bytes instead of String to be safe. Otherwise "verbatim" is questionable in the doc comment in ingest.rs 😅

@relrod

relrod commented Aug 1, 2026

Copy link
Copy Markdown
Member

Some thoughts inline, but I agree with the general shape of this. Nice work! 🙂

@racicLuka
racicLuka force-pushed the CMK-36613-linux-agent-ingest branch 2 times, most recently from b052b7c to c528387 Compare August 10, 2026 19:58
@racicLuka
racicLuka requested a review from relrod August 10, 2026 20:03

@relrod relrod left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Generally looks good, just a few minor tweaks, then I think this is good to go!

Comment thread metrics-cache/src/handlers/mod.rs Outdated
Comment thread metrics-cache/src/state.rs Outdated
Comment thread metrics-cache/src/handlers/mod.rs Outdated
- linux_agent_cache stores MetricsFetcherIngestion<Bytes> instead of a
  bare String/Arc<String>, matching kubelet_stats_summary_cache and
  giving self-health reporting a received_at timestamp to use later
- switch the ingest handler and cache to Bytes throughout, since
  check_mk_agent plugin output isn't guaranteed to be valid UTF-8; drop
  the false "charset=utf-8" claim on the content-type header sent by
  metrics-fetcher
- simplify NODE_NAME lookup and agent-timeout handling in
  metrics-fetcher's LinuxAgentScraper per suggested diffs
- fix metrics-fetcher main() silently exiting 0 if either scrape loop
  panics, by select!+log+bail on the join handles like metrics-cache's
  main() does
- move the linux_agent ingest router tests into handlers/mod.rs, since
  they exercise routing/middleware rather than the handler itself; add
  a manual, fail-closed Default for PullAgentMiddlewareConfig instead
  of an ad-hoc no_pull_agent() test helper
- drop the payload.rs unit tests that only asserted match arms
@racicLuka
racicLuka force-pushed the CMK-36613-linux-agent-ingest branch from c528387 to a3a33fb Compare August 12, 2026 16:11
@racicLuka
racicLuka requested a review from relrod August 12, 2026 16:14

@relrod relrod left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

:shipit:

use super::*;
use crate::state::tests::test_app_state;

/// Exercises the handler directly (no router, no auth middleware) — this

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi, Claude 🤣

@relrod

relrod commented Aug 13, 2026

Copy link
Copy Markdown
Member

Also: Note, we'll want to snapshot the cache at snapshot creation time when you work on the rendering part. Otherwise it could change out from under us as we're rendering sections.

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.

2 participants