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

Add definition for logging.metrics.enabled, pass config from agent to beats #26828

Merged
merged 11 commits into from
Aug 12, 2021

Conversation

michel-laterman
Copy link
Contributor

@michel-laterman michel-laterman commented Jul 9, 2021

What does this PR do?

Define logging.metrics.enabled and logging.metrics.period.
When logging.metrics.enabled is set to false the elastic-agent will
pass the setting to the underlying beats through a command line variable.

Checklist

  • 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.next.asciidoc or CHANGELOG-developer.next.asciidoc.

How to test this PR locally

Add agent.monitoring.log_metrics: false to elastic-agent.yml (in stand-alone mode) and ensure that the beat logs do not have metrics entries.

i.e.: default behaviour with agent.monitoring.log_metrics missing:

elastic-agent-7.14.0-SNAPSHOT-darwin-x86_64|⇒ ps aux | grep beat
laterman          4742   0.0  0.0  4408696    828 s000  R+    9:50am   0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox beat
root              4645   0.0  0.1  5747796  82824   ??  S     9:49am   0:00.49 /Library/Elastic/Agent/data/elastic-agent-6e0888/install/metricbeat-7.14.0-SNAPSHOT-darwin-x86_64/metricbeat -E setup.ilm.enabled=false -E setup.template.enabled=false -E management.enabled=true -E logging.level=debug -E gc_percent=${METRICBEAT_GOGC:100} -E logging.level=info -E http.enabled=true -E http.host=unix:///Library/Elastic/Agent/data/tmp/default/metricbeat/metricbeat.sock_monitor -E logging.json=true -E logging.ecs=true -E logging.files.path=/Library/Elastic/Agent/data/elastic-agent-6e0888/logs/default -E logging.files.name=metricbeat_monitor-json.log -E logging.files.keepfiles=7 -E logging.files.permission=0640 -E logging.files.interval=1h -E path.data=/Library/Elastic/Agent/data/elastic-agent-6e0888/run/default/metricbeat--7.14.0-SNAPSHOT--36643631373035623733363936343635
root              4644   0.0  0.1  6020232  68824   ??  S     9:49am   0:00.41 /Library/Elastic/Agent/data/elastic-agent-6e0888/install/filebeat-7.14.0-SNAPSHOT-darwin-x86_64/filebeat -E setup.ilm.enabled=false -E setup.template.enabled=false -E management.enabled=true -E logging.level=debug -E gc_percent=${FILEBEAT_GOGC:100} -E logging.level=info -E http.enabled=true -E http.host=unix:///Library/Elastic/Agent/data/tmp/default/filebeat/filebeat.sock_monitor -E logging.json=true -E logging.ecs=true -E logging.files.path=/Library/Elastic/Agent/data/elastic-agent-6e0888/logs/default -E logging.files.name=filebeat_monitor-json.log -E logging.files.keepfiles=7 -E logging.files.permission=0640 -E logging.files.interval=1h -E path.data=/Library/Elastic/Agent/data/elastic-agent-6e0888/run/default/filebeat--7.14.0-SNAPSHOT--36643631373035623733363936343635
root              4643   0.0  0.1  5808224 100492   ??  S     9:49am   0:06.82 /Library/Elastic/Agent/data/elastic-agent-6e0888/install/metricbeat-7.14.0-SNAPSHOT-darwin-x86_64/metricbeat -E setup.ilm.enabled=false -E setup.template.enabled=false -E management.enabled=true -E logging.level=debug -E gc_percent=${METRICBEAT_GOGC:100} -E logging.level=info -E http.enabled=true -E http.host=unix:///Library/Elastic/Agent/data/tmp/default/metricbeat/metricbeat.sock -E logging.json=true -E logging.ecs=true -E logging.files.path=/Library/Elastic/Agent/data/elastic-agent-6e0888/logs/default -E logging.files.name=metricbeat-json.log -E logging.files.keepfiles=7 -E logging.files.permission=0640 -E logging.files.interval=1h -E path.data=/Library/Elastic/Agent/data/elastic-agent-6e0888/run/default/metricbeat--7.14.0-SNAPSHOT
root              4641   0.0  0.1  5184168  68088   ??  S     9:48am   0:00.43 /Library/Elastic/Agent/data/elastic-agent-6e0888/install/filebeat-7.14.0-SNAPSHOT-darwin-x86_64/filebeat -E setup.ilm.enabled=false -E setup.template.enabled=false -E management.enabled=true -E logging.level=debug -E gc_percent=${FILEBEAT_GOGC:100} -E logging.level=info -E http.enabled=true -E http.host=unix:///Library/Elastic/Agent/data/tmp/default/filebeat/filebeat.sock -E logging.json=true -E logging.ecs=true -E logging.files.path=/Library/Elastic/Agent/data/elastic-agent-6e0888/logs/default -E logging.files.name=filebeat-json.log -E logging.files.keepfiles=7 -E logging.files.permission=0640 -E logging.files.interval=1h -E path.data=/Library/Elastic/Agent/data/elastic-agent-6e0888/run/default/filebeat--7.14.0-SNAPSHOT

setting log_metrics: false:

elastic-agent-7.14.0-SNAPSHOT-darwin-x86_64|⇒ ps aux | grep beat
root              4816   8.5  0.1  5941648  94980   ??  S     9:51am   0:01.27 /Library/Elastic/Agent/data/elastic-agent-6e0888/install/metricbeat-7.14.0-SNAPSHOT-darwin-x86_64/metricbeat -E setup.ilm.enabled=false -E setup.template.enabled=false -E management.enabled=true -E logging.level=debug -E gc_percent=${METRICBEAT_GOGC:100} -E logging.level=info -E http.enabled=true -E http.host=unix:///Library/Elastic/Agent/data/tmp/default/metricbeat/metricbeat.sock -E logging.json=true -E logging.ecs=true -E logging.files.path=/Library/Elastic/Agent/data/elastic-agent-6e0888/logs/default -E logging.files.name=metricbeat-json.log -E logging.files.keepfiles=7 -E logging.files.permission=0640 -E logging.files.interval=1h -E logging.metrics.enabled=false -E path.data=/Library/Elastic/Agent/data/elastic-agent-6e0888/run/default/metricbeat--7.14.0-SNAPSHOT
root              4825   3.7  0.1  5132456  61964   ??  S     9:51am   0:00.28 /Library/Elastic/Agent/data/elastic-agent-6e0888/install/filebeat-7.14.0-SNAPSHOT-darwin-x86_64/filebeat -E setup.ilm.enabled=false -E setup.template.enabled=false -E management.enabled=true -E logging.level=debug -E gc_percent=${FILEBEAT_GOGC:100} -E logging.level=info -E http.enabled=true -E http.host=unix:///Library/Elastic/Agent/data/tmp/default/filebeat/filebeat.sock_monitor -E logging.json=true -E logging.ecs=true -E logging.files.path=/Library/Elastic/Agent/data/elastic-agent-6e0888/logs/default -E logging.files.name=filebeat_monitor-json.log -E logging.files.keepfiles=7 -E logging.files.permission=0640 -E logging.files.interval=1h -E logging.metrics.enabled=false -E path.data=/Library/Elastic/Agent/data/elastic-agent-6e0888/run/default/filebeat--7.14.0-SNAPSHOT--36643631373035623733363936343635
laterman          4829   0.0  0.0  4408696    832 s000  R+    9:51am   0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox beat
root              4826   0.0  0.1  5139548  75556   ??  S     9:51am   0:00.26 /Library/Elastic/Agent/data/elastic-agent-6e0888/install/metricbeat-7.14.0-SNAPSHOT-darwin-x86_64/metricbeat -E setup.ilm.enabled=false -E setup.template.enabled=false -E management.enabled=true -E logging.level=debug -E gc_percent=${METRICBEAT_GOGC:100} -E logging.level=info -E http.enabled=true -E http.host=unix:///Library/Elastic/Agent/data/tmp/default/metricbeat/metricbeat.sock_monitor -E logging.json=true -E logging.ecs=true -E logging.files.path=/Library/Elastic/Agent/data/elastic-agent-6e0888/logs/default -E logging.files.name=metricbeat_monitor-json.log -E logging.files.keepfiles=7 -E logging.files.permission=0640 -E logging.files.interval=1h -E logging.metrics.enabled=false -E path.data=/Library/Elastic/Agent/data/elastic-agent-6e0888/run/default/metricbeat--7.14.0-SNAPSHOT--36643631373035623733363936343635
root              4818   0.0  0.1  5137808  59964   ??  S     9:51am   0:00.24 /Library/Elastic/Agent/data/elastic-agent-6e0888/install/filebeat-7.14.0-SNAPSHOT-darwin-x86_64/filebeat -E setup.ilm.enabled=false -E setup.template.enabled=false -E management.enabled=true -E logging.level=debug -E gc_percent=${FILEBEAT_GOGC:100} -E logging.level=info -E http.enabled=true -E http.host=unix:///Library/Elastic/Agent/data/tmp/default/filebeat/filebeat.sock -E logging.json=true -E logging.ecs=true -E logging.files.path=/Library/Elastic/Agent/data/elastic-agent-6e0888/logs/default -E logging.files.name=filebeat-json.log -E logging.files.keepfiles=7 -E logging.files.permission=0640 -E logging.files.interval=1h -E logging.metrics.enabled=false -E path.data=/Library/Elastic/Agent/data/elastic-agent-6e0888/run/default/filebeat--7.14.0-SNAPSHOT

Related issues

@michel-laterman michel-laterman added enhancement Team:Elastic-Agent Label for the Agent team v7.15.0 backport-v7.15.0 Automated backport with mergify labels Jul 9, 2021
@botelastic botelastic bot added needs_team Indicates that the issue/PR needs a Team:* label and removed needs_team Indicates that the issue/PR needs a Team:* label labels Jul 9, 2021
Add a log_metrics config option that defaults to true. When set to false
the agent will pass -E logging.metrice.enabled=false to disable the
underlying beats from adding metrics to their log streams.
@elasticmachine
Copy link
Collaborator

elasticmachine commented Jul 9, 2021

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2021-08-12T02:34:06.795+0000

  • Duration: 139 min 48 sec

  • Commit: 6caf83b

Test stats 🧪

Test Results
Failed 0
Passed 53000
Skipped 5318
Total 58318

Trends 🧪

Image of Build Times

Image of Tests

💚 Flaky test report

Tests succeeded.

Expand to view the summary

Test stats 🧪

Test Results
Failed 0
Passed 53000
Skipped 5318
Total 58318

@michel-laterman michel-laterman marked this pull request as ready for review July 12, 2021 17:48
@elasticmachine
Copy link
Collaborator

Pinging @elastic/agent (Team:Agent)

@ruflin
Copy link
Member

ruflin commented Jul 14, 2021

Can you share your thoughts on if we should set the default to true (as it is) or false?

@michel-laterman
Copy link
Contributor Author

@urso and I briefly discussed this, setting it to true does not change existing behaviour and allows us to use the logs when providing support to users.

@@ -33,6 +33,8 @@ inputs:
# logs: true
# # enables metrics monitoring
# metrics: true
# # running processes will emit metrics into logs
# log_metrics: true
Copy link

Choose a reason for hiding this comment

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

What is the difference between metrics and logs_metrics?

We already have the agent.logging.metrics.enabled settings. Should we rather use that setting?

@michalpristas WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

need to check if these settings are passed to beats

Copy link
Contributor

Choose a reason for hiding this comment

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

i'm not against of reusing what we have. these settings are not forwarded to beats but used for constructing our logger.

@mergify
Copy link
Contributor

mergify bot commented Jul 22, 2021

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b log-metrics-toggle upstream/log-metrics-toggle
git merge upstream/master
git push upstream log-metrics-toggle

@michalpristas
Copy link
Contributor

where are we on this. any updates?

//
// Currently these options are not used through this object in beats (as monitoring is setup elsewhere).
type MetricsConfig struct {
Enabled bool `config:"enabled" yaml:"enabled"`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@urso, I noticed that the beats load through

if b.Config.MetricLogging == nil || b.Config.MetricLogging.Enabled() {

but the logging config does define these variables, do you think it makes sense to define it as part of the logging config so it can be retrieved by the agent?

Copy link

Choose a reason for hiding this comment

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

+1

@michel-laterman
Copy link
Contributor Author

/test

{% if metrics_period -%}
logging.metrics.period: {{ metrics_period }}
{% if file_name -%}
logging.files.name: {{ file_name }}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The export command being tested disables environment variable resolution.

settings.DisableConfigResolver = true

I think it's so export config can be used to copy the config and ignore the local environment.
Originally the test was for logging.metrics.period but seeing as how this pr adds the definition for this attribute as a time.Duration the export fails because the string could not be parsed as a duration.
I instead changed the test to use a string type attribute so the export does not fail.

However going forward the export config command will run into this issue if logging.metrics.period or logging.metrics.enabled are set to environment variables.
This should not effect other commands (which resolve environment variables).

tldr; attribute+test has changed because environment variable expansion is disabled for the export commands

Copy link
Contributor

@blakerouse blakerouse left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@michel-laterman michel-laterman changed the title Add agent.monitoring.log_metrics config option. Add definition for logging.metrics.enabled, pass config from agent to beats Aug 12, 2021
@michel-laterman michel-laterman merged commit 393b2f0 into elastic:master Aug 12, 2021
@michel-laterman michel-laterman deleted the log-metrics-toggle branch August 12, 2021 17:41
mergify bot pushed a commit that referenced this pull request Aug 12, 2021
… beats (#26828)

Define logging.metrics.enabled and logging.metrics.period.
When logging.metrics.enabled is set to false the elastic-agent will
pass the setting to the underlying beats through a command line variable.

(cherry picked from commit 393b2f0)
michel-laterman added a commit that referenced this pull request Aug 13, 2021
… beats (#26828) (#27343)

Define logging.metrics.enabled and logging.metrics.period.
When logging.metrics.enabled is set to false the elastic-agent will
pass the setting to the underlying beats through a command line variable.

(cherry picked from commit 393b2f0)

Co-authored-by: Michel Laterman <82832767+michel-laterman@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v7.15.0 Automated backport with mergify enhancement Team:Elastic-Agent Label for the Agent team v7.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Elastic Agent] Sending monitoring metrics to logs datastream
6 participants