Skip to content

Improved support for CGroups to fix CPU usage values - #180

Merged
CodeDrivenMitch merged 1 commit into
axon-4from
fix/cpu-metrics-container-aware
Sep 22, 2026
Merged

CodeDrivenMitch merged 1 commit into
axon-4from
fix/cpu-metrics-container-aware

Conversation

@CodeDrivenMitch

Copy link
Copy Markdown
Collaborator

The current implementation of the CpuMetricsProvider uses the OperatingSystemMXBean's cpu usage properties to report them to Platform. However, its internal implementation divides cpu usage by the CFS time, instead of the wall time, thus reporting only the CPU usage in the time intervals it has any cpu usage. This specially becomes significant at 0.2 cpu request limit or lower, or applications that run idle more (no event processors constantly ticking).

So, this PR changes the CpuMetricsProvider to use wall-clock time and /proc/stat when available. It will fall back to the old method if unavailable.

This issue also surfaced that it's very useful for us to know the configuration of the jvm and container. As such, the setup payload was extended with many (non-sensitive) system properties, such as os and jvm vendors and versions, available processors, garbage collection, and more.

Disclaimer: Most of this has been created with the help of Claude. I have some basic Linux knowledge, and through this story I've read up on it. I've confirmed CGroup and /proc/stat format against our development containers, and it will work. In cases it doesn't, I've wrapped everything in a runCatching, so it doesn't affect the functionality.

Once merged, I will run Axoniq Platform with this first, to see the outcome in a real environment. Then, we will port it to the Axoniq Framework 5 main branch.

The current implementation of the CpuMetricsProvider uses the `OperatingSystemMXBean`'s cpu usage properties to report them to Platform. However, its internal implementation divides cpu usage by the CFS time, instead of the wall time, thus reporting only the CPU usage in the time intervals it has any cpu usage. This specially becomes significant at 0.2 cpu request limit or lower, or applications that run idle more (no event processors constantly ticking).

So, this PR changes the CpuMetricsProvider to use wall-clock time and /proc/stat when available. It will fall back to the old method if unavailable.

This issue also surfaced that it's very useful for us to know the configuration of the jvm and container. As such, the setup payload was extended with many (non-sensitive) system properties, such as os and jvm vendors and versions, available processors, garbage collection, and more.

Disclaimer: Most of this has been created with the help of Claude. I have some basic Linux knowledge, and through this story I've read up on it. I've confirmed CGroup and /proc/stat format against our development containers, and it will work. In cases it doesn't, I've wrapped everything in a `runCatching`, so it doesn't affect the functionality.

Once merged, I will run Axoniq Platform with this first, to see the outcome in a real environment. Then, we will port it to the Axoniq Framework 5 main branch.
@CodeDrivenMitch
CodeDrivenMitch requested a review from a team September 22, 2026 11:57
@CodeDrivenMitch CodeDrivenMitch self-assigned this Sep 22, 2026
@CodeDrivenMitch
CodeDrivenMitch requested review from Andrew-deVillier and stefanmirkovic and removed request for a team September 22, 2026 11:57
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

val versions: Versions,
val upcasters: List<String>,
val features: SupportedFeatures = SupportedFeatures(),
val runtime: RuntimeInformation? = null,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Non-blocking question: Is inspector's SetupPayload deserialization confirmed to tolerate unknown fields from newer clients, or is that worth a quick check before the client release goes out?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, this is set up this way by design due to supporting multiple versions

image

@CodeDrivenMitch
CodeDrivenMitch merged commit ea91b36 into axon-4 Sep 22, 2026
3 of 4 checks passed
@CodeDrivenMitch

Copy link
Copy Markdown
Collaborator Author

Ported to the AF5 line in #182.

This was referenced Sep 23, 2026
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