fix for chart and dimension renames - health variables are also renamed
Costa Tsaousis (ktsaou) committed
Nov 12, 2016 at 22:22 UTC
0e0509c094f8a522f7e34918fd52d77467f672c7
4 files changed
+320
-201
src/health.c
+234
-168
@@ -486,8 +486,10 @@ static inline void rrdvar_free(RRDHOST *host, avl_tree_lock *tree, RRDVAR *rv) {
486
487
if(!rv) return;
488
489
- if(tree)
489
+ if(tree) {
490
+ debug(D_VARIABLES, "Deleting variable '%s'", rv->name);
491
rrdvar_index_del(tree, rv);
492
+ }
493
494
freez(rv->name);
495
freez(rv);
@@ -518,6 +520,8 @@ static inline RRDVAR *rrdvar_create_and_index(const char *scope, avl_tree_lock *
520
debug(D_VARIABLES, "Variable '%s' created in scope '%s'", variable, scope);
521
}
522
else {
523
+ debug(D_VARIABLES, "Variable '%s' is already found in scope '%s'.", variable, scope);
524
+
525
// already exists
526
freez(variable);
527
@@ -606,205 +610,152 @@ int health_variable_lookup(const char *variable, uint32_t hash, RRDCALC *rc, cal
610
return 0;
611
}
612
609
-// ----------------------------------------------------------------------------
610
-// RRDSETVAR management
611
-
612
-RRDSETVAR *rrdsetvar_create(RRDSET *st, const char *variable, int type, void *value, uint32_t options) {
613
- debug(D_VARIABLES, "RRDVARSET create for chart id '%s' name '%s' with variable name '%s'", st->id, st->name, variable);
614
- RRDSETVAR *rs = (RRDSETVAR *)callocz(1, sizeof(RRDSETVAR));
615
-
616
- char buffer[RRDVAR_MAX_LENGTH + 1];
617
- snprintfz(buffer, RRDVAR_MAX_LENGTH, "%s.%s", st->id, variable);
618
- rs->fullid = strdupz(buffer);
619
-
620
- snprintfz(buffer, RRDVAR_MAX_LENGTH, "%s.%s", st->name, variable);
621
- rs->fullname = strdupz(buffer);
622
-
623
- rs->variable = strdupz(variable);
624
-
625
- rs->type = type;
626
- rs->value = value;
627
- rs->options = options;
628
- rs->rrdset = st;
629
-
630
- rs->local = rrdvar_create_and_index("local", &st->variables_root_index, rs->variable, rs->type, rs->value);
631
- rs->family = rrdvar_create_and_index("family", &st->rrdfamily->variables_root_index, rs->fullid, rs->type, rs->value);
632
- rs->host = rrdvar_create_and_index("host", &st->rrdhost->variables_root_index, rs->fullid, rs->type, rs->value);
633
- rs->family_name = rrdvar_create_and_index("family", &st->rrdfamily->variables_root_index, rs->fullname, rs->type, rs->value);
634
- rs->host_name = rrdvar_create_and_index("host", &st->rrdhost->variables_root_index, rs->fullname, rs->type, rs->value);
635
-
636
- rs->next = st->variables;
637
- st->variables = rs;
638
-
639
- return rs;
640
-}
641
-
642
-void rrdsetvar_rename_all(RRDSET *st) {
643
- debug(D_VARIABLES, "RRDSETVAR rename for chart id '%s' name '%s'", st->id, st->name);
644
-
645
- // only these 2 can change name
646
- // rs->family_name
647
- // rs->host_name
648
-
649
- char buffer[RRDVAR_MAX_LENGTH + 1];
650
- RRDSETVAR *rs, *next = st->variables;
651
- while((rs = next)) {
652
- next = rs->next;
653
-
654
- snprintfz(buffer, RRDVAR_MAX_LENGTH, "%s.%s", st->name, rs->variable);
655
-
656
- if (strcmp(buffer, rs->fullname)) {
657
- // name changed
658
- rrdvar_free(st->rrdhost, &st->rrdfamily->variables_root_index, rs->family_name);
659
- rrdvar_free(st->rrdhost, &st->rrdhost->variables_root_index, rs->host_name);
660
-
661
- freez(rs->fullname);
662
- rs->fullname = strdupz(st->name);
663
- rs->family_name = rrdvar_create_and_index("family", &st->rrdfamily->variables_root_index, rs->fullname, rs->type, rs->value);
664
- rs->host_name = rrdvar_create_and_index("host", &st->rrdhost->variables_root_index, rs->fullname, rs->type, rs->value);
665
- }
666
- }
667
-
668
- rrdsetcalc_link_matching(st);
669
-}
670
-
671
-void rrdsetvar_free(RRDSETVAR *rs) {
672
- RRDSET *st = rs->rrdset;
673
- debug(D_VARIABLES, "RRDSETVAR free for chart id '%s' name '%s', variable '%s'", st->id, st->name, rs->variable);
674
-
675
- rrdvar_free(st->rrdhost, &st->variables_root_index, rs->local);
676
- rrdvar_free(st->rrdhost, &st->rrdfamily->variables_root_index, rs->family);
677
- rrdvar_free(st->rrdhost, &st->rrdhost->variables_root_index, rs->host);
678
- rrdvar_free(st->rrdhost, &st->rrdfamily->variables_root_index, rs->family_name);
679
- rrdvar_free(st->rrdhost, &st->rrdhost->variables_root_index, rs->host_name);
680
-
681
- if(st->variables == rs) {
682
- st->variables = rs->next;
683
- }
684
- else {
685
- RRDSETVAR *t;
686
- for (t = st->variables; t && t->next != rs; t = t->next);
687
- if(!t) error("RRDSETVAR '%s' not found in chart '%s' variables linked list", rs->fullname, st->id);
688
- else t->next = rs->next;
689
- }
690
-
691
- freez(rs->fullid);
692
- freez(rs->fullname);
693
- freez(rs->variable);
694
- freez(rs);
695
-}
696
-
613
// ----------------------------------------------------------------------------
614
// RRDDIMVAR management
615
+// DIMENSION VARIABLES
616
617
#define RRDDIMVAR_ID_MAX 1024
618
702
-static inline void rrddimvar_free_instances(RRDDIMVAR *rs) {
619
+static inline void rrddimvar_free_variables(RRDDIMVAR *rs) {
620
RRDDIM *rd = rs->rrddim;
621
RRDSET *st = rd->rrdset;
622
706
- rrdvar_free(st->rrdhost, &st->variables_root_index, rs->local_id);
707
- rs->local_id = NULL;
623
+ // CHART VARIABLES FOR THIS DIMENSION
624
+
625
+ rrdvar_free(st->rrdhost, &st->variables_root_index, rs->var_local_id);
626
+ rs->var_local_id = NULL;
627
+
628
+ rrdvar_free(st->rrdhost, &st->variables_root_index, rs->var_local_name);
629
+ rs->var_local_name = NULL;
630
+
631
+ // FAMILY VARIABLES FOR THIS DIMENSION
632
709
- rrdvar_free(st->rrdhost, &st->variables_root_index, rs->local_name);
710
- rs->local_name = NULL;
633
+ rrdvar_free(st->rrdhost, &st->rrdfamily->variables_root_index, rs->var_family_id);
634
+ rs->var_family_id = NULL;
635
712
- rrdvar_free(st->rrdhost, &st->rrdfamily->variables_root_index, rs->family_id);
713
- rs->family_id = NULL;
636
+ rrdvar_free(st->rrdhost, &st->rrdfamily->variables_root_index, rs->var_family_name);
637
+ rs->var_family_name = NULL;
638
715
- rrdvar_free(st->rrdhost, &st->rrdfamily->variables_root_index, rs->family_name);
716
- rs->family_name = NULL;
639
+ rrdvar_free(st->rrdhost, &st->rrdfamily->variables_root_index, rs->var_family_contextid);
640
+ rs->var_family_contextid = NULL;
641
718
- rrdvar_free(st->rrdhost, &st->rrdfamily->variables_root_index, rs->family_contextid);
719
- rs->family_contextid = NULL;
642
+ rrdvar_free(st->rrdhost, &st->rrdfamily->variables_root_index, rs->var_family_contextname);
643
+ rs->var_family_contextname = NULL;
644
721
- rrdvar_free(st->rrdhost, &st->rrdfamily->variables_root_index, rs->family_contextname);
722
- rs->family_contextname = NULL;
645
+ // HOST VARIABLES FOR THIS DIMENSION
646
724
- rrdvar_free(st->rrdhost, &st->rrdhost->variables_root_index, rs->host_fullidid);
725
- rs->host_fullidid = NULL;
647
+ rrdvar_free(st->rrdhost, &st->rrdhost->variables_root_index, rs->var_host_chartidid);
648
+ rs->var_host_chartidid = NULL;
649
727
- rrdvar_free(st->rrdhost, &st->rrdhost->variables_root_index, rs->host_fullidname);
728
- rs->host_fullidname = NULL;
650
+ rrdvar_free(st->rrdhost, &st->rrdhost->variables_root_index, rs->var_host_chartidname);
651
+ rs->var_host_chartidname = NULL;
652
730
- rrdvar_free(st->rrdhost, &st->rrdhost->variables_root_index, rs->host_fullnameid);
731
- rs->host_fullnameid = NULL;
653
+ rrdvar_free(st->rrdhost, &st->rrdhost->variables_root_index, rs->var_host_chartnameid);
654
+ rs->var_host_chartnameid = NULL;
655
733
- rrdvar_free(st->rrdhost, &st->rrdhost->variables_root_index, rs->host_fullnamename);
734
- rs->host_fullnamename = NULL;
656
+ rrdvar_free(st->rrdhost, &st->rrdhost->variables_root_index, rs->var_host_chartnamename);
657
+ rs->var_host_chartnamename = NULL;
658
736
- freez(rs->id);
737
- rs->id = NULL;
659
+ // KEYS
660
739
- freez(rs->name);
740
- rs->name = NULL;
661
+ freez(rs->key_id);
662
+ rs->key_id = NULL;
663
742
- freez(rs->fullidid);
743
- rs->fullidid = NULL;
664
+ freez(rs->key_name);
665
+ rs->key_name = NULL;
666
745
- freez(rs->fullidname);
746
- rs->fullidname = NULL;
667
+ freez(rs->key_fullidid);
668
+ rs->key_fullidid = NULL;
669
748
- freez(rs->contextid);
749
- rs->contextid = NULL;
670
+ freez(rs->key_fullidname);
671
+ rs->key_fullidname = NULL;
672
751
- freez(rs->contextname);
752
- rs->contextname = NULL;
673
+ freez(rs->key_contextid);
674
+ rs->key_contextid = NULL;
675
754
- freez(rs->fullnameid);
755
- rs->fullnameid = NULL;
676
+ freez(rs->key_contextname);
677
+ rs->key_contextname = NULL;
678
757
- freez(rs->fullnamename);
758
- rs->fullnamename = NULL;
679
+ freez(rs->key_fullnameid);
680
+ rs->key_fullnameid = NULL;
681
+
682
+ freez(rs->key_fullnamename);
683
+ rs->key_fullnamename = NULL;
684
}
685
761
-static inline void rrddimvar_create_instances(RRDDIMVAR *rs) {
762
- rrddimvar_free_instances(rs);
686
+static inline void rrddimvar_create_variables(RRDDIMVAR *rs) {
687
+ rrddimvar_free_variables(rs);
688
689
RRDDIM *rd = rs->rrddim;
690
RRDSET *st = rd->rrdset;
691
692
char buffer[RRDDIMVAR_ID_MAX + 1];
693
694
+ // KEYS
695
+
696
snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s%s%s", rs->prefix, rd->id, rs->suffix);
770
- rs->id = strdupz(buffer);
697
+ rs->key_id = strdupz(buffer);
698
699
snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s%s%s", rs->prefix, rd->name, rs->suffix);
773
- rs->name = strdupz(buffer);
774
-
775
- snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", st->id, rs->id);
776
- rs->fullidid = strdupz(buffer);
777
-
778
- snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", st->id, rs->name);
779
- rs->fullidname = strdupz(buffer);
780
-
781
- snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", st->context, rs->id);
782
- rs->contextid = strdupz(buffer);
783
-
784
- snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", st->context, rs->name);
785
- rs->contextname = strdupz(buffer);
786
-
787
- snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", st->name, rs->id);
788
- rs->fullnameid = strdupz(buffer);
789
-
790
- snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", st->name, rs->name);
791
- rs->fullnamename = strdupz(buffer);
792
-
793
- rs->local_id = rrdvar_create_and_index("local", &st->variables_root_index, rs->id, rs->type, rs->value);
794
- rs->local_name = rrdvar_create_and_index("local", &st->variables_root_index, rs->name, rs->type, rs->value);
795
-
796
- rs->family_id = rrdvar_create_and_index("family", &st->rrdfamily->variables_root_index, rs->id, rs->type, rs->value);
797
- rs->family_name = rrdvar_create_and_index("family", &st->rrdfamily->variables_root_index, rs->name, rs->type, rs->value);
798
- rs->family_contextid = rrdvar_create_and_index("family", &st->rrdfamily->variables_root_index, rs->contextid, rs->type, rs->value);
799
- rs->family_contextname = rrdvar_create_and_index("family", &st->rrdfamily->variables_root_index, rs->contextname, rs->type, rs->value);
800
-
801
- rs->host_fullidid = rrdvar_create_and_index("host", &st->rrdhost->variables_root_index, rs->fullidid, rs->type, rs->value);
802
- rs->host_fullidname = rrdvar_create_and_index("host", &st->rrdhost->variables_root_index, rs->fullidname, rs->type, rs->value);
803
- rs->host_fullnameid = rrdvar_create_and_index("host", &st->rrdhost->variables_root_index, rs->fullnameid, rs->type, rs->value);
804
- rs->host_fullnamename = rrdvar_create_and_index("host", &st->rrdhost->variables_root_index, rs->fullnamename, rs->type, rs->value);
700
+ rs->key_name = strdupz(buffer);
701
+
702
+ snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", st->id, rs->key_id);
703
+ rs->key_fullidid = strdupz(buffer);
704
+
705
+ snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", st->id, rs->key_name);
706
+ rs->key_fullidname = strdupz(buffer);
707
+
708
+ snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", st->context, rs->key_id);
709
+ rs->key_contextid = strdupz(buffer);
710
+
711
+ snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", st->context, rs->key_name);
712
+ rs->key_contextname = strdupz(buffer);
713
+
714
+ snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", st->name, rs->key_id);
715
+ rs->key_fullnameid = strdupz(buffer);
716
+
717
+ snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", st->name, rs->key_name);
718
+ rs->key_fullnamename = strdupz(buffer);
719
+
720
+ // CHART VARIABLES FOR THIS DIMENSION
721
+ // -----------------------------------
722
+ //
723
+ // dimensions are available as:
724
+ // - $id
725
+ // - $name
726
+
727
+ rs->var_local_id = rrdvar_create_and_index("local", &st->variables_root_index, rs->key_id, rs->type, rs->value);
728
+ rs->var_local_name = rrdvar_create_and_index("local", &st->variables_root_index, rs->key_name, rs->type, rs->value);
729
+
730
+ // FAMILY VARIABLES FOR THIS DIMENSION
731
+ // -----------------------------------
732
+ //
733
+ // dimensions are available as:
734
+ // - $id (only the first, when multiple overlap)
735
+ // - $name (only the first, when multiple overlap)
736
+ // - $chart-context.id
737
+ // - $chart-context.name
738
+
739
+ rs->var_family_id = rrdvar_create_and_index("family", &st->rrdfamily->variables_root_index, rs->key_id, rs->type, rs->value);
740
+ rs->var_family_name = rrdvar_create_and_index("family", &st->rrdfamily->variables_root_index, rs->key_name, rs->type, rs->value);
741
+ rs->var_family_contextid = rrdvar_create_and_index("family", &st->rrdfamily->variables_root_index, rs->key_contextid, rs->type, rs->value);
742
+ rs->var_family_contextname = rrdvar_create_and_index("family", &st->rrdfamily->variables_root_index, rs->key_contextname, rs->type, rs->value);
743
+
744
+ // HOST VARIABLES FOR THIS DIMENSION
745
+ // -----------------------------------
746
+ //
747
+ // dimensions are available as:
748
+ // - $chart-id.id
749
+ // - $chart-id.name
750
+ // - $chart-name.id
751
+ // - $chart-name.name
752
+
753
+ rs->var_host_chartidid = rrdvar_create_and_index("host", &st->rrdhost->variables_root_index, rs->key_fullidid, rs->type, rs->value);
754
+ rs->var_host_chartidname = rrdvar_create_and_index("host", &st->rrdhost->variables_root_index, rs->key_fullidname, rs->type, rs->value);
755
+ rs->var_host_chartnameid = rrdvar_create_and_index("host", &st->rrdhost->variables_root_index, rs->key_fullnameid, rs->type, rs->value);
756
+ rs->var_host_chartnamename = rrdvar_create_and_index("host", &st->rrdhost->variables_root_index, rs->key_fullnamename, rs->type, rs->value);
757
}
758
807
-
759
RRDDIMVAR *rrddimvar_create(RRDDIM *rd, int type, const char *prefix, const char *suffix, void *value, uint32_t options) {
760
RRDSET *st = rd->rrdset;
761
@@ -826,7 +777,7 @@ RRDDIMVAR *rrddimvar_create(RRDDIM *rd, int type, const char *prefix, const char
777
rs->next = rd->variables;
778
rd->variables = rs;
779
829
- rrddimvar_create_instances(rs);
780
+ rrddimvar_create_variables(rs);
781
782
return rs;
783
}
@@ -838,9 +789,7 @@ void rrddimvar_rename_all(RRDDIM *rd) {
789
RRDDIMVAR *rs, *next = rd->variables;
790
while((rs = next)) {
791
next = rs->next;
841
-
842
- if (strcmp(rd->name, rs->name))
843
- rrddimvar_create_instances(rs);
792
+ rrddimvar_create_variables(rs);
793
}
794
}
795
@@ -849,7 +798,7 @@ void rrddimvar_free(RRDDIMVAR *rs) {
798
RRDSET *st = rd->rrdset;
799
debug(D_VARIABLES, "RRDDIMSET free for chart id '%s' name '%s', dimension id '%s', name '%s', prefix='%s', suffix='%s'", st->id, st->name, rd->id, rd->name, rs->prefix, rs->suffix);
800
852
- rrddimvar_free_instances(rs);
801
+ rrddimvar_free_variables(rs);
802
803
if(rd->variables == rs) {
804
debug(D_VARIABLES, "RRDDIMSET removing first entry for chart id '%s' name '%s', dimension id '%s', name '%s'", st->id, st->name, rd->id, rd->name);
@@ -859,7 +808,7 @@ void rrddimvar_free(RRDDIMVAR *rs) {
808
debug(D_VARIABLES, "RRDDIMSET removing non-first entry for chart id '%s' name '%s', dimension id '%s', name '%s'", st->id, st->name, rd->id, rd->name);
809
RRDDIMVAR *t;
810
for (t = rd->variables; t && t->next != rs; t = t->next) ;
862
- if(!t) error("RRDDIMVAR '%s' not found in dimension '%s/%s' variables linked list", rs->name, st->id, rd->id);
811
+ if(!t) error("RRDDIMVAR '%s' not found in dimension '%s/%s' variables linked list", rs->key_name, st->id, rd->id);
812
else t->next = rs->next;
813
}
814
@@ -868,6 +817,123 @@ void rrddimvar_free(RRDDIMVAR *rs) {
817
freez(rs);
818
}
819
820
+// ----------------------------------------------------------------------------
821
+// RRDSETVAR management
822
+// CHART VARIABLES
823
+
824
+static inline void rrdsetvar_free_variables(RRDSETVAR *rs) {
825
+ RRDSET *st = rs->rrdset;
826
+
827
+ // CHART
828
+
829
+ rrdvar_free(st->rrdhost, &st->variables_root_index, rs->var_local);
830
+ rs->var_local = NULL;
831
+
832
+ // FAMILY
833
+
834
+ rrdvar_free(st->rrdhost, &st->rrdfamily->variables_root_index, rs->var_family);
835
+ rs->var_family = NULL;
836
+
837
+ rrdvar_free(st->rrdhost, &st->rrdhost->variables_root_index, rs->var_host);
838
+ rs->var_host = NULL;
839
+
840
+ // HOST
841
+
842
+ rrdvar_free(st->rrdhost, &st->rrdfamily->variables_root_index, rs->var_family_name);
843
+ rs->var_family_name = NULL;
844
+
845
+ rrdvar_free(st->rrdhost, &st->rrdhost->variables_root_index, rs->var_host_name);
846
+ rs->var_host_name = NULL;
847
+
848
+ // KEYS
849
+
850
+ freez(rs->key_fullid);
851
+ rs->key_fullid = NULL;
852
+
853
+ freez(rs->key_fullname);
854
+ rs->key_fullname = NULL;
855
+}
856
+
857
+static inline void rrdsetvar_create_variables(RRDSETVAR *rs) {
858
+ rrdsetvar_free_variables(rs);
859
+
860
+ RRDSET *st = rs->rrdset;
861
+
862
+ // KEYS
863
+
864
+ char buffer[RRDVAR_MAX_LENGTH + 1];
865
+ snprintfz(buffer, RRDVAR_MAX_LENGTH, "%s.%s", st->id, rs->variable);
866
+ rs->key_fullid = strdupz(buffer);
867
+
868
+ snprintfz(buffer, RRDVAR_MAX_LENGTH, "%s.%s", st->name, rs->variable);
869
+ rs->key_fullname = strdupz(buffer);
870
+
871
+ // CHART
872
+
873
+ rs->var_local = rrdvar_create_and_index("local", &st->variables_root_index, rs->variable, rs->type, rs->value);
874
+
875
+ // FAMILY
876
+
877
+ rs->var_family = rrdvar_create_and_index("family", &st->rrdfamily->variables_root_index, rs->key_fullid, rs->type, rs->value);
878
+ rs->var_family_name = rrdvar_create_and_index("family", &st->rrdfamily->variables_root_index, rs->key_fullname, rs->type, rs->value);
879
+
880
+ // HOST
881
+
882
+ rs->var_host = rrdvar_create_and_index("host", &st->rrdhost->variables_root_index, rs->key_fullid, rs->type, rs->value);
883
+ rs->var_host_name = rrdvar_create_and_index("host", &st->rrdhost->variables_root_index, rs->key_fullname, rs->type, rs->value);
884
+
885
+}
886
+
887
+RRDSETVAR *rrdsetvar_create(RRDSET *st, const char *variable, int type, void *value, uint32_t options) {
888
+ debug(D_VARIABLES, "RRDVARSET create for chart id '%s' name '%s' with variable name '%s'", st->id, st->name, variable);
889
+ RRDSETVAR *rs = (RRDSETVAR *)callocz(1, sizeof(RRDSETVAR));
890
+
891
+ rs->variable = strdupz(variable);
892
+ rs->type = type;
893
+ rs->value = value;
894
+ rs->options = options;
895
+ rs->rrdset = st;
896
+
897
+ rs->next = st->variables;
898
+ st->variables = rs;
899
+
900
+ rrdsetvar_create_variables(rs);
901
+
902
+ return rs;
903
+}
904
+
905
+void rrdsetvar_rename_all(RRDSET *st) {
906
+ debug(D_VARIABLES, "RRDSETVAR rename for chart id '%s' name '%s'", st->id, st->name);
907
+
908
+ RRDSETVAR *rs, *next = st->variables;
909
+ while((rs = next)) {
910
+ next = rs->next;
911
+ rrdsetvar_create_variables(rs);
912
+ }
913
+
914
+ rrdsetcalc_link_matching(st);
915
+}
916
+
917
+void rrdsetvar_free(RRDSETVAR *rs) {
918
+ RRDSET *st = rs->rrdset;
919
+ debug(D_VARIABLES, "RRDSETVAR free for chart id '%s' name '%s', variable '%s'", st->id, st->name, rs->variable);
920
+
921
+ if(st->variables == rs) {
922
+ st->variables = rs->next;
923
+ }
924
+ else {
925
+ RRDSETVAR *t;
926
+ for (t = st->variables; t && t->next != rs; t = t->next);
927
+ if(!t) error("RRDSETVAR '%s' not found in chart '%s' variables linked list", rs->key_fullname, st->id);
928
+ else t->next = rs->next;
929
+ }
930
+
931
+ rrdsetvar_free_variables(rs);
932
+
933
+ freez(rs->variable);
934
+ freez(rs);
935
+}
936
+
937
// ----------------------------------------------------------------------------
938
// RRDCALC management
939
src/health.h
+25
-25
@@ -34,8 +34,8 @@ typedef struct rrdvar {
34
// This means, there will be no speed penalty for using
35
// these variables
36
typedef struct rrdsetvar {
37
- char *fullid; // chart type.chart id.variable
38
- char *fullname; // chart type.chart name.variable
37
+ char *key_fullid; // chart type.chart id.variable
38
+ char *key_fullname; // chart type.chart name.variable
39
char *variable; // variable
40
41
int type;
@@ -43,11 +43,11 @@ typedef struct rrdsetvar {
43
44
uint32_t options;
45
46
- RRDVAR *local;
47
- RRDVAR *family;
48
- RRDVAR *host;
49
- RRDVAR *family_name;
50
- RRDVAR *host_name;
46
+ RRDVAR *var_local;
47
+ RRDVAR *var_family;
48
+ RRDVAR *var_host;
49
+ RRDVAR *var_family_name;
50
+ RRDVAR *var_host_name;
51
52
struct rrdset *rrdset;
53
@@ -64,32 +64,32 @@ typedef struct rrddimvar {
64
char *prefix;
65
char *suffix;
66
67
- char *id; // dimension id
68
- char *name; // dimension name
69
- char *contextid; // context + dimension id
70
- char *contextname; // context + dimension name
71
- char *fullidid; // chart type.chart id + dimension id
72
- char *fullidname; // chart type.chart id + dimension name
73
- char *fullnameid; // chart type.chart name + dimension id
74
- char *fullnamename; // chart type.chart name + dimension name
67
+ char *key_id; // dimension id
68
+ char *key_name; // dimension name
69
+ char *key_contextid; // context + dimension id
70
+ char *key_contextname; // context + dimension name
71
+ char *key_fullidid; // chart type.chart id + dimension id
72
+ char *key_fullidname; // chart type.chart id + dimension name
73
+ char *key_fullnameid; // chart type.chart name + dimension id
74
+ char *key_fullnamename; // chart type.chart name + dimension name
75
76
int type;
77
void *value;
78
79
uint32_t options;
80
81
- RRDVAR *local_id;
82
- RRDVAR *local_name;
81
+ RRDVAR *var_local_id;
82
+ RRDVAR *var_local_name;
83
84
- RRDVAR *family_id;
85
- RRDVAR *family_name;
86
- RRDVAR *family_contextid;
87
- RRDVAR *family_contextname;
84
+ RRDVAR *var_family_id;
85
+ RRDVAR *var_family_name;
86
+ RRDVAR *var_family_contextid;
87
+ RRDVAR *var_family_contextname;
88
89
- RRDVAR *host_fullidid;
90
- RRDVAR *host_fullidname;
91
- RRDVAR *host_fullnameid;
92
- RRDVAR *host_fullnamename;
89
+ RRDVAR *var_host_chartidid;
90
+ RRDVAR *var_host_chartidname;
91
+ RRDVAR *var_host_chartnameid;
92
+ RRDVAR *var_host_chartnamename;
93
94
struct rrddim *rrddim;
95
src/rrd.c
+18
-8
@@ -355,18 +355,28 @@ void rrdset_set_name(RRDSET *st, const char *name)
355
{
356
debug(D_RRD_CALLS, "rrdset_set_name() old: %s, new: %s", st->name, name);
357
358
- if(st->name) {
359
- rrdset_index_del_name(&localhost, st);
360
- rrdsetvar_rename_all(st);
361
- }
362
-
358
char b[CONFIG_MAX_VALUE + 1];
359
char n[RRD_ID_LENGTH_MAX + 1];
360
361
snprintfz(n, RRD_ID_LENGTH_MAX, "%s.%s", st->type, name);
362
rrdset_strncpyz_name(b, n, CONFIG_MAX_VALUE);
368
- st->name = config_get(st->id, "name", b);
369
- st->hash_name = simple_hash(st->name);
363
+
364
+ if(st->name) {
365
+ rrdset_index_del_name(&localhost, st);
366
+ st->name = config_set_default(st->id, "name", b);
367
+ st->hash_name = simple_hash(st->name);
368
+ rrdsetvar_rename_all(st);
369
+ }
370
+ else {
371
+ st->name = config_get(st->id, "name", b);
372
+ st->hash_name = simple_hash(st->name);
373
+ }
374
+
375
+ pthread_rwlock_wrlock(&st->rwlock);
376
+ RRDDIM *rd;
377
+ for(rd = st->dimensions; rd ;rd = rd->next)
378
+ rrddimvar_rename_all(rd);
379
+ pthread_rwlock_unlock(&st->rwlock);
380
381
rrdset_index_add_name(&localhost, st);
382
}
@@ -759,7 +769,7 @@ void rrddim_set_name(RRDSET *st, RRDDIM *rd, const char *name)
769
770
char varname[CONFIG_MAX_NAME + 1];
771
snprintfz(varname, CONFIG_MAX_NAME, "dim %s name", rd->id);
762
- config_set_default(st->id, varname, name);
772
+ rd->name = config_set_default(st->id, varname, name);
773
774
rrddimvar_rename_all(rd);
775
}
src/unit_test.c
+43
@@ -975,8 +975,49 @@ int run_test(struct test *test)
975
return errors;
976
}
977
978
+void test_variable_renames(void) {
979
+ fprintf(stderr, "Creating chart\n");
980
+ RRDSET *st = rrdset_create("netdata", "CHARTID1", NULL, "netdata", NULL, "Unit Testing", "a value", 1, 1, RRDSET_TYPE_LINE);
981
+ fprintf(stderr, "Created chart with id '%s', name '%s'\n", st->id, st->name);
982
+
983
+ fprintf(stderr, "Creating dimension DIM1\n");
984
+ RRDDIM *rd1 = rrddim_add(st, "DIM1", NULL, 1, 1, RRDDIM_INCREMENTAL);
985
+ fprintf(stderr, "Created dimension with id '%s', name '%s'\n", rd1->id, rd1->name);
986
+
987
+ fprintf(stderr, "Creating dimension DIM2\n");
988
+ RRDDIM *rd2 = rrddim_add(st, "DIM2", NULL, 1, 1, RRDDIM_INCREMENTAL);
989
+ fprintf(stderr, "Created dimension with id '%s', name '%s'\n", rd2->id, rd2->name);
990
+
991
+ fprintf(stderr, "Renaming chart to CHARTNAME1\n");
992
+ rrdset_set_name(st, "CHARTNAME1");
993
+ fprintf(stderr, "Renamed chart with id '%s' to name '%s'\n", st->id, st->name);
994
+
995
+ fprintf(stderr, "Renaming chart to CHARTNAME2\n");
996
+ rrdset_set_name(st, "CHARTNAME2");
997
+ fprintf(stderr, "Renamed chart with id '%s' to name '%s'\n", st->id, st->name);
998
+
999
+ fprintf(stderr, "Renaming dimension DIM1 to DIM1NAME1\n");
1000
+ rrddim_set_name(st, rd1, "DIM1NAME1");
1001
+ fprintf(stderr, "Renamed dimension with id '%s' to name '%s'\n", rd1->id, rd1->name);
1002
+
1003
+ fprintf(stderr, "Renaming dimension DIM1 to DIM1NAME2\n");
1004
+ rrddim_set_name(st, rd1, "DIM1NAME2");
1005
+ fprintf(stderr, "Renamed dimension with id '%s' to name '%s'\n", rd1->id, rd1->name);
1006
+
1007
+ fprintf(stderr, "Renaming dimension DIM2 to DIM2NAME1\n");
1008
+ rrddim_set_name(st, rd2, "DIM2NAME1");
1009
+ fprintf(stderr, "Renamed dimension with id '%s' to name '%s'\n", rd2->id, rd2->name);
1010
+
1011
+ fprintf(stderr, "Renaming dimension DIM2 to DIM2NAME2\n");
1012
+ rrddim_set_name(st, rd2, "DIM2NAME2");
1013
+ fprintf(stderr, "Renamed dimension with id '%s' to name '%s'\n", rd2->id, rd2->name);
1014
+}
1015
+
1016
int run_all_mockup_tests(void)
1017
{
1018
+ test_variable_renames();
1019
+ exit(1);
1020
+
1021
if(run_test(&test1))
1022
return 1;
1023
@@ -1028,6 +1069,8 @@ int run_all_mockup_tests(void)
1069
if(run_test(&test15))
1070
return 1;
1071
1072
+
1073
+
1074
return 0;
1075
}
1076