Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: internal: sp: added environment initialization calls #7968

Merged
merged 6 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/filter_log_to_metrics/log_to_metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ static int set_labels(struct log_to_metrics_ctx *ctx,
snprintf(label_keys[counter], MAX_LABEL_LENGTH - 1, "%s", kv->val);
counter++;
}
else if (strcasecmp(kv->key, "label") == 0) {
else if (strcasecmp(kv->key, "add_label") == 0) {
split = flb_utils_split(kv->val, ' ', 1);
if (mk_list_size(split) != 2) {
flb_plg_error(ctx->ins, "invalid label, expected name and key");
Expand Down
14 changes: 14 additions & 0 deletions tests/internal/fuzzers/fstore_fuzzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
struct flb_fstore_stream *st;
struct flb_fstore_file *fsf;

/* Set flb_malloc_mod to be fuzzer-data dependent */
if (size < 4) {
return 0;
}
flb_malloc_p = 0;
flb_malloc_mod = *(int*)data;
data += 4;
size -= 4;

/* Avoid division by zero for modulo operations */
if (flb_malloc_mod == 0) {
flb_malloc_mod = 1;
}

cio_utils_recursive_delete(FSF_STORE_PATH);
fs = flb_fstore_create(FSF_STORE_PATH, FLB_FSTORE_FS);
st = flb_fstore_stream_create(fs, "abc");
Expand Down
42 changes: 41 additions & 1 deletion tests/internal/stream_processor.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* limitations under the License.
*/

#include <fluent-bit.h>
#include <fluent-bit/flb_info.h>
#include <fluent-bit/flb_mem.h>
#include <fluent-bit/flb_pack.h>
Expand Down Expand Up @@ -200,6 +201,8 @@ static void invalid_queries()
struct flb_sp *sp;
struct flb_sp_task *task;

flb_init_env();

/* Total number of checks for invalid queries */
checks = sizeof(invalid_query_checks) / sizeof(char *);

Expand Down Expand Up @@ -244,6 +247,8 @@ static void test_select_keys()
WSADATA wsa_data;
#endif

flb_init_env();

config = flb_calloc(1, sizeof(struct flb_config));
if (!config) {
flb_errno();
Expand Down Expand Up @@ -330,6 +335,8 @@ static void test_select_subkeys()
WSADATA wsa_data;
#endif

flb_init_env();

config = flb_calloc(1, sizeof(struct flb_config));
if (!config) {
flb_errno();
Expand Down Expand Up @@ -458,6 +465,8 @@ static void test_window()
WSADATA wsa_data;
#endif

flb_init_env();

config = flb_calloc(1, sizeof(struct flb_config));
if (!config) {
flb_errno();
Expand Down Expand Up @@ -503,6 +512,13 @@ static void test_window()

/* We ingest the buffer every second */
for (t = 0; t < check->window_size_sec; t++) {
if (out_buf.buffer != NULL) {
flb_free(out_buf.buffer);

out_buf.buffer = NULL;
out_buf.size = 0;
}

ret = flb_sp_do_test(sp, task,
"samples", strlen("samples"),
&data_buf, &out_buf);
Expand All @@ -517,6 +533,13 @@ static void test_window()
usleep(800000);
}

if (out_buf.buffer != NULL) {
flb_free(out_buf.buffer);

out_buf.buffer = NULL;
out_buf.size = 0;
}

flb_sp_fd_event_test(task->window.fd, task, &out_buf);

flb_info("[sp test] id=%i, SQL => '%s'", check->id, check->exec);
Expand Down Expand Up @@ -560,13 +583,26 @@ static void test_window()

/* Hopping event */
if ((t + 1) % check->window_hop_sec == 0) {
if (out_buf.buffer != NULL) {
flb_free(out_buf.buffer);

out_buf.buffer = NULL;
out_buf.size = 0;
}

flb_sp_fd_event_test(task->window.fd_hop, task, &out_buf);
}

/* Window event */
if ((t + 1) % check->window_size_sec == 0 ||
(t + 1 > check->window_size_sec && (t + 1 - check->window_size_sec) % check->window_hop_sec == 0)) {
flb_free(out_buf.buffer);
if (out_buf.buffer != NULL) {
flb_free(out_buf.buffer);

out_buf.buffer = NULL;
out_buf.size = 0;
}

flb_sp_fd_event_test(task->window.fd, task, &out_buf);
}
flb_free(data_buf.buffer);
Expand Down Expand Up @@ -612,6 +648,8 @@ static void test_snapshot()
WSADATA wsa_data;
#endif

flb_init_env();

config = flb_calloc(1, sizeof(struct flb_config));
if (!config) {
flb_errno();
Expand Down Expand Up @@ -773,6 +811,8 @@ static void test_conv_from_str_to_num()
#endif
out_buf.buffer = NULL;

flb_init_env();

config = flb_config_init();
config->evl = mk_event_loop_create(256);

Expand Down
2 changes: 1 addition & 1 deletion tests/runtime/filter_log_to_metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ void flb_test_log_to_metrics_label(void)
"metric_name", "test",
"metric_description", "Counts messages",
"kubernetes_mode", "off",
"label", "pod_name $kubernetes['pod_name']",
"add_label", "pod_name $kubernetes['pod_name']",
NULL);

out_ffd = flb_output(ctx, (char *) "lib", (void *)&cb_data);
Expand Down
Loading