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

[frontend] Use api/utils for loading Impala data #3263

Merged
merged 1 commit into from
Mar 31, 2023

Conversation

sreenaths
Copy link
Collaborator

@sreenaths sreenaths commented Mar 30, 2023

What changes were proposed in this pull request?

Use api/utils for loading Impala data. Remove the customer api implementation.

The change is based on the review comments at #3226 (comment)

How was this patch tested?

  • manually tested
  • UTs added for ApiError change

@sreenaths sreenaths self-assigned this Mar 30, 2023
Copy link
Contributor

@JohanAhlen JohanAhlen left a comment

Choose a reason for hiding this comment

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

Nice! Some comments to look into.

There are some lint warning for related .vue files below, perhaps easy to also fix these?

@@ -187,8 +192,10 @@ export const post = <T, U = unknown>(
const { cancelToken, cancel } = getCancelToken();
let completed = false;

const encodeData = options?.qsEncodeData == undefined || options?.qsEncodeData;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the undefined check and the ||?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

undefined check, to enabled qsEncodeData by default as expected by the existing calls to post

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 that now. So... In your case you want to prevent qsEncodeData? I assumed the opposite, sorry...

We should have a unified approach to whether or not the parameters should be encoded and this is related to the actual lib we use for the API calls and we shouldn't expose that through the options ideally...

Could you adjust the code elsewhere not to encode?

Copy link
Contributor

Choose a reason for hiding this comment

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

The alternative would be to change the type of "data" to URLSearchParams and adjust all the other code that calls this function.

Copy link
Contributor

Choose a reason for hiding this comment

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

... or, if you're indeed using URLSearchParams.. const encode = !(data instanceof URLSearchParams)

Copy link
Contributor

Choose a reason for hiding this comment

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

@sreenaths as far as the Hue UI is concerned it is a Hue API endpoint. The UI shouldn't know about the implementation details (proxy).

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree that the APIs should be consistent. But I think we are from from that today. The reason I was so confused about this default encoding is that it is not used by the file browser. So the file browsing APIs are expecting unencoded post data.. which I think makes sense. So what we probably should do is to change the APIs that do expect form data to be encoded, unless there is a good reason for them to do that in which case we have to support both scenarios.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@sreenaths That is obviously not a task for this PR :-)

Copy link
Contributor

@JohanAhlen JohanAhlen Mar 31, 2023

Choose a reason for hiding this comment

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

I see now that the Hue API endpoint for the QP is using json.loads(request.body) here. Searching through the Hue codebase it seems to be the only API endpoint that expects json directly from request.body and it feels reasonable to support this.

How about renaming options.qsEncodeData to options.sendJsonBody for now? Later we should look into making jsonBody the default and adjust where it breaks.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We can do that, although naming it options.sendJsonBody can be a bit confusing if the data is just a simple (non-json) string that we don't want to url encode. Since this function will continue to encode the post data by default using qs.stringify I think the originally suggested options.qsEncodeData is also good for now:

const {qsEncodeData = true } = options;

But this was enlightening! I agree that when we (or a future AI) later harmonize the HUE APIs the default should be not to encode the post data.

axiosInstance
.post<T & DefaultApiResponse>(url, qs.stringify(data), {
.post<T & DefaultApiResponse>(url, encodeData ? qs.stringify(data) : data, {
Copy link
Contributor

Choose a reason for hiding this comment

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

You could use the option right away here, i.e. options?.qsEncodeData ? qs.stringify...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because of the undefined check, the conditional statement would be lengthy.

Comment on lines +29 to +31
apiError = new ApiError('error message 2\nerror details\nerror details');
expect(apiError.message).toEqual('error message 2');
expect(apiError.details).toEqual('error details\nerror details');
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't these tests should be moved to utils.test.ts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should I rename desktop/core/src/desktop/js/apps/jobBrowser/commons/api-utils/api.ts to desktop/core/src/desktop/js/apps/jobBrowser/commons/api/utils.ts?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm thinking ApiError should be generic and belongs to our global utils.. Or is it very specific to the QP? In which case QueryProcessorApiError could be a better name.

Copy link
Collaborator Author

@sreenaths sreenaths Mar 31, 2023

Choose a reason for hiding this comment

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

Implementation of ApiError is generic, nothing specific to QP, I can move it into api/utils.ts

Copy link
Collaborator

@bjornalm bjornalm left a comment

Choose a reason for hiding this comment

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

NIce work @sreenaths sreenaths!
Sorry for the lengthy discussion in your PR :-)

@@ -187,8 +192,10 @@ export const post = <T, U = unknown>(
const { cancelToken, cancel } = getCancelToken();
let completed = false;

const encodeData = options?.qsEncodeData == undefined || options?.qsEncodeData;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can do that, although naming it options.sendJsonBody can be a bit confusing if the data is just a simple (non-json) string that we don't want to url encode. Since this function will continue to encode the post data by default using qs.stringify I think the originally suggested options.qsEncodeData is also good for now:

const {qsEncodeData = true } = options;

But this was enlightening! I agree that when we (or a future AI) later harmonize the HUE APIs the default should be not to encode the post data.

@sreenaths sreenaths merged commit 922e957 into cloudera:master Mar 31, 2023
@sreenaths
Copy link
Collaborator Author

@JohanAhlen & @bjornalm Thank you so much for the review.
Probably Hue native API improvements can be planned as part of Hue rewrite.

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.

3 participants