Skip to content

Commit

Permalink
metrics: add more metrics descriptions
Browse files Browse the repository at this point in the history
- auso implemented flb_sds_cat_auto so that we don't need to manually
counting the length of the string.

Signed-off-by: Yu Yi <[email protected]>
  • Loading branch information
erain committed Oct 23, 2020
1 parent 1c0f1fc commit d1c2a97
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 12 deletions.
1 change: 1 addition & 0 deletions include/fluent-bit/flb_sds.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ flb_sds_t flb_sds_create(const char *str);
flb_sds_t flb_sds_create_len(const char *str, int len);
flb_sds_t flb_sds_create_size(size_t size);
flb_sds_t flb_sds_cat(flb_sds_t s, const char *str, int len);
flb_sds_t flb_sds_cat_auto(flb_sds_t s, const char *str);
flb_sds_t flb_sds_cat_esc(flb_sds_t s, const char *str, int len,
char *esc, size_t esc_size);
flb_sds_t flb_sds_cat_utf8(flb_sds_t *sds, const char *str, int len);
Expand Down
12 changes: 10 additions & 2 deletions src/flb_sds.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ flb_sds_t flb_sds_cat(flb_sds_t s, const char *str, int len)
return s;
}

flb_sds_t flb_sds_cat_auto(flb_sds_t s, const char *str)
{
int len;

len = strlen(str);
return flb_sds_cat(s, str, len);
}

flb_sds_t flb_sds_cat_esc(flb_sds_t s, const char *str, int len,
char *esc, size_t esc_size)
{
Expand Down Expand Up @@ -389,6 +397,6 @@ void flb_sds_destroy(flb_sds_t s)
return;
}

head = FLB_SDS_HEADER(s);
flb_free(head);
head = FLB_SDS_HEADER(s);
flb_free(head);
}
35 changes: 25 additions & 10 deletions src/http_server/api/v1/metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,34 +181,49 @@ int is_same_metric(char *s1, char *s2) {
flb_sds_t metrics_help_txt(char *metric_name, flb_sds_t *metric_helptxt)
{
if (strstr(metric_name, "input_bytes")) {
return flb_sds_cat(*metric_helptxt, " Number of input bytes.\n", 24);
return flb_sds_cat_auto(*metric_helptxt, " Number of input bytes by Fluent Bit input plugin.\n");
}
else if (strstr(metric_name, "input_records")) {
return flb_sds_cat(*metric_helptxt, " Number of input records.\n", 26);
return flb_sds_cat_auto(*metric_helptxt, " Number of input records by Fluent Bit input plugin.\n");
}
else if (strstr(metric_name, "input_files_opened")) {
return flb_sds_cat_auto(*metric_helptxt, "Number of files opened by Fluent Bit input plugin.\n");
}
else if (strstr(metric_name, "input_files_closed")) {
return flb_sds_cat_auto(*metric_helptxt, "Number of files closed by Fluent Bit input plugin.\n");
}
else if (strstr(metric_name, "input_files_rotated")) {
return flb_sds_cat_auto(*metric_helptxt, "Number of files rotated by Fluent Bit input plugin.\n");
}
else if (strstr(metric_name, "output_bytes")) {
return flb_sds_cat(*metric_helptxt, " Number of output bytes.\n", 25);
return flb_sds_cat_auto(*metric_helptxt, " Number of output bytes by Fluent Bit output plugin.\n");
}
else if (strstr(metric_name, "output_records")) {
return flb_sds_cat(*metric_helptxt, " Number of output records.\n", 27);
return flb_sds_cat_auto(*metric_helptxt, " Number of output records by Fluent Bit output plugin.\n");
}
else if (strstr(metric_name, "output_errors")) {
return flb_sds_cat(*metric_helptxt, " Number of output errors.\n", 26);
return flb_sds_cat_auto(*metric_helptxt, " Number of output errors by Fluent Bit output plugin.\n");
}
else if (strstr(metric_name, "output_retries_failed")) {
return flb_sds_cat(*metric_helptxt, " Number of output retries failed.\n", 34);
return flb_sds_cat_auto(*metric_helptxt, " Number of output retries failed by Fluent Bit output plugin.\n");
}
else if (strstr(metric_name, "output_retries")) {
return flb_sds_cat(*metric_helptxt, " Number of output retries.\n", 27);
return flb_sds_cat_auto(*metric_helptxt, " Number of output retries by Fluent Bit output plugin.\n");
}
else if (strstr(metric_name, "output_proc_records")) {
return flb_sds_cat(*metric_helptxt, " Number of processed output records.\n", 37);
return flb_sds_cat_auto(*metric_helptxt, " Number of processed output records by Fluent Bit output plugin.\n");
}
else if (strstr(metric_name, "output_proc_bytes")) {
return flb_sds_cat(*metric_helptxt, " Number of processed output bytes.\n", 35);
return flb_sds_cat_auto(*metric_helptxt, " Number of processed output bytes by Fluent Bit output plugin.\n");
}
else if (strstr(metric_name, "filter_add_records")) {
return flb_sds_cat_auto(*metric_helptxt, " Number of records added by Fluent Bit filter plugin.\n");
}
else if (strstr(metric_name, "filter_drop_records")) {
return flb_sds_cat_auto(*metric_helptxt, " Number of records dropped by Fluent Bit filter plugin.\n");
}
else {
return (flb_sds_cat(*metric_helptxt, " Fluentbit metrics.\n", 20));
return (flb_sds_cat_auto(*metric_helptxt, " Fluentbit metrics.\n"));
}
}

Expand Down
13 changes: 13 additions & 0 deletions tests/internal/sds.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,22 @@ static void test_sds_cat_utf8()
flb_sds_destroy(s);
}

static void test_sds_cat_auto()
{
flb_sds_t s;
char *str = "1234567890\n";

flb_sds_cat_auto(s, str);
TEST_CHECK(flb_sds_len(s) == 11);
TEST_CHECK(strcmp(s, "1234567890\n") == 0);

flb_sds_destroy(s);
}

TEST_LIST = {
{ "sds_usage" , test_sds_usage},
{ "sds_printf", test_sds_printf},
{ "sds_cat_utf8", test_sds_cat_utf8},
{ "sds_cat_auto", test_sds_cat_auto},
{ 0 }
};

0 comments on commit d1c2a97

Please sign in to comment.