]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
change values_raw type to typed_value to support distributions
authorSvetlana Shmidt <sshmidt@google.com>
Tue, 15 Sep 2020 08:06:31 +0000 (08:06 +0000)
committerSvetlana Shmidt <sshmidt@google.com>
Tue, 15 Sep 2020 08:06:31 +0000 (08:06 +0000)
src/daemon/utils_cache.c

index 535343c058233c213b3cf754e1ef8b7b1d50b5f3..b894ddc9e47a6e9723e55f77343d4cae0c65ad80 100644 (file)
@@ -44,7 +44,7 @@ typedef struct cache_entry_s {
   char name[6 * DATA_MAX_NAME_LEN];
   distribution_t *distribution_increase;
   gauge_t values_gauge;
-  value_t values_raw;
+  typed_value_t values_raw;
   /* Time contained in the package
    * (for calculating rates) */
   cdtime_t last_time;
@@ -108,7 +108,7 @@ static cache_entry_t *cache_alloc() {
 
   ce->distribution_increase = NULL;
   ce->values_gauge = 0;
-  ce->values_raw = (value_t){.gauge = 0};
+  ce->values_raw = typed_value_create((value_t){.gauge = 0}, METRIC_TYPE_GAUGE);
   ce->history = NULL;
   ce->history_length = 0;
   ce->meta = NULL;
@@ -147,28 +147,28 @@ static int uc_insert(metric_t const *m, char const *key) {
   switch (m->family->type) {
   case DS_TYPE_COUNTER:
     ce->values_gauge = NAN;
-    ce->values_raw.counter = m->value.counter;
+    ce->values_raw = typed_value_create(m->value, METRIC_TYPE_COUNTER);
     ce->distribution_increase = NULL;
     ce->start_value = typed_value_create(m->value, METRIC_TYPE_COUNTER);
     break;
 
   case DS_TYPE_GAUGE:
     ce->values_gauge = m->value.gauge;
-    ce->values_raw.gauge = m->value.gauge;
+    ce->values_raw = typed_value_create(m->value, METRIC_TYPE_GAUGE);
     ce->distribution_increase = NULL;
     ce->start_value = typed_value_create(m->value, METRIC_TYPE_GAUGE);
     break;
 
   case DS_TYPE_DERIVE:
     ce->values_gauge = NAN;
-    ce->values_raw.derive = m->value.derive;
+    //ce->values_raw.derive = m->value.derive;
     ce->distribution_increase = NULL;
     /* TODO: METRIC_TYPE_DERIVE? */
     break;
 
   case DS_TYPE_DISTRIBUTION:
     ce->values_gauge = NAN;
-    ce->values_raw.distribution = distribution_clone(m->value.distribution);
+    ce->values_raw = typed_value_create(m->value, METRIC_TYPE_DISTRIBUTION);
     ce->distribution_increase = distribution_clone(m->value.distribution);
     ce->start_value = typed_value_create(m->value, METRIC_TYPE_DISTRIBUTION);
     break;
@@ -345,16 +345,16 @@ static int uc_update_metric(metric_t const *m) {
 
   switch (m->family->type) {
   case METRIC_TYPE_COUNTER: {
-    counter_t diff = counter_diff(ce->values_raw.counter, m->value.counter);
+    counter_t diff = counter_diff(ce->values_raw.value.counter, m->value.counter);
     ce->values_gauge =
         ((double)diff) / (CDTIME_T_TO_DOUBLE(m->time - ce->last_time));
-    ce->values_raw.counter = m->value.counter;
+    ce->values_raw.value.counter = m->value.counter;
     break;
   }
 
   case METRIC_TYPE_UNTYPED:
   case METRIC_TYPE_GAUGE: {
-    ce->values_raw.gauge = m->value.gauge;
+    ce->values_raw.value.gauge = m->value.gauge;
     ce->values_gauge = m->value.gauge;
     break;
   }
@@ -363,7 +363,7 @@ static int uc_update_metric(metric_t const *m) {
     distribution_destroy(ce->distribution_increase);
     ce->distribution_increase = distribution_clone(m->value.distribution);
     int status = distribution_sub(ce->distribution_increase,
-                                  ce->values_raw.distribution);
+                                  ce->values_raw.value.distribution);
     if (status == ERANGE) {
       distribution_destroy(ce->distribution_increase);
       ce->distribution_increase = distribution_clone(m->value.distribution);
@@ -379,8 +379,8 @@ static int uc_update_metric(metric_t const *m) {
       ERROR("uc_update: distribution_sub failed with status %d.", status);
       return status;
     }
-    distribution_destroy(ce->values_raw.distribution);
-    ce->values_raw.distribution = distribution_clone(m->value.distribution);
+    distribution_destroy(ce->values_raw.value.distribution);
+    ce->values_raw.value.distribution = distribution_clone(m->value.distribution);
     break;
   }
 #if 0
@@ -493,7 +493,7 @@ int uc_get_percentile_by_name(const char *name, gauge_t *ret_values,
       status = -1;
     } else {
       if (ce->distribution_increase == NULL &&
-          ce->values_raw.distribution !=
+          ce->values_raw.value.distribution !=
               NULL) { /* check if the cache entry is not the distribution */
         pthread_mutex_unlock(&cache_lock);
         ERROR("uc_get_percentile: Don't know how to handle data source type "
@@ -561,7 +561,7 @@ int uc_get_rate_by_name(const char *name, gauge_t *ret_values) {
     } else {
 
       if (ce->distribution_increase == NULL &&
-          ce->values_raw.distribution !=
+          ce->values_raw.value.distribution !=
               NULL) { /* check if the cache entry is not the distribution */
         *ret_values = ce->values_gauge;
       } else { /* in case where metric is a distribution, we
@@ -642,7 +642,7 @@ int uc_get_value_by_name(const char *name, value_t *ret_values) {
     if (ce->state == STATE_MISSING) {
       status = -1;
     } else {
-      *ret_values = ce->values_raw;
+      *ret_values = typed_value_clone(ce->values_raw).value;
     }
   } else {
     DEBUG("utils_cache: uc_get_value_by_name: No such value: %s", name);
@@ -1102,7 +1102,7 @@ int uc_iterator_get_values(uc_iter_t *iter, value_t *ret_values) {
   if ((iter == NULL) || (iter->entry == NULL) || (ret_values == NULL))
     return -1;
 
-  *ret_values = iter->entry->values_raw;
+  *ret_values = typed_value_clone(iter->entry->values_raw).value;
   return 0;
 } /* int uc_iterator_get_values */