Skip to content

Commit

Permalink
test: Using telemetry instead of prometheus for middleware benchmark
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Aug 17, 2023
1 parent c26296d commit cd5dfc6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions cmd/http/http_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"flag"
"net/http"
"net/http/httptest"
Expand All @@ -10,8 +11,8 @@ import (
"github.com/ViBiOh/httputils/v4/pkg/cors"
"github.com/ViBiOh/httputils/v4/pkg/model"
"github.com/ViBiOh/httputils/v4/pkg/owasp"
"github.com/ViBiOh/httputils/v4/pkg/prometheus"
"github.com/ViBiOh/httputils/v4/pkg/recoverer"
"github.com/ViBiOh/httputils/v4/pkg/telemetry"
)

var handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -53,14 +54,19 @@ func BenchmarkFullMiddlewares(b *testing.B) {
fs.String("test.run", "", "")
fs.String("test.paniconexit0", "", "")

prometheusConfig := prometheus.Flags(fs, "prometheus")
telemetryConfig := telemetry.Flags(fs, "telemetry")
owaspConfig := owasp.Flags(fs, "")
corsConfig := cors.Flags(fs, "cors")

if err := fs.Parse(os.Args[1:]); err != nil {
b.Error(err)
}

middlewares := model.ChainMiddlewares(handler, recoverer.Middleware, prometheus.New(prometheusConfig).Middleware, owasp.New(owaspConfig).Middleware, cors.New(corsConfig).Middleware)
telemetryApp, err := telemetry.New(context.Background(), telemetryConfig)
if err != nil {
b.Error(err)
}

middlewares := model.ChainMiddlewares(handler, recoverer.Middleware, telemetryApp.Middleware("http"), owasp.New(owaspConfig).Middleware, cors.New(corsConfig).Middleware)
benchmarkHandler(b, middlewares)
}

0 comments on commit cd5dfc6

Please sign in to comment.