mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-11 04:39:59 +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
|
||||
url := r.URL.Path
|
||||
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()
|
||||
}
|
||||
|
||||
|
@ -349,7 +349,7 @@ func setTimeoutMiddleware(next http.Handler) http.Handler {
|
||||
// check if route is not excluded
|
||||
url := r.URL.Path
|
||||
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()
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package constants
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"go.signoz.io/signoz/pkg/query-service/model"
|
||||
v3 "go.signoz.io/signoz/pkg/query-service/model/v3"
|
||||
@ -74,6 +75,17 @@ var DEFAULT_FEATURE_SET = model.FeatureSet{
|
||||
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 (
|
||||
TraceID = "traceID"
|
||||
ServiceName = "serviceName"
|
||||
@ -97,7 +109,6 @@ const (
|
||||
ResponseStatusCode = "responseStatusCode"
|
||||
Descending = "descending"
|
||||
Ascending = "ascending"
|
||||
ContextTimeout = 60 // seconds
|
||||
StatusPending = "pending"
|
||||
StatusFailed = "failed"
|
||||
StatusSuccess = "success"
|
||||
|
@ -3,6 +3,7 @@ package constants
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
. "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