diff options
Diffstat (limited to 'exporting')
-rw-r--r-- | exporting/process_data.c | 21 | ||||
-rw-r--r-- | exporting/tests/exporting_fixtures.c | 16 | ||||
-rw-r--r-- | exporting/tests/netdata_doubles.c | 23 | ||||
-rw-r--r-- | exporting/tests/test_exporting_engine.c | 2 | ||||
-rw-r--r-- | exporting/tests/test_exporting_engine.h | 8 |
5 files changed, 32 insertions, 38 deletions
diff --git a/exporting/process_data.c b/exporting/process_data.c index f70b39294c..d9154f81b6 100644 --- a/exporting/process_data.c +++ b/exporting/process_data.c @@ -77,8 +77,8 @@ NETDATA_DOUBLE exporting_calculate_value_from_stored_data( time_t before = instance->before; // find the edges of the rrd database for this chart - time_t first_t = rd->state->query_ops.oldest_time(rd); - time_t last_t = rd->state->query_ops.latest_time(rd); + time_t first_t = rd->tiers[0]->query_ops.oldest_time(rd->tiers[0]->db_metric_handle); + time_t last_t = rd->tiers[0]->query_ops.latest_time(rd->tiers[0]->db_metric_handle); time_t update_every = st->update_every; struct rrddim_query_handle handle; @@ -124,23 +124,20 @@ NETDATA_DOUBLE exporting_calculate_value_from_stored_data( size_t counter = 0; NETDATA_DOUBLE sum = 0; - NETDATA_DOUBLE value; - for (rd->state->query_ops.init(rd, &handle, after, before); !rd->state->query_ops.is_finished(&handle);) { - time_t curr_t, end_t; - SN_FLAGS flags; - value = rd->state->query_ops.next_metric(&handle, &curr_t, &end_t, &flags); + for (rd->tiers[0]->query_ops.init(rd->tiers[0]->db_metric_handle, &handle, after, before, TIER_QUERY_FETCH_SUM); !rd->tiers[0]->query_ops.is_finished(&handle);) { + STORAGE_POINT sp = rd->tiers[0]->query_ops.next_metric(&handle); - if (unlikely(!netdata_double_isnumber(value))) { + if (unlikely(storage_point_is_empty(sp))) { // not collected continue; } - sum += value; - - counter++; + sum += sp.sum; + counter += sp.count; } - rd->state->query_ops.finalize(&handle); + rd->tiers[0]->query_ops.finalize(&handle); + if (unlikely(!counter)) { debug( D_EXPORTING, diff --git a/exporting/tests/exporting_fixtures.c b/exporting/tests/exporting_fixtures.c index 4f5bd4b277..aae1c53fb2 100644 --- a/exporting/tests/exporting_fixtures.c +++ b/exporting/tests/exporting_fixtures.c @@ -63,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; } @@ -79,7 +79,7 @@ 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; diff --git a/exporting/tests/netdata_doubles.c b/exporting/tests/netdata_doubles.c index 066f52f215..ee36e887a2 100644 --- a/exporting/tests/netdata_doubles.c +++ b/exporting/tests/netdata_doubles.c @@ -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,16 +231,14 @@ int __mock_rrddim_query_is_finished(struct rrddim_query_handle *handle) return mock_type(int); } -NETDATA_DOUBLE __mock_rrddim_query_next_metric(struct rrddim_query_handle *handle, time_t *start_time, time_t *end_time, SN_FLAGS *flags) +STORAGE_POINT __mock_rrddim_query_next_metric(struct rrddim_query_handle *handle) { (void)handle; - (void)start_time; - (void)end_time; - (void) flags; - function_called(); - return mock_type(NETDATA_DOUBLE); + + STORAGE_POINT sp = {}; + return sp; } void __mock_rrddim_query_finalize(struct rrddim_query_handle *handle) diff --git a/exporting/tests/test_exporting_engine.c b/exporting/tests/test_exporting_engine.c index e265ef7de9..bc00e34e1a 100644 --- a/exporting/tests/test_exporting_engine.c +++ b/exporting/tests/test_exporting_engine.c @@ -307,12 +307,10 @@ 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, 27); 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, 45); expect_function_call(__mock_rrddim_query_is_finished); will_return(__mock_rrddim_query_is_finished, 1); diff --git a/exporting/tests/test_exporting_engine.h b/exporting/tests/test_exporting_engine.h index 298a77a9fd..2072dc64f8 100644 --- a/exporting/tests/test_exporting_engine.h +++ b/exporting/tests/test_exporting_engine.h @@ -57,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); -NETDATA_DOUBLE __mock_rrddim_query_next_metric(struct rrddim_query_handle *handle, time_t *start_time, time_t *end_time, SN_FLAGS *flags); +STORAGE_POINT __mock_rrddim_query_next_metric(struct rrddim_query_handle *handle); void __mock_rrddim_query_finalize(struct rrddim_query_handle *handle); // ----------------------------------------------------------------------- |