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

Changes to integrate rate-limit headers for Commands left component UI #67

Merged
merged 20 commits into from
Oct 18, 2024

Conversation

aasifkhan7
Copy link
Contributor

No description provided.

@aasifkhan7 aasifkhan7 force-pushed the integrate_ratelimit_commandsleft branch from bc60e1a to 268adb2 Compare October 11, 2024 17:06
@aasifkhan7
Copy link
Contributor Author

Hi @lucifercr07 , could you please review the PR?
Summary of changes:

  1. Integrated the x-ratelimit-remaining header to update the "Commands Left" value.
  2. Test changes are pending.
  3. Still investigating where to fetch the "Cleanup Time Left" value from Mono, so that's in progress.

Copy link
Contributor

@lucifercr07 lucifercr07 left a comment

Choose a reason for hiding this comment

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

Please add tests.

response.headers.forEach((value, key) => {
headers[key] = value;
});
headers['x-ratelimit-remaining'] = 101;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why're we hardcoding this number?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was just a temporary change, I'll remove it. It looks like chrome blocks ceratin response headers to be read by the react app, so I had to hardcode this to test it out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've removed this change and done this corresponding change in playground-mono: https://github.com/DiceDB/playground-mono/pull/41/files

Copy link
Contributor Author

Choose a reason for hiding this comment

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

setOutput((prevOutput) => [...prevOutput, newOutput, result?.body?.error]);
}
const commandsLeft = result?.headers?.['x-ratelimit-remaining'];
const cleanupTimeLeft = 10;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as 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.

yes, I have to fix this. waiting on this issue DiceDB/playground-mono#32

@aasifkhan7
Copy link
Contributor Author

added test cases as well @lucifercr07

@lucifercr07 lucifercr07 changed the title first draft of changes to integrate rate-limit Changes to integrate rate-limit Oct 16, 2024
@lucifercr07
Copy link
Contributor

@aasifkhan7 please resolve build issues.

@aasifkhan7
Copy link
Contributor Author

resolved formatting issues @lucifercr07

Copy link
Contributor

@lucifercr07 lucifercr07 left a comment

Choose a reason for hiding this comment

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

@aasifkhan7 shall we just keep changes for commandsLeft as part of this PR as discussed earlier? Since the PR for cleanup time left is still pending.

@aasifkhan7
Copy link
Contributor Author

Okay, let me do that @lucifercr07

@aasifkhan7
Copy link
Contributor Author

Done @lucifercr07

Copy link
Contributor

@KaviiSuri KaviiSuri left a comment

Choose a reason for hiding this comment

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

In general looks fine, but i'm a bit worried about introducing a lot of anys in the code, please avoid it and use zod to validate the payload immedately after we get the response.

I'm also not sure why we have both CLI and Shell, we should just have Shell. CLI is not used anymore and is the same thing.


// Parse the result as JSON
const result = await response.json();
return result;
const body = await response.json();
Copy link
Contributor

Choose a reason for hiding this comment

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

can we have a type defined here? preferrably using zod schema. Idea is to ensure and catch early if there is an issue with the response.

right now, we just have a lot of any which should be avoided

result: any,
newOutput: string,
setOutput: any,
onCommandExecuted: any,
Copy link
Contributor

Choose a reason for hiding this comment

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

can we avoid the any here? very easy to make mistakes on this. Let me know if you need any help with the actual types

Comment on lines 7 to 12
export const handleResult = (
result: any,
newOutput: string,
setOutput: any,
onCommandExecuted: any,
) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

when we have more than 3 arguments, let's convert it into an object, so that we can have named arguments. so instead of hanleResult(result, newOutput, setOutput, onComandExecuted) => hanleResult({ result, newOutput, setOutput, onComandExecuted })

@aasifkhan7
Copy link
Contributor Author

Done all the changes except removing the CLI @KaviiSuri . Please let me know if that also needs to be shipped with this PR as well.

@aasifkhan7 aasifkhan7 requested a review from KaviiSuri October 16, 2024 19:55
@aasifkhan7
Copy link
Contributor Author

resolved build failures @KaviiSuri @lucifercr07 , please review now

@lucifercr07
Copy link
Contributor

@aasifkhan7 can you please fix the failing tests.

@aasifkhan7
Copy link
Contributor Author

@lucifercr07 fixed the test.

Copy link
Contributor

@lucifercr07 lucifercr07 left a comment

Choose a reason for hiding this comment

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

LGTM

@KaviiSuri
Copy link
Contributor

@aasifkhan7 could you also remove the CLI? looks good otherwise, will merge post that

@aasifkhan7
Copy link
Contributor Author

removed cli @KaviiSuri

@lucifercr07 lucifercr07 changed the title Changes to integrate rate-limit Changes to integrate rate-limit headers for Commands left component UI Oct 17, 2024
@lucifercr07 lucifercr07 merged commit 02369c1 into DiceDB:master Oct 18, 2024
1 check passed
KaviiSuri added a commit to KaviiSuri/playground-web that referenced this pull request Nov 2, 2024
…setup-ui-packages-and-tailwind-for-console

* 'master' of github.com:DiceDB/playground-web:
  Fix docker compose file (DiceDB#77)
  integrate cleanup time from playground-mono (DiceDB#76)
  Changes to integrate rate-limit headers for `Commands left` component UI (DiceDB#67)
  Adding support for JSON.SET command (DiceDB#74)
  Unit tests for playground-web repository  (DiceDB#71)
  fix: docker compose contexts to ensure docker compose runs
KaviiSuri added a commit to KaviiSuri/playground-web that referenced this pull request Nov 2, 2024
…setup-ui-packages-and-tailwind-for-console

* 'master' of github.com:DiceDB/playground-web:
  Fix docker compose file (DiceDB#77)
  integrate cleanup time from playground-mono (DiceDB#76)
  Changes to integrate rate-limit headers for `Commands left` component UI (DiceDB#67)
  Adding support for JSON.SET command (DiceDB#74)
  Unit tests for playground-web repository  (DiceDB#71)
  fix: docker compose contexts to ensure docker compose runs
@aasifkhan7 aasifkhan7 deleted the integrate_ratelimit_commandsleft branch November 26, 2024 09:53
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