Merged in feature/prometheus (pull request #52)

API instrumentation - metrics and logging

* api instrumentation

prometheus metrics and logging for all routes

* Merge branch 'main' of bitbucket.org:aarete/query-orchestration into feature/prometheus

* add log_level

and sync the config initialize

* docs

* cleanup

* add to compose:up:test

* docs for prometheus testing

* custom metrics

* cleanup

* merge main

* add tests

* cleanup docs

* cleanup

* lint

* fix unit tests (attempt)

* fix tests

* resolvesetlogger

* expose 8080

* compose changes

* bugfixesformichael

* don't build _test

* merge in main

* job_sync_runner
This commit is contained in:
Jay Brown
2025-02-13 15:44:08 +00:00
parent f5bd522faf
commit 477518e5eb
203 changed files with 36848 additions and 118 deletions
+35 -1
View File
@@ -8,8 +8,10 @@ import (
"net/http"
"queryorchestration/internal/server"
"strconv"
"time"
"github.com/getkin/kin-openapi/openapi3"
"github.com/labstack/echo-contrib/echoprometheus"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
_ "github.com/lib/pq"
@@ -59,6 +61,33 @@ type Server struct {
cleanup func() error
}
func getSlogCustomEchoMiddleware(logger *slog.Logger) echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
start := time.Now()
err := next(c)
if err != nil {
c.Error(err)
}
req := c.Request()
res := c.Response()
logger.Info("HTTP request",
"method", req.Method,
"uri", req.RequestURI,
"status", res.Status,
"latency", time.Since(start).String(),
"error", err,
"remote_ip", c.RealIP(),
)
return err
}
}
}
func New(ctx context.Context, cfg Config) (*Server, error) {
cleanup, err := server.New(ctx, cfg)
@@ -68,7 +97,12 @@ func New(ctx context.Context, cfg Config) (*Server, error) {
e := echo.New()
e.Use(middleware.Logger())
// Add Prometheus middleware
e.Use(echoprometheus.NewMiddleware("echo")) // Add the middleware
e.GET("/metrics", echoprometheus.NewHandler())
// Other middlewares
e.Use(getSlogCustomEchoMiddleware(cfg.GetLogger()))
e.Use(middleware.Recover())
e.Use(middleware.CORS())