summaryrefslogtreecommitdiffstats
path: root/fluent-bit/lib/monkey/api
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 11:19:16 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-07-24 09:53:24 +0000
commitb5f8ee61a7f7e9bd291dd26b0585d03eb686c941 (patch)
treed4d31289c39fc00da064a825df13a0b98ce95b10 /fluent-bit/lib/monkey/api
parentAdding upstream version 1.44.3. (diff)
downloadnetdata-upstream.tar.xz
netdata-upstream.zip
Adding upstream version 1.46.3.upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'fluent-bit/lib/monkey/api')
-rw-r--r--fluent-bit/lib/monkey/api/CMakeLists.txt18
-rw-r--r--fluent-bit/lib/monkey/api/errors.c103
-rw-r--r--fluent-bit/lib/monkey/api/test.c186
3 files changed, 0 insertions, 307 deletions
diff --git a/fluent-bit/lib/monkey/api/CMakeLists.txt b/fluent-bit/lib/monkey/api/CMakeLists.txt
deleted file mode 100644
index 8833735ef..000000000
--- a/fluent-bit/lib/monkey/api/CMakeLists.txt
+++ /dev/null
@@ -1,18 +0,0 @@
-set(src
- test.c)
-
-add_executable(api_test ${src})
-
-set(src
- errors.c
- )
-
-add_executable(api_error ${src})
-
-if (CMAKE_SYSTEM_NAME MATCHES "Windows")
- target_link_libraries(api_test monkey-core-static mk_core ws2_32)
- target_link_libraries(api_error monkey-core-static mk_core ws2_32)
-else()
- target_link_libraries(api_test monkey-core-static)
- target_link_libraries(api_error monkey-core-static)
-endif()
diff --git a/fluent-bit/lib/monkey/api/errors.c b/fluent-bit/lib/monkey/api/errors.c
deleted file mode 100644
index 44e9c35fa..000000000
--- a/fluent-bit/lib/monkey/api/errors.c
+++ /dev/null
@@ -1,103 +0,0 @@
-#include <monkey/mk_lib.h>
-#include <mk_core/mk_unistd.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <signal.h>
-
-#define API_ADDR "127.0.0.1"
-#define API_PORT "2020"
-
-/* Main context set as global so the signal handler can use it */
-mk_ctx_t *ctx;
-
-static void signal_handler(int signal)
-{
- write(STDERR_FILENO, "[engine] caught signal\n", 23);
-
- switch (signal) {
- case SIGTERM:
- case SIGINT:
- mk_stop(ctx);
- mk_destroy(ctx);
- _exit(EXIT_SUCCESS);
- default:
- break;
- }
-}
-
-static void signal_init()
-{
- signal(SIGINT, &signal_handler);
- signal(SIGTERM, &signal_handler);
-}
-
-void cb_ok_200(mk_request_t *request, void *data)
-{
- int i = 0;
- (void) data;
- char tmp[32];
-
- mk_http_status(request, 200);
- mk_http_header(request, "X-Monkey", 8, "OK", 2);
-
- for (i = 0; i < 100; i++) {
- int len;
-
- len = snprintf(tmp, sizeof(tmp) - 1, "test %i\n", i);
- mk_http_send(request, tmp, len, NULL);
- }
- mk_http_done(request);
-}
-
-void cb_error_404(mk_request_t *request, void *data)
-{
- int i = 0;
- (void) data;
- char tmp[32];
-
- mk_http_status(request, 404);
- mk_http_header(request, "X-Monkey", 8, "OK", 2);
-
- for (i = 0; i < 100; i++) {
- int len;
-
- len = snprintf(tmp, sizeof(tmp) - 1, "test %i\n", i);
- mk_http_send(request, tmp, len, NULL);
- }
- mk_http_done(request);
-}
-
-int main()
-{
- int vid;
-
- signal_init();
-
- ctx = mk_create();
- if (!ctx) {
- return -1;
- }
-
- mk_config_set(ctx,
- "Listen", API_PORT,
- NULL);
-
- vid = mk_vhost_create(ctx, NULL);
- mk_vhost_set(ctx, vid,
- "Name", "mk_lib",
- NULL);
-
- mk_vhost_handler(ctx, vid, "/200", cb_ok_200, NULL);
- mk_vhost_handler(ctx, vid, "/404", cb_error_404, NULL);
- mk_info("Service: http://%s:%s/404", API_ADDR, API_PORT);
- mk_start(ctx);
-
- sleep(3600);
-
- mk_stop(ctx);
- mk_destroy(ctx);
-
-
- return 0;
-}
diff --git a/fluent-bit/lib/monkey/api/test.c b/fluent-bit/lib/monkey/api/test.c
deleted file mode 100644
index ffb96f135..000000000
--- a/fluent-bit/lib/monkey/api/test.c
+++ /dev/null
@@ -1,186 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-
-#include <monkey/mk_lib.h>
-#include <mk_core/mk_unistd.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <signal.h>
-
-#define API_ADDR "127.0.0.1"
-#define API_PORT "8080"
-
-/* Main context set as global so the signal handler can use it */
-mk_ctx_t *ctx;
-
-void cb_worker(void *data)
-{
- mk_info("[api test] test worker callback; data=%p", data);
-}
-
-
-void cb_sp_test_task_detail(mk_request_t *request, void *data)
-{
- (void) data;
-
- mk_http_status(request, 200);
- mk_http_send(request, "CB_SP_TEST_TASK_DETAIL", strlen("CB_SP_TEST_TASK_DETAIL"), NULL);
- mk_http_done(request);
-}
-
-void cb_sp_test_task_main(mk_request_t *request, void *data)
-{
- (void) data;
-
- mk_http_status(request, 200);
- mk_http_send(request, "CB_SP_TEST_TASK_MAIN", strlen("CB_SP_TEST_TASK_MAIN"), NULL);
- mk_http_done(request);
-}
-
-void cb_main(mk_request_t *request, void *data)
-{
- int i;
- (void) data;
-
- mk_http_status(request, 200);
-
- for (i = 0; i < 20; i++) {
- mk_http_send(request, "first", 5, NULL);
- mk_http_send(request, "second", 6, NULL);
- mk_http_send(request, "third", 5, NULL);
- }
- mk_http_done(request);
-}
-
-void cb_test_chunks(mk_request_t *request, void *data)
-{
- int i = 0;
- int len;
- char tmp[32];
- (void) data;
-
- mk_http_status(request, 200);
- mk_http_header(request, "X-Monkey", 8, "OK", 2);
-
- for (i = 0; i < 4; i++) {
- len = snprintf(tmp, sizeof(tmp) -1, "test-chunk %6i\n ", i);
- mk_http_send(request, tmp, len, NULL);
- }
- mk_http_done(request);
-}
-
-void cb_test_big_chunk(mk_request_t *request, void *data)
-{
- size_t chunk_size = 1024000000;
- char *chunk;
- (void) data;
-
- mk_http_status(request, 200);
- mk_http_header(request, "X-Monkey", 8, "OK", 2);
-
- chunk = calloc(1, chunk_size);
- mk_http_send(request, chunk, chunk_size, NULL);
- free(chunk);
- mk_http_done(request);
-}
-
-
-static void signal_handler(int signal)
-{
- write(STDERR_FILENO, "[engine] caught signal\n", 23);
-
- switch (signal) {
- case SIGTERM:
- case SIGINT:
- mk_stop(ctx);
- mk_destroy(ctx);
- _exit(EXIT_SUCCESS);
- default:
- break;
- }
-}
-
-static void signal_init()
-{
- signal(SIGINT, &signal_handler);
- signal(SIGTERM, &signal_handler);
-}
-
-static void cb_queue_message(mk_mq_t *queue, void *data, size_t size, void *ctx)
-{
- size_t i;
- char *buf;
- (void) ctx;
- (void) queue;
-
- printf("=== cb queue message === \n");
- printf(" => %zu bytes\n", size);
- printf(" => ");
-
- buf = data;
- for (i = 0; i < size; i++) {
- printf("%c", buf[i]);
- }
- printf("\n\n");
-}
-
-
-int main()
-{
- int i = 0;
- int len;
- int vid;
- int qid;
- char msg[800000];
-
- signal_init();
-
- ctx = mk_create();
- if (!ctx) {
- return -1;
- }
-
- /* Create a message queue and a callback for each message */
- qid = mk_mq_create(ctx, "/data", cb_queue_message, NULL);
-
- mk_config_set(ctx,
- "Listen", API_PORT,
- //"Timeout", "1",
- NULL);
-
- vid = mk_vhost_create(ctx, NULL);
- mk_vhost_set(ctx, vid,
- "Name", "monotop",
- NULL);
-
- mk_vhost_handler(ctx, vid, "/api/v1/stream_processor/task/[A-Za-z_][0-9A-Za-z_\\-]*",
- cb_sp_test_task_detail, NULL);
-
- mk_vhost_handler(ctx, vid, "/api/v1/stream_processor/task",
- cb_sp_test_task_main, NULL);
-
- mk_vhost_handler(ctx, vid, "/test_chunks", cb_test_chunks, NULL);
- mk_vhost_handler(ctx, vid, "/test_big_chunk", cb_test_big_chunk, NULL);
- mk_vhost_handler(ctx, vid, "/", cb_main, NULL);
-
-
- mk_worker_callback(ctx,
- cb_worker,
- ctx);
-
- mk_info("Service: http://%s:%s/test_chunks", API_ADDR, API_PORT);
- mk_start(ctx);
-
- for (i = 0; i < 5; i++) {
- len = snprintf(msg, sizeof(msg) - 1, "[...] message ID: %i\n", i);
- mk_mq_send(ctx, qid, &msg, len);
- }
-
- sleep(3600);
-
- mk_stop(ctx);
- mk_destroy(ctx);
-
-
- return 0;
-}