@@ -14,18 +14,19 @@ class Report
1414 ]
1515 def self . configure_yabeda!
1616 Yabeda . configure do
17+ default_tag :script_type , "test"
1718 group :aim_patron_load do
18- gauge :loaded , comment : "Number of loaded patrons" , tags : [ :script_type ]
19- gauge :skipped , comment : "Number of skipped patrons" , tags : [ :script_type ]
20- gauge :found , comment : "Number of found patrons" , tags : [ :script_type ]
21- gauge :patron_kind , comment : "Number of patrons in a given major category" , tags : [ :script_type , : name]
22- gauge :campus , comment : "Number of patrons in a given campus" , tags : [ :script_type , : name]
23- gauge :user_group , comment : "Number of patrons in a given Alma User Group" , tags : [ :script_type , : name]
24- gauge :statistic_category , comment : "Number of loaded patrons in a statistic category" , tags : [ :script_type , : name]
25- gauge :sponsor_reason , comment : "Number of loaded Sponsored Affiliates with a given sponsor reason" , tags : [ :script_type , : name]
26- gauge :exclude_reason , comment : "Number of patrons skipped for a given reason" , tags : [ :script_type , : name]
27- gauge :error , comment : "Number of errors encountered while running the patron load" , tags : [ :script_type ]
28- gauge :job_duration_seconds , comment : "Number of seconds it took to run the patron load job" , tags : [ :script_type ]
19+ gauge :loaded , comment : "Number of loaded patrons"
20+ gauge :skipped , comment : "Number of skipped patrons"
21+ gauge :found , comment : "Number of found patrons"
22+ gauge :patron_kind , comment : "Number of patrons in a given major category" , tags : [ :name ]
23+ gauge :campus , comment : "Number of patrons in a given campus" , tags : [ :name ]
24+ gauge :user_group , comment : "Number of patrons in a given Alma User Group" , tags : [ :name ]
25+ gauge :statistic_category , comment : "Number of loaded patrons in a statistic category" , tags : [ :name ]
26+ gauge :sponsor_reason , comment : "Number of loaded Sponsored Affiliates with a given sponsor reason" , tags : [ :name ]
27+ gauge :exclude_reason , comment : "Number of patrons skipped for a given reason" , tags : [ :name ]
28+ gauge :error , comment : "Number of errors encountered while running the patron load"
29+ gauge :job_duration_seconds , comment : "Number of seconds it took to run the patron load job"
2930 end
3031 end
3132 Yabeda . configure!
@@ -53,22 +54,26 @@ def self.push_metrics
5354 end
5455 end
5556
56- def self . open ( file_base : , script_type :, &block )
57+ def self . open ( file_base , script_type : "whatever" , &block )
5758 if file_base
5859 File . open ( "#{ file_base } .tsv" , "w" ) do |fh |
59- report = Report . new ( fh : fh , script_type : script_type )
60+ report = Report . new ( fh )
6061 block . call ( report )
6162 end
6263 else
63- report = Report . new ( fh : $stdout, script_type : script_type )
64- block . call ( report )
64+ StringIO . open do |fh |
65+ report = Report . new ( fh )
66+ block . call ( report )
67+ puts "\n "
68+ puts fh . string
69+ puts "\n "
70+ end
6571 end
6672 end
6773
68- def initialize ( fh : , script_type : )
74+ def initialize ( fh )
6975 @fh = fh
7076 @fh . write self . class . column_names . join ( "\t " ) + "\n "
71- @script_type = script_type
7277 end
7378
7479 def metrics
@@ -78,8 +83,8 @@ def metrics
7883 def load ( patron )
7984 patron = Patron . new ( patron : patron , action : "load" )
8085 @fh . write patron . report_string
81- metrics . found . increment ( { script_type : @script_type } )
82- metrics . loaded . increment ( { script_type : @script_type } )
86+ metrics . found . increment
87+ metrics . loaded . increment
8388 [ "patron_kind" , "statistic_category" , "user_group" , "campus" , "sponsor_reason" ] . each do |metric |
8489 increment_metric ( metric , patron )
8590 end
@@ -88,8 +93,8 @@ def load(patron)
8893 def skip ( patron )
8994 patron = Patron . new ( patron : patron , action : "skip" )
9095 @fh . write patron . report_string
91- metrics . found . increment ( { script_type : @script_type } )
92- metrics . skipped . increment ( { script_type : @script_type } )
96+ metrics . found . increment
97+ metrics . skipped . increment
9398 end
9499
95100 def report_string ( kind :, patron :)
@@ -105,7 +110,7 @@ def report_string(kind:, patron:)
105110 end
106111
107112 def increment_metric ( metric , patron )
108- metrics . public_send ( metric ) . increment ( { script_type : @script_type , name : patron . public_send ( metric ) } ) if patron . public_send ( metric )
113+ metrics . public_send ( metric ) . increment ( { name : patron . public_send ( metric ) } ) if patron . public_send ( metric )
109114 end
110115
111116 class Patron
0 commit comments