@@ -20,12 +20,12 @@ function passFail (x) {
20
20
} ) ;
21
21
}
22
22
23
- test ( 'The factory function errors when no circuits are passed in ' , t => {
23
+ test ( 'The factory function accept no parameter ' , t => {
24
24
t . plan ( 1 ) ;
25
25
26
- t . throws ( ( ) => {
27
- new PrometheusMetrics ( ) ;
28
- } , 'A circuit or a list of circuits is required' ) ;
26
+ const prometheus = new PrometheusMetrics ( ) ;
27
+ t . ok ( prometheus ) ;
28
+ prometheus . clear ( ) ;
29
29
30
30
t . end ( ) ;
31
31
} ) ;
@@ -73,6 +73,43 @@ test('The factory function uses a custom prom-client registry', t => {
73
73
t . end ( ) ;
74
74
} ) ;
75
75
76
+ test ( 'The add function takes an object instead of just an Array' , t => {
77
+ t . plan ( 2 ) ;
78
+ const c1 = new CircuitBreaker ( passFail , { name : 'fred' } ) ;
79
+ const prometheus = new PrometheusMetrics ( ) ;
80
+ prometheus . add ( c1 ) ;
81
+ t . equal ( c1 . name , 'fred' ) ;
82
+ t . ok ( / c i r c u i t _ f r e d _ / . test ( prometheus . metrics ) ) ;
83
+ prometheus . clear ( ) ;
84
+ t . end ( ) ;
85
+ } ) ;
86
+
87
+ test ( 'The add function provides access to metrics for all circuits' , t => {
88
+ t . plan ( 6 ) ;
89
+ const c1 = new CircuitBreaker ( passFail , { name : 'fred' } ) ;
90
+ const c2 = new CircuitBreaker ( passFail , { name : 'bob' } ) ;
91
+ const c3 = new CircuitBreaker ( passFail , { name : 'foo' } ) ;
92
+ const prometheus = new PrometheusMetrics ( [ c1 ] ) ;
93
+ prometheus . add ( [ c2 , c3 ] ) ;
94
+ t . equal ( c1 . name , 'fred' ) ;
95
+ t . equal ( c2 . name , 'bob' ) ;
96
+ t . equal ( c3 . name , 'foo' ) ;
97
+ t . ok ( / c i r c u i t _ f r e d _ / . test ( prometheus . metrics ) ) ;
98
+ t . ok ( / c i r c u i t _ b o b _ / . test ( prometheus . metrics ) ) ;
99
+ t . ok ( / c i r c u i t _ f o o _ / . test ( prometheus . metrics ) ) ;
100
+ prometheus . clear ( ) ;
101
+ t . end ( ) ;
102
+ } ) ;
103
+
104
+ test ( 'The add function accepts zero parameters' , t => {
105
+ t . plan ( 1 ) ;
106
+ const prometheus = new PrometheusMetrics ( ) ;
107
+ prometheus . add ( ) ;
108
+ t . notOk ( / c i r c u i t _ / . test ( prometheus . metrics ) ) ;
109
+ prometheus . clear ( ) ;
110
+ t . end ( ) ;
111
+ } ) ;
112
+
76
113
test ( 'Circuit fire/success/failure are counted' , t => {
77
114
const circuit = new CircuitBreaker ( passFail ) ;
78
115
const fire = / c i r c u i t _ p a s s F a i l _ f i r e 2 / ;
@@ -150,6 +187,38 @@ test('Should not add default metrics to custom registry', t => {
150
187
t . end ( ) ;
151
188
} ) ;
152
189
190
+ test ( 'Default prometheus metrics are enabled without circuit' , t => {
191
+ const registry = new Registry ( ) ;
192
+ const prometheus = new PrometheusMetrics ( registry ) ;
193
+ const metrics = prometheus . metrics ;
194
+ const names = [
195
+ 'nodejs_eventloop_lag' ,
196
+ 'nodejs_active_handles' ,
197
+ 'nodejs_active_requests' ,
198
+ 'nodejs_heap_size_total_bytes' ,
199
+ 'nodejs_heap_size_used_bytes' ,
200
+ 'nodejs_external_memory_bytes' ,
201
+ 'nodejs_heap_space_size_total_bytes' ,
202
+ 'nodejs_heap_space_size_used_bytes' ,
203
+ 'nodejs_heap_space_size_available_bytes' ,
204
+ 'nodejs_version_info' ,
205
+ 'process_cpu_seconds_total' ,
206
+ 'process_open_fds' ,
207
+ 'process_max_fds' ,
208
+ 'process_virtual_memory_bytes' ,
209
+ 'process_resident_memory_bytes' ,
210
+ 'process_heap_bytes' ,
211
+ 'process_start_time_seconds'
212
+ ] ;
213
+ t . plan ( names . length ) ;
214
+ for ( const name of names ) {
215
+ const match = new RegExp ( `opossum_${ name } ` ) ;
216
+ t . notOk ( match . test ( metrics ) , name ) ;
217
+ }
218
+ prometheus . clear ( ) ;
219
+ t . end ( ) ;
220
+ } ) ;
221
+
153
222
test ( 'Node.js specific metrics are enabled' , t => {
154
223
const circuit = new CircuitBreaker ( passFail ) ;
155
224
const prometheus = new PrometheusMetrics ( [ circuit ] ) ;
0 commit comments