Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Detailed query plan errors #1996

Merged
merged 3 commits into from
Aug 30, 2021
Merged

Detailed query plan errors #1996

merged 3 commits into from
Aug 30, 2021

Conversation

colega
Copy link
Contributor

@colega colega commented Aug 27, 2021

Right now when we fail the plan we see an error message which is:

argument bad type. expected int - got etString

If the query is not trivial (with nested function calls, for instancer), it becomes very complicated to understand which arg it's referring too.

This adds context to the errors returned by NewPlan() (specifically, newplanFunc()), telling which function and which arg caused the error. The error message is now:

can't plan function "myfunction", arg 3: argument bad type. expected int - got etString

The original error is wrapped now so all the usages of NewPlan() now check the wrapped error rather than specific type. Additionally, added wrapping/unwrapping logic to the response.WrapError() (we could skip this, but since it says it wraps it, why not wrapping it for real).

Right now when we fail the plan we see an error message which is:

    argument bad type. expected int - got etString

If the query is not trivial (with nested function calls, for instancer),
it becomes very complicated to understand which arg it's referring too.

This adds context to the errors returned by NewPlan() (specifically,
newplanFunc()), telling which function and which arg caused the error.

The original error is wrapped now so all the usages of NewPlan() now
check the wrapped error rather than specific type.

Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
@colega colega marked this pull request as ready for review August 27, 2021 15:03
@colega colega requested review from Dieterbe, fkaleo and shanson7 and removed request for Dieterbe August 27, 2021 15:03
api/graphite.go Show resolved Hide resolved
expr/plan_test.go Show resolved Hide resolved
var (
argExp Arg
nextPos int
)
Copy link
Contributor

Choose a reason for hiding this comment

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

what are all these pos vs nextPos changes about?
this is non-obvious. I would recommend to leave this PR for just the detailed errors, and if you want to do other unrelated cleanups, to do them separately, or at least in separate commits that explain the reasoning of the change. (also, this seems to make the code more complicated and i'm not sure why)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Methods like e.consumeBasicArg(pos, argExp) return the next position to consume as their first param, but they return 0 for error cases. I need to know which was the position they were processing for the error messages so I split the advancing logic into two steps in each call: only update pos if the error was nil.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah i'm sorry. that makes perfect sense now. i'll blame it on being monday morning.

// When graphite issues a request (and sets the request.NoProxy flag),
// it should be for raw data only without any function processing.
ctx.Error(err.HTTPStatusCode(), err.Error())
return
Copy link
Contributor

Choose a reason for hiding this comment

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

why did you take out this clause? if this condition is triggered it would result in an infinite proxy loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

!request.NoProxy is still a condition to proxy the request below. All the logic for unknown function is the same except for the stats call, so I just left the stats call alone.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah i see. you are right! nice code simplification!

Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
@Dieterbe Dieterbe changed the title Detailed plan errors Detailed query plan errors Aug 30, 2021
@Dieterbe Dieterbe merged commit 97d59b8 into master Aug 30, 2021
@Dieterbe Dieterbe deleted the detailed-plan-errors branch August 30, 2021 10:09
colega added a commit that referenced this pull request Aug 30, 2021
See #1996

I missed the CHANGELOG.md there.

Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants