Skip to content
Draft
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
50 changes: 50 additions & 0 deletions .github/workflows/performance.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Performance Test

concurrency:
# Run only for most recent commit in PRs but for all tags and commits on main
# Ref: https://docs.github.com/en/actions/using-jobs/using-concurrency
group: ${{ github.workflow }}-${{ github.head_ref || github.sha }}
cancel-in-progress: true

on:
push:
branches:
- main
pull_request: {}

jobs:
performance:
timeout-minutes: 5
strategy:
matrix:
kong_image:
- 'kong/kong-gateway:3.10'
env:
KONG_ANONYMOUS_REPORTS: "off"
KONG_IMAGE: ${{ matrix.kong_image }}

runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{secrets.DOCKERHUB_PULL_USERNAME}}
password: ${{secrets.DOCKERHUB_PULL_TOKEN}}
- uses: Kong/kong-license@master
id: license
with:
op-token: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
- name: Setup Kong
env:
KONG_LICENSE_DATA: ${{ steps.license.outputs.license }}
run: make setup-kong-ee
- name: Run performance tests
env:
KONG_LICENSE_DATA: ${{ steps.license.outputs.license }}
run: make test-performance
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ test-integration:
$(GOTESTFLAGS) \
./tests/integration/...

.PHONY: test-performance
test-performance:
go test -v -count=1 -tags=performance \
-race \
$(GOTESTFLAGS) \
./tests/performance/...

.PHONY: clean
clean:
bash .ci/clean_kong.sh
96 changes: 96 additions & 0 deletions tests/performance/sync_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//go:build performance

package performance

import (
"bytes"
"context"
"fmt"
"io"
"os"
"regexp"
"strings"
"testing"

"github.com/stretchr/testify/require"
)

func countHTTPMethods(log string) map[string]int {
methodCounts := make(map[string]int)

// Match HTTP request lines like: GET /path HTTP/1.1
re := regexp.MustCompile(`(?m)^(GET|POST|PUT|DELETE|PATCH|OPTIONS|HEAD)\s+\/.*\s+HTTP\/[0-9.]+`)

lines := strings.Split(log, "\n")
for _, line := range lines {
if re.MatchString(line) {
matches := re.FindStringSubmatch(line)
if len(matches) > 1 {
method := matches[1]
methodCounts[method]++
methodCounts["total"]++
}
}
}

return methodCounts
}

// scope
// - konnect
// - enterprise
func Test_Sync_Network_Throughput(t *testing.T) {
tests := []struct {
name string
stateFile string
thresholdPOST int
thresholdPUT int
thresholdTotal int
}{
{
name: "Entities with UUIDs",
// This file contains 100 services, 100 routes, 10 consumer groups, and 100 consumers in total.
// Note that real world latency for http response will be about 10x of local instance (which is used in testing)
// so keeping the acceptable duration low.
stateFile: "testdata/sync/regression-entities-with-id.yaml",
thresholdPUT: 372, // 20% more than 1 request each per entity - we use PUT for create since ID is given.
thresholdPOST: 120, // 20% more than required - for adding consumers to groups
thresholdTotal: 525, // Sum of last two + count of GET expected - (310+100+27)*1.2
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
setup(t)

// overwrite default standard output
rescueStderr := os.Stderr
r, w, _ := os.Pipe()
os.Stderr = w

var buf bytes.Buffer
done := make(chan struct{})

go func() {
_, _ = io.Copy(&buf, r)
close(done)
}()

err := sync(context.Background(), tc.stateFile, "--verbose", "2")
require.NoError(t, err)

w.Close()

os.Stderr = rescueStderr
<-done

result := countHTTPMethods(buf.String())

fmt.Println(result)

if result["total"] > tc.thresholdTotal {
t.Fatalf("expected < %d HTTP requests, sent %d", tc.thresholdTotal, result["total"])
}
})
}
}
Loading
Loading