Skip to content

Commit

Permalink
Merge branch 'bfenetworks:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Tovi163 authored Mar 12, 2024
2 parents b89fbee + 1c4a923 commit aa5f761
Show file tree
Hide file tree
Showing 40 changed files with 782 additions and 55 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:

# Check license header
- name: Check License Header
uses: apache/skywalking-eyes@main
uses: apache/skywalking-eyes/[email protected]

# Setup golang sdk
- name: Setup Go
Expand All @@ -75,8 +75,8 @@ jobs:
- name: setup Python
uses: actions/setup-python@v2
with:
python-version: '2.x' # Version range or exact version of a Python version to use, using SemVer's version range syntax
- run: python -m SimpleHTTPServer 8181&
python-version: '3.x' # Version range or exact version of a Python version to use, using SemVer's version range syntax
- run: python3 -m http.server 8181&

# Modify Conf and Run
- name: Run
Expand Down
2 changes: 2 additions & 0 deletions ADOPTERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Some of our users include:

* [Haier](https://www.haier.com)

* [PITS Global Data Recovery Services](https://pitsdatarecovery.net/)

* [Postal Savings Bank of China](https://www.psbc.com)

* [Resolink](https://www.crresolink.com.cn)
Expand Down
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,27 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [v1.6.0] - 2022-10-21

### Added

- Allow user to disable monitor port ([Issue #936](https://github.com/bfenetworks/bfe/issues/936))
- Support HTTP2 fingerprint ([Issue #1071](https://github.com/bfenetworks/bfe/issues/1071))
- Documents optimization

### Changed

- Optimize idle connection handling ([Pull #1044](https://github.com/bfenetworks/bfe/pull/1044))
- Performance optimize in smooth least connection balancing algorithm([Pull #1062](https://github.com/bfenetworks/bfe/pull/1062))
- Miscellaneous golang dependency updates
- Miscellaneous improvements in makefile and other CI tools

### Fixed

- mod_trust_clientip: fix incorrect private IP address range ([Issue #856](https://github.com/bfenetworks/bfe/issues/856))
- arm build error in golang 1.18


## [v1.5.0] - 2022-01-11

### Added
Expand Down Expand Up @@ -327,6 +348,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Flexible plugin framework to extend functionality. Based on the framework, developer can add new features rapidly
- Detailed built-in metrics available for service status monitor

[v1.6.0]: https://github.com/bfenetworks/bfe/compare/v1.5.0...v1.6.0
[v1.5.0]: https://github.com/bfenetworks/bfe/compare/v1.4.0...v1.5.0
[v1.4.0]: https://github.com/bfenetworks/bfe/compare/v1.3.0...v1.4.0
[v1.3.0]: https://github.com/bfenetworks/bfe/compare/v1.2.0...v1.3.0
Expand Down
14 changes: 9 additions & 5 deletions MAINTAINERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@ This file lists who are the maintainers of the BFE project. The responsibilities

| Name | GitHub ID | Affiliation |
| ---- | --------- | ----------- |
| [Miao Zhang](mailto:zhangmiao02@baidu.com) | [mileszhang2016](https://github.com/mileszhang2016) | Baidu |
| [Sijie Yang](mailto:[email protected]) | [iyangsj](https://github.com/iyangsj) | Baidu |
| [Miao Zhang](mailto:zhangmiao@yf-networks.com) | [mileszhang2016](https://github.com/mileszhang2016) | Yingfei Networks |
| [Sijie Yang](mailto:[email protected]) | [iyangsj](https://github.com/iyangsj) | Tencent |

## Senior Maintainers

| Name | GitHub ID | Affiliation |
| ---- | --------- | ----------- |
| [Sijie Yang](mailto:[email protected]) | [iyangsj](https://github.com/iyangsj) | Baidu |
| [Sijie Yang](mailto:[email protected]) | [iyangsj](https://github.com/iyangsj) | Tencent |

## Maintainers

| Name | GitHub ID | Affiliation |
| ---- | --------- | ----------- |
| [Derek Zheng](mailto:[email protected]) | [shanhuhai5739](https://github.com/shanhuhai5739) | Kuaishou |
| [Xiaofei Yu](mailto:[email protected]) | [xiaofei0800](https://github.com/xiaofei0800) | Baidu |
| [Xiaofei Yu](mailto:[email protected]) | [xiaofei0800](https://github.com/xiaofei0800) | Tencent |
| [Wensi Yang](mailto:[email protected]) | [tianxinheihei](https://github.com/tianxinheihei) | ByteDance |
| [Kaiyu Zheng](mailto:[email protected]) | [kaiyuzheng](https://github.com/kaiyuzheng) | ByteDance |
| [Yuqi Xiao](mailto:[email protected]) | [Yuqi Xiao](https://github.com/YuqiXiao) | Baidu |
| [Yuqi Xiao](mailto:[email protected]) | [YuqiXiao](https://github.com/YuqiXiao) | ByteDance |
| [Wei Wei](mailto:[email protected]) | [weiwei99](https://github.com/weiwei99) | Baidu |
| [Andy Liang](mailto:[email protected]) | [andyxmu](https://github.com/andyxmu) | Yingfei Networks |
| [Leiming Xu](mailto:[email protected]) | [xuleiming](https://github.com/xuleiming) | Yingfei Networks |
| [Jian Song](mailto:[email protected]) | [clarinette9](https://github.com/clarinette9) | Yingfei Networks |
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# init project path
WORKROOT := $(shell pwd)
OUTDIR := $(WORKROOT)/output
OS := $(shell go env GOOS)

# init environment variables
export PATH := $(shell go env GOPATH)/bin:$(PATH)
Expand Down Expand Up @@ -80,12 +81,20 @@ prepare-gen:
# make compile, go build
compile: test build
build:
ifeq ($(OS),darwin)
$(GOBUILD) -ldflags "-X main.version=$(BFE_VERSION) -X main.commit=$(GIT_COMMIT)"
else
$(GOBUILD) -ldflags "-X main.version=$(BFE_VERSION) -X main.commit=$(GIT_COMMIT) -extldflags=-static"
endif

# make compile-strip, go build without symbols and DWARFs
compile-strip: test build-strip
build-strip:
ifeq ($(OS),darwin)
$(GOBUILD) -ldflags "-X main.version=$(BFE_VERSION) -X main.commit=$(GIT_COMMIT) -s -w"
else
$(GOBUILD) -ldflags "-X main.version=$(BFE_VERSION) -X main.commit=$(GIT_COMMIT) -extldflags=-static -s -w"
endif

# make test, test your code
test: test-case vet-case
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ Besides, we also implement [BFE Ingress Controller](https://github.com/bfenetwor
- [English version](https://www.bfe-networks.net/en_us/ABOUT/)
- [Chinese version](https://www.bfe-networks.net/zh_cn/ABOUT/)

## Book

- [In-depth Understanding of BFE](https://github.com/baidu/bfe-book) (Released in Feb 2023)

This book focuses on BFE open source project, introduces the relevant technical principles of network access, explains the design idea of BFE open source software, and how to build a network front-end platform based on BFE open source software. Readers with development capabilities can also develop BFE extension modules according to their own needs or contribute code to BFE open source projects according to the instructions in this book.


## Contributing

- Please create an issue in [issue list](http://github.com/bfenetworks/bfe/issues).
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.0
1.6.0
28 changes: 24 additions & 4 deletions bfe.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var (
showVersion = flag.Bool("v", false, "to show version of bfe")
showVerbose = flag.Bool("V", false, "to show verbose information about bfe")
debugLog = flag.Bool("d", false, "to show debug log (otherwise >= info)")
testConf = flag.Bool("t", false, "test configuration and exit")
)

var version string
Expand Down Expand Up @@ -74,7 +75,12 @@ func main() {
logSwitch = "DEBUG"
bfe_debug.DebugIsOpen = true
} else {
logSwitch = "INFO"
// ignore under ERROR level
if *testConf {
logSwitch = "ERROR"
} else {
logSwitch = "INFO"
}
bfe_debug.DebugIsOpen = false
}

Expand All @@ -84,7 +90,7 @@ func main() {
log4go.SetLogFormat(log4go.FORMAT_DEFAULT_WITH_PID)
log4go.SetSrcLineForBinLog(false)

err = log.Init("bfe", logSwitch, *logPath, *stdOut, "midnight", 7)
err = log.Init("bfe", logSwitch, *logPath, *stdOut || *testConf, "midnight", 7)
if err != nil {
fmt.Printf("bfe: err in log.Init():%s\n", err.Error())
bfe_util.AbnormalExit()
Expand All @@ -97,10 +103,13 @@ func main() {
config, err = bfe_conf.BfeConfigLoad(confPath, *confRoot)
if err != nil {
log.Logger.Error("main(): in BfeConfigLoad():%s", err.Error())
if *testConf {
fmt.Printf("bfe: configuration file %s test failed\n", confPath)
}
bfe_util.AbnormalExit()
}

// maximum number of CPUs (GOMAXPROCS) defaults to runtime.CPUNUM
// maximum number of CPUs (GOMAXPROCS) defaults to runtime.CPUNUM
// if running on machine, or CPU quota if running on container
// (with the help of "go.uber.org/automaxprocs").
// here, we change maximum number of cpus if the MaxCpus is positive.
Expand All @@ -112,11 +121,22 @@ func main() {
bfe_debug.SetDebugFlag(config.Server)

// start and serve
if err = bfe_server.StartUp(config, version, *confRoot); err != nil {
if err = bfe_server.StartUp(config, version, *confRoot, *testConf); err != nil {
log.Logger.Error("main(): bfe_server.StartUp(): %s", err.Error())
}

// waiting for logger finish jobs
time.Sleep(1 * time.Second)
log.Logger.Close()

// output final configuration test result
if *testConf {
if err != nil {
fmt.Printf("bfe: configuration file %s test failed\n", confPath)
bfe_util.AbnormalExit()
} else {
fmt.Printf("bfe: configuration file %s test is successful\n", confPath)
bfe_util.NormalExit()
}
}
}
20 changes: 7 additions & 13 deletions bfe_balance/bal_slb/bal_rr.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,12 @@ func leastConnsBalance(backs BackendList) (BackendList, error) {
singleBackend = true
} else if ret == 0 {
singleBackend = false
if len(candidates) > 0 {
candidates = append(candidates, backendRR)
} else {
candidates = append(candidates, best, backendRR)
}

}
}

Expand All @@ -354,22 +360,10 @@ func leastConnsBalance(backs BackendList) (BackendList, error) {

// single backend, return directly
if singleBackend {
candidates = append(candidates, best)
return candidates, nil
return BackendList{best}, nil
}

// more than one backend have same connections/weight,
// return all the candidates
for _, backendRR := range backs {
if !backendRR.backend.Avail() || backendRR.weight <= 0 {
continue
}

if ret := compLCWeight(best, backendRR); ret == 0 {
candidates = append(candidates, backendRR)
}
}

return candidates, nil
}

Expand Down
64 changes: 64 additions & 0 deletions bfe_balance/bal_slb/bal_rr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,39 @@ func prepareBalanceRR() *BalanceRR {
return rr
}

func prepareBalanceRRLcw() *BalanceRR {
b1 := populateBackend("b1", "127.0.0.1", 80, true)
b2 := populateBackend("b2", "127.0.0.1", 81, true)
b3 := populateBackend("b3", "127.0.0.1", 82, true)
b4 := populateBackend("b4", "127.0.0.1", 83, true)

rr := &BalanceRR{
backends: []*BackendRR{
{
weight: 300,
current: 300,
backend: b1,
},
{
weight: 200,
current: 200,
backend: b2,
},
{
weight: 100,
current: 100,
backend: b3,
},
{
weight: 50,
current: 50,
backend: b4,
},
},
}
return rr
}

func processBalance(t *testing.T, label string, algor int, key []byte, rr *BalanceRR, result []string) {
var l []string
for i := 1; i < 10; i++ {
Expand All @@ -80,6 +113,22 @@ func processBalance(t *testing.T, label string, algor int, key []byte, rr *Balan
}
}

func processBalancLoopTwenty(t *testing.T, label string, algor int, key []byte, rr *BalanceRR, result []string) {
var l []string
for i := 1; i < 20; i++ {
r, err := rr.Balance(algor, key)
if err != nil {
t.Errorf("should not error")
}
r.IncConnNum()
l = append(l, r.Name)
}

if !reflect.DeepEqual(l, result) {
t.Errorf("balance error [%s] %v, expect %v", label, l, result)
}
}

func processSimpleBalance(t *testing.T, label string, algor int, key []byte, rr *BalanceRR, result []string) {
var l []string
loopCount := (300+200+100)+4
Expand Down Expand Up @@ -176,6 +225,12 @@ func TestBalance(t *testing.T) {
rr = prepareBalanceRR()
expectResult = []string{"b1", "b2", "b3", "b1", "b2", "b1", "b3", "b1", "b2"}
processBalance(t, "case 7", WlcSmooth, []byte{1}, rr, expectResult)

// case 8, lcw balance same weight
rr = prepareBalanceRRLcw()
expectResult = []string{"b1", "b2", "b3", "b4", "b1", "b2", "b1", "b1", "b2", "b3", "b1", "b2", "b1",
"b1", "b2", "b3", "b4", "b1", "b2"}
processBalancLoopTwenty(t, "case 8", WlcSmooth, []byte{1}, rr, expectResult)
}

func TestUpdate(t *testing.T) {
Expand Down Expand Up @@ -284,6 +339,15 @@ func BenchmarkSimpleBalance(b *testing.B) {
}
}

func BenchmarkWlcBalance(b *testing.B) {
rr := prepareBalanceRRForBench()

b.ResetTimer()
for i := 0; i < b.N; i++ {
rr.leastConnsSmoothBalance()
}
}

func BenchmarkStickyBalance(b *testing.B) {
rr := prepareBalanceRRForBench()
key := []byte{100}
Expand Down
1 change: 0 additions & 1 deletion bfe_basic/condition/primitive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ func TestContextValueFetcher(t *testing.T) {
contextVal, err := hf.Fetch(req)
if err != nil {
t.Fatalf("Fetch(): %v", err)
t.FailNow()
}

// check
Expand Down
2 changes: 1 addition & 1 deletion bfe_config/bfe_conf/testdata/conf_https_basic/bfe_4.conf
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ cipherSuites=TLS_RSA_WITH_AES_256_CBC_SHA
cipherSuites=TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA
cipherSuites=TLS_RSA_WITH_3DES_EDE_CBC_SHA

# supported curve perference settings
# supported curve preference settings
# support curves: CurveP256, CurveP384, CurveP521
curvePreferences=CurveP256

Expand Down
2 changes: 2 additions & 0 deletions bfe_http/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ type RequestState struct {

// BodySize is the size of request body.
BodySize uint32

H2Fingerprint string
}

// ProtoAtLeast reports whether the HTTP protocol used
Expand Down
Loading

0 comments on commit aa5f761

Please sign in to comment.