@cryptotaxi247 / netdata-1 / commits / baa6b9376

weights endpoint: volume diff of anomaly rates (#15004)

when querying the volume delta of anomaly rates, only consider higher highlighted area anomalies

Costa Tsaousis committed May 3, 2023 at 17:16 UTC baa6b9376b443f29007c92091ec90d55b75a698e
1 file changed +21 -36
web/api/queries/weights.c
+21 -36
@@ -91,7 +91,7 @@ static void register_result(DICTIONARY *results, RRDHOST *host, RRDCONTEXT_ACQUI
91 return;
92
93 // keep track of the max of the baseline / highlight ratio
94 - if(flags & RESULT_IS_BASE_HIGH_RATIO && v > stats->max_base_high_ratio)
94 + if((flags & RESULT_IS_BASE_HIGH_RATIO) && v > stats->max_base_high_ratio)
95 stats->max_base_high_ratio = v;
96
97 struct register_result t = {
@@ -730,14 +730,6 @@ static inline struct dict_unique_id_name *dict_unique_id_name_add(DICTIONARY *di
730 return dun;
731 }
732
733 -static inline bool storage_point_should_be_exposed(struct aggregated_weight *aw, RRDR_OPTIONS options, bool baseline) {
734 - if((options & RRDR_OPTION_NONZERO) && netdata_double_is_zero(aw->min) && netdata_double_is_zero(aw->max) && netdata_double_is_zero(aw->sum) &&
735 - storage_point_is_zero(aw->hsp) && (!baseline || storage_point_is_zero(aw->bsp)))
736 - return false;
737 -
738 - return true;
739 -}
740 -
733 static size_t registered_results_to_json_multinode_no_group_by(
734 DICTIONARY *results, BUFFER *wb,
735 time_t after, time_t before,
@@ -782,31 +774,24 @@ static size_t registered_results_to_json_multinode_no_group_by(
774
775 // close instance
776 if(t->ria != last_ria && last_ria) {
785 - if(storage_point_should_be_exposed(&instance_aw, options, baseline)) {
786 - storage_point_to_json(wb, WPT_INSTANCE, di, ii, ci, ni, &instance_aw, options, baseline);
787 - instance_dun->exposed = true;
788 - }
789 -
777 + storage_point_to_json(wb, WPT_INSTANCE, di, ii, ci, ni, &instance_aw, options, baseline);
778 + instance_dun->exposed = true;
779 last_ria = NULL;
780 instance_aw = AGGREGATED_WEIGHT_EMPTY;
781 }
782
783 // close context
784 if(t->rca != last_rca && last_rca) {
796 - if(storage_point_should_be_exposed(&context_aw, options, baseline)) {
797 - storage_point_to_json(wb, WPT_CONTEXT, di, ii, ci, ni, &context_aw, options, baseline);
798 - context_dun->exposed = true;
799 - }
785 + storage_point_to_json(wb, WPT_CONTEXT, di, ii, ci, ni, &context_aw, options, baseline);
786 + context_dun->exposed = true;
787 last_rca = NULL;
788 context_aw = AGGREGATED_WEIGHT_EMPTY;
789 }
790
791 // close node
792 if(t->host != last_host && last_host) {
806 - if(storage_point_should_be_exposed(&node_aw, options, baseline)) {
807 - storage_point_to_json(wb, WPT_NODE, di, ii, ci, ni, &node_aw, options, baseline);
808 - node_dun->exposed = true;
809 - }
793 + storage_point_to_json(wb, WPT_NODE, di, ii, ci, ni, &node_aw, options, baseline);
794 + node_dun->exposed = true;
795 last_host = NULL;
796 node_aw = AGGREGATED_WEIGHT_EMPTY;
797 }
@@ -845,13 +830,11 @@ static size_t registered_results_to_json_multinode_no_group_by(
830 .bsp = t->baseline,
831 };
832
848 - if(storage_point_should_be_exposed(&aw, options, baseline)) {
849 - storage_point_to_json(wb, WPT_DIMENSION, di, ii, ci, ni, &aw, options, baseline);
850 - node_dun->exposed = true;
851 - context_dun->exposed = true;
852 - instance_dun->exposed = true;
853 - dimension_dun->exposed = true;
854 - }
833 + storage_point_to_json(wb, WPT_DIMENSION, di, ii, ci, ni, &aw, options, baseline);
834 + node_dun->exposed = true;
835 + context_dun->exposed = true;
836 + instance_dun->exposed = true;
837 + dimension_dun->exposed = true;
838
839 merge_into_aw(instance_aw, t);
840 merge_into_aw(context_aw, t);
@@ -863,19 +846,19 @@ static size_t registered_results_to_json_multinode_no_group_by(
846 dfe_done(t);
847
848 // close instance
866 - if(last_ria && storage_point_should_be_exposed(&instance_aw, options, baseline)) {
849 + if(last_ria) {
850 storage_point_to_json(wb, WPT_INSTANCE, di, ii, ci, ni, &instance_aw, options, baseline);
851 instance_dun->exposed = true;
852 }
853
854 // close context
872 - if(last_rca && storage_point_should_be_exposed(&context_aw, options, baseline)) {
855 + if(last_rca) {
856 storage_point_to_json(wb, WPT_CONTEXT, di, ii, ci, ni, &context_aw, options, baseline);
857 context_dun->exposed = true;
858 }
859
860 // close node
878 - if(last_host && storage_point_should_be_exposed(&node_aw, options, baseline)) {
861 + if(last_host) {
862 storage_point_to_json(wb, WPT_NODE, di, ii, ci, ni, &node_aw, options, baseline);
863 node_dun->exposed = true;
864 }
@@ -1070,9 +1053,6 @@ static size_t registered_results_to_json_multinode_group_by(
1053 const char *k = aw_dfe.name;
1054 const char *n = aw->name;
1055
1073 - if(!storage_point_should_be_exposed(aw, options, baseline))
1074 - continue;
1075 -
1056 buffer_json_add_array_item_object(wb);
1057 buffer_json_member_add_string(wb, "id", k);
1058
@@ -1454,6 +1434,11 @@ static void rrdset_metric_correlations_volume(
1434 return;
1435 }
1436
1437 + if((options & RRDR_OPTION_ANOMALY_BIT) && highlight_average.value < baseline_average.value) {
1438 + // when working on anomaly bits, we are looking for an increase in the anomaly rate
1439 + return;
1440 + }
1441 +
1442 char highlight_countif_options[50 + 1];
1443 snprintfz(highlight_countif_options, 50, "%s" NETDATA_DOUBLE_FORMAT, highlight_average.value < baseline_average.value ? "<" : ">", baseline_average.value);
1444 QUERY_VALUE highlight_countif = rrdmetric2value(host, rca, ria, rma, after, before,
@@ -1627,7 +1612,7 @@ static size_t spread_results_evenly(DICTIONARY *results, WEIGHTS_STATS *stats) {
1612 NETDATA_DOUBLE slots[dimensions];
1613 dimensions = 0;
1614 dfe_start_read(results, t) {
1630 - if(t->flags & (RESULT_IS_PERCENTAGE_OF_TIME))
1615 + if(t->flags & RESULT_IS_PERCENTAGE_OF_TIME)
1616 t->value = t->value * stats->max_base_high_ratio;
1617
1618 slots[dimensions++] = t->value;