Skip to content

Commit

Permalink
Cherry-pick elastic#17759 to 7.7: Add fields validation for histogram…
Browse files Browse the repository at this point in the history
… subfields (elastic#17786)

Add validation to histogram subfields in a way that they don't need to
be added to the mappings, but they can still be checked. This is helpful
to avoid having to add exceptions to all the modules based on Prometheus
when Elasticsearch types are used.

(cherry picked from commit 4912b78)
  • Loading branch information
jsoriano authored Apr 21, 2020
1 parent 7b110b3 commit ee30832
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-developer.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ The list below covers the major changes between 7.0.0-rc2 and master only.
- Compare event by event in `testadata` framework to avoid sorting problems {pull}13747[13747]
- Added a `default_field` option to fields in fields.yml to offer a way to exclude fields from the default_field list. {issue}14262[14262] {pull}14341[14341]
- `supported-versions.yml` can be used in metricbeat python system tests to obtain the build args for docker compose builds. {pull}14520[14520]
- Add fields validation for histogram subfields. {pull}17759[17759]
4 changes: 4 additions & 0 deletions libbeat/mapping/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ func (f Fields) getKeys(namespace string) []string {
} else {
keys = append(keys, field.Fields.getKeys(fieldName)...)
}
if field.ObjectType == "histogram" {
keys = append(keys, fieldName+".values")
keys = append(keys, fieldName+".counts")
}
}

return keys
Expand Down
4 changes: 4 additions & 0 deletions libbeat/tests/system/beat/beat.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,10 @@ def extract_fields(doc_list, name):
if field.get("type") in ["object", "geo_point"]:
dictfields.append(newName)

if field.get("type") == "object" and field.get("object_type") == "histogram":
fields.append(newName + ".values")
fields.append(newName + ".counts")

if field.get("type") == "alias":
aliases.append(newName)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
type: http
url: "/metrics"
suffix: plain
omit_documented_fields_check:
# these are not mapped by this module but the oss one
- prometheus.labels.*
# histogram values & counts are not mapped (it's part of the type data)
- '*.histogram.values'
- '*.histogram.counts'
remove_fields_from_comparison: ["prometheus.labels.instance"]
module:
use_types: true
rate_counters: true
rate_counters: true
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (
mbtest "github.com/elastic/beats/v7/metricbeat/mb/testing"

_ "github.com/elastic/beats/v7/x-pack/metricbeat/module/prometheus"

// Import common fields for validation
_ "github.com/elastic/beats/v7/metricbeat/module/prometheus"
)

func TestData(t *testing.T) {
Expand Down

0 comments on commit ee30832

Please sign in to comment.