Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

agent: Fix a bug where all syslog lines are notice when using JSON #24865

Merged
merged 3 commits into from
Jan 16, 2025

Conversation

jrasell
Copy link
Member

@jrasell jrasell commented Jan 15, 2025

The agent syslog write handler was unable to handle JSON log lines correctly, meaning all syslog entries when using JSON log format showed as NOTICE level.

This change adds a new handler to the Nomad agent which can parse JSON log lines and correctly understand the expected log level entry.

The change also removes the use of a filter from the default log format handler. This is not needed as the logs are fed into the syslog handler via hclog, which is responsible for level filtering.

Testing & Reproduction steps

Running on a Linux workstation (Ubuntu 24.04) I added the following lines to the /etc/rsyslog.conf before restarting rsyslog via sudo service rsyslog restart.

$template verbose, "%syslogseverity-text%, %syslogfacility%, %timegenerated%, %HOSTNAME%, %syslogtag%, %msg%\n"
*.* /var/log/all-messages.log;verbose

I then ran Nomad via sudo -i nomad agent -dev -log-json -log-level=<LEVEL> -config=/home/jrasell/config.hcl using the following configuration:

enable_syslog = true

Links

Jira: https://hashicorp.atlassian.net/browse/NET-11973

Contributor Checklist

  • Changelog Entry If this PR changes user-facing behavior, please generate and add a
    changelog entry using the make cl command.
  • Testing Please add tests to cover any new functionality or to demonstrate bug fixes and
    ensure regressions will be caught.
  • Documentation If the change impacts user-facing functionality such as the CLI, API, UI,
    and job configuration, please update the Nomad website documentation to reflect this. Refer to
    the website README for docs guidelines. Please also consider whether the
    change requires notes within the upgrade guide.

Reviewer Checklist

  • Backport Labels Please add the correct backport labels as described by the internal
    backporting document.
  • Commit Type Ensure the correct merge method is selected which should be "squash and merge"
    in the majority of situations. The main exceptions are long-lived feature branches or merges where
    history should be preserved.
  • Enterprise PRs If this is an enterprise only PR, please add any required changelog entry
    within the public repository.

The agent syslog write handler was unable to handle JSON log lines
correctly, meaning all syslog entries when using JSON log format
showed as NOTICE level.

This change adds a new handler to the Nomad agent which can parse
JSON log lines and correctly understand the expected log level
entry.

The change also removes the use of a filter from the default log
format handler. This is not needed as the logs are fed into the
syslog handler via hclog, which is responsible for level
filtering.
@jrasell jrasell added backport/ent/1.7.x+ent Changes are backported to 1.7.x+ent backport/ent/1.8.x+ent Changes are backported to 1.8.x+ent backport/1.9.x backport to 1.9.x release line labels Jan 15, 2025
@jrasell jrasell marked this pull request as ready for review January 15, 2025 10:23
@jrasell jrasell requested review from a team as code owners January 15, 2025 10:23
tgross
tgross previously approved these changes Jan 15, 2025
Copy link
Member

@tgross tgross left a comment

Choose a reason for hiding this comment

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

LGTM

command/agent/syslog.go Outdated Show resolved Hide resolved
@jrasell jrasell merged commit 1ae9785 into main Jan 16, 2025
30 checks passed
@jrasell jrasell deleted the b-NET-11973 branch January 16, 2025 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/ent/1.7.x+ent Changes are backported to 1.7.x+ent backport/ent/1.8.x+ent Changes are backported to 1.8.x+ent backport/1.9.x backport to 1.9.x release line
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants