@@ -250,7 +250,6 @@ def build_metric(name, documentation, typ, unit, samples):
250
250
raise ValueError ("Units not allowed for this metric type: " + name )
251
251
metric = core .Metric (name , documentation , typ , unit )
252
252
# TODO: check labelvalues are valid utf8
253
- # TODO: check only histogram buckets have exemplars.
254
253
# TODO: check samples are appropriately grouped and ordered
255
254
# TODO: check info/stateset values are 1/0
256
255
# TODO: check for metadata in middle of samples
@@ -320,18 +319,22 @@ def build_metric(name, documentation, typ, unit, samples):
320
319
raise ValueError ("Invalid line: " + line )
321
320
else :
322
321
sample = _parse_sample (line )
323
- if sample [ 0 ] not in allowed_names :
322
+ if sample . name not in allowed_names :
324
323
if name != '' :
325
324
yield build_metric (name , documentation , typ , unit , samples )
326
325
# Start an untyped metric.
327
- name = sample [ 0 ]
326
+ name = sample . name
328
327
documentation = ''
329
328
unit = ''
330
329
typ = 'untyped'
331
330
samples = [sample ]
332
- allowed_names = [sample [ 0 ] ]
331
+ allowed_names = [sample . name ]
333
332
else :
334
333
samples .append (sample )
334
+ if sample .exemplar and not (
335
+ typ in ['histogram' , 'gaugehistogram' ]
336
+ and sample .name .endswith ('_bucket' )):
337
+ raise ValueError ("Invalid line only histogram/gaugehistogram buckets can have exemplars: " + line )
335
338
336
339
if name != '' :
337
340
yield build_metric (name , documentation , typ , unit , samples )
0 commit comments