@@ -1414,6 +1414,52 @@ void test_pr_168()
14141414 cmt_decode_prometheus_destroy (cmt );
14151415}
14161416
1417+ void test_histogram_different_label_count ()
1418+ {
1419+ char errbuf [256 ];
1420+ int status ;
1421+ struct cmt * cmt ;
1422+ cfl_sds_t result = NULL ;
1423+ struct cmt_decode_prometheus_parse_opts opts ;
1424+ memset (& opts , 0 , sizeof (opts ));
1425+ opts .errbuf = errbuf ;
1426+ opts .errbuf_size = sizeof (errbuf );
1427+ cfl_sds_t in_buf = read_file (CMT_TESTS_DATA_PATH "/histogram_different_label_count.txt" );
1428+ const char expected [] =
1429+ "# HELP k8s_network_load Network load\n"
1430+ "# TYPE k8s_network_load histogram\n"
1431+ "k8s_network_load_bucket{le=\"0.05\"} 0 0\n"
1432+ "k8s_network_load_bucket{le=\"5.0\"} 1 0\n"
1433+ "k8s_network_load_bucket{le=\"10.0\"} 2 0\n"
1434+ "k8s_network_load_bucket{le=\"+Inf\"} 3 0\n"
1435+ "k8s_network_load_sum 1013 0\n"
1436+ "k8s_network_load_count 3 0\n"
1437+ "# HELP k8s_network_load Network load\n"
1438+ "# TYPE k8s_network_load histogram\n"
1439+ "k8s_network_load_bucket{le=\"0.05\",my_label=\"my_val\"} 0 0\n"
1440+ "k8s_network_load_bucket{le=\"5.0\",my_label=\"my_val\"} 1 0\n"
1441+ "k8s_network_load_bucket{le=\"10.0\",my_label=\"my_val\"} 2 0\n"
1442+ "k8s_network_load_bucket{le=\"+Inf\",my_label=\"my_val\"} 3 0\n"
1443+ "k8s_network_load_sum{my_label=\"my_val\"} 1013 0\n"
1444+ "k8s_network_load_count{my_label=\"my_val\"} 3 0\n"
1445+ ;
1446+
1447+ cmt_initialize ();
1448+ status = cmt_decode_prometheus_create (& cmt , in_buf , cfl_sds_len (in_buf ), & opts );
1449+ TEST_CHECK (status == 0 );
1450+ if (!status ) {
1451+ result = cmt_encode_prometheus_create (cmt , CMT_TRUE );
1452+ status = strcmp (result , expected );
1453+ TEST_CHECK (status == 0 );
1454+ if (status ) {
1455+ fprintf (stderr , "EXPECTED:\n======\n%s\n======\nRESULT:\n======\n%s\n======\n" , expected , result );
1456+ }
1457+ cfl_sds_destroy (result );
1458+ }
1459+ cfl_sds_destroy (in_buf );
1460+ cmt_decode_prometheus_destroy (cmt );
1461+ }
1462+
14171463TEST_LIST = {
14181464 {"header_help" , test_header_help },
14191465 {"header_type" , test_header_type },
@@ -1444,5 +1490,6 @@ TEST_LIST = {
14441490 {"issue_fluent_bit_6021" , test_issue_fluent_bit_6021 },
14451491 {"override_timestamp" , test_override_timestamp },
14461492 {"pr_168" , test_pr_168 },
1493+ {"histogram_different_label_count" , test_histogram_different_label_count },
14471494 { 0 }
14481495};
0 commit comments