-
Notifications
You must be signed in to change notification settings - Fork 5.9k
/
Copy pathdata_cluster_info.go
60 lines (56 loc) · 2.14 KB
/
data_cluster_info.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2020 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package telemetry
import (
"github.com/pingcap/errors"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/util/sqlexec"
)
type clusterInfoItem struct {
InstanceType string `json:"instanceType"`
ListenHostHash string `json:"listenHostHash"`
ListenPort string `json:"listenPort"`
StatusHostHash string `json:"statusHostHash,omitempty"`
StatusPort string `json:"statusPort,omitempty"`
Version string `json:"version,omitempty"`
GitHash string `json:"gitHash,omitempty"`
StartTime string `json:"startTime,omitempty"`
UpTime string `json:"upTime,omitempty"`
}
func getClusterInfo(ctx sessionctx.Context) ([]*clusterInfoItem, error) {
// Explicitly list all field names instead of using `*` to avoid potential leaking sensitive info when adding new fields in future.
rows, _, err := ctx.(sqlexec.RestrictedSQLExecutor).ExecRestrictedSQL(`SELECT TYPE, INSTANCE, STATUS_ADDRESS, VERSION, GIT_HASH, START_TIME, UPTIME FROM information_schema.cluster_info`)
if err != nil {
return nil, errors.Trace(err)
}
r := make([]*clusterInfoItem, 0)
for _, row := range rows {
if row.Len() < 7 {
continue
}
listenHostHash, listenPort := parseAddressAndHash(row.GetString(1))
statusHostHash, statusPort := parseAddressAndHash(row.GetString(2))
r = append(r, &clusterInfoItem{
InstanceType: row.GetString(0),
ListenHostHash: listenHostHash,
ListenPort: listenPort,
StatusHostHash: statusHostHash,
StatusPort: statusPort,
Version: row.GetString(3),
GitHash: row.GetString(4),
StartTime: row.GetString(5),
UpTime: row.GetString(6),
})
}
return r, nil
}