@@ -371,5 +371,59 @@ def collect(self):
371
371
self .assertEqual (text .encode ('utf-8' ), generate_latest (registry , ALLOWUTF8 ))
372
372
373
373
374
+ def test_benchmark_text_string_to_metric_families (benchmark ):
375
+ text = """# HELP go_gc_duration_seconds A summary of the GC invocation durations.
376
+ # TYPE go_gc_duration_seconds summary
377
+ go_gc_duration_seconds{quantile="0"} 0.013300656000000001
378
+ go_gc_duration_seconds{quantile="0.25"} 0.013638736
379
+ go_gc_duration_seconds{quantile="0.5"} 0.013759906
380
+ go_gc_duration_seconds{quantile="0.75"} 0.013962066
381
+ go_gc_duration_seconds{quantile="1"} 0.021383540000000003
382
+ go_gc_duration_seconds_sum 56.12904785
383
+ go_gc_duration_seconds_count 7476.0
384
+ # HELP go_goroutines Number of goroutines that currently exist.
385
+ # TYPE go_goroutines gauge
386
+ go_goroutines 166.0
387
+ # HELP prometheus_local_storage_indexing_batch_duration_milliseconds Quantiles for batch indexing duration in milliseconds.
388
+ # TYPE prometheus_local_storage_indexing_batch_duration_milliseconds summary
389
+ prometheus_local_storage_indexing_batch_duration_milliseconds{quantile="0.5"} NaN
390
+ prometheus_local_storage_indexing_batch_duration_milliseconds{quantile="0.9"} NaN
391
+ prometheus_local_storage_indexing_batch_duration_milliseconds{quantile="0.99"} NaN
392
+ prometheus_local_storage_indexing_batch_duration_milliseconds_sum 871.5665949999999
393
+ prometheus_local_storage_indexing_batch_duration_milliseconds_count 229.0
394
+ # HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.
395
+ # TYPE process_cpu_seconds_total counter
396
+ process_cpu_seconds_total 29323.4
397
+ # HELP process_virtual_memory_bytes Virtual memory size in bytes.
398
+ # TYPE process_virtual_memory_bytes gauge
399
+ process_virtual_memory_bytes 2.478268416e+09
400
+ # HELP prometheus_build_info A metric with a constant '1' value labeled by version, revision, and branch from which Prometheus was built.
401
+ # TYPE prometheus_build_info gauge
402
+ prometheus_build_info{branch="HEAD",revision="ef176e5",version="0.16.0rc1"} 1.0
403
+ # HELP prometheus_local_storage_chunk_ops_total The total number of chunk operations by their type.
404
+ # TYPE prometheus_local_storage_chunk_ops_total counter
405
+ prometheus_local_storage_chunk_ops_total{type="clone"} 28.0
406
+ prometheus_local_storage_chunk_ops_total{type="create"} 997844.0
407
+ prometheus_local_storage_chunk_ops_total{type="drop"} 1.345758e+06
408
+ prometheus_local_storage_chunk_ops_total{type="load"} 1641.0
409
+ prometheus_local_storage_chunk_ops_total{type="persist"} 981408.0
410
+ prometheus_local_storage_chunk_ops_total{type="pin"} 32662.0
411
+ prometheus_local_storage_chunk_ops_total{type="transcode"} 980180.0
412
+ prometheus_local_storage_chunk_ops_total{type="unpin"} 32662.0
413
+ # TYPE hist histogram
414
+ # HELP hist help
415
+ hist_bucket{le="1"} 0
416
+ hist_bucket{le="+Inf"} 3
417
+ hist_count 3
418
+ hist_sum 2
419
+ """
420
+
421
+ @benchmark
422
+ def _ ():
423
+ # We need to convert the generator to a full list in order to
424
+ # accurately measure the time to yield everything.
425
+ return list (text_string_to_metric_families (text ))
426
+
427
+
374
428
if __name__ == '__main__' :
375
429
unittest .main ()
0 commit comments