Skip to content

fix: don't override log level from state for standalone agents#8784

Merged
pkoutsovasilis merged 4 commits intoelastic:mainfrom
pkoutsovasilis:fix/agent_standalone_stale_log_level
Jul 7, 2025
Merged

fix: don't override log level from state for standalone agents#8784
pkoutsovasilis merged 4 commits intoelastic:mainfrom
pkoutsovasilis:fix/agent_standalone_stale_log_level

Conversation

@pkoutsovasilis
Copy link
Contributor

@pkoutsovasilis pkoutsovasilis commented Jul 2, 2025

What does this PR do?

This PR fixes a bug where the log level for standalone Elastic Agent installations was incorrectly restored from the persisted state directory (/var/lib/elastic-agent-standalone/...) instead of being sourced from the current configuration file. This resulted in stale configuration values after updates to the ConfigMap, particularly when the pod was restarted without clearing the state directory.

The change ensures that for standalone mode, the log.level value is always taken from the configuration, not restored from previously persisted agent state. For managed (Fleet) mode, the previous behavior is preserved.

Why is it important?

This fix addresses an issue where changes to logging configuration were not taking effect unless the agent's state directory was manually deleted. This led to operational confusion and could cause logs to be emitted at incorrect verbosity levels.

Ensuring that the standalone agent reliably reflects the current configuration helps users maintain observability and avoid side effects like duplicated logs when restarting pods.

Checklist

  • I have read and understood the pull request guidelines of this project.
  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in ./changelog/fragments using the changelog tool
  • I have added an integration test or an E2E test

Disruptive User Impact

This change should not cause disruption. It fixes the logic so that standalone agents correctly reflect updated configuration values after pod restarts, without requiring manual state cleanup. Users relying on previously persisted log levels (instead of ConfigMap changes) may see a difference in behavior, but this aligns with the intended functionality.

How to test this PR locally

helm install elastic-agent ./deploy/helm/elastic-agent -n kube-system  --set outputs.default.type=ESPlainAuthBasic --set outputs.default.url='...' --set outputs.default.username='...' --set outputs.default.password='...' --set agent.presets.perNode.agent.logging.level=info

helm upgrade elastic-agent ./deploy/helm/elastic-agent -n kube-system  --set outputs.default.type=ESPlainAuthBasic --set outputs.default.url='...' --set outputs.default.username='...' --set outputs.default.password='...' --set agent.presets.perNode.agent.logging.level=debug

Related issues

@pkoutsovasilis pkoutsovasilis self-assigned this Jul 2, 2025
@pkoutsovasilis pkoutsovasilis added bug Something isn't working Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team skip-changelog backport-active-all Automated backport with mergify to all the active branches labels Jul 2, 2025
@pkoutsovasilis pkoutsovasilis marked this pull request as ready for review July 2, 2025 13:26
@pkoutsovasilis pkoutsovasilis requested a review from a team as a code owner July 2, 2025 13:26
@elasticmachine
Copy link
Contributor

Pinging @elastic/elastic-agent-control-plane (Team:Elastic-Agent-Control-Plane)

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

History

cc @pkoutsovasilis

swiatekm
swiatekm previously approved these changes Jul 2, 2025
Copy link
Contributor

@swiatekm swiatekm left a comment

Choose a reason for hiding this comment

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

LGTM, though I'd love to have a simple unit test for this function.

@pkoutsovasilis
Copy link
Contributor Author

LGTM, though I'd love to have a simple unit test for this function.

more than a fair point, lemme check what I can cook for it

@pkoutsovasilis pkoutsovasilis force-pushed the fix/agent_standalone_stale_log_level branch from e1eb762 to 7ee14ed Compare July 3, 2025 06:37
@pkoutsovasilis pkoutsovasilis requested a review from swiatekm July 3, 2025 09:16
Copy link
Member

@pchila pchila left a comment

Choose a reason for hiding this comment

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

LGTM

@pkoutsovasilis pkoutsovasilis merged commit e8f759b into elastic:main Jul 7, 2025
19 checks passed
@github-actions
Copy link
Contributor

github-actions bot commented Jul 7, 2025

@Mergifyio backport 8.17 8.18 8.19 9.0 9.1

@mergify
Copy link
Contributor

mergify bot commented Jul 7, 2025

mergify bot pushed a commit that referenced this pull request Jul 7, 2025
* fix: don't override log level from state for standalone agents

* doc: add changelog fragment

* fix: add unit test for NewAgentInfoWithLog

* fix: derive unprivileged from utils.HasRoot

(cherry picked from commit e8f759b)
mergify bot pushed a commit that referenced this pull request Jul 7, 2025
* fix: don't override log level from state for standalone agents

* doc: add changelog fragment

* fix: add unit test for NewAgentInfoWithLog

* fix: derive unprivileged from utils.HasRoot

(cherry picked from commit e8f759b)
mergify bot pushed a commit that referenced this pull request Jul 7, 2025
* fix: don't override log level from state for standalone agents

* doc: add changelog fragment

* fix: add unit test for NewAgentInfoWithLog

* fix: derive unprivileged from utils.HasRoot

(cherry picked from commit e8f759b)
mergify bot pushed a commit that referenced this pull request Jul 7, 2025
* fix: don't override log level from state for standalone agents

* doc: add changelog fragment

* fix: add unit test for NewAgentInfoWithLog

* fix: derive unprivileged from utils.HasRoot

(cherry picked from commit e8f759b)
mergify bot pushed a commit that referenced this pull request Jul 7, 2025
* fix: don't override log level from state for standalone agents

* doc: add changelog fragment

* fix: add unit test for NewAgentInfoWithLog

* fix: derive unprivileged from utils.HasRoot

(cherry picked from commit e8f759b)
pkoutsovasilis added a commit that referenced this pull request Jul 7, 2025
#8857)

* fix: don't override log level from state for standalone agents

* doc: add changelog fragment

* fix: add unit test for NewAgentInfoWithLog

* fix: derive unprivileged from utils.HasRoot

(cherry picked from commit e8f759b)

Co-authored-by: Panos Koutsovasilis <panos.koutsovasilis@elastic.co>
pkoutsovasilis added a commit that referenced this pull request Jul 7, 2025
#8858)

* fix: don't override log level from state for standalone agents

* doc: add changelog fragment

* fix: add unit test for NewAgentInfoWithLog

* fix: derive unprivileged from utils.HasRoot

(cherry picked from commit e8f759b)

Co-authored-by: Panos Koutsovasilis <panos.koutsovasilis@elastic.co>
pkoutsovasilis added a commit that referenced this pull request Jul 7, 2025
#8859)

* fix: don't override log level from state for standalone agents

* doc: add changelog fragment

* fix: add unit test for NewAgentInfoWithLog

* fix: derive unprivileged from utils.HasRoot

(cherry picked from commit e8f759b)

Co-authored-by: Panos Koutsovasilis <panos.koutsovasilis@elastic.co>
pkoutsovasilis added a commit that referenced this pull request Jul 7, 2025
#8860)

* fix: don't override log level from state for standalone agents

* doc: add changelog fragment

* fix: add unit test for NewAgentInfoWithLog

* fix: derive unprivileged from utils.HasRoot

(cherry picked from commit e8f759b)

Co-authored-by: Panos Koutsovasilis <panos.koutsovasilis@elastic.co>
pkoutsovasilis added a commit that referenced this pull request Jul 7, 2025
#8861)

* fix: don't override log level from state for standalone agents

* doc: add changelog fragment

* fix: add unit test for NewAgentInfoWithLog

* fix: derive unprivileged from utils.HasRoot

(cherry picked from commit e8f759b)

Co-authored-by: Panos Koutsovasilis <panos.koutsovasilis@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-active-all Automated backport with mergify to all the active branches bug Something isn't working Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team

5 participants