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

Updated the response for reload API to be pretty printed #11608

Merged
merged 10 commits into from Oct 19, 2023

Conversation

ArnavBalyan
Copy link
Contributor

@ArnavBalyan ArnavBalyan commented Sep 17, 2023

  • Reload API returns an encoded JSON which is hard to understand.
  • Updated the response to remove the additional string.
  • Added a Pretty printed string which will print the json in an understandable format.
    performance fix for Reload API has a difficult response #11588

@ArnavBalyan ArnavBalyan changed the title Fix for #11588. Updated the response for reload API to be pretty printed Updated the response for reload API to be pretty printed Sep 17, 2023
Copy link
Contributor

@Jackie-Jiang Jackie-Jiang left a comment

Choose a reason for hiding this comment

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

cc @jadami10 to also provide some feedback

@@ -782,7 +782,7 @@ public SuccessResponse reloadAllSegments(
LOGGER.error("Failed to add reload all segments job meta into zookeeper for table: {}", tableNameWithType, e);
}
}
return new SuccessResponse("Segment reload details: " + JsonUtils.objectToString(perTableMsgData));
return new SuccessResponse(JsonUtils.objectToPrettyString(perTableMsgData));
Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't need to be a json, maybe simply

Suggested change
return new SuccessResponse(JsonUtils.objectToPrettyString(perTableMsgData));
return new SuccessResponse("Segment reload details: " + perTableMsgData);

Copy link
Contributor

Choose a reason for hiding this comment

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

it doesn't need to be, but what value is Segment reload details: to the result of an endpoint that is clearly already the reload details. The impetus for this change was to make it easier to parse the result in java/scala so you don't have to go from request -> strip the prefix -> decode the json string -> decode the json. You should be able to go from request -> json in 1 hop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now, I've just kept the json string in the success response which makes it easier to parse/understand. Please let me know what you think Thanks!

@codecov-commenter
Copy link

codecov-commenter commented Sep 18, 2023

Codecov Report

Merging #11608 (4057e25) into master (0cf091a) will decrease coverage by 0.03%.
The diff coverage is 100.00%.

@@             Coverage Diff              @@
##             master   #11608      +/-   ##
============================================
- Coverage     66.36%   66.34%   -0.03%     
  Complexity      207      207              
============================================
  Files          2350     2350              
  Lines        127248   127248              
  Branches      19593    19593              
============================================
- Hits          84449    84420      -29     
- Misses        36912    36935      +23     
- Partials       5887     5893       +6     
Flag Coverage Δ
custom-integration1 <0.01% <0.00%> (ø)
integration <0.01% <0.00%> (ø)
integration1 <0.01% <0.00%> (ø)
integration2 0.00% <0.00%> (ø)
java-11 49.98% <0.00%> (-16.33%) ⬇️
java-17 66.20% <100.00%> (+<0.01%) ⬆️
java-20 66.20% <100.00%> (-0.03%) ⬇️
temurin 66.34% <100.00%> (-0.03%) ⬇️
unittests 66.34% <100.00%> (-0.03%) ⬇️
unittests1 67.13% <ø> (+<0.01%) ⬆️
unittests2 17.80% <100.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
...ler/api/resources/PinotSegmentRestletResource.java 41.13% <100.00%> (ø)

... and 19 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@jadami10 jadami10 left a comment

Choose a reason for hiding this comment

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

you also need to update

const statusResponseObj = JSON.parse(result.status.replace("Segment reload details: ", ""))
since that's parsing this result.

You should run this through the quickstart to make sure it's still working

@@ -782,7 +782,7 @@ public SuccessResponse reloadAllSegments(
LOGGER.error("Failed to add reload all segments job meta into zookeeper for table: {}", tableNameWithType, e);
}
}
return new SuccessResponse("Segment reload details: " + JsonUtils.objectToString(perTableMsgData));
return new SuccessResponse(JsonUtils.objectToPrettyString(perTableMsgData));
Copy link
Contributor

Choose a reason for hiding this comment

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

it doesn't need to be, but what value is Segment reload details: to the result of an endpoint that is clearly already the reload details. The impetus for this change was to make it easier to parse the result in java/scala so you don't have to go from request -> strip the prefix -> decode the json string -> decode the json. You should be able to go from request -> json in 1 hop.

@ArnavBalyan
Copy link
Contributor Author

you also need to update

const statusResponseObj = JSON.parse(result.status.replace("Segment reload details: ", ""))

since that's parsing this result.
You should run this through the quickstart to make sure it's still working

Got it thanks let me do this

@jadami10
Copy link
Contributor

looks like there's still some tests failing

String tableNameWithType = TableNameBuilder.forType(tableType).tableNameWithType(tableName);
JsonNode tableLevelDetails =
JsonUtils.stringToJsonNode(StringEscapeUtils.unescapeJava(response.split(": ")[1])).get(tableNameWithType);
JsonUtils.stringToJsonNode(response.substring(
Copy link
Contributor

Choose a reason for hiding this comment

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

This is very hard to understand. I think we might need to parse twice? Something like:

JsonNode responseJson = JsonUtils.stringToJsonNode(response);
JsonNode tableLevelDetails = JsonUtils.stringToJsonNode(responseJson.get("status").asText()).get(tableNameWithType);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @Jackie-Jiang the the value corresponding to the "status" is another json string. So parsing it into json fails because the value is wrapped in "". I just did the substring logic to get the wrapped string. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

The json string is encoded as the value field of the top level json, so parsing the json twice should be able to extract it. See the code example above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it thanks, I did this, it seems the 6 tests fail. The result is wrapped in "", so the JsonUtils.stringToJsonNode fails parsing it, to fix the test we would have to extract the value and then parse it. What do you think. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

The problem is the unnecessary unescape. Applied a commit and let's see if it fixes the problem

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh got it thank you so much!

@Jackie-Jiang Jackie-Jiang merged commit 0d08316 into apache:master Oct 19, 2023
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants