vitess.io/vitess@v0.16.2/go/vt/vttablet/endtoend/framework/livequeryz.go (about) 1 /* 2 Copyright 2019 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package framework 18 19 import ( 20 "encoding/json" 21 "fmt" 22 "net/http" 23 "time" 24 ) 25 26 // LiveQuery contains the streaming query info. 27 type LiveQuery struct { 28 Type string 29 Query string 30 ContextHTML string 31 Start time.Time 32 Duration int64 33 ConnID int 34 State string 35 ShowTerminateLink bool 36 } 37 38 // OLAPQueryz returns the contents of /livequeryz?format=json. 39 // as a []LiveQuery. The function returns an empty list on error. 40 func LiveQueryz() []LiveQuery { 41 var out []LiveQuery 42 response, err := http.Get(fmt.Sprintf("%s/livequeryz?format=json", ServerAddress)) 43 if err != nil { 44 return out 45 } 46 defer response.Body.Close() 47 _ = json.NewDecoder(response.Body).Decode(&out) 48 return out 49 } 50 51 // StreamTerminate terminates the specified streaming query. 52 func StreamTerminate(connID int) error { 53 response, err := http.Get(fmt.Sprintf("%s/livequeryz/terminate?format=json&connID=%d", ServerAddress, connID)) 54 if err != nil { 55 return err 56 } 57 response.Body.Close() 58 return nil 59 }