Skip to content

[Metricbeat] Add JetStream metricset to NATS module#43310

Merged
rdner merged 95 commits intoelastic:mainfrom
JAndritsch:nats-jetstream
May 6, 2025
Merged

[Metricbeat] Add JetStream metricset to NATS module#43310
rdner merged 95 commits intoelastic:mainfrom
JAndritsch:nats-jetstream

Conversation

@JAndritsch
Copy link
Contributor

@JAndritsch JAndritsch commented Mar 17, 2025

Proposed commit message

feat(metricbeat): Add JetStream metricset to NATS module

  • Add ability to report metrics on JetStream stats, accounts, streams, and consumers
  • Update supported NATS versions to 2.2.6 - 2.11+
  • Add additional data points to connection metricset
  • Fix compatibility issues in existing NATS metricsets in regards to newer versions of NATS

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.

Disruptive User Impact

Those using older versions of NATS (<2.2.6) may find compatibility issues with the module. Support for v1 has been dropped.

Author's Checklist

  • Go unit tests were added for the jetstream metricset.
  • All unit tests for the NATS module pass.
  • Code coverage relating to unit tests is sufficient
  • Go/Python integration tests for the jetstream metricset were added
  • Go/Python integration tests for the NATS module pass
  • Metrics collected by the NATS module are compatible with NATS versions between 2.2.6 and 2.11.x (latest)
  • The connection metricset no longer produces errors related to schema application when ran against newer versions of NATS
  • The jetstream metricset (new) can be configured to collect metrics about JetStream stats, accounts, streams, and consumers
  • Configuration for the jetstream metricset supports filtering on account names, stream names, and consumer names. No filters configured report on everything. These filters can compound.
  • Fields added to existing metrics are documented
  • Fields introduced in new jetstream metricset are all documented
  • Events produced by the jetstream metricset are ingested properly into Elasticsearch (confirmation of valid mappings)

How to test this PR locally

  1. Clone and check out the branch
  2. cd into metricbeat
  3. Run mage update
  4. Run mage build
  5. cd into modules/nats and run docker compose up -d to deploy a NATS 2.11 cluster
  6. Deploy an Elastic Stack composed of at least Elasticsearch and Kibana
  7. Set up a metricbeat.yml config to enable all metricsets for the nats module (see the reference module config). Configure the hosts setting to match the local NATS server running in Docker (run docker ps to obtain the mapped port). Configure the output to be the local Elasticsearch server running in Docker.
  8. Confirm that metrics from the nats module eventually appear in Discover. Check to make sure there are metrics for the jetstream metricset.
  9. Confirm there are no errors logged by Metricbeat nor any error events relating to the nats module ingested into Elasticsearch

Related issues

Use cases

Scenario: Upgrading to newer versions of NATS and/or Metricbeat
Given a system using Metricbeat's NATS module to monitor a NATS server or cluster
When either Metricbeat or NATS are upgraded
Then there should be no compatibility issues in the collection of NATS metrics
And relevant metrics should be reported

Scenario: Monitoring JetStream streams and consumers
Given a system using NATS JetStream
When deploying Metricbeat to monitor the NATS server
Then Metricbeat should report metrics about JetStream stats, accounts, streams, and consumers

Screenshots

Logs

Attempting to generate the moduleFields once and share them across
multiple mb.Event instances results in a fatal error: concurrent
map iteration and map write panic.

Instead, generate a unique set of module fields for each metricset
event.
Idea is to allow filtering on:
- stream names
- consumer names

Could potentially add more filtering options later
Also remove CompressOK. It's always true in JetStream
It seems 'mage update' doesn't recognize this type
Use configuration options to specify which sub-category of metrics
should be reported.
API does not seem to respond to it.
Update and commit anything documentation-related
@rdner
Copy link
Member

rdner commented May 5, 2025

/test

@JAndritsch
Copy link
Contributor Author

@rdner Are the test failures for libbeat related to this PR? I can't access the buildkite results (still getting a 404) and I don't have any test failures when running mage goIntegTest or mage pythonIntegTest.

@mauri870
Copy link
Member

mauri870 commented May 5, 2025

@rdner Are the test failures for libbeat related to this PR? I can't access the buildkite results (still getting a 404) and I don't have any test failures when running mage goIntegTest or mage pythonIntegTest.

For security reasons, the Buildkite pipelines are private. All the failures appear to be unrelated to the changes in this PR. I’ll retrigger the tests.

@rdner
Copy link
Member

rdner commented May 5, 2025

/test

@rdner rdner merged commit 6e3634f into elastic:main May 6, 2025
194 checks passed
@JAndritsch
Copy link
Contributor Author

Thanks everyone!

@JAndritsch JAndritsch deleted the nats-jetstream branch May 6, 2025 11:35
dliappis added a commit to dliappis/beats that referenced this pull request May 6, 2025
This commit removes the nats Dockerfile from the bump-golang
GH action, since after elastic#43310 it no longer references golang
docker images.
dliappis added a commit that referenced this pull request May 7, 2025
This commit removes the nats Dockerfile from the bump-golang
GH action, since after #43310 it no longer references golang
docker images.
colleenmcginnis pushed a commit to colleenmcginnis/beats that referenced this pull request Jul 30, 2025
colleenmcginnis pushed a commit to colleenmcginnis/beats that referenced this pull request Aug 7, 2025
colleenmcginnis pushed a commit to colleenmcginnis/beats that referenced this pull request Aug 7, 2025
colleenmcginnis pushed a commit to colleenmcginnis/beats that referenced this pull request Aug 8, 2025
colleenmcginnis pushed a commit that referenced this pull request Aug 18, 2025
* add versioning information to fields.yml files related to #43310

* run update

* add tabs for example document in docs/reference/metricbeat/metricbeat-metricset-nats-connection.md

* add tabs for example document in docs/reference/metricbeat/metricbeat-metricset-nats-stats.md

* apply suggestions from code review
mergify bot pushed a commit that referenced this pull request Aug 18, 2025
* add versioning information to fields.yml files related to #43310

* run update

* add tabs for example document in docs/reference/metricbeat/metricbeat-metricset-nats-connection.md

* add tabs for example document in docs/reference/metricbeat/metricbeat-metricset-nats-stats.md

* apply suggestions from code review

(cherry picked from commit b814855)
rdner pushed a commit that referenced this pull request Aug 18, 2025
* add versioning information to fields.yml files related to #43310

* run update

* add tabs for example document in docs/reference/metricbeat/metricbeat-metricset-nats-connection.md

* add tabs for example document in docs/reference/metricbeat/metricbeat-metricset-nats-stats.md

* apply suggestions from code review

(cherry picked from commit b814855)

Co-authored-by: Colleen McGinnis <colleen.mcginnis@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team Team:obs-ds-hosted-services Label for the Observability Hosted Services team

8 participants