Browse Source

Family{C}: use keyword arguments for construction.

pull/4/head
Fredrik Ekre 2 years ago
parent
commit
858af35d3e
  1. 12
      src/Prometheus.jl
  2. 10
      test/runtests.jl

12
src/Prometheus.jl

@ -381,12 +381,12 @@ struct Family{C} <: Collector @@ -381,12 +381,12 @@ struct Family{C} <: Collector
lock::ReentrantLock
function Family{C}(
registry::Union{CollectorRegistry, Nothing},
metric_name::String, help::String, labelnames::LabelNames,
metric_name::String, help::String, labelnames::Vector{String};
registry::Union{CollectorRegistry, Nothing}=DEFAULT_REGISTRY,
) where C
children = Dict{LabelValues, C}()
lock = ReentrantLock()
family = new(metric_name, help, labelnames, children, lock)
family = new(metric_name, help, LabelNames(labelnames), children, lock)
if registry !== nothing
register(registry, family)
end
@ -394,12 +394,6 @@ struct Family{C} <: Collector @@ -394,12 +394,6 @@ struct Family{C} <: Collector
end
end
function Family{C}(metric_name::String, help::String, labelnames) where C
return Family{C}(DEFAULT_REGISTRY, metric_name, help, LabelNames(labelnames))
end
function Family{C}(registry::Union{CollectorRegistry, Nothing}, metric_name::String, help::String, labelnames) where C
return Family{C}(registry, metric_name, help, LabelNames(labelnames))
end
function metric_names(family::Family)
return (family.metric_name, )

10
test/runtests.jl

@ -172,8 +172,9 @@ end @@ -172,8 +172,9 @@ end
@test c in Prometheus.DEFAULT_REGISTRY.collectors
r = Prometheus.CollectorRegistry()
c = Prometheus.Family{Collector}(
r, "http_requests", "Number of HTTP requests.",
["endpoint", "status_code"],
"http_requests", "Number of HTTP requests.",
["endpoint", "status_code"];
registry = r,
)
@test c in r.collectors
@test length(c.children) == 0
@ -225,8 +226,9 @@ end @@ -225,8 +226,9 @@ end
@testset "Prometheus.Family{Summary}" begin
r = Prometheus.CollectorRegistry()
c = Prometheus.Family{Prometheus.Summary}(
r, "http_request_time", "Time to process requests.",
["endpoint", "status_code"],
"http_request_time", "Time to process requests.",
["endpoint", "status_code"];
registry = r,
)
@test c in r.collectors
@test length(c.children) == 0

Loading…
Cancel
Save