@@ -30,6 +30,7 @@ gauge_t *uc_get_rate(const data_set_t *dset, const value_list_t *vl) {
30
30
if (dset -> ds [i ].type != DS_TYPE_GAUGE ) {
31
31
INFO ("uc_get_rate: %d, calc fake rate" , i );
32
32
rates [i ] = (gauge_t )(val /10.0 );
33
+ INFO ("uc_get_rate: %f, calc fake rate was " , rates [i ]);
33
34
}
34
35
}
35
36
@@ -51,6 +52,9 @@ int plugin_register_config (const char *name,
51
52
int (* callback ) (const char * key , const char * val ),
52
53
const char * * keys , int keys_num ) { return 0 ;}
53
54
55
+ int plugin_register_init (const char * name ,
56
+ int (* callback ) (void )) { return 0 ;}
57
+
54
58
int plugin_register_write (const char * name ,
55
59
plugin_write_cb callback , user_data_t * user_data ) { return 0 ;}
56
60
@@ -63,7 +67,19 @@ static void c_assert_str_equal(const char *fname, int line, const char *s1, cons
63
67
}
64
68
}
65
69
70
+ static void c_assert_equal (const char * fname , int line , const int s1 , const int s2 ) {
71
+ if (s1 != s2 ) {
72
+ fprintf (stderr , "ERROR %s: %d - \"%d\" does not equal \"%d\"\n" , fname , line , s1 , s2 );
73
+ error_count ++ ;
74
+ }
75
+ }
76
+
77
+
66
78
#define assert_str_equal (s1 ,s2 ) c_assert_str_equal(__FILE__, __LINE__, (s1), (s2))
79
+ #define assert_equal (v1 ,v2 ) c_assert_equal(__FILE__, __LINE__, (v1), (v2))
80
+ #define assert_true (b1 ) c_assert_equal(__FILE__, __LINE__, (b1), (1))
81
+ #define assert_false (b1 ) c_assert_equal(__FILE__, __LINE__, (b1), (0))
82
+
67
83
68
84
void test_make_istatd_metric_name () {
69
85
char buffer [1024 ];
@@ -151,8 +167,8 @@ void make_fake_data(data_set_t *dset, value_list_t *vl,
151
167
152
168
vl -> values = values ;
153
169
vl -> values_len = num_values ;
154
- vl -> time = ( cdtime_t ) 0 ;
155
- vl -> interval = ( cdtime_t ) 10 ;
170
+ vl -> time = TIME_T_TO_CDTIME_T ( 0 ) ;
171
+ vl -> interval = TIME_T_TO_CDTIME_T ( 10 ) ;
156
172
strcpy (vl -> host , "localhost" );
157
173
strcpy (vl -> plugin , plugin );
158
174
strcpy (vl -> plugin_instance , plugin_instance );
@@ -177,7 +193,7 @@ void test_map_to_istatd() {
177
193
make_fake_data (& ds , & vl , DS_TYPE_COUNTER , "cpu" , "" , "idle" , "" , values , 1 );
178
194
179
195
map_to_istatd (buffer , sizeof (buffer ), & ds , & vl );
180
- assert_str_equal ("cpu.idle^buildbot.linu-15-14^host.linu-15-14 0.900000 \n" , buffer );
196
+ assert_str_equal ("* cpu.idle^buildbot.linu-15-14^host.linu-15-14 9 \n" , buffer );
181
197
destroy_fake_data (& ds , & vl );
182
198
183
199
// test memcache_ps_count
@@ -216,8 +232,8 @@ void test_map_to_istatd() {
216
232
values [1 ].derive = 5.0 ;
217
233
make_fake_data (& ds , & vl , DS_TYPE_DERIVE , "interface" , "eth0" , "if_packets" , "" , values , 2 );
218
234
map_to_istatd (buffer , sizeof (buffer ), & ds , & vl );
219
- assert_str_equal ("interface.eth0.if_packets.in ^buildbot.linu-15-14^host.linu-15-14 0.100000 \n"
220
- "interface.eth0.if_packets.out ^buildbot.linu-15-14^host.linu-15-14 0.500000 \n"
235
+ assert_str_equal ("* interface.eth0.if_packets.fake_data_source ^buildbot.linu-15-14^host.linu-15-14 1 \n"
236
+ "* interface.eth0.if_packets.fake_data_source ^buildbot.linu-15-14^host.linu-15-14 5 \n"
221
237
, buffer );
222
238
destroy_fake_data (& ds , & vl );
223
239
@@ -256,21 +272,90 @@ void test_get_counter_suffix() {
256
272
char * suffix ;
257
273
258
274
// test non-existant file
259
- suffix = get_counter_suffix (buffer , sizeof (buffer ), "test_data/does_not_exist" , "fakehost" );
275
+ suffix = get_counter_suffix (buffer , sizeof (buffer ), "test_data/does_not_exist" , "fakehost" , true );
260
276
assert_str_equal ("^host.fakehost" , suffix );
261
277
262
278
// test empty file
263
- suffix = get_counter_suffix (buffer , sizeof (buffer ), "test_data/empty_istatd.categories" , "fakehost" );
279
+ suffix = get_counter_suffix (buffer , sizeof (buffer ), "test_data/empty_istatd.categories" , "fakehost" , true );
264
280
assert_str_equal ("^host.fakehost" , suffix );
265
281
266
282
// test sample file
267
- suffix = get_counter_suffix (buffer , sizeof (buffer ), "test_data/istatd.categories" , "fakehost" );
283
+ suffix = get_counter_suffix (buffer , sizeof (buffer ), "test_data/istatd.categories" , "fakehost" , true );
268
284
assert_str_equal ("^class^trailing_ws^leading_ws^surrounded_ws^clean_me_up__por_-favor5^host.fakehost" , suffix );
285
+
286
+ //Test no suffix addition
287
+
288
+ // test non-existant file
289
+ suffix = get_counter_suffix (buffer , sizeof (buffer ), "test_data/does_not_exist" , "fakehost" , false);
290
+ assert_str_equal ("" , suffix );
291
+
292
+ // test empty file
293
+ suffix = get_counter_suffix (buffer , sizeof (buffer ), "test_data/empty_istatd.categories" , "fakehost" , false);
294
+ assert_str_equal ("" , suffix );
295
+
296
+ // test sample file
297
+ suffix = get_counter_suffix (buffer , sizeof (buffer ), "test_data/istatd.categories" , "fakehost" , false);
298
+ assert_str_equal ("" , suffix );
299
+ }
300
+
301
+ void test_should_skip_recording () {
302
+ value_list_t vl ;
303
+ int res = 0 ;
304
+
305
+ memset (& vl , 0 , sizeof (vl ));
306
+ strcpy (vl .type , "type" );
307
+ strcpy (vl .plugin , "disk" );
308
+ strcpy (vl .plugin_instance , "sda1" );
309
+ strcpy (vl .type_instance , "more" );
310
+ res = should_skip_recording (& vl );
311
+ assert_true (res );
312
+
313
+ memset (& vl , 0 , sizeof (vl ));
314
+ strcpy (vl .type , "type" );
315
+ strcpy (vl .plugin , "disk" );
316
+ strcpy (vl .plugin_instance , "sdb" );
317
+ strcpy (vl .type_instance , "more" );
318
+ res = should_skip_recording (& vl );
319
+ assert_false (res );
320
+
321
+ memset (& vl , 0 , sizeof (vl ));
322
+ strcpy (vl .type , "type" );
323
+ strcpy (vl .plugin , "disk" );
324
+ strcpy (vl .plugin_instance , "md0" );
325
+ strcpy (vl .type_instance , "more" );
326
+ res = should_skip_recording (& vl );
327
+ assert_false (res );
328
+
329
+ memset (& vl , 0 , sizeof (vl ));
330
+ strcpy (vl .type , "type" );
331
+ strcpy (vl .plugin , "disk" );
332
+ strcpy (vl .plugin_instance , "sdmd0" );
333
+ strcpy (vl .type_instance , "more" );
334
+ res = should_skip_recording (& vl );
335
+ assert_true (res );
336
+
337
+ memset (& vl , 0 , sizeof (vl ));
338
+ strcpy (vl .type , "type" );
339
+ strcpy (vl .plugin , "cpu" );
340
+ strcpy (vl .plugin_instance , "idle" );
341
+ strcpy (vl .type_instance , "more" );
342
+ res = should_skip_recording (& vl );
343
+ assert_false (res );
344
+
345
+ memset (& vl , 0 , sizeof (vl ));
346
+ strcpy (vl .type , "type" );
347
+ strcpy (vl .plugin , "others" );
348
+ strcpy (vl .plugin_instance , "idle" );
349
+ strcpy (vl .type_instance , "more" );
350
+ res = should_skip_recording (& vl );
351
+ assert_false (res );
269
352
}
270
353
354
+
271
355
int main (int argc , char * * argv ) {
272
356
test_make_istatd_metric_name ();
273
357
test_map_to_istatd ();
274
358
test_get_counter_suffix ();
359
+ test_should_skip_recording ();
275
360
return (0 );
276
361
}
0 commit comments