@@ -89,34 +89,42 @@ func (sh structuredSearchHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque
89
89
ctx := sh .api .Context ()
90
90
logger := shared .GetLogger (ctx )
91
91
92
- // Check if the query is a simple (empty/just True, or test name only) query
93
92
var simpleQ TestNamePattern
93
+
94
+ r2 := r .Clone (r .Context ())
95
+ r2url := * r .URL
96
+ r2 .URL = & r2url
97
+ r2 .Method = "GET"
98
+ q := r .URL .Query ()
99
+ q .Add ("q" , simpleQ .Pattern )
100
+ // Assemble list of run IDs for later use.
101
+ runIDStrs := make ([]string , 0 , len (rq .RunIDs ))
102
+ for _ , id := range rq .RunIDs {
103
+ runID := strconv .FormatInt (id , 10 )
104
+ q .Add ("run_id" , runID )
105
+ runIDStrs = append (runIDStrs , strconv .FormatInt (id , 10 ))
106
+ }
107
+ runIDsStr := strings .Join (runIDStrs , "," )
108
+ r2 .URL .RawQuery = q .Encode ()
109
+
110
+ // Check if the query is a simple (empty/just True, or test name only) query
94
111
var isSimpleQ bool
95
112
{
96
113
if _ , isTrueQ := rq .AbstractQuery .(True ); isTrueQ {
97
114
isSimpleQ = true
98
115
} else if exists , isExists := rq .AbstractQuery .(AbstractExists ); isExists && len (exists .Args ) == 1 {
99
116
simpleQ , isSimpleQ = exists .Args [0 ].(TestNamePattern )
100
117
}
101
- q := r .URL .Query ()
102
118
for _ , param := range []string {"interop" , "subtests" , "diff" } {
103
119
val , _ := shared .ParseBooleanParam (q , param )
104
120
isSimpleQ = isSimpleQ && (val == nil || ! * val )
105
121
}
106
122
107
- q .Add ("q" , url .QueryEscape (simpleQ .Pattern ))
108
123
// Check old summary files. If any can't be found,
109
124
// use the searchcache to aggregate the runs.
110
- for _ , id := range rq .RunIDs {
111
- q .Add ("run_id" , strconv .FormatInt (id , 10 ))
112
- }
113
-
114
- r2 := r .Clone (r .Context ())
115
- r2 .Method = "GET"
116
- r2 .URL .RawQuery = q .Encode ()
117
- summariesValid , err := sh .validateSummaryVersions (r2 .URL .Query ())
125
+ summariesValid , err := sh .validateSummaryVersions (r2 .URL .Query (), logger )
118
126
if err != nil {
119
- logger .Debugf ("Error checking version files : %v" , err )
127
+ logger .Debugf ("Error checking summary file names : %v" , err )
120
128
}
121
129
isSimpleQ = isSimpleQ && summariesValid
122
130
}
@@ -136,35 +144,24 @@ func (sh structuredSearchHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque
136
144
}
137
145
return
138
146
}
139
- sh .handleSimpleQuery (w , r , simpleQ , rq )
140
- }
141
-
142
- func (sh structuredSearchHandler ) handleSimpleQuery (w http.ResponseWriter ,
143
- r * http.Request , simpleQ TestNamePattern , rq RunQuery ) {
144
- // Assemble list of run IDs for later use.
145
- runIDStrs := make ([]string , 0 , len (rq .RunIDs ))
146
- for _ , id := range rq .RunIDs {
147
- runIDStrs = append (runIDStrs , strconv .FormatInt (id , 10 ))
148
- }
149
- runIDsStr := strings .Join (runIDStrs , "," )
150
147
148
+ q = r .URL .Query ()
149
+ q .Set ("q" , simpleQ .Pattern )
150
+ q .Set ("run_ids" , runIDsStr )
151
+ r2 .URL .RawQuery = q .Encode ()
151
152
// Structured query is equivalent to unstructured query.
152
- // Create an unstructured query request and delegate to unstructured query
153
- // handler.
154
- r2 := r .Clone (r .Context ())
155
- r2url := * r .URL
156
- r2 .URL = & r2url
157
- r2 .Method = "GET"
158
- r2 .URL .RawQuery = fmt .Sprintf ("run_ids=%s&q=%s" ,
159
- url .QueryEscape (runIDsStr ), url .QueryEscape (simpleQ .Pattern ))
160
-
153
+ //delegate to unstructured query handler.
161
154
unstructuredSearchHandler {queryHandler : sh .queryHandler }.ServeHTTP (w , r2 )
162
155
}
163
156
164
- func (sh structuredSearchHandler ) useSearchcache (w http.ResponseWriter , r * http.Request , data []byte , logger shared.Logger ) (* http.Response , error ) {
157
+ func (sh structuredSearchHandler ) useSearchcache (w http.ResponseWriter , r * http.Request ,
158
+ data []byte , logger shared.Logger ) (* http.Response , error ) {
165
159
hostname := sh .api .GetServiceHostname ("searchcache" )
166
- // TODO: This will not work when hostname is localhost (http scheme needed).
167
- fwdURL , _ := url .Parse (fmt .Sprintf ("https://%s/api/search/cache" , hostname ))
160
+ // TODO(Issue #2941): This will not work when hostname is localhost (http scheme needed).
161
+ fwdURL , err := url .Parse (fmt .Sprintf ("https://%s/api/search/cache" , hostname ))
162
+ if err != nil {
163
+ logger .Debugf ("Error parsing hostname." )
164
+ }
168
165
fwdURL .RawQuery = r .URL .RawQuery
169
166
170
167
logger .Infof ("Forwarding structured search request to %s: %s" , hostname , string (data ))
0 commit comments