@@ -418,7 +418,7 @@ function verify_label_name(label_name::String)
418
418
end
419
419
420
420
struct LabelNames{N}
421
- labelnames :: NTuple{N, String}
421
+ label_names :: NTuple{N, String}
422
422
function LabelNames (label_names:: NTuple{N, String} ) where N
423
423
for label_name in label_names
424
424
verify_label_name (label_name)
@@ -428,36 +428,36 @@ struct LabelNames{N}
428
428
end
429
429
430
430
struct LabelValues{N}
431
- labelvalues :: NTuple{N, String}
431
+ label_values :: NTuple{N, String}
432
432
end
433
433
434
434
function Base. hash (l:: LabelValues , h:: UInt )
435
435
h = hash (0x94a2d04ee9e5a55b , h) # hash("Prometheus.LabelValues") on Julia 1.9.3
436
- for v in l. labelvalues
436
+ for v in l. label_values
437
437
h = hash (v, h)
438
438
end
439
439
return h
440
440
end
441
441
442
442
function Base.:(== )(l1:: LabelValues , l2:: LabelValues )
443
- return l1. labelvalues == l2. labelvalues
443
+ return l1. label_values == l2. label_values
444
444
end
445
445
446
446
struct Family{C, N} <: Collector
447
447
metric_name:: String
448
448
help:: String
449
- labelnames :: LabelNames{N}
449
+ label_names :: LabelNames{N}
450
450
children:: Dict{LabelValues{N}, C}
451
451
lock:: ReentrantLock
452
452
453
453
function Family {C} (
454
- metric_name:: String , help:: String , labelnames :: NTuple{N, String} ;
454
+ metric_name:: String , help:: String , label_names :: NTuple{N, String} ;
455
455
registry:: Union{CollectorRegistry, Nothing} = DEFAULT_REGISTRY,
456
456
) where {C, N}
457
457
children = Dict {LabelValues{N}, C} ()
458
458
lock = ReentrantLock ()
459
459
family = new {C, N} (
460
- verify_metric_name (metric_name), help, LabelNames (labelnames ), children, lock,
460
+ verify_metric_name (metric_name), help, LabelNames (label_names ), children, lock,
461
461
)
462
462
if registry != = nothing
463
463
register (registry, family)
@@ -467,15 +467,15 @@ struct Family{C, N} <: Collector
467
467
end
468
468
469
469
"""
470
- Prometheus.Family{C}(name, help, labelnames ; registry=DEFAULT_REGISTRY)
470
+ Prometheus.Family{C}(name, help, label_names ; registry=DEFAULT_REGISTRY)
471
471
472
- Create a labeled collector family with labels given by `labelnames `. For every new set of
472
+ Create a labeled collector family with labels given by `label_names `. For every new set of
473
473
label values encountered a new collector of type `C <: Collector` will be created.
474
474
475
475
**Arguments**
476
476
- `name :: String`: the name of the family metric.
477
477
- `help :: String`: the documentation for the family metric.
478
- - `labelnames :: Tuple{String, ...}`: the label names.
478
+ - `label_names :: Tuple{String, ...}`: the label names.
479
479
480
480
**Keyword arguments**
481
481
- `registry :: Prometheus.CollectorRegistry`: the registry in which to register the
@@ -505,37 +505,37 @@ function metric_names(family::Family)
505
505
end
506
506
507
507
"""
508
- Prometheus.labels(family::Family{C}, labelvalues ::Tuple{String, ...}) where C
508
+ Prometheus.labels(family::Family{C}, label_values ::Tuple{String, ...}) where C
509
509
510
510
Return the collector of type `C` from the family corresponding to the labels given by
511
- `labelvalues `.
511
+ `label_values `.
512
512
513
513
!!! note
514
514
This method does an acquire/release of a lock, and a dictionary lookup, to find the
515
515
collector matching the label names. For typical applications this overhead does not
516
516
matter (below 100ns for some basic benchmarks) but it is safe to cache the returned
517
517
collector if required.
518
518
"""
519
- function labels (family:: Family{C, N} , labelvalues :: NTuple{N, String} ) where {C, N}
520
- collector = @lock family. lock get! (family. children, LabelValues (labelvalues )) do
519
+ function labels (family:: Family{C, N} , label_values :: NTuple{N, String} ) where {C, N}
520
+ collector = @lock family. lock get! (family. children, LabelValues (label_values )) do
521
521
# TODO : Avoid the re-verification of the metric name?
522
522
C (family. metric_name, family. help; registry= nothing )
523
523
end
524
524
return collector
525
525
end
526
526
527
527
"""
528
- Prometheus.remove(family::Family, labelvalues ::Tuple{String, ...})
528
+ Prometheus.remove(family::Family, label_values ::Tuple{String, ...})
529
529
530
- Remove the collector corresponding to `labelvalues `. Effectively this resets the collector
530
+ Remove the collector corresponding to `label_values `. Effectively this resets the collector
531
531
since [`Prometheus.labels`](@ref) will recreate the collector when called with the same
532
532
label names.
533
533
534
534
!!! note
535
535
This method invalidates cached collectors for the label names.
536
536
"""
537
- function remove (family:: Family{<:Any, N} , labelvalues :: NTuple{N, String} ) where N
538
- @lock family. lock delete! (family. children, LabelValues (labelvalues ))
537
+ function remove (family:: Family{<:Any, N} , label_values :: NTuple{N, String} ) where N
538
+ @lock family. lock delete! (family. children, LabelValues (label_values ))
539
539
return
540
540
end
541
541
@@ -576,19 +576,22 @@ function collect!(metrics::Vector, family::Family{C}) where C
576
576
else
577
577
@assert (child_samples isa Vector{Sample})
578
578
for child_sample in child_samples
579
- @assert (child_sample. labels === nothing )
579
+ @assert (child_sample. label_values === nothing )
580
580
push! (samples, Sample (child_sample. suffix, labels, child_sample. value))
581
581
end
582
582
end
583
583
end
584
584
end
585
585
# Sort samples lexicographically by the labels
586
586
sort! (samples; by = function (x)
587
- labels = x. labels
587
+ labels = x. label_values
588
588
@assert (labels != = nothing )
589
- return labels. labelvalues
589
+ return labels. label_values
590
590
end )
591
- push! (metrics, Metric (type, family. metric_name, family. help, family. labelnames, samples))
591
+ push! (
592
+ metrics,
593
+ Metric (type, family. metric_name, family. help, family. label_names, samples),
594
+ )
592
595
return metrics
593
596
end
594
597
@@ -599,15 +602,15 @@ end
599
602
600
603
struct Sample
601
604
suffix:: Union{String, Nothing} # e.g. _count or _sum
602
- labels :: Union{LabelValues, Nothing}
605
+ label_values :: Union{LabelValues, Nothing}
603
606
value:: Float64
604
607
end
605
608
606
609
struct Metric
607
610
type:: String
608
611
metric_name:: String
609
612
help:: String
610
- labelnames :: Union{LabelNames, Nothing}
613
+ label_names :: Union{LabelNames, Nothing}
611
614
# TODO : Union{Tuple{Sample}, Vector{Sample}} would always make this iterable.
612
615
samples:: Union{Sample, Vector{Sample}}
613
616
end
@@ -628,12 +631,12 @@ function expose_metric(io::IO, metric::Metric)
628
631
print_escaped (io, metric. help, (' \\ ' , ' \n ' ))
629
632
println (io)
630
633
println (io, " # TYPE " , metric. metric_name, " " , metric. type)
631
- labelnames = metric. labelnames
634
+ label_names = metric. label_names
632
635
samples = metric. samples
633
636
if samples isa Sample
634
637
# Single sample, no labels
635
- @assert (labelnames === nothing )
636
- @assert (samples. labels === nothing )
638
+ @assert (label_names === nothing )
639
+ @assert (samples. label_values === nothing )
637
640
@assert (samples. suffix === nothing )
638
641
val = samples. value
639
642
println (io, metric. metric_name, " " , isinteger (val) ? Int (val) : val)
@@ -648,11 +651,11 @@ function expose_metric(io::IO, metric::Metric)
648
651
print (io, sample. suffix)
649
652
end
650
653
# Print potential labels
651
- labels = sample. labels
652
- if labelnames != = nothing && labels != = nothing
654
+ labels = sample. label_values
655
+ if label_names != = nothing && labels != = nothing
653
656
first = true
654
657
print (io, " {" )
655
- for (name, value) in zip (labelnames . labelnames , labels. labelvalues )
658
+ for (name, value) in zip (label_names . label_names , labels. label_values )
656
659
first || print (io, " ," )
657
660
print (io, name, " =\" " )
658
661
print_escaped (io, value, (' \\ ' , ' \" ' , ' \n ' ))
0 commit comments