Skip to content

Commit

Permalink
Merge pull request #937 from kwanhur/feature-monitor-enable
Browse files Browse the repository at this point in the history
Feature: Add web monitor enable config item resolve #936
  • Loading branch information
mileszhang2016 authored Jan 12, 2022
2 parents a970f7f + 0b2a17f commit de249f9
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 18 deletions.
4 changes: 2 additions & 2 deletions bfe_config/bfe_conf/bfe_config_load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestBfeConfigLoadNormal(t *testing.T) {
t.Errorf("config.HttpPort should be 80")
}

if config.Server.MonitorPort != 8080 {
if config.Server.MonitorEnabled && config.Server.MonitorPort != 8080 {
t.Errorf("config.MonitorPort should be 8080")
}

Expand Down Expand Up @@ -90,7 +90,7 @@ func TestBfeConfigLoadUsingDefault(t *testing.T) {
t.Errorf("config.HttpPort should be 8080")
}

if config.Server.MonitorPort != 8421 {
if config.Server.MonitorEnabled && config.Server.MonitorPort != 8421 {
t.Errorf("config.MonitorPort should be 8421")
}

Expand Down
16 changes: 9 additions & 7 deletions bfe_config/bfe_conf/conf_basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ const (
)

type ConfigBasic struct {
HttpPort int // listen port for http
HttpsPort int // listen port for https
MonitorPort int // web server port for monitor
MaxCpus int // number of max cpus to use
AcceptNum int // number of accept goroutine for each listener, default 1
HttpPort int // listen port for http
HttpsPort int // listen port for https
MonitorPort int // web server port for monitor
MaxCpus int // number of max cpus to use
AcceptNum int // number of accept goroutine for each listener, default 1
MonitorEnabled bool // web server for monitor enable or not

// settings of layer-4 load balancer
Layer4LoadBalancer string
Expand Down Expand Up @@ -84,6 +85,7 @@ func (cfg *ConfigBasic) SetDefaultConf() {
cfg.HttpPort = 8080
cfg.HttpsPort = 8443
cfg.MonitorPort = 8421
cfg.MonitorEnabled = true
cfg.MaxCpus = 0

cfg.TlsHandshakeTimeout = 30
Expand Down Expand Up @@ -141,8 +143,8 @@ func basicConfCheck(cfg *ConfigBasic) error {
cfg.HttpsPort)
}

// check MonitorPort
if cfg.MonitorPort < 1 || cfg.MonitorPort > 65535 {
// check MonitorPort if MonitorEnabled enabled
if cfg.MonitorEnabled && (cfg.MonitorPort < 1 || cfg.MonitorPort > 65535) {
return fmt.Errorf("MonitorPort[%d] should be in [1, 65535]",
cfg.MonitorPort)
}
Expand Down
9 changes: 5 additions & 4 deletions bfe_config/bfe_conf/conf_basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func Test_conf_basic_case1(t *testing.T) {
t.Error("config.HttpPort should be 80")
}

if config.Server.MonitorPort != 8080 {
if config.Server.MonitorEnabled && config.Server.MonitorPort != 8080 {
t.Error("config.MonitorPort should be 8080")
}

Expand Down Expand Up @@ -101,10 +101,11 @@ func Test_conf_basic_check(t *testing.T) {
conf *ConfigBasic
err string
}{
{&ConfigBasic{HttpPort: 80, HttpsPort: 443, MonitorPort: 8080, MaxCpus: -1}, "MaxCpus[-1] is too small"},
{&ConfigBasic{HttpPort: 80, HttpsPort: 443, MonitorPort: 8080, MaxCpus: 10, TlsHandshakeTimeout: 30,
{&ConfigBasic{HttpPort: 80, HttpsPort: 443, MonitorPort: -1, MonitorEnabled: true},"MonitorPort[-1] should be in [1, 65535]"},
{&ConfigBasic{HttpPort: 80, HttpsPort: 443, MonitorPort: 8080, MonitorEnabled: false, MaxCpus: -1}, "MaxCpus[-1] is too small"},
{&ConfigBasic{HttpPort: 80, HttpsPort: 443, MonitorPort: 8080, MonitorEnabled: true, MaxCpus: 10, TlsHandshakeTimeout: 30,
GracefulShutdownTimeout: 30}, "ClientReadTimeout[0] should > 0"},
{&ConfigBasic{HttpPort: 80, HttpsPort: 443, MonitorPort: 8080, MaxCpus: 10, TlsHandshakeTimeout: 30,
{&ConfigBasic{HttpPort: 80, HttpsPort: 443, MonitorPort: 8080, MonitorEnabled: true, MaxCpus: 10, TlsHandshakeTimeout: 30,
GracefulShutdownTimeout: 30, ClientReadTimeout: 10, ClientWriteTimeout: 10, MonitorInterval: 33},
"MonitorInterval[33] can not divide 60"},
}
Expand Down
2 changes: 2 additions & 0 deletions bfe_config/bfe_conf/testdata/conf_all/bfe.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ httpPort = 80
httpsPort = 443
# listen port for monitor request
monitorPort = 8080
# enable monitor server
MonitorEnabled = true
# max number of CPUs to use
maxCpus = 2

Expand Down
2 changes: 2 additions & 0 deletions bfe_config/bfe_conf/testdata/conf_basic/bfe_1.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ httpPort = 80
httpsPort = 443
# listen port for monitor request
monitorPort = 8080
# enable monitor server
MonitorEnabled = true
# max number of CPUs to use
maxCpus = 5

Expand Down
12 changes: 7 additions & 5 deletions bfe_server/bfe_server_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@ func StartUp(cfg bfe_conf.BfeConfig, version string, confRoot string) error {
bfeServer.InitSignalTable()
log.Logger.Info("StartUp():bfeServer.InitSignalTable() OK")

// init web monitor
monitorPort := cfg.Server.MonitorPort
if err = bfeServer.InitWebMonitor(monitorPort); err != nil {
log.Logger.Error("StartUp(): InitWebMonitor():%s", err.Error())
return err
// init web monitor if enabled
if cfg.Server.MonitorEnabled {
monitorPort := cfg.Server.MonitorPort
if err = bfeServer.InitWebMonitor(monitorPort); err != nil {
log.Logger.Error("StartUp(): InitWebMonitor():%s", err.Error())
return err
}
}

// register modules
Expand Down
2 changes: 2 additions & 0 deletions conf/bfe.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ HttpPort = 8080
HttpsPort = 8443
# listen port for monitor request
MonitorPort = 8421
# if false, disable monitor server
MonitorEnabled = true

# max number of CPUs to use (0 to use all CPUs)
MaxCpus = 0
Expand Down

0 comments on commit de249f9

Please sign in to comment.