@@ -1014,6 +1014,66 @@ func testSingleNodeMetric(t *testing.T) {
1014
1014
ix .AddOrUpdate (mkey , data , getPartition (data ))
1015
1015
}
1016
1016
1017
+ func TestMetricNameStartingWithTilde (t * testing.T ) {
1018
+ withAndWithoutPartitonedIndex (testMetricNameStartingWithTilde )(t )
1019
+ }
1020
+
1021
+ func testMetricNameStartingWithTilde (t * testing.T ) {
1022
+ ix := New ()
1023
+ ix .Init ()
1024
+ defer func () {
1025
+ ix .Stop ()
1026
+ ix = nil
1027
+ }()
1028
+
1029
+ metricName := "~~~weird~.~metric~"
1030
+ expectedNameTag := "weird~.~metric~"
1031
+
1032
+ data := & schema.MetricData {
1033
+ Name : metricName ,
1034
+ Interval : 1 ,
1035
+ OrgId : 1 ,
1036
+ }
1037
+ data .SetId ()
1038
+ mkey , err := schema .MKeyFromString (data .Id )
1039
+ if err != nil {
1040
+ t .Fatal (err )
1041
+ }
1042
+
1043
+ arch , _ , _ := ix .AddOrUpdate (mkey , data , getPartition (data ))
1044
+ if arch .Name != metricName {
1045
+ t .Fatalf ("Expected metric name to be %q, but it was %q" , metricName , arch .Name )
1046
+ }
1047
+
1048
+ // query by the name minus the leading ~ characters
1049
+ query , err := tagquery .NewQueryFromStrings ([]string {"name=" + expectedNameTag }, 0 )
1050
+ if err != nil {
1051
+ t .Fatalf ("Unexpected error when parsing query expression: %q" , err )
1052
+ }
1053
+
1054
+ findResult := ix .FindByTag (1 , query )
1055
+ if len (findResult ) != 1 {
1056
+ t .Fatalf ("Expected 1 result, but got %d" , len (findResult ))
1057
+ }
1058
+
1059
+ if findResult [0 ].Path != metricName {
1060
+ t .Fatalf ("Expected metric name to be %q, but it was %q" , metricName , findResult [0 ].Path )
1061
+ }
1062
+
1063
+ tagDetails := ix .TagDetails (1 , "name" , nil , 0 )
1064
+ if len (tagDetails ) != 1 {
1065
+ t .Fatalf ("Expected 1 result, but got %d" , len (tagDetails ))
1066
+ }
1067
+
1068
+ count , ok := tagDetails [expectedNameTag ]
1069
+ if ! ok {
1070
+ t .Fatalf ("Did not get expected name as tag value in result" )
1071
+ }
1072
+ if count != 1 {
1073
+ t .Fatalf ("Expected 1 result, but got %d" , count )
1074
+ }
1075
+ }
1076
+
1017
1077
// TestMemoryIndexHeapUsageWithTagsUniqueNone5 gives a rough estimate of how much memory the index is using with tag support turned on.
1018
1078
// It uses 0 unique tags and 10 identical tags
1019
1079
func TestMemoryIndexHeapUsageWithTagsUniqueNone5 (t * testing.T ) {
0 commit comments