Fix non-existing gauge duplicate
In Elasticsearch 7.x hits,total field
is not integer, but dictionary causing
failure to create proper gauge,
which is registered in collector
causing duplicate error.
For other cases - reregister Gauge collector
Change-Id: Ied8cc69a4ea4c1482b3670e2fab9a66ff0d386e7
Related-bug: PROD-32451
diff --git a/prometheus_es_exporter/parser.py b/prometheus_es_exporter/parser.py
index 9ec59fe..f978cf2 100644
--- a/prometheus_es_exporter/parser.py
+++ b/prometheus_es_exporter/parser.py
@@ -80,7 +80,10 @@
result = []
if not response['timed_out']:
- result.append((metric + ['hits'], {}, response['hits']['total']))
+ hits_total = response['hits']['total']
+ if isinstance(hits_total, dict):
+ hits_total = hits_total.get('value', 0)
+ result.append((metric + ['hits'], {}, hits_total))
result.append((metric + ['took', 'milliseconds'], {}, response['took']))
if 'aggregations' in response.keys():