feat: reusable rule engine to prevent memory reallocation
All checks were successful
Cadoles/bouncer/pipeline/pr-develop This commit looks good
All checks were successful
Cadoles/bouncer/pipeline/pr-develop This commit looks good
This commit is contained in:
@ -3,7 +3,6 @@ package proxy_test
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/http/httputil"
|
||||
@ -24,6 +23,7 @@ import (
|
||||
redisStore "forge.cadoles.com/cadoles/bouncer/internal/store/redis"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"gitlab.com/wpetit/goweb/logger"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"forge.cadoles.com/cadoles/bouncer/internal/setup"
|
||||
@ -39,6 +39,19 @@ func BenchmarkProxies(b *testing.B) {
|
||||
name := strings.TrimSuffix(filepath.Base(f), filepath.Ext(f))
|
||||
|
||||
b.Run(name, func(b *testing.B) {
|
||||
heap, err := os.Create(filepath.Join("testdata", "proxies", name+"_heap.prof"))
|
||||
if err != nil {
|
||||
b.Fatalf("%+v", errors.Wrapf(err, "could not create heap profile"))
|
||||
}
|
||||
|
||||
defer func() {
|
||||
defer heap.Close()
|
||||
|
||||
if err := pprof.WriteHeapProfile(heap); err != nil {
|
||||
b.Fatalf("%+v", errors.WithStack(err))
|
||||
}
|
||||
}()
|
||||
|
||||
conf, err := loadProxyBenchConfig(f)
|
||||
if err != nil {
|
||||
b.Fatalf("%+v", errors.Wrapf(err, "could notre load bench config"))
|
||||
@ -78,7 +91,7 @@ func BenchmarkProxies(b *testing.B) {
|
||||
|
||||
b.Logf("fetching url '%s'", rawProxyURL)
|
||||
|
||||
profile, err := os.Create(filepath.Join("testdata", "proxies", name+".prof"))
|
||||
profile, err := os.Create(filepath.Join("testdata", "proxies", name+"_cpu.prof"))
|
||||
if err != nil {
|
||||
b.Fatalf("%+v", errors.Wrapf(err, "could not create cpu profile"))
|
||||
}
|
||||
@ -86,7 +99,7 @@ func BenchmarkProxies(b *testing.B) {
|
||||
defer profile.Close()
|
||||
|
||||
if err := pprof.StartCPUProfile(profile); err != nil {
|
||||
log.Fatal(err)
|
||||
b.Fatalf("%+v", errors.WithStack(err))
|
||||
}
|
||||
|
||||
defer pprof.StopCPUProfile()
|
||||
@ -227,7 +240,12 @@ func createProxy(name string, conf *proxyBenchConfig, logf func(format string, a
|
||||
|
||||
}
|
||||
|
||||
layers, err := setup.GetLayers(context.Background(), config.NewDefault())
|
||||
appConf := config.NewDefault()
|
||||
appConf.Logger.Level = config.InterpolatedInt(logger.LevelError)
|
||||
appConf.Layers.Authn.TemplateDir = "../../layers/authn/templates"
|
||||
appConf.Layers.Queue.TemplateDir = "../../layers/queue/templates"
|
||||
|
||||
layers, err := setup.GetLayers(context.Background(), appConf)
|
||||
if err != nil {
|
||||
return nil, nil, errors.WithStack(err)
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ proxy:
|
||||
attributes:
|
||||
email: foo@bar.com
|
||||
rules:
|
||||
- set_header("Remote-User-Attr-Email", user.attrs.email)
|
||||
- set_header(ctx, "Remote-User-Attr-Email", vars.user.attrs.email)
|
||||
fetch:
|
||||
url:
|
||||
user:
|
||||
|
10
internal/bench/testdata/proxies/queue.yml
vendored
Normal file
10
internal/bench/testdata/proxies/queue.yml
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
proxy:
|
||||
from: ["*"]
|
||||
to: ""
|
||||
layers:
|
||||
queue:
|
||||
type: queue
|
||||
enabled: true
|
||||
options:
|
||||
capacity: 100
|
||||
keepAlive: 10s
|
4
internal/bench/testdata/proxies/rewriter.yml
vendored
4
internal/bench/testdata/proxies/rewriter.yml
vendored
@ -8,5 +8,5 @@ proxy:
|
||||
options:
|
||||
rules:
|
||||
request:
|
||||
- set_host(request.url.host)
|
||||
- set_header("X-Proxied-With", "bouncer")
|
||||
- set_host(ctx, vars.request.url.host)
|
||||
- set_header(ctx, "X-Proxied-With", "bouncer")
|
||||
|
Reference in New Issue
Block a user