Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(flags): Add query timeout as a limit config #7599

Merged
merged 2 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions dgraph/cmd/alpha/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ func parseBool(r *http.Request, name string) (bool, error) {

// parseDuration reads the value for given URL parameter from request and
// parses it into time.Duration, empty string is converted into zero value
func parseDuration(r *http.Request, name string) (time.Duration, error) {
func parseDuration(r *http.Request, name string, defaultVal time.Duration) (time.Duration, error) {
value := r.URL.Query().Get(name)
if value == "" {
return 0, nil
return defaultVal, nil
}

durationValue, err := time.ParseDuration(value)
Expand All @@ -159,7 +159,7 @@ func queryHandler(w http.ResponseWriter, r *http.Request) {
x.SetStatus(w, x.ErrorInvalidRequest, err.Error())
return
}
queryTimeout, err := parseDuration(r, "timeout")
queryTimeout, err := parseDuration(r, "timeout", x.Config.QueryTimeout)
if err != nil {
x.SetStatus(w, x.ErrorInvalidRequest, err.Error())
return
Expand Down
4 changes: 4 additions & 0 deletions dgraph/cmd/alpha/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ they form a Raft group and provide synchronous replication.
Flag("disallow-drop",
"Set disallow-drop to true to block drop-all and drop-data operation. It still"+
" allows dropping attributes and types.").
Flag("query-timeout",
"Maximum time after which a query execution will fail. If set to"+
" 0, the timeout is infinite.").
String())

flag.String("ludicrous", worker.LudicrousDefaults, z.NewSuperFlagHelp(worker.LudicrousDefaults).
Expand Down Expand Up @@ -731,6 +734,7 @@ func run() {
x.Config.LimitMutationsNquad = int(x.Config.Limit.GetInt64("mutations-nquad"))
x.Config.LimitQueryEdge = x.Config.Limit.GetUint64("query-edge")
x.Config.BlockClusterWideDrop = x.Config.Limit.GetBool("disallow-drop")
x.Config.QueryTimeout = x.Config.Limit.GetDuration("query-timeout")

x.Config.GraphQL = z.NewSuperFlag(Alpha.Conf.GetString("graphql")).MergeAndCheckDefault(
worker.GraphQLDefaults)
Expand Down
2 changes: 1 addition & 1 deletion worker/server_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const (
CDCDefaults = `file=; kafka=; sasl_user=; sasl_password=; ca_cert=; client_cert=; ` +
`client_key=;`
LimitDefaults = `mutations=allow; query-edge=1000000; normalize-node=10000; ` +
`mutations-nquad=1000000; disallow-drop=false;`
`mutations-nquad=1000000; disallow-drop=false; query-timeout=500ms;`
GraphQLDefaults = `introspection=true; debug=false; extensions=true; poll-interval=1s; ` +
`lambda-url=;`
)
Expand Down
10 changes: 6 additions & 4 deletions x/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ type Options struct {
// normalize directive
// mutations-nquad int - maximum number of nquads that can be inserted in a mutation request
// BlockDropAll bool - if set to true, the drop all operation will be rejected by the server.
Limit *z.SuperFlag
LimitMutationsNquad int
LimitQueryEdge uint64
BlockClusterWideDrop bool
// query-timeout duration - Maximum time after which a query execution will fail.
Limit *z.SuperFlag
LimitMutationsNquad int
LimitQueryEdge uint64
BlockClusterWideDrop bool
QueryTimeout time.Duration

// GraphQL options:
//
Expand Down