Skip to content

Commit 33cf842

Browse files
committed
feat(backend): Optimize the way of collecting data from multiple database instances using probes. issue: #14123
1 parent 0b81cba commit 33cf842

File tree

17 files changed

+690
-543
lines changed

17 files changed

+690
-543
lines changed

dbm-services/common/dbha-v2/etc/probe.yaml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,25 @@ reporter:
1010
connTimeout: 5s
1111

1212
harvester:
13-
- name: mysql
14-
endpoint: ""
15-
user: root
16-
password: 123456
13+
mysql:
14+
user: "root"
15+
password: "root"
16+
# The time interval for each data collection from MySQL.
1717
interval: 20s
1818

19+
endpoints:
20+
# If this 'proto' is not set, the default value is 'tcp'.
21+
- proto: tcp
22+
clusterType: ""
23+
machineType: ""
24+
accessLayer: ""
25+
ip: 127.0.0.1
26+
27+
# Ports configuration format is: 1000~2000,20003, 3000, 5000-6000
28+
# The target port number to be probed are such that begin <= port <= end.
29+
ports: [1000-2000,20003, 3000, 5000-6000]
30+
adminPorts: []
31+
1932
log:
2033
path: ./logs/probe.log
2134
level: debug
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
dbType: mysql
2+
endpoint: ""
3+
interval: 20s
4+
user: root
5+
password: 123456

dbm-services/common/dbha-v2/go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ require (
88
github.com/shirou/gopsutil v3.21.11+incompatible
99
github.com/spf13/cobra v1.9.1
1010
github.com/spf13/viper v1.20.1
11-
github.com/stretchr/testify v1.11.1
1211
github.com/xdg-go/scram v1.1.2
1312
go.etcd.io/etcd/client/v3 v3.6.0
1413
go.uber.org/zap v1.27.0
@@ -72,7 +71,6 @@ require (
7271
require (
7372
github.com/ebitengine/purego v0.8.4 // indirect
7473
github.com/go-ole/go-ole v1.2.6 // indirect
75-
github.com/pmezard/go-difflib v1.0.0 // indirect
7674
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
7775
github.com/shirou/gopsutil/v4 v4.25.6
7876
github.com/tklauser/go-sysconf v0.3.12 // indirect

dbm-services/common/dbha-v2/internal/probe/config/config.go

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,36 @@ var Cfg = Configuration{
4141
},
4242
}
4343

44-
// ReporterConfig reporter's config
44+
// ReporterConfig reporter config
4545
type ReporterConfig struct {
4646
Name string `yaml:"name" mapstructure:"name"`
4747
Endpoint string `yaml:"endpoint" mapstructure:"endpoint"`
4848
DataID uint64 `yaml:"dataID" mapstructure:"dataID"`
4949
ConnTimeout time.Duration `yaml:"connTimeout" mapstructure:"connTimeout"`
5050
}
5151

52-
// HarvesterConfig harvester's config
52+
// DbEndpointConfig db instance endpoint config
53+
type DbEndpointConfig struct {
54+
Proto string `yaml:"proto" mapstructure:"proto"`
55+
ClusterType string `yaml:"clusterType" mapstructure:"clusterType"`
56+
MachineType string `yaml:"machineType" mapstructure:"machineType"`
57+
AccessLayer string `yaml:"accessLayer" mapstructure:"accessLayer"`
58+
Ip string `yaml:"ip" mapstructure:"ip"`
59+
Ports []string `yaml:"ports" mapstructure:"ports"`
60+
AdminPorts []string `yaml:"adminPorts" mapstructure:"adminPorts"`
61+
}
62+
63+
// MySqlHarvesterConfig MySQL harvester config
64+
type MySqlHarvesterConfig struct {
65+
User string `yaml:"user" mapstructure:"user"`
66+
Password string `yaml:"password" mapstructure:"password"`
67+
Interval time.Duration `yaml:"interval" mapstructure:"interval"`
68+
Endpoints []DbEndpointConfig `yaml:"endpoints" mapstructure:"endpoints"`
69+
}
70+
71+
// HarvesterConfig harvester config
5372
type HarvesterConfig struct {
54-
Name string `yaml:"name" mapstructure:"name"`
55-
Endpoint string `yaml:"endpoint" mapstructure:"endpoint"`
56-
User string `yaml:"user" mapstructure:"user"`
57-
Password string `yaml:"password" mapstructure:"password"`
58-
Interval time.Duration `yaml:"interval" mapstructure:"interval"`
73+
MySql *MySqlHarvesterConfig
5974
}
6075

6176
// LogConfig log configuration
@@ -68,11 +83,11 @@ type LogConfig struct {
6883

6984
// Configuration receiver's configuration
7085
type Configuration struct {
71-
Name string `yaml:"name" mapstructure:"name"`
72-
Version string `yaml:"version" mapstructure:"version"`
73-
ServiceID string `yaml:"serviceID" mapstructure:"serviceID"`
74-
PidFile string `yaml:"pidFile" mapstructure:"pidFile"`
75-
Reporters []ReporterConfig `yaml:"reporter" mapstructure:"reporter"`
76-
Harvesters []HarvesterConfig `yaml:"harvester" mapstructure:"harvester"`
77-
Log LogConfig `yaml:"log" mapstructure:"log"`
86+
Name string `yaml:"name" mapstructure:"name"`
87+
Version string `yaml:"version" mapstructure:"version"`
88+
ServiceID string `yaml:"serviceID" mapstructure:"serviceID"`
89+
PidFile string `yaml:"pidFile" mapstructure:"pidFile"`
90+
Reporters []ReporterConfig `yaml:"reporter" mapstructure:"reporter"`
91+
Harvester HarvesterConfig `yaml:"harvester" mapstructure:"harvester"`
92+
Log LogConfig `yaml:"log" mapstructure:"log"`
7893
}

dbm-services/common/dbha-v2/internal/probe/harvester/harvester.go

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,11 @@
2525
package harvester
2626

2727
import (
28-
"strings"
29-
30-
"dbm-services/common/dbha-v2/internal/probe/config"
3128
"dbm-services/common/dbha-v2/internal/probe/harvester/mysql"
32-
"dbm-services/common/dbha-v2/internal/probe/harvester/plugin"
33-
"dbm-services/common/dbha-v2/pkg/gerrors"
34-
"dbm-services/common/dbha-v2/pkg/logger"
3529
)
3630

3731
var (
38-
ErrUnknownPlugin = gerrors.Newf(gerrors.Unknown, "unknown harvester plugin")
32+
// NewPluginMySql To avoid potential ambiguity caused by directly using 'mysql',
33+
// the method for creating the mysql plugin has been renamed here.
34+
NewPluginMySql = mysql.NewMySql
3935
)
40-
41-
// NewPlugin creates a new probe plugin.
42-
func NewPlugin(cfg config.HarvesterConfig) (plugin.Plugin, error) {
43-
switch strings.ToLower(cfg.Name) {
44-
case strings.ToLower(mysql.Name):
45-
return mysql.NewMySql(cfg)
46-
47-
default:
48-
logger.Error("unknown harvester plugin: %s", cfg.Name)
49-
return nil, ErrUnknownPlugin
50-
}
51-
}

dbm-services/common/dbha-v2/internal/probe/harvester/harvester_test.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,8 @@ package harvester_test
2626

2727
import (
2828
"testing"
29-
30-
"dbm-services/common/dbha-v2/internal/probe/config"
31-
"dbm-services/common/dbha-v2/internal/probe/harvester"
32-
33-
"github.com/stretchr/testify/assert"
3429
)
3530

3631
func TestNewPlugin(t *testing.T) {
37-
tests := []struct {
38-
name string
39-
cfg config.HarvesterConfig
40-
}{
41-
{"mysql", config.HarvesterConfig{Name: "mysql"}},
42-
{"redis", config.HarvesterConfig{Name: "redis"}},
43-
{"mysql uppercase", config.HarvesterConfig{Name: "MYSQL"}},
44-
}
45-
46-
for _, tt := range tests {
4732

48-
t.Run(tt.name, func(t *testing.T) {
49-
plugin, err := harvester.NewPlugin(tt.cfg)
50-
assert.NoError(t, err)
51-
assert.NotNil(t, plugin)
52-
})
53-
}
5433
}

0 commit comments

Comments
 (0)