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

Use Elasticsearch histogram type to store Prometheus histograms #17061

Merged
merged 34 commits into from
Mar 24, 2020

Conversation

exekias
Copy link
Contributor

@exekias exekias commented Mar 17, 2020

What does this PR do?

Allow to store Prometheus histograms as Elasticsearch histograms when using the collector metricset. This change adds a new use_types feature flag to enable the new behavior. When enabled it will use a new schema for Prometheus metrics:

  • Store counters as prometheus.*.counter
  • Store gauges/untyped as prometheus.*.value
  • Store histograms as prometheus.*.histogram
  • Summaries use the previous types

Also, when using rate_counters, a new prometheus.*.rate field will be created for all counter metrics. It stores the increment of the counter since the last fetch.

image

image

For better results, it is recommended to use tdigest.compression: 1 when calculating percentiles:

image

A note on graph fidelity

This is a first stab at supporting Prometheus Histograms using Elasticsearch histograms. As algorithms and query semantics differ between these two projects, the resulting graphs are not exactly the same (while both are representing correct data).

We will keep working with the Elasticsearch team to provide better fidelity when compared to Prometheus way of graphing histograms. This will be a good start: elastic/elasticsearch#49452

Why is it important?

Histograms are a big part of Prometheus metrics, and being able to store and query them correctly is a great feature when dealing with these.

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

This feature requires Elasticsearch 7.6 or later. Also Kibana support is not yet merged into master, I'm testing this in combination with elastic/kibana#59387.

Related issues

Closes #14843

@exekias exekias added enhancement in progress Pull request is currently in progress. Metricbeat Metricbeat needs_backport PR is waiting to be backported to other branches. v7.7.0 Team:Platforms Label for the Integrations - Platforms team labels Mar 17, 2020
@elasticmachine
Copy link
Collaborator

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

@exekias exekias changed the title Prometheus histograms Use Elasticsearch histogram type to store Prometheus histograms Mar 17, 2020
)

// promHistogramToES takes a Prometheus histogram and converts it to
func promHistogramToES(cc CounterCache, name string, labels common.MapStr, histogram *dto.Histogram) common.MapStr {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@iverase FYI, I'm working on this now 🙂, in case you want to have a look

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.

It LGTM. I think we could use use the new implementation by default in openmetrics from the very beginning as we haven't released it yet, would it make sense?
Apart of that, some minor suggestions and nitpicking.

metricbeat/module/prometheus/collector/_meta/docs.asciidoc Outdated Show resolved Hide resolved
metricbeat/module/prometheus/collector/_meta/docs.asciidoc Outdated Show resolved Hide resolved
metricbeat/module/prometheus/collector/collector.go Outdated Show resolved Hide resolved
x-pack/metricbeat/module/prometheus/collector/counter.go Outdated Show resolved Hide resolved
}

func (g *typedGenerator) Start() {
cfgwarn.Beta("Prometheus 'use_types' setting is beta")
Copy link
Member

Choose a reason for hiding this comment

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

This would need to be parameterized for openmetrics if used also there.

x-pack/metricbeat/module/prometheus/collector/data.go Outdated Show resolved Hide resolved
var counts []uint64

// calculate centroids and rated counts
var lastUpper, prevUpper float64
Copy link
Member

Choose a reason for hiding this comment

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

Nit. Use prevLastUpper or secondLastUpper to know that it refers to the second last upper bound seen?

Suggested change
var lastUpper, prevUpper float64
var lastUpper, prevLastUpper float64

x-pack/metricbeat/module/prometheus/docker-compose.yml Outdated Show resolved Hide resolved
exekias and others added 8 commits March 24, 2020 14:21
Co-Authored-By: Jaime Soriano Pastor <jaime.soriano@elastic.co>
Co-Authored-By: Jaime Soriano Pastor <jaime.soriano@elastic.co>
Co-Authored-By: Jaime Soriano Pastor <jaime.soriano@elastic.co>
Co-Authored-By: Jaime Soriano Pastor <jaime.soriano@elastic.co>
Co-Authored-By: Jaime Soriano Pastor <jaime.soriano@elastic.co>
@exekias exekias removed the in progress Pull request is currently in progress. label Mar 24, 2020
Copy link
Member

@ChrsMark ChrsMark left a comment

Choose a reason for hiding this comment

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

LGTM!

Carlos Pérez-Aradros Herce added 2 commits March 24, 2020 16:53
@exekias exekias merged commit 142b859 into elastic:master Mar 24, 2020
exekias pushed a commit to exekias/beats that referenced this pull request Mar 24, 2020
…tic#17061)

* Allow to override already defined metricsets

This is useful when we want to have different behaviors between flavours

* Add new Prometheus skeleton for basic types usage

* Refactor Prometheus module to accommodate newer uses

* Add typed schema to Prometheus module

This should make room for using different Elasticsearch types depending
on the Prometheus metric

* Convert Prometheus histograms to ES histograms

Co-authored-by: Chris Mark <chrismarkou92@gmail.com>
Co-authored-by: Jaime Soriano Pastor <jaime.soriano@elastic.co>
(cherry picked from commit 142b859)
@exekias exekias removed the needs_backport PR is waiting to be backported to other branches. label Mar 24, 2020
exekias pushed a commit that referenced this pull request Mar 25, 2020
…Prometheus histograms (#17227)

* Use Elasticsearch histogram type to store Prometheus histograms (#17061)

* Allow to override already defined metricsets

This is useful when we want to have different behaviors between flavours

* Add new Prometheus skeleton for basic types usage

* Refactor Prometheus module to accommodate newer uses

* Add typed schema to Prometheus module

This should make room for using different Elasticsearch types depending
on the Prometheus metric

* Convert Prometheus histograms to ES histograms

Co-authored-by: Chris Mark <chrismarkou92@gmail.com>
Co-authored-by: Jaime Soriano Pastor <jaime.soriano@elastic.co>
(cherry picked from commit 142b859)

* make update
@exekias exekias added the test-plan Add this PR to be manual test plan label Mar 27, 2020
@andresrc andresrc added test-plan-added This PR has been added to the test plan and removed [zube]: Done labels 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 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.

[Metricbeat] Use histograms type in Prometheus module
5 participants