From 3c315f0fff93aa072472abc10815963ac0035268 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 12 Aug 2022 09:26:11 +0200 Subject: Adding upstream version 1.36.0. Signed-off-by: Daniel Baumann --- exporting/tests/exporting_doubles.c | 14 +++++++++--- exporting/tests/exporting_fixtures.c | 39 +++++++++++---------------------- exporting/tests/netdata_doubles.c | 30 ++++++++++++++++--------- exporting/tests/test_exporting_engine.c | 38 +++++++++++++------------------- exporting/tests/test_exporting_engine.h | 20 ++++++++++++----- 5 files changed, 73 insertions(+), 68 deletions(-) (limited to 'exporting/tests') diff --git a/exporting/tests/exporting_doubles.c b/exporting/tests/exporting_doubles.c index b8c9f3756..75ab7ba43 100644 --- a/exporting/tests/exporting_doubles.c +++ b/exporting/tests/exporting_doubles.c @@ -52,11 +52,11 @@ int __wrap_mark_scheduled_instances(struct engine *engine) return mock_type(int); } -calculated_number __real_exporting_calculate_value_from_stored_data( +NETDATA_DOUBLE __real_exporting_calculate_value_from_stored_data( struct instance *instance, RRDDIM *rd, time_t *last_timestamp); -calculated_number __wrap_exporting_calculate_value_from_stored_data( +NETDATA_DOUBLE __wrap_exporting_calculate_value_from_stored_data( struct instance *instance, RRDDIM *rd, time_t *last_timestamp) @@ -67,7 +67,7 @@ calculated_number __wrap_exporting_calculate_value_from_stored_data( *last_timestamp = 15052; function_called(); - return mock_type(calculated_number); + return mock_type(NETDATA_DOUBLE); } int __real_prepare_buffers(struct engine *engine); @@ -156,6 +156,14 @@ int __mock_end_chart_formatting(struct instance *instance, RRDSET *st) return mock_type(int); } +int __mock_variables_formatting(struct instance *instance, RRDHOST *host) +{ + function_called(); + check_expected_ptr(instance); + check_expected_ptr(host); + return mock_type(int); +} + int __mock_end_host_formatting(struct instance *instance, RRDHOST *host) { function_called(); diff --git a/exporting/tests/exporting_fixtures.c b/exporting/tests/exporting_fixtures.c index 501fc405c..aae1c53fb 100644 --- a/exporting/tests/exporting_fixtures.c +++ b/exporting/tests/exporting_fixtures.c @@ -41,17 +41,9 @@ int setup_rrdhost() localhost->tags = strdupz("TAG1=VALUE1 TAG2=VALUE2"); - struct label *label = calloc(1, sizeof(struct label)); - label->key = strdupz("key1"); - label->value = strdupz("value1"); - label->label_source = LABEL_SOURCE_NETDATA_CONF; - localhost->labels.head = label; - - label = calloc(1, sizeof(struct label)); - label->key = strdupz("key2"); - label->value = strdupz("value2"); - label->label_source = LABEL_SOURCE_AUTO; - localhost->labels.head->next = label; + localhost->host_labels = rrdlabels_create(); + rrdlabels_add(localhost->host_labels, "key1", "value1", RRDLABEL_SRC_CONFIG); + rrdlabels_add(localhost->host_labels, "key2", "value2", RRDLABEL_SRC_CONFIG); localhost->rrdset_root = calloc(1, sizeof(RRDSET)); RRDSET *st = localhost->rrdset_root; @@ -71,13 +63,13 @@ int setup_rrdhost() rd->collections_counter++; rd->next = NULL; - rd->state = calloc(1, sizeof(*rd->state)); - rd->state->query_ops.oldest_time = __mock_rrddim_query_oldest_time; - rd->state->query_ops.latest_time = __mock_rrddim_query_latest_time; - rd->state->query_ops.init = __mock_rrddim_query_init; - rd->state->query_ops.is_finished = __mock_rrddim_query_is_finished; - rd->state->query_ops.next_metric = __mock_rrddim_query_next_metric; - rd->state->query_ops.finalize = __mock_rrddim_query_finalize; + rd->tiers[0] = calloc(1, sizeof(struct rrddim_tier)); + rd->tiers[0]->query_ops.oldest_time = __mock_rrddim_query_oldest_time; + rd->tiers[0]->query_ops.latest_time = __mock_rrddim_query_latest_time; + rd->tiers[0]->query_ops.init = __mock_rrddim_query_init; + rd->tiers[0]->query_ops.is_finished = __mock_rrddim_query_is_finished; + rd->tiers[0]->query_ops.next_metric = __mock_rrddim_query_next_metric; + rd->tiers[0]->query_ops.finalize = __mock_rrddim_query_finalize; return 0; } @@ -87,19 +79,14 @@ int teardown_rrdhost() RRDDIM *rd = localhost->rrdset_root->dimensions; free((void *)rd->name); free((void *)rd->id); - free(rd->state); + free(rd->tiers[0]); free(rd); RRDSET *st = localhost->rrdset_root; free((void *)st->name); free(st); - free(localhost->labels.head->next->key); - free(localhost->labels.head->next->value); - free(localhost->labels.head->next); - free(localhost->labels.head->key); - free(localhost->labels.head->value); - free(localhost->labels.head); + rrdlabels_destroy(localhost->host_labels); free((void *)localhost->tags); free(localhost); @@ -124,7 +111,7 @@ int teardown_initialized_engine(void **state) struct engine *engine = *state; teardown_rrdhost(); - buffer_free(engine->instance_root->labels); + buffer_free(engine->instance_root->labels_buffer); buffer_free(engine->instance_root->buffer); teardown_configured_engine(state); diff --git a/exporting/tests/netdata_doubles.c b/exporting/tests/netdata_doubles.c index a9a184336..ee36e887a 100644 --- a/exporting/tests/netdata_doubles.c +++ b/exporting/tests/netdata_doubles.c @@ -177,7 +177,7 @@ const char *rrd_memory_mode_name(RRD_MEMORY_MODE id) return RRD_MEMORY_MODE_NONE_NAME; } -calculated_number rrdvar2number(RRDVAR *rv) +NETDATA_DOUBLE rrdvar2number(RRDVAR *rv) { (void)rv; return 0; @@ -196,26 +196,27 @@ void rrdset_update_heterogeneous_flag(RRDSET *st) (void)st; } -time_t __mock_rrddim_query_oldest_time(RRDDIM *rd) +time_t __mock_rrddim_query_oldest_time(STORAGE_METRIC_HANDLE *db_metric_handle) { - (void)rd; + (void)db_metric_handle; function_called(); return mock_type(time_t); } -time_t __mock_rrddim_query_latest_time(RRDDIM *rd) +time_t __mock_rrddim_query_latest_time(STORAGE_METRIC_HANDLE *db_metric_handle) { - (void)rd; + (void)db_metric_handle; function_called(); return mock_type(time_t); } -void __mock_rrddim_query_init(RRDDIM *rd, struct rrddim_query_handle *handle, time_t start_time, time_t end_time) +void __mock_rrddim_query_init(STORAGE_METRIC_HANDLE *db_metric_handle, struct rrddim_query_handle *handle, time_t start_time, time_t end_time, TIER_QUERY_FETCH tier_query_fetch_type) { - (void)rd; + (void)db_metric_handle; (void)handle; + (void)tier_query_fetch_type; function_called(); check_expected(start_time); @@ -230,13 +231,14 @@ int __mock_rrddim_query_is_finished(struct rrddim_query_handle *handle) return mock_type(int); } -storage_number __mock_rrddim_query_next_metric(struct rrddim_query_handle *handle, time_t *current_time) +STORAGE_POINT __mock_rrddim_query_next_metric(struct rrddim_query_handle *handle) { (void)handle; - (void)current_time; function_called(); - return mock_type(storage_number); + + STORAGE_POINT sp = {}; + return sp; } void __mock_rrddim_query_finalize(struct rrddim_query_handle *handle) @@ -245,3 +247,11 @@ void __mock_rrddim_query_finalize(struct rrddim_query_handle *handle) function_called(); } + +void sql_store_chart_label(uuid_t *chart_uuid, int source_type, char *label, char *value) +{ + (void)chart_uuid; + (void)source_type; + (void)label; + (void)value; +} diff --git a/exporting/tests/test_exporting_engine.c b/exporting/tests/test_exporting_engine.c index 6bb7d2efd..56a28059f 100644 --- a/exporting/tests/test_exporting_engine.c +++ b/exporting/tests/test_exporting_engine.c @@ -307,19 +307,17 @@ static void test_exporting_calculate_value_from_stored_data(void **state) expect_function_call(__mock_rrddim_query_is_finished); will_return(__mock_rrddim_query_is_finished, 0); expect_function_call(__mock_rrddim_query_next_metric); - will_return(__mock_rrddim_query_next_metric, pack_storage_number(27, SN_DEFAULT_FLAGS)); expect_function_call(__mock_rrddim_query_is_finished); will_return(__mock_rrddim_query_is_finished, 0); expect_function_call(__mock_rrddim_query_next_metric); - will_return(__mock_rrddim_query_next_metric, pack_storage_number(45, SN_DEFAULT_FLAGS)); expect_function_call(__mock_rrddim_query_is_finished); will_return(__mock_rrddim_query_is_finished, 1); expect_function_call(__mock_rrddim_query_finalize); - assert_int_equal(__real_exporting_calculate_value_from_stored_data(instance, rd, ×tamp), 36); + assert_float_equal(__real_exporting_calculate_value_from_stored_data(instance, rd, ×tamp), 36, 0.1); } static void test_prepare_buffers(void **state) @@ -381,7 +379,7 @@ static void test_prepare_buffers(void **state) expect_value(__mock_end_batch_formatting, instance, instance); will_return(__mock_end_batch_formatting, 0); - assert_int_equal(__real_prepare_buffers(engine), 0); + __real_prepare_buffers(engine); assert_int_equal(instance->stats.buffered_metrics, 1); @@ -393,7 +391,7 @@ static void test_prepare_buffers(void **state) instance->end_chart_formatting = NULL; instance->end_host_formatting = NULL; instance->end_batch_formatting = NULL; - assert_int_equal(__real_prepare_buffers(engine), 0); + __real_prepare_buffers(engine); assert_int_equal(instance->scheduled, 0); assert_int_equal(instance->after, 2); @@ -705,7 +703,7 @@ static void test_format_host_labels_json_plaintext(void **state) instance->config.options |= EXPORTING_OPTION_SEND_AUTOMATIC_LABELS; assert_int_equal(format_host_labels_json_plaintext(instance, localhost), 0); - assert_string_equal(buffer_tostring(instance->labels), "\"labels\":{\"key1\":\"value1\",\"key2\":\"value2\"},"); + assert_string_equal(buffer_tostring(instance->labels_buffer), "\"labels\":{\"key1\":\"value1\",\"key2\":\"value2\"},"); } static void test_format_host_labels_graphite_plaintext(void **state) @@ -717,7 +715,7 @@ static void test_format_host_labels_graphite_plaintext(void **state) instance->config.options |= EXPORTING_OPTION_SEND_AUTOMATIC_LABELS; assert_int_equal(format_host_labels_graphite_plaintext(instance, localhost), 0); - assert_string_equal(buffer_tostring(instance->labels), ";key1=value1;key2=value2"); + assert_string_equal(buffer_tostring(instance->labels_buffer), ";key1=value1;key2=value2"); } static void test_format_host_labels_opentsdb_telnet(void **state) @@ -729,7 +727,7 @@ static void test_format_host_labels_opentsdb_telnet(void **state) instance->config.options |= EXPORTING_OPTION_SEND_AUTOMATIC_LABELS; assert_int_equal(format_host_labels_opentsdb_telnet(instance, localhost), 0); - assert_string_equal(buffer_tostring(instance->labels), " key1=value1 key2=value2"); + assert_string_equal(buffer_tostring(instance->labels_buffer), " key1=value1 key2=value2"); } static void test_format_host_labels_opentsdb_http(void **state) @@ -741,7 +739,7 @@ static void test_format_host_labels_opentsdb_http(void **state) instance->config.options |= EXPORTING_OPTION_SEND_AUTOMATIC_LABELS; assert_int_equal(format_host_labels_opentsdb_http(instance, localhost), 0); - assert_string_equal(buffer_tostring(instance->labels), ",\"key1\":\"value1\",\"key2\":\"value2\""); + assert_string_equal(buffer_tostring(instance->labels_buffer), ",\"key1\":\"value1\",\"key2\":\"value2\""); } static void test_flush_host_labels(void **state) @@ -749,12 +747,12 @@ static void test_flush_host_labels(void **state) struct engine *engine = *state; struct instance *instance = engine->instance_root; - instance->labels = buffer_create(12); - buffer_strcat(instance->labels, "check string"); - assert_int_equal(buffer_strlen(instance->labels), 12); + instance->labels_buffer = buffer_create(12); + buffer_strcat(instance->labels_buffer, "check string"); + assert_int_equal(buffer_strlen(instance->labels_buffer), 12); assert_int_equal(flush_host_labels(instance, localhost), 0); - assert_int_equal(buffer_strlen(instance->labels), 0); + assert_int_equal(buffer_strlen(instance->labels_buffer), 0); } static void test_create_main_rusage_chart(void **state) @@ -1048,7 +1046,7 @@ static void test_format_host_labels_prometheus(void **state) instance->config.options |= EXPORTING_OPTION_SEND_AUTOMATIC_LABELS; format_host_labels_prometheus(instance, localhost); - assert_string_equal(buffer_tostring(instance->labels), "key1=\"value1\",key2=\"value2\""); + assert_string_equal(buffer_tostring(instance->labels_buffer), "key1=\"value1\",key2=\"value2\""); } static void rrd_stats_api_v1_charts_allmetrics_prometheus(void **state) @@ -1071,9 +1069,7 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(void **state) assert_string_equal( buffer_tostring(buffer), - "netdata_info{instance=\"test_hostname\",application=\"(null)\",version=\"(null)\"} 1\n" - "netdata_host_tags_info{key1=\"value1\",key2=\"value2\"} 1\n" - "netdata_host_tags{key1=\"value1\",key2=\"value2\"} 1\n" + "netdata_info{instance=\"test_hostname\",application=\"(null)\",version=\"(null)\",key1=\"value1\",key2=\"value2\"} 1\n" "test_prefix_test_context{chart=\"chart_id\",family=\"test_family\",dimension=\"dimension_id\"} 690565856.0000000\n"); buffer_flush(buffer); @@ -1089,9 +1085,7 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(void **state) assert_string_equal( buffer_tostring(buffer), - "netdata_info{instance=\"test_hostname\",application=\"(null)\",version=\"(null)\"} 1\n" - "netdata_host_tags_info{key1=\"value1\",key2=\"value2\"} 1\n" - "netdata_host_tags{key1=\"value1\",key2=\"value2\"} 1\n" + "netdata_info{instance=\"test_hostname\",application=\"(null)\",version=\"(null)\",key1=\"value1\",key2=\"value2\"} 1\n" "# TYPE test_prefix_test_context gauge\n" "test_prefix_test_context{chart=\"chart_name\",family=\"test_family\",dimension=\"dimension_name\"} 690565856.0000000\n"); @@ -1107,9 +1101,7 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(void **state) assert_string_equal( buffer_tostring(buffer), - "netdata_info{instance=\"test_hostname\",application=\"(null)\",version=\"(null)\"} 1\n" - "netdata_host_tags_info{instance=\"test_hostname\",key1=\"value1\",key2=\"value2\"} 1\n" - "netdata_host_tags{instance=\"test_hostname\",key1=\"value1\",key2=\"value2\"} 1\n" + "netdata_info{instance=\"test_hostname\",application=\"(null)\",version=\"(null)\",key1=\"value1\",key2=\"value2\"} 1\n" "test_prefix_test_context{chart=\"chart_id\",family=\"test_family\",dimension=\"dimension_id\",instance=\"test_hostname\"} 690565856.0000000\n"); free(localhost->rrdset_root->context); diff --git a/exporting/tests/test_exporting_engine.h b/exporting/tests/test_exporting_engine.h index 800be1b99..ae0b7df9a 100644 --- a/exporting/tests/test_exporting_engine.h +++ b/exporting/tests/test_exporting_engine.h @@ -30,7 +30,14 @@ #include #include #include + +#ifndef UNIT_TESTING +#include +#else +#undef UNIT_TESTING #include +#define UNIT_TESTING +#endif #define MAX_LOG_LINE 1024 extern char log_line[]; @@ -50,11 +57,11 @@ int __wrap_connect_to_one_of( void __rrdhost_check_rdlock(RRDHOST *host, const char *file, const char *function, const unsigned long line); void __rrdset_check_rdlock(RRDSET *st, const char *file, const char *function, const unsigned long line); void __rrd_check_rdlock(const char *file, const char *function, const unsigned long line); -time_t __mock_rrddim_query_oldest_time(RRDDIM *rd); -time_t __mock_rrddim_query_latest_time(RRDDIM *rd); -void __mock_rrddim_query_init(RRDDIM *rd, struct rrddim_query_handle *handle, time_t start_time, time_t end_time); +time_t __mock_rrddim_query_oldest_time(STORAGE_METRIC_HANDLE *db_metric_handle); +time_t __mock_rrddim_query_latest_time(STORAGE_METRIC_HANDLE *db_metric_handle); +void __mock_rrddim_query_init(STORAGE_METRIC_HANDLE *db_metric_handle, struct rrddim_query_handle *handle, time_t start_time, time_t end_time, TIER_QUERY_FETCH tier_query_fetch_type); int __mock_rrddim_query_is_finished(struct rrddim_query_handle *handle); -storage_number __mock_rrddim_query_next_metric(struct rrddim_query_handle *handle, time_t *current_time); +STORAGE_POINT __mock_rrddim_query_next_metric(struct rrddim_query_handle *handle); void __mock_rrddim_query_finalize(struct rrddim_query_handle *handle); // ----------------------------------------------------------------------- @@ -81,11 +88,11 @@ int __wrap_init_connectors(struct engine *engine); int __real_mark_scheduled_instances(struct engine *engine); int __wrap_mark_scheduled_instances(struct engine *engine); -calculated_number __real_exporting_calculate_value_from_stored_data( +NETDATA_DOUBLE __real_exporting_calculate_value_from_stored_data( struct instance *instance, RRDDIM *rd, time_t *last_timestamp); -calculated_number __wrap_exporting_calculate_value_from_stored_data( +NETDATA_DOUBLE __wrap_exporting_calculate_value_from_stored_data( struct instance *instance, RRDDIM *rd, time_t *last_timestamp); @@ -113,6 +120,7 @@ int __mock_start_host_formatting(struct instance *instance, RRDHOST *host); int __mock_start_chart_formatting(struct instance *instance, RRDSET *st); int __mock_metric_formatting(struct instance *instance, RRDDIM *rd); int __mock_end_chart_formatting(struct instance *instance, RRDSET *st); +int __mock_variables_formatting(struct instance *instance, RRDHOST *host); int __mock_end_host_formatting(struct instance *instance, RRDHOST *host); int __mock_end_batch_formatting(struct instance *instance); -- cgit v1.2.3