13
13
#define MAX_BUFFER_SIZE 256
14
14
15
15
PROMETHEUS_COUNTER_DEFINE (test_counter , "Test counter" ,
16
- ({ .key = "test" , .value = "counter" }));
16
+ ({ .key = "test" , .value = "counter" }), NULL );
17
+ PROMETHEUS_COUNTER_DEFINE (test_counter2 , "Test counter 2" ,
18
+ ({ .key = "test" , .value = "counter" }), NULL );
17
19
18
20
PROMETHEUS_COLLECTOR_DEFINE (test_custom_collector );
19
21
@@ -28,11 +30,15 @@ ZTEST(test_formatter, test_prometheus_formatter_simple)
28
30
int ret ;
29
31
char formatted [MAX_BUFFER_SIZE ] = { 0 };
30
32
struct prometheus_counter * counter ;
31
- char exposed [] = "# HELP test_counter Test counter\n"
33
+ char exposed [] = "# HELP test_counter2 Test counter 2\n"
34
+ "# TYPE test_counter2 counter\n"
35
+ "test_counter2{test=\"counter\"} 1\n"
36
+ "# HELP test_counter Test counter\n"
32
37
"# TYPE test_counter counter\n"
33
38
"test_counter{test=\"counter\"} 1\n" ;
34
39
35
40
prometheus_collector_register_metric (& test_custom_collector , & test_counter .base );
41
+ prometheus_collector_register_metric (& test_custom_collector , & test_counter2 .base );
36
42
37
43
counter = (struct prometheus_counter * )prometheus_collector_get_metric (
38
44
& test_custom_collector , "test_counter" );
@@ -44,13 +50,16 @@ ZTEST(test_formatter, test_prometheus_formatter_simple)
44
50
ret = prometheus_counter_inc (& test_counter );
45
51
zassert_ok (ret , "Error incrementing counter" );
46
52
53
+ ret = prometheus_counter_inc (& test_counter2 );
54
+ zassert_ok (ret , "Error incrementing counter 2" );
55
+
47
56
zassert_equal (counter -> value , 1 , "Counter value is not 1" );
48
57
49
58
ret = prometheus_format_exposition (& test_custom_collector , formatted , sizeof (formatted ));
50
59
zassert_ok (ret , "Error formatting exposition data" );
51
60
52
61
zassert_equal (strcmp (formatted , exposed ), 0 ,
53
- "Exposition format is not as expected (expected \ "%s\", got \"%s\")" ,
62
+ "Exposition format is not as expected (expected\n\ "%s\", got\n \"%s\")" ,
54
63
exposed , formatted );
55
64
}
56
65
0 commit comments