@@ -1002,8 +1002,8 @@ func testAutoCompleteTagValuesWithQuery(t *testing.T) {
1002
1002
},
1003
1003
}
1004
1004
1005
- for _ , tc := range testCases {
1006
- autoCompleteTagValuesWithQueryAndCompare (t , tc .tag , tc .prefix , tc .expr , tc .limit , tc .expRes )
1005
+ for i , tc := range testCases {
1006
+ autoCompleteTagValuesWithQueryAndCompare (t , i , tc .tag , tc .prefix , tc .expr , tc .limit , tc .expRes )
1007
1007
}
1008
1008
}
1009
1009
@@ -1022,18 +1022,29 @@ func testAutoCompleteTagValuesWithQueryWithMetaTagSupport(t *testing.T) {
1022
1022
if err != nil {
1023
1023
t .Fatalf ("Unexpected error when parsing expression: %s" , err )
1024
1024
}
1025
+ // since "direction" is a tag in the metric tag index, we don't
1026
+ // include values of the meta tag index in the autocomplete results
1025
1027
ix .MetaTagRecordUpsert (1 , tagquery.MetaTagRecord {
1026
1028
MetaTags : tagquery.Tags {tagquery.Tag {Key : "direction" , Value : "none" }},
1027
1029
Expressions : tagquery.Expressions {metaRecordExpression1 },
1028
1030
})
1029
1031
1030
- metaRecordExpression2 , err := tagquery .ParseExpression ("name!=" )
1032
+ metaRecordExpressions2 , err := tagquery .ParseExpressions ([]string {"direction=~.+" })
1033
+ if err != nil {
1034
+ t .Fatalf ("Unexpected error when parsing expressions: %s" , err )
1035
+ }
1036
+ ix .MetaTagRecordUpsert (1 , tagquery.MetaTagRecord {
1037
+ MetaTags : tagquery.Tags {{Key : "has_direction" , Value : "true" }, {Key : "has_direction" , Value : "yes" }},
1038
+ Expressions : metaRecordExpressions2 ,
1039
+ })
1040
+
1041
+ metaRecordExpression3 , err := tagquery .ParseExpression ("name!=" )
1031
1042
if err != nil {
1032
1043
t .Fatalf ("Unexpected error when parsing expression: %s" , err )
1033
1044
}
1034
1045
ix .MetaTagRecordUpsert (1 , tagquery.MetaTagRecord {
1035
1046
MetaTags : tagquery.Tags {tagquery.Tag {Key : "all" , Value : "metrics" }},
1036
- Expressions : tagquery.Expressions {metaRecordExpression2 },
1047
+ Expressions : tagquery.Expressions {metaRecordExpression3 },
1037
1048
})
1038
1049
1039
1050
type testCase struct {
@@ -1056,7 +1067,7 @@ func testAutoCompleteTagValuesWithQueryWithMetaTagSupport(t *testing.T) {
1056
1067
prefix : "" ,
1057
1068
expr : []string {"host=~.+" },
1058
1069
limit : 100 ,
1059
- expRes : []string {"none" , " read" , "write" },
1070
+ expRes : []string {"read" , "write" },
1060
1071
}, {
1061
1072
tag : "direction" ,
1062
1073
prefix : "wr" ,
@@ -1068,45 +1079,63 @@ func testAutoCompleteTagValuesWithQueryWithMetaTagSupport(t *testing.T) {
1068
1079
prefix : "no" ,
1069
1080
expr : []string {"host=~.+" },
1070
1081
limit : 100 ,
1071
- expRes : []string {"none" },
1082
+ expRes : []string {},
1072
1083
}, {
1073
1084
tag : "direction" ,
1074
1085
prefix : "" ,
1075
1086
expr : []string {"host=~.+" },
1076
- limit : 2 ,
1077
- expRes : []string {"none" , " read" },
1087
+ limit : 1 ,
1088
+ expRes : []string {"read" },
1078
1089
}, {
1079
1090
tag : "all" ,
1080
1091
prefix : "" ,
1081
1092
expr : []string {"__tag=name" },
1082
1093
limit : 100 ,
1083
1094
expRes : []string {"metrics" },
1095
+ }, {
1096
+ tag : "has_direction" ,
1097
+ prefix : "" ,
1098
+ expr : []string {"name=~.+" },
1099
+ limit : 100 ,
1100
+ expRes : []string {"true" , "yes" },
1101
+ }, {
1102
+ tag : "has_direction" ,
1103
+ prefix : "tr" ,
1104
+ expr : []string {"name=~.+" },
1105
+ limit : 100 ,
1106
+ expRes : []string {"true" },
1107
+ }, {
1108
+ tag : "has_direction" ,
1109
+ prefix : "" ,
1110
+ expr : []string {"name=~.+" },
1111
+ limit : 1 ,
1112
+ expRes : []string {"true" },
1084
1113
},
1085
1114
}
1086
1115
1087
- for _ , tc := range testCases {
1088
- autoCompleteTagValuesWithQueryAndCompare (t , tc .tag , tc .prefix , tc .expr , tc .limit , tc .expRes )
1116
+ for i , tc := range testCases {
1117
+ autoCompleteTagValuesWithQueryAndCompare (t , i , tc .tag , tc .prefix , tc .expr , tc .limit , tc .expRes )
1089
1118
}
1090
1119
}
1091
1120
1092
- func autoCompleteTagValuesWithQueryAndCompare (t testing.TB , tag , prefix string , expr []string , limit uint , expRes []string ) {
1121
+ func autoCompleteTagValuesWithQueryAndCompare (t testing.TB , tc int , tag , prefix string , expr []string , limit uint , expRes []string ) {
1093
1122
t .Helper ()
1094
1123
1095
1124
query , err := tagquery .NewQueryFromStrings (expr , 0 )
1096
1125
if err != nil {
1097
- t .Fatalf ("Unexpected error when instantiating query: %s" , err )
1126
+ t .Fatalf ("TC %d: Unexpected error when instantiating query: %s" , tc , err )
1098
1127
}
1099
1128
res := ix .FindTagValuesWithQuery (1 , tag , prefix , query , limit )
1100
1129
1101
1130
if len (res ) != len (expRes ) {
1102
- t .Fatalf ("Wrong result, Expected:\n %s\n Got:\n %s\n " , expRes , res )
1131
+ t .Fatalf ("TC %d: Wrong result, Expected:\n %s\n Got:\n %s\n " , tc , expRes , res )
1103
1132
}
1104
1133
1105
1134
sort .Strings (expRes )
1106
1135
sort .Strings (res )
1107
1136
for i := range res {
1108
1137
if expRes [i ] != res [i ] {
1109
- t .Fatalf ("Wrong result, Expected:\n %s\n Got:\n %s\n " , expRes , res )
1138
+ t .Fatalf ("TC %d: Wrong result, Expected:\n %s\n Got:\n %s\n " , tc , expRes , res )
1110
1139
}
1111
1140
}
1112
1141
}
0 commit comments