@cryptotaxi247 / netdata-1 / commits / a763d4111

Store dimension hidden option in the metadata db (#12196)

* Add a function to update dimension options in the metadata database * Update the option for dimension to be hidden/unhinden when rrdim_hide/rrdim_unhide is called * Store the hidden option for dimensions to the database

Stelios Fragkakis committed Feb 23, 2022 at 18:31 UTC a763d4111c13022f7b2014a2444d232a7edc7f7c
4 files changed +52 -1
collectors/plugins.d/pluginsd_parser.c
+6 -1
@@ -132,13 +132,18 @@ PARSER_RC pluginsd_dimension_action(void *user, RRDSET *st, char *id, char *name
132 rrddim_is_obsolete(st, rd);
133 else
134 rrddim_isnot_obsolete(st, rd);
135 - if (strstr(options, "hidden") != NULL)
135 + if (strstr(options, "hidden") != NULL) {
136 rrddim_flag_set(rd, RRDDIM_FLAG_HIDDEN);
137 + (void) sql_set_dimension_option(&rd->state->metric_uuid, "hidden");
138 + }
139 + else
140 + (void) sql_set_dimension_option(&rd->state->metric_uuid, NULL);
141 if (strstr(options, "noreset") != NULL)
142 rrddim_flag_set(rd, RRDDIM_FLAG_DONT_DETECT_RESETS_OR_OVERFLOWS);
143 if (strstr(options, "nooverflow") != NULL)
144 rrddim_flag_set(rd, RRDDIM_FLAG_DONT_DETECT_RESETS_OR_OVERFLOWS);
145 } else {
146 + (void) sql_set_dimension_option(&rd->state->metric_uuid, NULL);
147 rrddim_isnot_obsolete(st, rd);
148 }
149 return PARSER_RC_OK;
database/rrddim.c
+2
@@ -541,6 +541,7 @@ int rrddim_hide(RRDSET *st, const char *id) {
541 error("Cannot find dimension with id '%s' on stats '%s' (%s) on host '%s'.", id, st->name, st->id, host->hostname);
542 return 1;
543 }
544 + (void) sql_set_dimension_option(&rd->state->metric_uuid, "hidden");
545
546 rrddim_flag_set(rd, RRDDIM_FLAG_HIDDEN);
547 #ifdef ENABLE_ACLK
@@ -558,6 +559,7 @@ int rrddim_unhide(RRDSET *st, const char *id) {
559 error("Cannot find dimension with id '%s' on stats '%s' (%s) on host '%s'.", id, st->name, st->id, host->hostname);
560 return 1;
561 }
562 + (void) sql_set_dimension_option(&rd->state->metric_uuid, NULL);
563
564 rrddim_flag_clear(rd, RRDDIM_FLAG_HIDDEN);
565 #ifdef ENABLE_ACLK
database/sqlite/sqlite_functions.c
+43
@@ -905,6 +905,49 @@ bind_fail:
905 return 1;
906 }
907
908 +/*
909 + * Store set option for a dimension
910 + */
911 +int sql_set_dimension_option(uuid_t *dim_uuid, char *option)
912 +{
913 + sqlite3_stmt *res = NULL;
914 + int rc;
915 +
916 + if (unlikely(!db_meta)) {
917 + if (default_rrd_memory_mode != RRD_MEMORY_MODE_DBENGINE)
918 + return 0;
919 + error_report("Database has not been initialized");
920 + return 1;
921 + }
922 +
923 + rc = sqlite3_prepare_v2(db_meta, "UPDATE dimension SET options = @options WHERE dim_id = @dim_id", -1, &res, 0);
924 + if (unlikely(rc != SQLITE_OK)) {
925 + error_report("Failed to prepare statement to update dimension options");
926 + return 0;
927 + };
928 +
929 + rc = sqlite3_bind_blob(res, 2, dim_uuid, sizeof(*dim_uuid), SQLITE_STATIC);
930 + if (unlikely(rc != SQLITE_OK))
931 + goto bind_fail;
932 +
933 + if (!option || !strcmp(option,"unhide"))
934 + rc = sqlite3_bind_null(res, 1);
935 + else
936 + rc = sqlite3_bind_text(res, 1, option, -1, SQLITE_STATIC);
937 + if (unlikely(rc != SQLITE_OK))
938 + goto bind_fail;
939 +
940 + rc = execute_insert(res);
941 + if (unlikely(rc != SQLITE_DONE))
942 + error_report("Failed to update dimension option, rc = %d", rc);
943 +
944 +bind_fail:
945 + rc = sqlite3_finalize(res);
946 + if (unlikely(rc != SQLITE_OK))
947 + error_report("Failed to finalize statement in update dimension options, rc = %d", rc);
948 + return 0;
949 +}
950 +
951
952 //
953 // Support for archived charts
database/sqlite/sqlite_functions.h
+1
@@ -98,4 +98,5 @@ extern void invalidate_node_instances(uuid_t *host_id, uuid_t *claim_id);
98 extern struct node_instance_list *get_node_list(void);
99 extern void sql_load_node_id(RRDHOST *host);
100 extern void compute_chart_hash(RRDSET *st);
101 +extern int sql_set_dimension_option(uuid_t *dim_uuid, char *option);
102 #endif //NETDATA_SQLITE_FUNCTIONS_H