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 GetProcessedMetrics method to Prometheus helper #6916

Merged
merged 4 commits into from
Apr 25, 2018

Conversation

exekias
Copy link
Contributor

@exekias exekias commented Apr 23, 2018

This PR adds a new GetProcessedMetrics method to ease the creation of metricsets based on Prometheus. It moves from code (current approach) to a mapping template for the conversion of Prometheus metrics to our format, better suited for Elasticsearch mappings.

With this new method you only need to fill the MetricsMapping structure to map all metrics to events. There are a couple of different use cases to support different patterns in Prometheus metrics, like a way to extract labels into keyworud values, or doing boolean conversion.

This PR is divided into 2 commits:

  1. Introducing the method
  2. Adapt existing state_* metricsets to make use of it

I plan to use this for incoming modules/metricsets.

⚠️ There is a breaking change affecting the state_container metricset (currently beta):

  • Fixed a typo in status.phase value: terminate -> terminated

Also this deprecates calculated metric cpu.*.nanocores in favor of cpu.*.cores.

New `GetProcessedMetrics` method to fetch all families and map them to
Metricbeat fields based on a given mapping.
@exekias exekias force-pushed the prometheus-helper-reloaded branch 2 times, most recently from 0f3dd50 to 30cabe8 Compare April 23, 2018 00:55
@exekias exekias force-pushed the prometheus-helper-reloaded branch from 30cabe8 to a74d300 Compare April 23, 2018 00:57
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.

Quite a nice change 🙂

}
}

// KeyLabel maps a Prometheus label to a Metricbeat field. The lable is flagged as key.
Copy link
Member

Choose a reason for hiding this comment

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

Typo lable

}

// Metric directly maps a Prometheus metric to a Metricbeat field
func Metric(field string) MetricMap {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we make a difference between float and int?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Uhm that's a good question, so far I think that mapping should take care of that?

Copy link
Contributor

Choose a reason for hiding this comment

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

It indeed does for the define fields. Coming from the schema package I kind of expected to have both.

@@ -26,14 +26,14 @@
- name: cpu
type: group
fields:
- name: limit.nanocores
- name: limit.cores
Copy link
Contributor

Choose a reason for hiding this comment

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

As state_container is already GA we should not do breaking changes. Could we perhaps keep both fields but mark one as deprecated? Same below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've pushed a change keeping them (deprecated)

ExtraFields map[string]string
}

func (p *prometheus) GetProcessedMetrics(mapping *MetricsMapping) ([]common.MapStr, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It reminds me a lot of our schema package.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Definitely inspired on it :)


// Ignore unknown metrics
if !ok {
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

We should sync up the behaviour with the schema package on what we do on error / missing fields. I'm not happy with the current error handling in schema. Let's have a follow up chat on how we should push that forward.

@@ -39,6 +39,8 @@ https://github.com/elastic/beats/compare/v6.0.0-beta2...master[Check the HEAD di
- Add config option for windows/perfmon metricset to ignore non existent counters. {pull}6432[6432]
- Refactor docker CPU calculations to be more consistent with `docker stats`. {pull}6608[6608]
- Update logstash.node_stats metricset to write data under `logstash.node.stats.*`. {pull}6714[6714]
- Changed `state_container` metric from `cpu.*.nanocores` to `cpu.*.cores`.
- Fixed typo in values for `state_container` `status.phase`, from `terminate` to `terminated`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Here we could perhaps use copy_to to copy the field for now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used code as there is a change on the scale, so needed to perform the math

@exekias exekias added review Metricbeat Metricbeat containers Related to containers use case labels Apr 25, 2018
@ruflin ruflin merged commit 08bc4e7 into elastic:master Apr 25, 2018
- name: limit.nanocores
type: long
deprecated: true
Copy link
Contributor

@ruflin ruflin Apr 25, 2018

Choose a reason for hiding this comment

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

Now we need a way so that this shows up in our docs ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
containers Related to containers use case Metricbeat Metricbeat review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants