Skip to content

Commit 991c12c

Browse files
committed
tests: issues: add test for prom text without subsystem
Signed-off-by: Eduardo Silva <[email protected]>
1 parent a3cbd2f commit 991c12c

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/issues.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include <cmetrics/cmt_encode_msgpack.h>
2323
#include <cmetrics/cmt_decode_msgpack.h>
2424
#include <cmetrics/cmt_encode_text.h>
25+
#include <cmetrics/cmt_decode_prometheus.h>
26+
#include <cmetrics/cmt_encode_prometheus.h>
2527

2628
#include "cmt_tests.h"
2729

@@ -89,7 +91,34 @@ void test_issue_54()
8991
cmt_destroy(cmt1);
9092
}
9193

94+
/* issue: https://github.com/fluent/fluent-bit/issues/10761 */
95+
void test_prometheus_metric_no_subsystem()
96+
{
97+
const char text[] =
98+
"# HELP up A simple example metric no subsystem\n"
99+
"# TYPE up gauge\n"
100+
"up{job=\"42\"} 1\n";
101+
struct cmt *cmt;
102+
cfl_sds_t result;
103+
int ret;
104+
105+
cmt_initialize();
106+
107+
ret = cmt_decode_prometheus_create(&cmt, text, strlen(text), NULL);
108+
TEST_CHECK(ret == CMT_DECODE_PROMETHEUS_SUCCESS);
109+
if (ret == CMT_DECODE_PROMETHEUS_SUCCESS) {
110+
result = cmt_encode_prometheus_create(cmt, CMT_TRUE);
111+
TEST_CHECK(result != NULL);
112+
if (result) {
113+
TEST_CHECK(strstr(result, "up{job=\"42\"} 1") != NULL);
114+
cmt_encode_prometheus_destroy(result);
115+
}
116+
cmt_decode_prometheus_destroy(cmt);
117+
}
118+
}
119+
92120
TEST_LIST = {
93121
{"issue_54", test_issue_54},
122+
{"prometheus_metric_no_subsystem", test_prometheus_metric_no_subsystem},
94123
{ 0 }
95124
};

0 commit comments

Comments
 (0)