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

Add LogRequest variable to config input #5197

Merged
merged 6 commits into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
2 changes: 1 addition & 1 deletion edgraph/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ func (s *Server) Query(ctx context.Context, req *api.Request) (*api.Response, er

func (s *Server) doQuery(ctx context.Context, req *api.Request, doAuth AuthMode) (
resp *api.Response, rerr error) {
if glog.V(3) {
if glog.V(3) || atomic.LoadInt32(&x.WorkerConfig.LogRequest) > 0 {
glog.Infof("Got a query: %+v", req)
}
isGraphQL, _ := ctx.Value(IsGraphql).(bool)
Expand Down
10 changes: 8 additions & 2 deletions graphql/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const (
schema: String! @dgraph(pred: "dgraph.graphql.schema")

"""
The GraphQL schema that was generated from the 'schema' field.
The GraphQL schema that was generated from the 'schema' field.
This is the schema that is being served by Dgraph at /graphql.
"""
generatedSchema: String!
Expand Down Expand Up @@ -220,10 +220,16 @@ const (
input ConfigInput {

"""
Estimated memory the LRU cache can take. Actual usage by the process would be
Estimated memory the LRU cache can take. Actual usage by the process would be
more than specified here. (default -1 means no set limit)
"""
lruMb: Float

"""
True value of logRequest enables logging of all the requests coming to alphas.
False value of logRequest disables above.
"""
logRequest: Boolean
}

type ConfigPayload {
Expand Down
22 changes: 19 additions & 3 deletions graphql/admin/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,21 @@ package admin
import (
"context"
"encoding/json"
"sync/atomic"

"github.com/dgraph-io/dgraph/graphql/resolve"
"github.com/dgraph-io/dgraph/graphql/schema"
"github.com/dgraph-io/dgraph/worker"
"github.com/dgraph-io/dgraph/x"
"github.com/golang/glog"
)

type configInput struct {
LruMB float64
// LogRequest is used to update WorkerOptions.LogRequest. true value of LogRequest enables
// logging of all requests coming to alphas. LogRequest type has been kept as *bool instead of
// bool to avoid updating WorkerOptions.LogRequest when it has default value of false.
LogRequest *bool
}

func resolveConfig(ctx context.Context, m schema.Mutation) (*resolve.Resolved, bool) {
Expand All @@ -38,9 +44,19 @@ func resolveConfig(ctx context.Context, m schema.Mutation) (*resolve.Resolved, b
return emptyResult(m, err), false
}

err = worker.UpdateLruMb(input.LruMB)
if err != nil {
return emptyResult(m, err), false
if input.LruMB > 0 {
if err = worker.UpdateLruMb(input.LruMB); err != nil {
return emptyResult(m, err), false
}
}

// input.LogRequest will be nil, when it is not specified explicitly in config request.
if input.LogRequest != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

workerConfig.SetLogRequest(true)

workerConfig.ShouldLogRequest()

if *input.LogRequest {
atomic.StoreInt32(&x.WorkerConfig.LogRequest, 1)
} else {
atomic.StoreInt32(&x.WorkerConfig.LogRequest, -1)
}
}

return &resolve.Resolved{
Expand Down
5 changes: 5 additions & 0 deletions x/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ type WorkerOptions struct {
LudicrousMode bool
// BadgerKeyFile is the file containing the key used for encryption. Enterprise only feature.
BadgerKeyFile string
// LogRequest indicates whether alpha should log all query/mutation requests coming to it.
// Ideally LogRequest should be a bool value. But we are reading it using atomics across
// queries hence it has been kept as int32. Postive value of LogRequest enables logging of
// requests coming to alphas.
LogRequest int32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this private, and use the getters / setters

}

// WorkerConfig stores the global instance of the worker package's options.
Expand Down