aksd: MetricsTab & MetricsCard: Separate presentation from logic; Tests, refactors, documentation#273
Conversation
There was a problem hiding this comment.
Pull request overview
Refactors the AKS Desktop plugin’s MetricsTab to follow a presentation/logic separation approach (per #97), while also relocating Prometheus helper utilities into a shared utils/prometheus location for reuse across tabs.
Changes:
- Split MetricsTab into dedicated hooks (
useDeployments,usePods,useNamespaceLabels,usePrometheusMetrics) and presentational components (charts grid, summary bar, selectors, loading/empty states, pod table). - Introduced shared MetricsTab utility types/helpers for memory unit selection and formatting.
- Updated other features (ScalingTab, MetricsCard) to import Prometheus helpers from the new shared utils location.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| plugins/aks-desktop/src/utils/prometheus/queryPrometheus.tsx | Adjusts import path and adds TSDoc for shared Prometheus querying utility. |
| plugins/aks-desktop/src/utils/prometheus/getPrometheusEndpoint.tsx | Adjusts import paths and adds TSDoc for shared endpoint discovery utility. |
| plugins/aks-desktop/src/components/ScalingTab/ScalingTab.tsx | Updates Prometheus helper imports to shared utils location. |
| plugins/aks-desktop/src/components/MetricsTab/utils.ts | Adds shared MetricsTab types and memory formatting/unit conversion helpers. |
| plugins/aks-desktop/src/components/MetricsTab/hooks/usePrometheusMetrics.ts | New hook to fetch/poll Prometheus and transform results for charts/summary. |
| plugins/aks-desktop/src/components/MetricsTab/hooks/usePods.ts | New hook to list pods for the selected deployment and derive status/total pod count. |
| plugins/aks-desktop/src/components/MetricsTab/hooks/useNamespaceLabels.ts | New hook to read subscription/resource-group labels from the namespace metadata. |
| plugins/aks-desktop/src/components/MetricsTab/hooks/useDeployments.ts | New hook to list deployments and manage initial selection/loading/error. |
| plugins/aks-desktop/src/components/MetricsTab/components/PodDetailsTable.tsx | Extracted pod table into a dedicated presentational component. |
| plugins/aks-desktop/src/components/MetricsTab/components/MetricsSummaryBar.tsx | Extracted metrics summary bar into a dedicated component. |
| plugins/aks-desktop/src/components/MetricsTab/components/MetricsLoadingSkeleton.tsx | Extracted loading skeleton UI into a dedicated component. |
| plugins/aks-desktop/src/components/MetricsTab/components/MetricsChartsGrid.tsx | New component composing the set of metric charts into a grid layout. |
| plugins/aks-desktop/src/components/MetricsTab/components/MetricsChart.tsx | New reusable chart wrapper component for Recharts line charts. |
| plugins/aks-desktop/src/components/MetricsTab/components/EmptyStateCard.tsx | Extracted empty-state UI into a reusable component. |
| plugins/aks-desktop/src/components/MetricsTab/components/DeploymentSelector.tsx | Extracted deployment selector dropdown into its own component. |
| plugins/aks-desktop/src/components/MetricsTab/MetricsTab.tsx | Simplifies MetricsTab to composition of hooks + presentational components. |
| plugins/aks-desktop/src/components/Metrics/MetricsCard.tsx | Updates Prometheus helper imports to shared utils location. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
plugins/aks-desktop/src/components/Metrics/hooks/usePrometheusMetrics.ts
Show resolved
Hide resolved
plugins/aks-desktop/src/components/Metrics/hooks/usePrometheusMetrics.ts
Show resolved
Hide resolved
plugins/aks-desktop/src/components/MetricsTab/hooks/useDeployments.ts
Outdated
Show resolved
Hide resolved
plugins/aks-desktop/src/components/Metrics/hooks/usePrometheusMetrics.ts
Show resolved
Hide resolved
plugins/aks-desktop/src/components/MetricsTab/components/DeploymentSelector.tsx
Outdated
Show resolved
Hide resolved
f8510cf to
2b00035
Compare
skoeva
left a comment
There was a problem hiding this comment.
could you write unit tests for this? I think TDD is the move and would be very helpful to for these component refactors moving forward
Yep, currently working on these. |
2b00035 to
022310f
Compare
022310f to
dcb5f40
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 25 out of 25 changed files in this pull request and generated 5 comments.
Comments suppressed due to low confidence (1)
plugins/aks-desktop/src/components/MetricsTab/MetricsTab.tsx:96
- The error state mixes
error(deployments) andmetricsError(Prometheus) but the UI only renders{error}. WhenmetricsErroris set anderroris null, the alert body will be blank. Also the AlertTitle string is hard-coded and bypasses i18n. Prefer renderingt('Metrics Unavailable')and showerror ?? metricsError(and consider surfacingmetricsErroreven when deployments exist so Prometheus failures are visible).
if ((error || metricsError) && deployments.length === 0) {
return (
<Box p={3}>
<Alert severity="warning">
<AlertTitle>Metrics Unavailable</AlertTitle>
<Typography variant="body2">{error}</Typography>
</Alert>
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
plugins/aks-desktop/src/components/Metrics/hooks/usePrometheusMetrics.ts
Show resolved
Hide resolved
plugins/aks-desktop/src/components/MetricsTab/hooks/usePrometheusMetrics.ts
Outdated
Show resolved
Hide resolved
|
@skoeva can you please check the changes in here relating to ScalingTab? I don't know if they conflict with yours? |
There was a problem hiding this comment.
I read through all this and it's looking good IMHO.
- Can you please describe how to manually test this in the PR description?
- I think the commit message subject could have the context part added (maybe just MetricsTab) and a longer description of the changes.
- Can you please look at the open review comments?
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 25 out of 25 changed files in this pull request and generated 5 comments.
Comments suppressed due to low confidence (1)
plugins/aks-desktop/src/components/MetricsTab/MetricsTab.tsx:96
- The error banner is gated on
deployments.length === 0, and within the banner it renders{error}even when the failure came frommetricsError. This can result in a warning with an empty message and also hides Prometheus fetch errors once deployments are loaded. Consider (1) renderingerror ?? metricsErrorand (2) surfacingmetricsErroreven when deployments exist (e.g., inline alert above charts). AlsoMetrics Unavailableis currently hard-coded instead of translated viat(...).
if ((error || metricsError) && deployments.length === 0) {
return (
<Box p={3}>
<Alert severity="warning">
<AlertTitle>Metrics Unavailable</AlertTitle>
<Typography variant="body2">{error}</Typography>
</Alert>
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
plugins/aks-desktop/src/components/Metrics/hooks/usePrometheusMetrics.ts
Show resolved
Hide resolved
plugins/aks-desktop/src/components/Metrics/components/MetricsChartsGrid.tsx
Show resolved
Hide resolved
plugins/aks-desktop/src/components/Metrics/components/MetricsChartsGrid.tsx
Show resolved
Hide resolved
dcb5f40 to
fa0adba
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 24 out of 24 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
plugins/aks-desktop/src/components/MetricsTab/hooks/usePrometheusMetrics.ts
Outdated
Show resolved
Hide resolved
plugins/aks-desktop/src/components/MetricsTab/hooks/usePrometheusMetrics.ts
Outdated
Show resolved
Hide resolved
plugins/aks-desktop/src/components/MetricsTab/hooks/usePrometheusMetrics.ts
Outdated
Show resolved
Hide resolved
skoeva
left a comment
There was a problem hiding this comment.
I just took a look at MetricsCard - since both components query the same prometheus metrics with the same refresh logic, it might be worth consolidating them in this PR (structured similarly to ScalingCard and ScalingTab)
illume
left a comment
There was a problem hiding this comment.
There are open review comments and now git conflicts.
Can you please have a look, and address the copilot comments when you push?
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 24 out of 24 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
plugins/aks-desktop/src/components/MetricsTab/MetricsTab.tsx:96
- The error UI can render an empty message: the condition includes
metricsError, but the Alert body prints onlyerror. If Prometheus fetch fails (settingmetricsError) whileerroris null, users see a blank warning. Consider renderingmetricsError ?? error(or both), and also localizing the AlertTitle string for consistency with the rest of the tab.
<Alert severity="warning">
<AlertTitle>Metrics Unavailable</AlertTitle>
<Typography variant="body2">{error}</Typography>
</Alert>
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
fa0adba to
4402288
Compare
4402288 to
49335d6
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 27 out of 27 changed files in this pull request and generated 8 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
plugins/aks-desktop/src/components/Metrics/hooks/usePrometheusMetrics.ts
Outdated
Show resolved
Hide resolved
plugins/aks-desktop/src/components/Metrics/hooks/usePrometheusMetrics.ts
Show resolved
Hide resolved
plugins/aks-desktop/src/components/Metrics/components/MetricsChart.tsx
Outdated
Show resolved
Hide resolved
plugins/aks-desktop/src/components/Metrics/hooks/useCardMetrics.ts
Outdated
Show resolved
Hide resolved
|
I think it's probably enough to run "npm run i18n" to fix the CI error. There's a bunch of open review comments. |
49335d6 to
d0fe5c4
Compare
…gic into hooks & components; Tests, refactors & documentation.
d0fe5c4 to
c5a194f
Compare
Description
This PR splits the MetricsTab and MetricsCard into modular components & extracts functionality into hooks following the presentation/logic separation pattern outlined in #97 & #120 .
Changes Made
useNamespaceLabels,useDeployments,usePods,usePrometheusMetrics,useCardMetricshooksDeploymentSelector,EmptyStateCard,MetricsSummaryBar,MetricsChart,MetricsChartsGrid,MetricsLoadingSkeleton,PodDetailsTable,MetricStatCardcomponentsChartDataPoint,ResponseTimeDataPoint,MetricSummary,MemoryUnit& functionspickMemoryUnit,convertBytesToUnit,formatMemoryBriefutils/prometheus/locationRebase Changes
In order to preserve the translation preparation that was done with
useTranslation, I've moved theuseTranslationinvokations to match the same strings but in their new file locations across the components/hooks.All Metrics related content is now in the shared Metrics folder.
Translations, new constants & UI changes have all been included in rebase.
Type of changes
Related Issues
Closes #97, #120
Testing
For automated testing, you can either run
npm run plugin:testfor the full suite including these new ones. If you want to test these suites alone, you can runcd plugins/aks-desktop, and thennpx vitest run src/components/Metrics.To manually test the components / data are rendering properly,
Test Cases
Describe the test cases that were run:
Documentation Updates