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] Add 'query' metricset for prometheus module #17104

Merged
merged 29 commits into from
Mar 23, 2020

Conversation

ChrsMark
Copy link
Member

@ChrsMark ChrsMark commented Mar 19, 2020

What does this PR do?

Adds 'query' metricset for prometheus module. It continues the PR #15177, and aims to the cleanups/changes required.

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

How to test this PR locally

  1. Start a Prometheus container: docker run -p 9090:9090 prom/prometheus
  2. Enable Prometheus module of Metricbeat and test with the following cases:
    a.
- module: prometheus
  period: 10s
  hosts: ["localhost:9090"]
  metricsets: ["query"]
  queries:
  - query_name: "string"
    path: "/api/v1/query"
    query_params:
      query: "some_value"

b.

- module: prometheus
  period: 10s
  hosts: ["localhost:9090"]
  metricsets: ["query"]
  queries:
  - query_name: "scalar"
    path: "/api/v1/query"
    query_params:
      query: "100"

c.

- module: prometheus
  period: 10s
  hosts: ["localhost:9090"]
  metricsets: ["query"]
  queries:
  - query_name: "instant_vector"
    path: "/api/v1/query"
    query_params:
      query: "sum(rate(prometheus_http_requests_total[1m]))"

d.
Change time range accordingly. Also some time is needed so the metrics to have been populated in Prometheus for the respective range

- module: prometheus
  period: 10s
  hosts: ["localhost:9090"]
  metricsets: ["query"]
  queries:
  - query_name: "range_vector"
    path: "/api/v1/query_range"
    query_params:
      query: "up"
      start: "2020-03-20T00:00:00.000Z"
      end:  "2020-03-20T00:00:10.000Z"
      step: 1m

Related issues

estherk0 and others added 10 commits December 21, 2019 18:50
* Remove array from response body.  Original response body has an array (Vector type). It makes difficult
to query with Elasticsearch QL.
New data schema:
  "prometheus": {
    "query": {
      "mem_usage": {
        "status": "success",
        "data": {
          "resultType": "vector",
          "result": [
            {
              "metric": {},
              "reconciledValue": {
                "unixtimestamp": 1.576751116531e+09,
                "value": "2947656593408"
              }
            }
          ]
        }
      }
    }
  }
* Prometheus API returns "string" type for query result. But actual
result type is a number.
* Make it easy to use ES SQL
Signed-off-by: chrismark <[email protected]>
Signed-off-by: chrismark <[email protected]>
Signed-off-by: chrismark <[email protected]>
Signed-off-by: chrismark <[email protected]>
Signed-off-by: chrismark <[email protected]>
@ChrsMark ChrsMark added enhancement review Metricbeat Metricbeat [zube]: In Review Team:Platforms Label for the Integrations - Platforms team labels Mar 19, 2020
@ChrsMark ChrsMark requested review from exekias and a team March 19, 2020 08:33
@ChrsMark ChrsMark self-assigned this Mar 19, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/integrations-platforms (Team:Platforms)

Signed-off-by: chrismark <[email protected]>
Copy link
Contributor

@sayden sayden left a comment

Choose a reason for hiding this comment

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

Code needs some improvements, but not so much

metricbeat/module/prometheus/query/data.go Outdated Show resolved Hide resolved
metricbeat/module/prometheus/query/data.go Outdated Show resolved Hide resolved
metricbeat/module/prometheus/query/data.go Outdated Show resolved Hide resolved
metricbeat/module/prometheus/query/query.go Outdated Show resolved Hide resolved
metricbeat/module/prometheus/query/query.go Show resolved Hide resolved
metricbeat/module/prometheus/query/query.go Outdated Show resolved Hide resolved
Signed-off-by: chrismark <[email protected]>
Signed-off-by: chrismark <[email protected]>
Signed-off-by: chrismark <[email protected]>
@ChrsMark ChrsMark added the test-plan Add this PR to be manual test plan label Mar 20, 2020
@ChrsMark
Copy link
Member Author

jenkins, test this again

@ChrsMark
Copy link
Member Author

ChrsMark commented Mar 20, 2020

@exekias this seems to be ready for merge, however would you like to have a look too since you had done the initial review on the initial PR?

Copy link
Contributor

@exekias exekias left a comment

Choose a reason for hiding this comment

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

Thank you for working on this! Just a few minor questions and comments.

It would be nice to add tests for the other types of queries (range/matrix/string)

metricbeat/module/prometheus/query/config.go Outdated Show resolved Hide resolved
Signed-off-by: chrismark <[email protected]>
Signed-off-by: chrismark <[email protected]>
@ChrsMark ChrsMark merged commit 7c82034 into elastic:master Mar 23, 2020
ChrsMark added a commit to ChrsMark/beats that referenced this pull request Mar 23, 2020
ChrsMark added a commit that referenced this pull request Mar 23, 2020
@andresrc andresrc added test-plan-added This PR has been added to the test plan and removed [zube]: Done labels Mar 27, 2020
@sayden sayden assigned sayden and ChrsMark and unassigned ChrsMark and sayden Mar 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Metricbeat Metricbeat review Team:Platforms Label for the Integrations - Platforms 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.

6 participants