Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 26 additions & 49 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,62 +6,32 @@ linters:
- cyclop
- noctx
- errcheck

# TODO: Tweak for current project needs
- lll
- noinlineerr
- nlreturn
- gocyclo
- testpackage
- funlen
- gochecknoinits
- godox
- gocognit
- contextcheck
- paralleltest
- nestif
- maintidx
- depguard
- dupl
- err113
- exhaustruct
- wrapcheck
- varnamelen
- gochecknoglobals
- intrange
- ireturn
- nlreturn
- noinlineerr
- nonamedreturns
- err113
- tagliatelle
- testpackage
- varnamelen
- wrapcheck
- wsl
- wsl_v5
- nonamedreturns
- ireturn
- dupl

# TODO: Disabled, because they are failing at the moment, we should fix them and enable (step by step)

- contextcheck
- dogsled
- embeddedstructfieldcheck
- exhaustive
- forbidigo
- forcetypeassert
- funlen
- gochecknoinits
- gocognit
- goconst
- gocritic
- gocyclo
- godox
- goprintffuncname
- govet
- ineffassign
- lll
- maintidx
- mnd
- modernize
- nakedret
- nestif
- paralleltest
- perfsprint
- prealloc
- predeclared
- revive
- tagalign
- testifylint
- thelper
- unparam
- usestdlibvars
- usetesting
- wastedassign
- whitespace
settings:
errcheck:
check-type-assertions: true
Expand Down Expand Up @@ -143,6 +113,13 @@ linters:
- gocognit
- gocyclo
path: _test\.go$
- linters:
- revive
path: ^pkg/proxy/http/
- linters:
- tagalign
path: ^pkg/config/options\.go$


issues:
max-issues-per-linter: 0
Expand Down
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix missing access log and metrics tracers for HTTP/2 requests in standard library bridge ([#116](https://github.com/nite-coder/bifrost/pull/116) by [0x5487](https://github.com/0x5487))
- Fix gRPC proxy to preserve response trailers and set content type correctly ([#117](https://github.com/nite-coder/bifrost/pull/117) by [0x5487](https://github.com/0x5487))
- rename `LoggingOtions` to `LoggingOptions` ([#121](https://github.com/nite-coder/bifrost/pull/121) by [0x5487](https://github.com/0x5487))
- Resolve various linting warnings (gosec, nilnil, bodyclose, etc.) and follow security best practices ([#122](https://github.com/nite-coder/bifrost/pull/122) by [0x5487](https://github.com/0x5487))
- Resolve various linting warnings (gosec, nilnil, bodyclose, etc.) and follow security best practices ([#122](https://github.com/nite-coder/bifrost/pull/122), [#124](https://github.com/nite-coder/bifrost/pull/124) by [0x5487](https://github.com/0x5487))

## Security

Expand Down Expand Up @@ -194,7 +194,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- move `fail_timeout` and `max_fails` from target to upstream level (passive healthcheck) in [[#17](https://github.com/nite-coder/bifrost/pull/17)]
- change `resolver` to support multiple dns servers, order, and hostfile, timeout in [[#18](https://github.com/nite-coder/bifrost/pull/18)] [[#20](https://github.com/nite-coder/bifrost/pull/20)]
- rename `http_status_code`, `http_content_type`, `http_response_body` to `rejected_http_status_code`, `rejected_http_content_type`, `rejected_http_response_body` for `rate_limit` middleware in [[#21](https://github.com/nite-coder/bifrost/pull/21)]
- Use `safety.Go` to run goroutine.
- Use `go safety.Go` to run goroutine.
- Stop logging errors when the upstream is unavailable (returns HTTP 503)
- redesign redis rate limit middleware and improve performance

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ lintd:
docker run -it --rm -v "${LOCAL_WORKSPACE_FOLDER}:/app" -w /app golangci/golangci-lint:v2.7.2-alpine golangci-lint run --timeout 5m --verbose ./pkg/...

fix:
go tool golangci-lint run --fix
go tool golangci-lint run --fix ./pkg/... ./internal/pkg/...

build:
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -o bin/bifrost server/bifrost/main.go
Expand Down
16 changes: 6 additions & 10 deletions internal/pkg/consistent/comparison_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestStathatDistribution(t *testing.T) {
numKeys := 100000
distribution := make(map[string]int)

for i := 0; i < numKeys; i++ {
for i := range numKeys {
/* #nosec G115 */
userID := uint32(i)
key := strconv.FormatUint(uint64(userID), 10)
Expand Down Expand Up @@ -57,7 +57,7 @@ func TestOurDistribution(t *testing.T) {
numKeys := 100000
distribution := make(map[string]int)

for i := 0; i < numKeys; i++ {
for i := range numKeys {
/* #nosec G115 */
userID := uint32(i)
key := strconv.FormatUint(uint64(userID), 10)
Expand Down Expand Up @@ -87,8 +87,7 @@ func BenchmarkStathatGet(b *testing.B) {
c.Add("node2")
c.Add("node3")

b.ResetTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
key := fmt.Sprintf("key%d", i%10000)
_, _ = c.Get(key)
}
Expand All @@ -101,17 +100,15 @@ func BenchmarkOurGet(b *testing.B) {
_ = ring.Add("node2")
_ = ring.Add("node3")

b.ResetTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
key := fmt.Sprintf("key%d", i%10000)
_, _ = ring.Get(key)
}
}

// BenchmarkStathatAdd benchmarks stathat/consistent Add operation.
func BenchmarkStathatAdd(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
c := consistent.New()
c.NumberOfReplicas = 160
c.Add(fmt.Sprintf("node%d", i))
Expand All @@ -120,8 +117,7 @@ func BenchmarkStathatAdd(b *testing.B) {

// BenchmarkOurAdd benchmarks our implementation's Add operation.
func BenchmarkOurAdd(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
ring := New()
_ = ring.Add(fmt.Sprintf("node%d", i))
}
Expand Down
6 changes: 3 additions & 3 deletions internal/pkg/consistent/consistent.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (c *Consistent) AddWithReplicas(nodeID string, replicas int) error {
}

// Add virtual nodes for this physical node
for i := 0; i < replicas; i++ {
for i := range replicas {
// Virtual node IDs are hashed to distribute them along the ring
// Using idx+nodeID pattern for better distribution (same as stathat/consistent)
virtualNodeKey := strconv.Itoa(i) + nodeID
Expand Down Expand Up @@ -173,7 +173,7 @@ func (c *Consistent) GetN(key string, n int) ([]string, error) {
seen := make(map[string]bool)

// Traverse the ring clockwise to find unique physical nodes
for i := 0; i < len(c.sortedNodes); i++ {
for i := range len(c.sortedNodes) {
currIdx := (idx + i) % len(c.sortedNodes)
nodeID := c.ring[c.sortedNodes[currIdx]]
if !seen[nodeID] {
Expand Down Expand Up @@ -213,7 +213,7 @@ func (c *Consistent) removeUnsafe(nodeID string) {
replicas := c.nodes[nodeID]

// Remove all virtual nodes for this physical node
for i := 0; i < replicas; i++ {
for i := range replicas {
virtualNodeKey := strconv.Itoa(i) + nodeID
hash := c.hashFunc([]byte(virtualNodeKey))
delete(c.ring, hash)
Expand Down
Loading
Loading