[release] v0.12.0-unstable31

This commit is contained in:
Yann Stepienik 2023-11-01 21:17:16 +00:00
parent 0daf229b56
commit bdfcf0a2bf
2 changed files with 42 additions and 42 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "cosmos-server", "name": "cosmos-server",
"version": "0.12.0-unstable30", "version": "0.12.0-unstable31",
"description": "", "description": "",
"main": "test-server.js", "main": "test-server.js",
"bugs": { "bugs": {

View file

@ -9,15 +9,15 @@ import (
) )
// responseWriter wraps the original http.ResponseWriter to capture the status code. // responseWriter wraps the original http.ResponseWriter to capture the status code.
type responseWriter struct { // type responseWriter struct {
http.ResponseWriter // http.ResponseWriter
status int // status int
} // }
func (rw *responseWriter) WriteHeader(status int) { // func (rw *responseWriter) WriteHeader(status int) {
rw.status = status // rw.status = status
rw.ResponseWriter.WriteHeader(status) // rw.ResponseWriter.WriteHeader(status)
} // }
func MetricsMiddleware(route utils.ProxyRouteConfig) func(next http.Handler) http.Handler { func MetricsMiddleware(route utils.ProxyRouteConfig) func(next http.Handler) http.Handler {
return func(next http.Handler) http.Handler { return func(next http.Handler) http.Handler {
@ -25,9 +25,9 @@ func MetricsMiddleware(route utils.ProxyRouteConfig) func(next http.Handler) htt
startTime := time.Now() startTime := time.Now()
// Call the next handler (which can be another middleware or the final handler). // Call the next handler (which can be another middleware or the final handler).
wrappedWriter := &responseWriter{ResponseWriter: w} // wrappedWriter := &responseWriter{ResponseWriter: w}
next.ServeHTTP(wrappedWriter, r) next.ServeHTTP(w, r)
// Calculate and log the response time. // Calculate and log the response time.
responseTime := time.Since(startTime) responseTime := time.Since(startTime)
@ -36,37 +36,37 @@ func MetricsMiddleware(route utils.ProxyRouteConfig) func(next http.Handler) htt
if !utils.GetMainConfig().MonitoringDisabled { if !utils.GetMainConfig().MonitoringDisabled {
go func() { go func() {
if wrappedWriter.status >= 400 { // if wrappedWriter.status >= 400 {
PushSetMetric("proxy.all.error", 1, DataDef{ // PushSetMetric("proxy.all.error", 1, DataDef{
Max: 0, // Max: 0,
Period: time.Second * 30, // Period: time.Second * 30,
Label: "Global Request Errors", // Label: "Global Request Errors",
AggloType: "sum", // AggloType: "sum",
SetOperation: "sum", // SetOperation: "sum",
}) // })
PushSetMetric("proxy.route.error."+route.Name, 1, DataDef{ // PushSetMetric("proxy.route.error."+route.Name, 1, DataDef{
Max: 0, // Max: 0,
Period: time.Second * 30, // Period: time.Second * 30,
Label: "Request Errors " + route.Name, // Label: "Request Errors " + route.Name,
AggloType: "sum", // AggloType: "sum",
SetOperation: "sum", // SetOperation: "sum",
}) // })
} else { // } else {
PushSetMetric("proxy.all.success", 1, DataDef{ // PushSetMetric("proxy.all.success", 1, DataDef{
Max: 0, // Max: 0,
Period: time.Second * 30, // Period: time.Second * 30,
Label: "Global Request Success", // Label: "Global Request Success",
AggloType: "sum", // AggloType: "sum",
SetOperation: "sum", // SetOperation: "sum",
}) // })
PushSetMetric("proxy.route.success."+route.Name, 1, DataDef{ // PushSetMetric("proxy.route.success."+route.Name, 1, DataDef{
Max: 0, // Max: 0,
Period: time.Second * 30, // Period: time.Second * 30,
Label: "Request Success " + route.Name, // Label: "Request Success " + route.Name,
AggloType: "sum", // AggloType: "sum",
SetOperation: "sum", // SetOperation: "sum",
}) // })
} // }
PushSetMetric("proxy.all.time", int(responseTime.Milliseconds()), DataDef{ PushSetMetric("proxy.all.time", int(responseTime.Milliseconds()), DataDef{
Max: 0, Max: 0,