2025-12-26 09:37:14: merge [main:2b5ee66527f48ea4e6111148c0ba3c23611d6772];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
This commit is contained in:
1 parent
9b18fe7351
commit
a841cd082b
4 files changed
+40
-1
No files matched your search
@@ -1,3 +1,5 @@
|
||||
### v5.6.0
|
||||
* Добавлена поддержка метрик для http запросов
|
||||
### v5.5.1
|
||||
* повышен приоритет `x-application-token` над basic-auth, при поиске в запросе токена приложения
|
||||
### v5.5.0
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package assembly
|
||||
|
||||
import (
|
||||
"github.com/txix-open/isp-kit/metrics"
|
||||
"github.com/txix-open/isp-kit/metrics/http_metrics"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
@@ -94,6 +96,8 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location) (http.Ha
|
||||
forwardReqIdByAppId[setting.ApplicationId] = setting.ForwardRequestId
|
||||
}
|
||||
|
||||
metricsStorage := http_metrics.NewServerStorage(metrics.DefaultRegistry)
|
||||
|
||||
handler := middleware.Chain(
|
||||
proxyFunc,
|
||||
middleware.Logger(
|
||||
@@ -110,6 +114,7 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location) (http.Ha
|
||||
middleware.Throttling(throttlingService),
|
||||
middleware.DailyLimit(dailyLimitService),
|
||||
middleware.RequestId(config.EnableClientRequestIdForwarding, forwardReqIdByAppId),
|
||||
middleware.Metrics(metricsStorage),
|
||||
)
|
||||
if location.SkipAuth {
|
||||
handler = middleware.Chain(
|
||||
@@ -121,6 +126,7 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location) (http.Ha
|
||||
),
|
||||
middleware.ErrorHandler(l.logger),
|
||||
middleware.RequestId(config.EnableClientRequestIdForwarding, forwardReqIdByAppId),
|
||||
middleware.Metrics(metricsStorage),
|
||||
)
|
||||
}
|
||||
entrypoint := middleware.Entrypoint(
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"isp-gate-service/request"
|
||||
"time"
|
||||
|
||||
"github.com/txix-open/isp-kit/metrics/http_metrics"
|
||||
)
|
||||
|
||||
func Metrics(storage *http_metrics.ServerStorage) Middleware {
|
||||
return func(next Handler) Handler {
|
||||
return HandlerFunc(func(ctx *request.Context) error {
|
||||
endpoint := ctx.Endpoint()
|
||||
if endpoint == "" {
|
||||
return next.Handle(ctx)
|
||||
}
|
||||
|
||||
r := ctx.Request()
|
||||
|
||||
start := time.Now()
|
||||
err := next.Handle(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
storage.ObserveDuration(r.Method, endpoint, time.Since(start))
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user