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

cluster status issue fix #291

Merged
merged 4 commits into from
Sep 10, 2024
Merged

cluster status issue fix #291

merged 4 commits into from
Sep 10, 2024

Conversation

tulsiojha
Copy link
Contributor

@tulsiojha tulsiojha commented Sep 10, 2024

Summary by Sourcery

Fix the cluster status issue by implementing a new GraphQL query to list cluster statuses and updating the cluster status retrieval logic. Enhance the cluster status provider to refresh data when the network connection is restored.

New Features:

  • Introduce a new GraphQL query to list cluster statuses, including the last online time and metadata name.

Bug Fixes:

  • Fix the cluster status issue by updating the cluster status retrieval logic to use the new listClusterStatus query.

Enhancements:

  • Add an event listener to refresh cluster status when the network connection is restored.

Copy link

sourcery-ai bot commented Sep 10, 2024

Reviewer's Guide by Sourcery

This pull request addresses a cluster status issue by implementing a new query for listing cluster statuses and updating the related components. The changes improve the efficiency of fetching cluster status information and add an online event listener to update the status when the network connection is restored.

File-Level Changes

Change Details Files
Implemented a new GraphQL query for listing cluster statuses
  • Added a new GraphQL query 'consoleListClusterStatus'
  • Created a new type 'IClustersStatus' for the query result
  • Added a new executor function 'listClusterStatus' to handle the query
src/apps/console/server/gql/queries/cluster-queries.ts
gql-queries-generator/doc/queries.graphql
src/generated/gql/server.ts
Updated the cluster status hook to use the new query
  • Modified the 'listCluster' function to use the new 'listClusterStatus' query
  • Updated the IClusterMap type to use IClustersStatus instead of IByocClusters
  • Removed unused import of IByocClusters
src/apps/console/hooks/use-cluster-status-v2.tsx
Added an online event listener to update cluster status
  • Implemented an 'onlineEvent' function to trigger a status update when the network connection is restored
  • Added an event listener for the 'online' event
  • Included cleanup for the event listener in the useEffect hook
src/apps/console/hooks/use-cluster-status-v2.tsx
Removed console.log statement and unused effect
  • Deleted a console.log statement
  • Removed an unused useEffect hook
src/apps/console/hooks/use-cluster-status-v2.tsx
Fixed code formatting and added missing commas
  • Added missing commas at the end of object properties
  • Removed extra newlines
src/apps/console/server/gql/queries/cluster-queries.ts

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @tulsiojha - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider making the pagination limit in listClusterStatus configurable or explain the reasoning behind the fixed value of 5. This could impact scalability if the number of clusters grows beyond this limit.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

(acc, c) => {
acc[c.metadata.name] = c;
return acc;
const cl = await api.listClusterStatus({
Copy link

Choose a reason for hiding this comment

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

issue (complexity): Consider refactoring the code to improve readability and reduce complexity.

While the changes introduce necessary functionality, we can improve readability and reduce complexity:

  1. Refactor listCluster using async/await and reduce nesting:
const listCluster = useCallback(async () => {
  try {
    const { data } = await api.listClusterStatus({
      pagination: { first: 5 },
    });
    const parsed = parseNodes(data).reduce((acc, c) => {
      acc[c.metadata.name] = c;
      return acc;
    }, {} as IClusterMap);
    setClusters(parsed);
    return parsed;
  } catch (err) {
    console.error(err);
    return false;
  }
}, [api]);
  1. Split the useEffect hook for better separation of concerns:
useEffect(() => {
  const intervalId = setInterval(listCluster, 30 * 1000);
  return () => clearInterval(intervalId);
}, [listCluster]);

useEffect(() => {
  const onlineEvent = () => {
    setTimeout(listCluster, 3000);
  };
  window.addEventListener('online', onlineEvent);
  return () => window.removeEventListener('online', onlineEvent);
}, [listCluster]);
  1. Consider removing the pagination limit of 5 in the API call, or add a comment explaining why it's necessary:
const { data } = await api.listClusterStatus({
  // pagination: { first: 5 }, // Removed unless there's a specific reason for this limit
});

These changes maintain the added functionality while improving code readability and reducing complexity.

@tulsiojha tulsiojha merged commit 12de338 into release-v1.0.5 Sep 10, 2024
5 checks passed
@tulsiojha tulsiojha deleted the cluster/status-update branch September 10, 2024 11:15
abdheshnayak pushed a commit that referenced this pull request Oct 28, 2024
tulsiojha added a commit that referenced this pull request Nov 1, 2024
abdheshnayak pushed a commit that referenced this pull request Nov 5, 2024
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.

1 participant