Fix activity list

This commit is contained in:
Dan Sosedoff 2018-06-05 15:48:16 -05:00
parent 77770112bd
commit 56f3b45a4e
2 changed files with 20 additions and 3 deletions

View File

@ -154,7 +154,7 @@ func (client *Client) setServerVersion() {
// Detect cockroachdb
matches = cockroachSignature.FindAllStringSubmatch(version, 1)
if len(matches) > 0 {
client.serverType = postgresType
client.serverType = cockroachType
client.serverVersion = matches[0][1]
return
}
@ -255,9 +255,11 @@ func (client *Client) TableConstraints(table string) (*Result, error) {
// Returns all active queriers on the server
func (client *Client) Activity() (*Result, error) {
chunks := strings.Split(client.serverVersion, ".")
version := strings.Join(chunks[0:2], ".")
if client.serverType == cockroachType {
return client.query("SHOW QUERIES")
}
version := getMajorMinorVersion(client.serverVersion)
query := statements.Activity[version]
if query == "" {
query = statements.Activity["default"]

15
pkg/client/util.go Normal file
View File

@ -0,0 +1,15 @@
package client
import (
"strings"
)
// Get short version from the string
// Example: 10.2.3.1 -> 10.2
func getMajorMinorVersion(str string) string {
chunks := strings.Split(str, ".")
if len(chunks) == 0 {
return str
}
return strings.Join(chunks[0:2], ".")
}