Skip to content

Commit 754dd4c

Browse files
committed
feat(backend): Report metrics by GSE sdk. issue #11845
1 parent 9181029 commit 754dd4c

File tree

27 files changed

+394
-704
lines changed

27 files changed

+394
-704
lines changed
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
*.swp
22
build
3-
etc
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: admin
2+
version: v2.0.0
3+
4+
discovery:
5+
endpoints: http://127.0.0.1:2379;http://127.0.0.2:2379
6+
user: root
7+
password: 1234567890
8+
9+
storage:
10+
endpoints: 127.0.0.1:3306
11+
user: root
12+
password: 123456
13+
14+
log:
15+
path: /var/log/dbha/logs/admin.log
16+
level: debug
17+
fileCount: 10
18+
fileSize: 100
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: analysis
2+
version: v2.0.0
3+
4+
discovery:
5+
endpoint: http://127.0.0.1:2379;http://127.0.0.2:2379
6+
user: root
7+
password: 1234567890
8+
9+
workflow:
10+
lockBusinessWaitTimeout: 5s
11+
scanTimeout: 60s
12+
scanInterval: 3s
13+
14+
monitor:
15+
dataID: 0
16+
bkMonitorBeat: ""
17+
bkMonitorEndpoint: 127.0.0.1:9090
18+
19+
storage:
20+
endpoint: tcp://127.0.0.1:3306
21+
user: root
22+
password: 123456
23+
24+
log:
25+
path: /var/log/dbha/logs/analysis.log
26+
level: debug
27+
fileCount: 10
28+
fileSize: 100
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: probe
2+
version: v2.0.0
3+
4+
reporter:
5+
- name: gse
6+
endpoint: ""
7+
dataID: 0
8+
connTimeout: 5s
9+
10+
harvester:
11+
- name: mysql
12+
endpoint: ""
13+
user: root
14+
password: 123456
15+
interval: 20s
16+
17+
log:
18+
path: /var/log/dbha/probe.log
19+
level: debug
20+
fileCount: 10
21+
fileSize: 100
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: receiver
2+
version: v2.0.0
3+
4+
discovery:
5+
endpoint: http://etcd-server:2379
6+
user: root
7+
password: 1234567890
8+
9+
input:
10+
- name: probe
11+
enable: false
12+
endpoint: 127.0.0.1:25560
13+
14+
- name: kafka
15+
enable: true
16+
endpoint: http://kafk-server:9092
17+
user: root
18+
password: 1234567890
19+
mechanism: plaintext
20+
topics: [test]
21+
22+
output:
23+
- name: mysql
24+
enable: false
25+
endpoint: 127.0.0.1:3306
26+
user: root
27+
password: 123456
28+
29+
log:
30+
path: /var/log/dbha/logs/receiver.log
31+
level: debug
32+
fileCount: 10
33+
fileSize: 100

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ require (
1717
gopkg.in/natefinch/lumberjack.v2 v2.2.1
1818
gorm.io/driver/mysql v1.6.0
1919
gorm.io/gorm v1.30.0
20-
k8s.io/apimachinery v0.33.2
2120
)
2221

2322
require (
@@ -80,8 +79,6 @@ require (
8079
google.golang.org/genproto/googleapis/api v0.0.0-20250303144028-a0af3efb3deb // indirect
8180
google.golang.org/genproto/googleapis/rpc v0.0.0-20250303144028-a0af3efb3deb // indirect
8281
gopkg.in/yaml.v3 v3.0.1 // indirect
83-
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
84-
sigs.k8s.io/yaml v1.4.0 // indirect
8582
)
8683

8784
replace github.com/Shopify/sarama => github.com/IBM/sarama v1.45.2

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6
4444
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
4545
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
4646
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
47-
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
4847
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
4948
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
5049
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
@@ -248,9 +247,3 @@ gorm.io/driver/mysql v1.6.0 h1:eNbLmNTpPpTOVZi8MMxCi2aaIm0ZpInbORNXDwyLGvg=
248247
gorm.io/driver/mysql v1.6.0/go.mod h1:D/oCC2GWK3M/dqoLxnOlaNKmXz8WNTfcS9y5ovaSqKo=
249248
gorm.io/gorm v1.30.0 h1:qbT5aPv1UH8gI99OsRlvDToLxW5zR7FzS9acZDOZcgs=
250249
gorm.io/gorm v1.30.0/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE=
251-
k8s.io/apimachinery v0.33.2 h1:IHFVhqg59mb8PJWTLi8m1mAoepkUNYmptHsV+Z1m5jY=
252-
k8s.io/apimachinery v0.33.2/go.mod h1:BHW0YOu7n22fFv/JkYOEfkUYNRN0fj0BlvMFWA7b+SM=
253-
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 h1:/Rv+M11QRah1itp8VhT6HoVx1Ray9eB4DBr+K+/sCJ8=
254-
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3/go.mod h1:18nIHnGi6636UCz6m8i4DhaJ65T6EruyzmoQqI2BVDo=
255-
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
256-
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=

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

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,27 @@
2424

2525
package config
2626

27+
import "time"
28+
2729
var Cfg Configuration
2830

31+
// ReporterConfig reporter's config
32+
type ReporterConfig struct {
33+
Name string `yaml:"name" mapstructure:"name"`
34+
Endpoint string `yaml:"endpoint" mapstructure:"endpoint"`
35+
DataID uint64 `yaml:"dataID" mapstructure:"dataID"`
36+
ConnTimeout time.Duration `yaml:"connTimeout" mapstructure:"connTimeout"`
37+
}
38+
39+
// HarvesterConfig harvester's config
40+
type HarvesterConfig struct {
41+
Name string `yaml:"name" mapstructure:"name"`
42+
Endpoint string `yaml:"endpoint" mapstructure:"endpoint"`
43+
User string `yaml:"user" mapstructure:"user"`
44+
Password string `yaml:"password" mapstructure:"password"`
45+
Interval time.Duration `yaml:"interval" mapstructure:"interval"`
46+
}
47+
2948
// LogConfig log configuration
3049
type LogConfig struct {
3150
Path string `yaml:"path" mapstructure:"path"`
@@ -34,49 +53,11 @@ type LogConfig struct {
3453
FileSize int `yaml:"fileSize" mapstructure:"fileSize"`
3554
}
3655

37-
// AdminService admin service configuration
38-
type AdminService struct {
39-
Endpoints string `yaml:"endpoints" mapstructure:"endpoints"`
40-
SyncInterval int `yaml:"syncInterval" mapstructure:"syncInterval"`
41-
}
42-
43-
// ReceiverService receiver service configuration
44-
type ReceiverService struct {
45-
Endpoints string `yaml:"endpoints" mapstructure:"endpoints"`
46-
SyncInterval int `yaml:"syncInterval" mapstructure:"syncInterval"`
47-
}
48-
49-
// InstanceConfig single instance config
50-
type InstanceConfig struct {
51-
Host string `yaml:"host" mapstructure:"host"`
52-
Port int `yaml:"port" mapstructure:"port"`
53-
User string `yaml:"user" mapstructure:"user"`
54-
Password string `yaml:"password" mapstructure:"password"`
55-
Name string `yaml:"name" mapstructure:"name"`
56-
}
57-
58-
// HarvesterConfig harvester's config
59-
type HarvesterConfig struct {
60-
Name string `yaml:"name" mapstructure:"name"`
61-
ReportInterval int `yaml:"reportInterval" mapstructure:"reportInterval"`
62-
Instances []InstanceConfig `yaml:"instances" mapstructure:"instances"`
63-
}
64-
6556
// Configuration receiver's configuration
6657
type Configuration struct {
67-
Name string `yaml:"name" mapstructure:"name"`
68-
Version string `yaml:"version" mapstructure:"version"`
69-
Admin AdminService `yaml:"admin" mapstructure:"admin"`
70-
Receiver ReceiverService `yaml:"receiver" mapstructure:"receiver"`
71-
Harvester []HarvesterConfig `yaml:"harvester" mapstructure:"harvester"`
72-
Log LogConfig `yaml:"log" mapstructure:"log"`
73-
GSE GSEConfig `yaml:"gse" mapstructure:"gse"`
74-
}
75-
76-
// GSEConfig defines the GSE basic config.
77-
type GSEConfig struct {
78-
// DomainSocketPath is the domain socket path.
79-
// DataID is the data-id(channel-id) to report.
80-
DomainSocketPath string `yaml:"domain_socket_path" mapstructure:"domain_socket_path"`
81-
DataID uint32 `yaml:"data_id" mapstructure:"data_id"`
58+
Name string `yaml:"name" mapstructure:"name"`
59+
Version string `yaml:"version" mapstructure:"version"`
60+
Reporters []ReporterConfig `yaml:"reporter" mapstructure:"reporter"`
61+
Harvesters []HarvesterConfig `yaml:"harvester" mapstructure:"harvester"`
62+
Log LogConfig `yaml:"log" mapstructure:"log"`
8263
}

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,24 @@ package config_test
2626

2727
import (
2828
"dbm-services/common/dbha-v2/internal/probe/config"
29-
"os"
3029
"testing"
3130

32-
"k8s.io/apimachinery/pkg/util/yaml"
31+
"github.com/spf13/viper"
3332
)
3433

3534
var configFile = "../../../etc/probe.yaml"
3635

3736
func TestConfig(t *testing.T) {
38-
content, err := os.ReadFile(configFile)
39-
if err != nil {
40-
t.Error(err)
37+
viper.SetConfigType("yaml")
38+
viper.SetConfigFile(configFile)
39+
40+
if err := viper.ReadInConfig(); err != nil {
41+
t.Fatalf("viper read in config failed, %v", err)
4142
}
4243

43-
if err := yaml.Unmarshal(content, &config.Cfg); err != nil {
44-
t.Error(err)
44+
if err := viper.Unmarshal(&config.Cfg); err != nil {
45+
t.Fatalf("viper unmarhsal failed, %v", err)
4546
}
4647

47-
t.Logf("probe config:%v", config.Cfg)
48+
t.Log("probe cfg:", config.Cfg)
4849
}

0 commit comments

Comments
 (0)