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

Parse the time arg as a float #65

Merged
merged 1 commit into from
Jun 26, 2018
Merged

Conversation

jacksontj
Copy link
Contributor

The time arg in the params can contain decimal points for more
precision. Before this patch that would cause an error on the time
parse, which was ignored, causing the time sent downstream to be 0.
This patch (1) properly parses the time as a float64-- then casts to
int64 and (2) checks for errors in the parsing

@CLAassistant
Copy link

CLAassistant commented Jun 26, 2018

CLA assistant check
All committers have signed the CLA.

@jranson
Copy link
Member

jranson commented Jun 26, 2018

Hey Thomas, thanks for your contribution! Once you complete the CLA as per above, we can let the changes run through the pipeline. @juliusv or @SuperQ would you be able to review this one? Thank you!

handlers.go Outdated
floatEnd, err := strconv.ParseFloat(ts[0], 64)
if err != nil {
level.Error(t.Logger).Log(lfEvent, "error parsing time", "params", params, lfDetail, err.Error())
return []byte{}, &http.Response{}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this PR against an up-to-date master branch? The upstream version already allows returning errors from fetchPromQuery(), which we should do here too. https://github.com/Comcast/trickster/blob/master/handlers.go#L363

handlers.go Outdated
// As such we need to parse the value as a float64. For the sake of the
// rest of the code here we'll cast back to an int64 (effectively
// truncating the precision)
floatEnd, err := strconv.ParseFloat(ts[0], 64)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually it can also be an rfc3339 timestamp. Use this function instead to parse it (and then call Unix() on it to get back to seconds): https://github.com/Comcast/trickster/blob/master/handlers.go#L1066-L1077

@jacksontj
Copy link
Contributor Author

@juliusv rebased on master, apparently I had an old checkout :)

handlers.go Outdated
if t, ok := params[upTime]; ok {
end, err = strconv.ParseInt(t[0], 10, 64)
if ts, ok := params[upTime]; ok {
// time is actually a decimal value to include sub-second granularity.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment needs updating (or removal) now, as it can be rfc3339 as well.

handlers.go Outdated
// truncating the precision)
reqStart, err := parseTime(ts[0])
if err != nil {
return []byte{}, nil, err
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can just be return nil, nil, err

The time arg in the params can contain decimal points for more
precision. Before this patch that would cause an error on the time
parse, which was ignored, causing the time sent downstream to be `0`.
This patch (1) properly parses the time as a float64-- then casts to
int64 and (2) checks for errors in the parsing
@juliusv
Copy link
Collaborator

juliusv commented Jun 26, 2018

👍

@jacksontj
Copy link
Contributor Author

@juliusv @jranson should be all set, just signed the CLA

@juliusv
Copy link
Collaborator

juliusv commented Jun 26, 2018

Good from my side, but I can't merge :)

@jranson
Copy link
Member

jranson commented Jun 26, 2018

Deferring to Julius's approval on this one and merging ;) Thanks to everyone! @juliusv I'm checking with Comcast as to whether I am permitted to make you an approver who can merge as well. When I hear back in the affirmative, I'll hook you up with that access.

@jranson jranson closed this Jun 26, 2018
@jranson jranson reopened this Jun 26, 2018
@jranson jranson merged commit 7043642 into trickstercache:master Jun 26, 2018
@juliusv
Copy link
Collaborator

juliusv commented Jun 26, 2018

@jranson Uh oh, am I on the hook for reviews now? ;) But yeah, I won't say no to merge rights.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants