diff --git a/README.md b/README.md index aee63e9..42a365d 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ Sum by index to calculate the total fields per index. Useful for checking if an ``` sum(es_indices_mappings_field_count) by(index) > 900 ``` +Note that these counts don't include system fields (ones prefixed with `_`, e.g. `_id`), so may be slightly lower than the field count used by Elasticsearch to check the field limit. # Installation The exporter requires Python 3 and Pip 3 to be installed. diff --git a/prometheus_es_exporter/indices_mappings_parser.py b/prometheus_es_exporter/indices_mappings_parser.py index 1896b7e..66e9cbd 100644 --- a/prometheus_es_exporter/indices_mappings_parser.py +++ b/prometheus_es_exporter/indices_mappings_parser.py @@ -13,6 +13,12 @@ def count_object_fields(object_mappings, counts=None): for field, mapping in object_mappings['properties'].items(): # This field is an object, so count its fields. if 'properties' in mapping: + field_type = 'object' + if field_type in counts: + counts[field_type] += 1 + else: + counts[field_type] = 1 + counts = count_object_fields(mapping, counts=counts) else: diff --git a/setup.py b/setup.py index 575a8a3..b15eddb 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( name='prometheus-es-exporter', - version='0.14.1a1', + version='0.14.1', description='Elasticsearch query Prometheus exporter', long_description=long_description, long_description_content_type='text/markdown', diff --git a/tests/test_indices_mappings_parser.py b/tests/test_indices_mappings_parser.py index 3ed18ca..0d68b55 100644 --- a/tests/test_indices_mappings_parser.py +++ b/tests/test_indices_mappings_parser.py @@ -11,7 +11,7 @@ class Test(unittest.TestCase): # server populated with the following data (http command = Httpie utility): # > http -v POST localhost:9200/foo/_doc/1 val:=1 group1=a group2=a # > http -v POST localhost:9200/foo/_doc/2 val:=2 group1=a group2=b - # > http -v POST localhost:9200/foo/_doc/3 val:=3 group1=b group2=b + # > http -v POST localhost:9200/foo/_doc/3 val:=3 group1=b group2=b sub:='{"sub_val": 4}' def test_endpoint(self): # Endpoint: /_mappings?pretty response = { @@ -36,6 +36,13 @@ def test_endpoint(self): } } }, + "sub": { + "properties": { + "sub_val": { + "type": "long" + } + } + }, "val": { "type": "long" } @@ -46,8 +53,9 @@ def test_endpoint(self): expected = { 'field_count{index="foo",field_type="keyword"}': 2, - 'field_count{index="foo",field_type="long"}': 1, - 'field_count{index="foo",field_type="text"}': 2 + 'field_count{index="foo",field_type="long"}': 2, + 'field_count{index="foo",field_type="text"}': 2, + 'field_count{index="foo",field_type="object"}': 1 } result = convert_result(parse_response(response)) self.assertEqual(expected, result) @@ -75,7 +83,7 @@ def test_endpoint_no_properties(self): # server populated with the following data (http command = Httpie utility): # > http -v POST localhost:9200/foo/bar/1 val:=1 group1=a group2=a # > http -v POST localhost:9200/foo/bar/2 val:=2 group1=a group2=b - # > http -v POST localhost:9200/foo/bar/3 val:=3 group1=b group2=b + # > http -v POST localhost:9200/foo/bar/3 val:=3 group1=b group2=b sub:='{"sub_val": 4}' def test_old_endpoint(self): # Endpoint: /_mappings?pretty response = { @@ -101,6 +109,13 @@ def test_old_endpoint(self): } } }, + "sub": { + "properties": { + "sub_val": { + "type": "long" + } + } + }, "val": { "type": "long" } @@ -112,8 +127,9 @@ def test_old_endpoint(self): expected = { 'field_count{index="foo",field_type="keyword"}': 2, - 'field_count{index="foo",field_type="long"}': 1, - 'field_count{index="foo",field_type="text"}': 2 + 'field_count{index="foo",field_type="long"}': 2, + 'field_count{index="foo",field_type="text"}': 2, + 'field_count{index="foo",field_type="object"}': 1 } result = convert_result(parse_response(response)) self.assertEqual(expected, result)