forked from pingcap/tidb-dashboard
/
fetch.go
88 lines (80 loc) · 2.6 KB
/
fetch.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// 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 clusterinfo
import (
"context"
"github.com/LinuxGit/tidb-dashboard/pkg/utils/clusterinfo"
)
type ClusterInfo struct {
TiDB struct {
Nodes []clusterinfo.TiDBInfo `json:"nodes"`
Err *string `json:"err"`
} `json:"tidb"`
TiKV struct {
Nodes []clusterinfo.TiKVInfo `json:"nodes"`
Err *string `json:"err"`
} `json:"tikv"`
PD struct {
Nodes []clusterinfo.PDInfo `json:"nodes"`
Err *string `json:"err"`
} `json:"pd"`
Grafana *clusterinfo.GrafanaInfo `json:"grafana"`
AlertManager *clusterinfo.AlertManagerInfo `json:"alert_manager"`
}
// fetches etcd, and parses the ns below:
// * /topology/grafana
// * /topology/alertmanager
// * /topology/tidb
func fillTopologyUnderEtcd(ctx context.Context, service *Service, fillTargetInfo *ClusterInfo) {
tidb, grafana, alertManager, err := clusterinfo.GetTopologyUnderEtcd(ctx, service.etcdProvider.GetEtcdClient())
if err != nil {
// Note: GetTopology return error only when fetch etcd failed.
// So it's ok to fill all of them err
errString := err.Error()
fillTargetInfo.TiDB.Err = &errString
return
}
if grafana != nil {
fillTargetInfo.Grafana = grafana
}
if alertManager != nil {
fillTargetInfo.AlertManager = alertManager
}
if len(tidb) == 0 {
tidb, err = clusterinfo.GetTiDBTopologyFromOld(ctx, service.etcdProvider.GetEtcdClient())
if err != nil {
errString := err.Error()
fillTargetInfo.TiDB.Err = &errString
return
}
}
fillTargetInfo.TiDB.Nodes = tidb
}
func fillPDTopology(ctx context.Context, service *Service, fillTargetInfo *ClusterInfo) {
pdPeers, err := clusterinfo.GetPDTopology(service.config.PDEndPoint, service.httpClient)
if err != nil {
errString := err.Error()
fillTargetInfo.PD.Err = &errString
return
}
fillTargetInfo.PD.Nodes = pdPeers
}
func fillTiKVTopology(ctx context.Context, service *Service, fillTargetInfo *ClusterInfo) {
kv, err := clusterinfo.GetTiKVTopology(service.config.PDEndPoint, service.httpClient)
if err != nil {
errString := err.Error()
fillTargetInfo.TiKV.Err = &errString
return
}
fillTargetInfo.TiKV.Nodes = kv
}