Skip to content

Commit cf64dca

Browse files
authored
conprof: support ticdc backend (#167)
ref #166
1 parent 4555b18 commit cf64dca

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

component/conprof/http/api.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ func getProfileEstimateSize(component topology.Component) int {
115115
100*1024 + // goroutine size
116116
400*1024 + // heap size
117117
30*1024 // mutex size
118+
case topology.ComponentTiCDC:
119+
return 100*1024 + // profile size
120+
100*1024 + // goroutine size
121+
400*1024 + // heap size
122+
30*1024 // mutex size
118123
case topology.ComponentTiKV:
119124
return 200 * 1024 // profile size
120125
case topology.ComponentTiFlash:
@@ -128,6 +133,7 @@ type ComponentNum struct {
128133
PD int `json:"pd"`
129134
TiKV int `json:"tikv"`
130135
TiFlash int `json:"tiflash"`
136+
TiCDC int `json:"ticdc"`
131137
}
132138

133139
type GroupProfiles struct {
@@ -227,6 +233,8 @@ func (sc *StatusCounterAndTargets) getComponentNum() ComponentNum {
227233
compNum.TiKV = num
228234
case topology.ComponentTiFlash:
229235
compNum.TiFlash = num
236+
case topology.ComponentTiCDC:
237+
compNum.TiCDC = num
230238
}
231239
}
232240
return compNum

component/conprof/scrape/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func (m *Manager) stopScrape(component topology.Component) {
229229

230230
func (m *Manager) getProfilingConfig(component topology.Component) *config.ProfilingConfig {
231231
switch component.Name {
232-
case topology.ComponentTiDB, topology.ComponentPD:
232+
case topology.ComponentTiDB, topology.ComponentPD, topology.ComponentTiCDC:
233233
return goAppProfilingConfig(m.config.ContinueProfiling)
234234
default:
235235
return nonGoAppProfilingConfig(m.config.ContinueProfiling)

component/topology/discovery.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ package topology
22

33
import (
44
"context"
5+
"encoding/json"
6+
"strconv"
7+
"strings"
58
"sync"
69
"sync/atomic"
710
"time"
811

912
"github.com/pingcap/ng-monitoring/component/domain"
1013
"github.com/pingcap/ng-monitoring/utils"
14+
clientv3 "go.etcd.io/etcd/client/v3"
1115

1216
"github.com/pingcap/log"
1317
"github.com/pingcap/tidb-dashboard/util/topo"
@@ -20,6 +24,7 @@ const (
2024
ComponentTiKV = "tikv"
2125
ComponentTiFlash = "tiflash"
2226
ComponentPD = "pd"
27+
ComponentTiCDC = "ticdc"
2328
)
2429

2530
var (
@@ -126,6 +131,7 @@ func (d *TopologyDiscoverer) fetchAllScrapeTargets(ctx context.Context) ([]Compo
126131
d.getTiDBComponents,
127132
d.getPDComponents,
128133
d.getStoreComponents,
134+
d.getTiCDCComponents,
129135
}
130136
components := make([]Component, 0, 8)
131137
for _, fn := range fns {
@@ -220,3 +226,58 @@ func (d *TopologyDiscoverer) getStoreComponents(ctx context.Context) ([]Componen
220226
}
221227
return components, nil
222228
}
229+
230+
func (d *TopologyDiscoverer) getTiCDCComponents(ctx context.Context) ([]Component, error) {
231+
etcdCli, err := d.do.GetEtcdClient()
232+
if err != nil {
233+
return nil, err
234+
}
235+
return getTiCDCComponents(ctx, etcdCli)
236+
}
237+
238+
const ticdcTopologyKeyPrefix = "/tidb/cdc/default/__cdc_meta__/capture/"
239+
240+
type ticdcNodeItem struct {
241+
ID string `json:"id"`
242+
Address string `json:"address"`
243+
Version string `json:"version"`
244+
}
245+
246+
func getTiCDCComponents(ctx context.Context, etcdCli *clientv3.Client) ([]Component, error) {
247+
resp, err := etcdCli.Get(ctx, ticdcTopologyKeyPrefix, clientv3.WithPrefix())
248+
if err != nil {
249+
return nil, err
250+
}
251+
components := make([]Component, 0, 3)
252+
for _, kv := range resp.Kvs {
253+
key := string(kv.Key)
254+
if !strings.HasPrefix(key, ticdcTopologyKeyPrefix) {
255+
continue
256+
}
257+
var item ticdcNodeItem
258+
if err := json.Unmarshal(kv.Value, &item); err != nil {
259+
log.Warn("invalid ticdc node item in etcd", zap.Error(err))
260+
continue
261+
}
262+
arr := strings.Split(item.Address, ":")
263+
if len(arr) != 2 {
264+
log.Warn("invalid ticdc node address in etcd", zap.String("address", item.Address))
265+
continue
266+
}
267+
ip := arr[0]
268+
port, err := strconv.Atoi(arr[1])
269+
if err != nil {
270+
log.Warn("invalid ticdc node address in etcd",
271+
zap.Error(err),
272+
zap.String("address", item.Address))
273+
continue
274+
}
275+
components = append(components, Component{
276+
Name: ComponentTiCDC,
277+
IP: ip,
278+
Port: uint(port),
279+
StatusPort: uint(port),
280+
})
281+
}
282+
return components, nil
283+
}

0 commit comments

Comments
 (0)