@cryptotaxi247 / netdata-1 / commits / c649ebb24

go_expavar fix: don't check for duplicate expvars (#5141)

* don't check for duplicate expvars * use list for expvar instead of dict

Ilya Mashchenko committed Jan 9, 2019 at 13:05 UTC c649ebb24770c565438a2d27b0c48de8dd6bfddd
1 file changed +26 -18
collectors/python.d.plugin/go_expvar/go_expvar.chart.py
+26 -18
@@ -6,6 +6,8 @@
6 from __future__ import division
7 import json
8
9 +from collections import namedtuple
10 +
11 from bases.FrameworkServices.UrlService import UrlService
12
13
@@ -72,6 +74,15 @@ MEMSTATS_CHARTS = {
74 }
75 }
76
77 +EXPVAR = namedtuple(
78 + "EXPVAR",
79 + [
80 + "key",
81 + "type",
82 + "id",
83 + ]
84 +)
85 +
86
87 def flatten(d, top='', sep='.'):
88 items = []
@@ -119,7 +130,7 @@ class Service(UrlService):
130 def _parse_extra_charts_config(self, extra_charts_config):
131
132 # a place to store the expvar keys and their types
122 - self.expvars = dict()
133 + self.expvars = list()
134
135 for chart in extra_charts_config:
136
@@ -157,11 +168,8 @@ class Service(UrlService):
168 self.info('Unsupported expvar_type "{0}". Must be "int" or "float"'.format(ev_type))
169 continue
170
160 - if ev_key in self.expvars:
161 - self.info('Duplicate expvar key {0}: skipping line.'.format(ev_key))
162 - continue
163 -
164 - self.expvars[ev_key] = (ev_type, line_id)
171 + # self.expvars[ev_key] = (ev_type, line_id)
172 + self.expvars.append(EXPVAR(ev_key, ev_type, line_id))
173
174 chart_dict['lines'].append(
175 [
@@ -198,21 +206,21 @@ class Service(UrlService):
206 # the rest of the data, thus avoiding needless iterating over the multiply nested memstats dict.
207 del (data['memstats'])
208 flattened = flatten(data)
201 - for k, v in flattened.items():
202 - ev = self.expvars.get(k)
203 - if not ev:
204 - # expvar is not defined in config, skip it
209 +
210 + for ev in self.expvars:
211 + v = flattened.get(ev.key)
212 +
213 + if v is None:
214 continue
215 +
216 try:
207 - key_type, line_id = ev
208 - if key_type == 'int':
209 - expvars[line_id] = int(v)
210 - elif key_type == 'float':
211 - # if the value type is float, multiply it by 1000 and set line divisor to 1000
212 - expvars[line_id] = float(v) * 100
217 + if ev.type == 'int':
218 + expvars[ev.id] = int(v)
219 + elif ev.type == 'float':
220 + expvars[ev.id] = float(v) * 100
221 except ValueError:
214 - self.info('Failed to parse value for key {0} as {1}, ignoring key.'.format(k, key_type))
215 - del self.expvars[k]
222 + self.info('Failed to parse value for key {0} as {1}, ignoring key.'.format(ev.key, ev.type))
223 + return None
224
225 return expvars
226