-
Notifications
You must be signed in to change notification settings - Fork 2
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
refactor(apiserver): don't need to fail the request when querying podmetrics failed #226
Conversation
…metrics failed Signed-off-by: zyy17 <[email protected]>
WalkthroughThe changes in the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (2)
pkg/apiserver/apiserver.go (2)
331-332
: LGTM! Consider enhancing the error messageThe error handling improvement aligns well with the PR objective, making the API more resilient by preventing pod metrics retrieval failures from blocking the entire response.
Consider making the error message more specific about the impact:
- klog.Errorf("failed to get pod metrics for pod %s/%s: %v", namespace, pod.Name, err) + klog.Errorf("failed to get pod metrics for pod %s/%s (continuing without metrics): %v", namespace, pod.Name, err)
399-406
: LGTM! Consider simplifying the error handlingThe special handling for NotFound errors is appropriate and well-documented. However, the code structure could be simplified.
Consider this more concise version:
func (s *Server) getPodMetrics(ctx context.Context, namespace, name string) (*podmetricsv1beta1.PodMetrics, error) { var podMetrics podmetricsv1beta1.PodMetrics err := s.Get(ctx, client.ObjectKey{Namespace: namespace, Name: name}, &podMetrics) - - // It's possible when the pod just started, the metrics-server hasn't collected the metrics yet. - if apierrors.IsNotFound(err) { - return nil, nil - } - - if err != nil { + // Return nil when metrics are not found (possible when pod just started) + if err != nil && !errors.IsNotFound(err) { return nil, err } - return &podMetrics, nil + if err == nil { + return &podMetrics, nil + } + return nil, nil }
Summary by CodeRabbit
New Features
Bug Fixes