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

[Metricbeat] Support processors defined for light modules #15923

Merged
merged 25 commits into from
Jan 31, 2020

Conversation

mtojek
Copy link
Contributor

@mtojek mtojek commented Jan 29, 2020

This PR adds processor support for light modules. Processors can be enabled using definitions in manifest.yml.

Issue: #14740

Let me start with draft and if we're fine with design and implementation, I will cover it with tests.

How to test this PR

  1. Rollback changes in the IBM MQ module manifest to use script processors:
  module: prometheus
  metricset: collector
  defaults:
    metrics_path: /metrics

# The custom processor is responsible for filtering Prometheus metrics
# not stricly related to the IBM MQ domain, e.g. system load, process,
# metrics HTTP server.
processors:
  - script:
      lang: javascript
      source: >
        function process(event) {
          var metrics = event.Get("prometheus.metrics");
          if (metrics == null) {
            event.Cancel();
            return;
          }
          Object.keys(metrics).forEach(function(key) {
            if (!(key.match(/^ibmmq_.*$/))) {
              event.Delete("prometheus.metrics." + key);
            }
          });
          metrics = event.Get("prometheus.metrics");
          if (Object.keys(metrics).length == 0) {
            event.Cancel();
          }
        }

(Remove metrics_filters)

  1. Use docker-compose up to boot up IBM MQ module. The port localhost:9157 should be exposed.
  2. Enable ibmmq metricbeat (x-pack) module.
  3. Start metricbeat with -e -d processors and observe events flow.

Filtering should be applied. To make sure that the processor is used, make a mistake in the configuration. It should appear in the processor's debug logs.

@mtojek mtojek self-assigned this Jan 29, 2020
@mtojek mtojek added the Metricbeat Metricbeat label Jan 29, 2020
@mtojek mtojek requested a review from a team January 29, 2020 08:33
@mtojek mtojek added the needs_backport PR is waiting to be backported to other branches. label Jan 29, 2020
@mtojek mtojek requested a review from jsoriano January 29, 2020 08:36
Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

Thanks @mtojek for working on this!

I have added some comments, the main issues I see:

  • Processors defined in the manifest should be executed before processors defined in the configuration. This will be important to know what to expect from the metricset itself, and what fields are available for processors in the configuration.
  • The link between the metricsets and the connectors, based on a map with the metricset name, and the content of a field in the event, looks a bit weak to me. It'd be nice if we could find a more explicit way of connecting the metricsets with the runners.

Have you considered to create one wrapper per metricset when needed? Not sure about the implications. But this would allow to create also a runner per metricset without modifying the current runner. For these cases Factory.Create could return a runner group struct that implements the Runner interface and contains all the runners generated for a configuration.

Or maybe we need to have multiple outputs in each wrapper, and attach them to each one of its specific clients.

metricbeat/docs/modules/activemq.asciidoc Show resolved Hide resolved
metricbeat/mb/lightmodules.go Outdated Show resolved Hide resolved
metricbeat/mb/module/connector.go Outdated Show resolved Hide resolved
metricbeat/mb/module/publish.go Outdated Show resolved Hide resolved
metricbeat/mb/module/publish.go Outdated Show resolved Hide resolved
metricbeat/mb/module/runner.go Outdated Show resolved Hide resolved
@mtojek
Copy link
Contributor Author

mtojek commented Jan 29, 2020

I fixed all your concerns and got rid of map of clients. A runner group combining all wrappers has been applied.
When we agree on implementation, I'll proceed with testing.

@mtojek mtojek requested review from a team and jsoriano January 29, 2020 17:15
Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

I think we can continue with this approach, good job!

metricbeat/mb/lightmodules.go Outdated Show resolved Hide resolved
metricbeat/mb/lightmodules.go Show resolved Hide resolved
metricbeat/mb/lightmodules_test.go Outdated Show resolved Hide resolved
metricbeat/mb/module/wrapper.go Show resolved Hide resolved
metricbeat/mb/registry.go Outdated Show resolved Hide resolved
metricbeat/mb/registry.go Outdated Show resolved Hide resolved
x-pack/metricbeat/module/activemq/docker-compose.yml Outdated Show resolved Hide resolved
metricbeat/mb/module/connector.go Show resolved Hide resolved
metricbeat/mb/module/factory.go Show resolved Hide resolved
@mtojek
Copy link
Contributor Author

mtojek commented Jan 31, 2020

Thanks for adding the assertion to the system test!

... and it passed. I will proceed with merging the PR.

@mtojek mtojek merged commit a70d6e8 into elastic:master Jan 31, 2020
mtojek added a commit to mtojek/beats that referenced this pull request Jan 31, 2020
)

* Adjust test cases first

* Setup processors for light modules

* Fix: comments, mage check

* Adjust code

* Fix: missing comment

* Fix: mage check

* Test light modules

* Test connector

* Test runner

* Fix: ToLower

* Adjust code after review

* Fix: mage check

* Adjust code after review

* Adjust code after review

* Fix: check error

* Fix: imports

* Increase test coverage

* Add unit tests

* Fix: hound

* beater: use factory

* Beater: modules

* Fix: system tests

* Fix: implements interface

* Add changelog entry

* Verify if processors are setup

(cherry picked from commit a70d6e8)
@mtojek mtojek added v7.7.0 and removed needs_backport PR is waiting to be backported to other branches. labels Jan 31, 2020
mtojek added a commit that referenced this pull request Jan 31, 2020
…15992)

* Adjust test cases first

* Setup processors for light modules

* Fix: comments, mage check

* Adjust code

* Fix: missing comment

* Fix: mage check

* Test light modules

* Test connector

* Test runner

* Fix: ToLower

* Adjust code after review

* Fix: mage check

* Adjust code after review

* Adjust code after review

* Fix: check error

* Fix: imports

* Increase test coverage

* Add unit tests

* Fix: hound

* beater: use factory

* Beater: modules

* Fix: system tests

* Fix: implements interface

* Add changelog entry

* Verify if processors are setup

(cherry picked from commit a70d6e8)
@jsoriano jsoriano mentioned this pull request Feb 17, 2020
7 tasks
@mtojek mtojek added the test-plan Add this PR to be manual test plan label Mar 16, 2020
@andresrc andresrc added the Team:Integrations Label for the Integrations team label Mar 21, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/integrations (Team:Integrations)

@andresrc andresrc added the test-plan-added This PR has been added to the test plan label Mar 21, 2020
jsoriano added a commit to jsoriano/beats that referenced this pull request May 27, 2020
Since metricbeat light modules support processors (elastic#15923), module
initialization requires a publisher in the beat so modules can attach
their processors. `metricbeat test modules` is not initializing as
normal metricbeat commands, and it is not initializing any output or
publisher pipeline, so metricbeat panics when trying to initialize
modules with the new method.

This change adds a dummy publisher for this case, and fixes also a
condition that was adding a `nil` module option, causing additional
panics. A test that reproduced the issue is also added.
jsoriano added a commit that referenced this pull request May 29, 2020
Since metricbeat light modules support processors (#15923), module
initialization requires a publisher in the beat so modules can attach
their processors. `metricbeat test modules` is not initializing as
normal metricbeat commands, and it is not initializing any output or
publisher pipeline, so metricbeat panics when trying to initialize
modules with the new method.

This change adds a dummy publisher for this case, and fixes also a
condition that was adding a `nil` module option, causing additional
panics. A test that reproduced the issues is also added.
jsoriano added a commit to jsoriano/beats that referenced this pull request May 29, 2020
Since metricbeat light modules support processors (elastic#15923), module
initialization requires a publisher in the beat so modules can attach
their processors. `metricbeat test modules` is not initializing as
normal metricbeat commands, and it is not initializing any output or
publisher pipeline, so metricbeat panics when trying to initialize
modules with the new method.

This change adds a dummy publisher for this case, and fixes also a
condition that was adding a `nil` module option, causing additional
panics. A test that reproduced the issues is also added.

(cherry picked from commit 25b8bf1)
jsoriano added a commit to jsoriano/beats that referenced this pull request May 29, 2020
Since metricbeat light modules support processors (elastic#15923), module
initialization requires a publisher in the beat so modules can attach
their processors. `metricbeat test modules` is not initializing as
normal metricbeat commands, and it is not initializing any output or
publisher pipeline, so metricbeat panics when trying to initialize
modules with the new method.

This change adds a dummy publisher for this case, and fixes also a
condition that was adding a `nil` module option, causing additional
panics. A test that reproduced the issues is also added.

(cherry picked from commit 25b8bf1)
jsoriano added a commit to jsoriano/beats that referenced this pull request May 29, 2020
Since metricbeat light modules support processors (elastic#15923), module
initialization requires a publisher in the beat so modules can attach
their processors. `metricbeat test modules` is not initializing as
normal metricbeat commands, and it is not initializing any output or
publisher pipeline, so metricbeat panics when trying to initialize
modules with the new method.

This change adds a dummy publisher for this case, and fixes also a
condition that was adding a `nil` module option, causing additional
panics. A test that reproduced the issues is also added.

(cherry picked from commit 25b8bf1)
jsoriano added a commit that referenced this pull request Jun 3, 2020
Since metricbeat light modules support processors (#15923), module
initialization requires a publisher in the beat so modules can attach
their processors. `metricbeat test modules` is not initializing as
normal metricbeat commands, and it is not initializing any output or
publisher pipeline, so metricbeat panics when trying to initialize
modules with the new method.

This change adds a dummy publisher for this case, and fixes also a
condition that was adding a `nil` module option, causing additional
panics. A test that reproduced the issues is also added.

(cherry picked from commit 25b8bf1)
jsoriano added a commit that referenced this pull request Jun 3, 2020
Since metricbeat light modules support processors (#15923), module
initialization requires a publisher in the beat so modules can attach
their processors. `metricbeat test modules` is not initializing as
normal metricbeat commands, and it is not initializing any output or
publisher pipeline, so metricbeat panics when trying to initialize
modules with the new method.

This change adds a dummy publisher for this case, and fixes also a
condition that was adding a `nil` module option, causing additional
panics. A test that reproduced the issues is also added.

(cherry picked from commit 25b8bf1)
jsoriano added a commit that referenced this pull request Jun 4, 2020
…8853)

Since metricbeat light modules support processors (#15923), module
initialization requires a publisher in the beat so modules can attach
their processors. `metricbeat test modules` is not initializing as
normal metricbeat commands, and it is not initializing any output or
publisher pipeline, so metricbeat panics when trying to initialize
modules with the new method.

This change adds a dummy publisher for this case, and fixes also a
condition that was adding a `nil` module option, causing additional
panics. A test that reproduced the issues is also added.

(cherry picked from commit 25b8bf1)

Add nil pipeline from #16715, required for the fix.

(cherry picked from commit 7a1b524)

Co-authored-by: Steffen Siering <steffen.siering@elastic.co>
leweafan pushed a commit to leweafan/beats that referenced this pull request Apr 28, 2023
…es` (elastic#18853)

Since metricbeat light modules support processors (elastic#15923), module
initialization requires a publisher in the beat so modules can attach
their processors. `metricbeat test modules` is not initializing as
normal metricbeat commands, and it is not initializing any output or
publisher pipeline, so metricbeat panics when trying to initialize
modules with the new method.

This change adds a dummy publisher for this case, and fixes also a
condition that was adding a `nil` module option, causing additional
panics. A test that reproduced the issues is also added.

(cherry picked from commit 316793d)

Add nil pipeline from elastic#16715, required for the fix.

(cherry picked from commit 257fdfc)

Co-authored-by: Steffen Siering <steffen.siering@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Metricbeat Metricbeat Team:Integrations Label for the Integrations team test-plan Add this PR to be manual test plan test-plan-added This PR has been added to the test plan v7.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants