mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-14 03:25:57 +08:00
feat: added configuration via env for context timeout (#2585)
This commit is contained in:
parent
b27bdac1f6
commit
dcad77746a
@ -402,7 +402,7 @@ func setTimeoutMiddleware(next http.Handler) http.Handler {
|
|||||||
// check if route is not excluded
|
// check if route is not excluded
|
||||||
url := r.URL.Path
|
url := r.URL.Path
|
||||||
if _, ok := baseconst.TimeoutExcludedRoutes[url]; !ok {
|
if _, ok := baseconst.TimeoutExcludedRoutes[url]; !ok {
|
||||||
ctx, cancel = context.WithTimeout(r.Context(), baseconst.ContextTimeout*time.Second)
|
ctx, cancel = context.WithTimeout(r.Context(), baseconst.ContextTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -349,7 +349,7 @@ func setTimeoutMiddleware(next http.Handler) http.Handler {
|
|||||||
// check if route is not excluded
|
// check if route is not excluded
|
||||||
url := r.URL.Path
|
url := r.URL.Path
|
||||||
if _, ok := constants.TimeoutExcludedRoutes[url]; !ok {
|
if _, ok := constants.TimeoutExcludedRoutes[url]; !ok {
|
||||||
ctx, cancel = context.WithTimeout(r.Context(), constants.ContextTimeout*time.Second)
|
ctx, cancel = context.WithTimeout(r.Context(), constants.ContextTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package constants
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
"go.signoz.io/signoz/pkg/query-service/model"
|
"go.signoz.io/signoz/pkg/query-service/model"
|
||||||
v3 "go.signoz.io/signoz/pkg/query-service/model/v3"
|
v3 "go.signoz.io/signoz/pkg/query-service/model/v3"
|
||||||
@ -74,6 +75,17 @@ var DEFAULT_FEATURE_SET = model.FeatureSet{
|
|||||||
TimestampSort: IsTimestampSortFeatureEnabled(),
|
TimestampSort: IsTimestampSortFeatureEnabled(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetContextTimeout() time.Duration {
|
||||||
|
contextTimeoutStr := GetOrDefaultEnv("CONTEXT_TIMEOUT", "60")
|
||||||
|
contextTimeoutDuration, err := time.ParseDuration(contextTimeoutStr + "s")
|
||||||
|
if err != nil {
|
||||||
|
return time.Minute
|
||||||
|
}
|
||||||
|
return contextTimeoutDuration
|
||||||
|
}
|
||||||
|
|
||||||
|
var ContextTimeout = GetContextTimeout()
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TraceID = "traceID"
|
TraceID = "traceID"
|
||||||
ServiceName = "serviceName"
|
ServiceName = "serviceName"
|
||||||
@ -97,7 +109,6 @@ const (
|
|||||||
ResponseStatusCode = "responseStatusCode"
|
ResponseStatusCode = "responseStatusCode"
|
||||||
Descending = "descending"
|
Descending = "descending"
|
||||||
Ascending = "ascending"
|
Ascending = "ascending"
|
||||||
ContextTimeout = 60 // seconds
|
|
||||||
StatusPending = "pending"
|
StatusPending = "pending"
|
||||||
StatusFailed = "failed"
|
StatusFailed = "failed"
|
||||||
StatusSuccess = "success"
|
StatusSuccess = "success"
|
||||||
|
@ -3,6 +3,7 @@ package constants
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
. "github.com/smartystreets/goconvey/convey"
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
)
|
)
|
||||||
@ -19,3 +20,16 @@ func TestGetAlertManagerApiPrefix(t *testing.T) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetContextTimeout(t *testing.T) {
|
||||||
|
Convey("TestGetContextTimeout", t, func() {
|
||||||
|
res := GetContextTimeout()
|
||||||
|
So(res, ShouldEqual, time.Duration(60000000000))
|
||||||
|
|
||||||
|
Convey("WithEnvSet", func() {
|
||||||
|
os.Setenv("CONTEXT_TIMEOUT", "120")
|
||||||
|
res = GetContextTimeout()
|
||||||
|
So(res, ShouldEqual, time.Duration(120000000000))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user