@@ -23,28 +23,9 @@ def type
2323 end
2424
2525 def metrics
26- return [ ] if good_job_metrics . length == 0
27-
28- good_job_metrics . map do |metric |
29- labels = metric . fetch ( "custom_labels" , { } )
30-
31- GOOD_JOB_GAUGES . map do |name , help |
32- value = metric [ name . to_s ]
33-
34- if value
35- gauge = gauges [ name ] ||= PrometheusExporter ::Metric ::Gauge . new ( "good_job_#{ name } " , help )
36-
37- if metric [ "by_queue" ]
38- value . each do |queue_name , count |
39- gauge . observe ( count , labels . merge ( queue_name : queue_name ) )
40- end
41- else
42- gauge . observe ( value , labels )
43- end
44- end
45- end
46- end
26+ return [ ] if good_job_metrics . empty?
4727
28+ good_job_metrics . each ( &method ( :process_metric ) )
4829 gauges . values
4930 end
5031
@@ -55,5 +36,24 @@ def collect(object)
5536 private
5637
5738 attr_reader :good_job_metrics , :gauges
39+
40+ def process_metric ( metric )
41+ labels = metric . fetch ( "custom_labels" , { } )
42+
43+ GOOD_JOB_GAUGES . each do |name , help |
44+ next unless ( value = metric [ name . to_s ] )
45+
46+ gauge = gauges [ name ] ||= PrometheusExporter ::Metric ::Gauge . new ( "good_job_#{ name } " , help )
47+ observe_metric ( gauge , metric , labels , value )
48+ end
49+ end
50+
51+ def observe_metric ( gauge , metric , labels , value )
52+ if metric [ "by_queue" ]
53+ value . each { |queue_name , count | gauge . observe ( count , labels . merge ( queue_name : queue_name ) ) }
54+ else
55+ gauge . observe ( value , labels )
56+ end
57+ end
5858 end
5959end
0 commit comments