-
Notifications
You must be signed in to change notification settings - Fork 456
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
[query]Add debug param to namespace get API #1698
Conversation
@@ -71,6 +74,19 @@ func (h *GetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |||
Registry: &nsRegistry, | |||
} | |||
|
|||
urlParams := r.URL.Query() | |||
if strings.ToLower(urlParams.Get("debug")) == "true" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's do
if debug, err := strconv.ParseBool(r.URL.Query().Get(_debugParam)); err == nil && debug {
// ...
xhttp.WriteJSONResponse(w, nanosToDurationMap, logger)
return
}
(const
ing _debugParam
as well)
|
||
func nanosToDuration(resp proto.Message) (map[string]interface{}, error) { | ||
marshaler := jsonpb.Marshaler{EmitDefaults: true} | ||
nsString, err := marshaler.MarshalToString(resp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just use an io.ReadWriter
here to skip the intermediate string
?
func NanosToDurationBytes(r io.Reader) (map[string]interface{}, error) { | ||
var dict map[string]interface{} | ||
d := json.NewDecoder(r) | ||
d.UseNumber() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're already handling the float64
case below, wouldn't it be simpler just to stick with that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I think we actually want something like this {"fieldNanos":100.5}
to fail (e.g. nanos shouldn't be floats). I'm fine with removing the case float64
below though as it will never actually be called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@benraskin92 The namespace API accepts input in the format of durations right? Can we just drop the nanos entirely and make the debug=true
behavior the default behavior?
I can't think of a single situation where I'd ever want to interact with raw nanos here
Codecov Report
@@ Coverage Diff @@
## master #1698 +/- ##
=========================================
- Coverage 71.9% 54.6% -17.3%
=========================================
Files 970 859 -111
Lines 81324 73103 -8221
=========================================
- Hits 58476 39964 -18512
- Misses 19016 29948 +10932
+ Partials 3832 3191 -641
Continue to review full report at Codecov.
|
If we do that, I'd rather do that in another PR. I'm all for making it the default though. |
I don't think we can do that without adding a new endpoint or some careful coordinator with operator compatibility. The operator parses the responses from the coordinator as jsonpb Proto messages, changing the proto or the response marshaling would likely break the operator. If we really want to make that change we have to do it in a manner such that users of older operator with newer M3DB and vice-versa don't have breakages. |
+1 to Matt’s point. We should stick with current format for b/w compat. More generally, when we add a separate debug endpoint (should do this for a variety of reasons), we can ensure it calls the format that’s easier to grok. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@schallert @prateek Fair enough. I assumed this only affected the JSON output and that the operator was using GRPC or something but that makes sense |
What this PR does / why we need it:
This PR allows you to pass in an optional
debug
parameter to the/api1/v1/namespace
endpoint in the coordinator, which returns durations instead of nanoseconds for the duration fields. This should help with readability and debugging. Below is a sample output using start_m3.Special notes for your reviewer:
Does this PR introduce a user-facing and/or backwards incompatible change?:
Does this PR require updating code package or user-facing documentation?: