Skip to content

aksd: MetricsTab & MetricsCard: Separate presentation from logic; Tests, refactors, documentation#273

Merged
illume merged 1 commit intoAzure:mainfrom
tejhan:metricsTabComponentHookExtractionAndDocumentation3
Apr 8, 2026
Merged

aksd: MetricsTab & MetricsCard: Separate presentation from logic; Tests, refactors, documentation#273
illume merged 1 commit intoAzure:mainfrom
tejhan:metricsTabComponentHookExtractionAndDocumentation3

Conversation

@tejhan
Copy link
Copy Markdown
Collaborator

@tejhan tejhan commented Feb 20, 2026

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

  • Created useNamespaceLabels, useDeployments, usePods, usePrometheusMetrics, useCardMetrics hooks
  • Created DeploymentSelector, EmptyStateCard, MetricsSummaryBar, MetricsChart, MetricsChartsGrid, MetricsLoadingSkeleton, PodDetailsTable, MetricStatCard components
  • Created types ChartDataPoint, ResponseTimeDataPoint, MetricSummary, MemoryUnit & functions pickMemoryUnit, convertBytesToUnit, formatMemoryBrief
  • Prometheus utils moved to shared utils/prometheus/ location
  • Implemented more explicit cleanup functions
  • Fixed rendering issues during loading state
  • Full Tsdoc documentation for relevant elements
  • Implemented caching for all metrics
  • UI fixes & alignment

Rebase Changes

In order to preserve the translation preparation that was done with useTranslation, I've moved the useTranslation invokations 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

  • [ x] Bug fix (non-breaking change which fixes an issue)
  • [x ] Code refactoring

Related Issues

Closes #97, #120

Testing

For automated testing, you can either run npm run plugin:test for the full suite including these new ones. If you want to test these suites alone, you can run cd plugins/aks-desktop, and then npx vitest run src/components/Metrics.

To manually test the components / data are rendering properly,

  1. Create/use an AKS cluster with Prometheus monitoring enabled.
  2. Create an Aks managed project
  3. Deploy an application to that project
  4. Observe metrics tab populate.

Test Cases

Describe the test cases that were run:

  1. Full test suite for all hooks & utility functions.
  2. Manual testing via creating & utilizing existing projects & observing if Metrics Tab properly loads components initially, and updates state correctly after time.

Documentation Updates

  • [x ] Code comments updated

Copilot AI review requested due to automatic review settings February 20, 2026 04:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment thread plugins/aks-desktop/src/components/Metrics/hooks/useDeployments.ts
Comment thread plugins/aks-desktop/src/components/Metrics/hooks/useDeployments.ts
Comment thread plugins/aks-desktop/src/components/MetricsTab/hooks/useDeployments.ts Outdated
Comment thread plugins/aks-desktop/src/components/MetricsTab/hooks/usePods.ts Outdated
Comment thread plugins/aks-desktop/src/components/MetricsTab/components/DeploymentSelector.tsx Outdated
Comment thread plugins/aks-desktop/src/components/MetricsTab/hooks/usePods.ts Outdated
@tejhan tejhan force-pushed the metricsTabComponentHookExtractionAndDocumentation3 branch from f8510cf to 2b00035 Compare February 20, 2026 05:43
@tejhan tejhan self-assigned this Feb 20, 2026
@tejhan tejhan added the p1 priority label Feb 20, 2026
Comment thread plugins/aks-desktop/src/components/Metrics/hooks/useDeployments.ts
skoeva
skoeva previously requested changes Feb 23, 2026
Copy link
Copy Markdown
Collaborator

@skoeva skoeva left a comment

Choose a reason for hiding this comment

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

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

@tejhan
Copy link
Copy Markdown
Collaborator Author

tejhan commented Feb 24, 2026

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.

@illume illume marked this pull request as draft February 25, 2026 10:37
@illume illume added the quality label Feb 27, 2026
@tejhan tejhan force-pushed the metricsTabComponentHookExtractionAndDocumentation3 branch from 2b00035 to 022310f Compare February 28, 2026 15:44
@tejhan tejhan changed the title aksd: Separate presentation from logic & documentation for MetricsTab aksd:Separate presentation from logic; Create documentation & tests for MetricsTab Feb 28, 2026
@tejhan tejhan changed the title aksd:Separate presentation from logic; Create documentation & tests for MetricsTab aksd: Separate presentation from logic; Create documentation & tests for MetricsTab Feb 28, 2026
@tejhan tejhan force-pushed the metricsTabComponentHookExtractionAndDocumentation3 branch from 022310f to dcb5f40 Compare February 28, 2026 15:53
@tejhan tejhan marked this pull request as ready for review February 28, 2026 16:08
Copilot AI review requested due to automatic review settings February 28, 2026 16:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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) and metricsError (Prometheus) but the UI only renders {error}. When metricsError is set and error is null, the alert body will be blank. Also the AlertTitle string is hard-coded and bypasses i18n. Prefer rendering t('Metrics Unavailable') and show error ?? metricsError (and consider surfacing metricsError even 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.

Comment thread plugins/aks-desktop/src/components/Metrics/hooks/useDeployments.ts
Comment thread plugins/aks-desktop/src/components/Metrics/hooks/usePods.ts Outdated
Comment thread plugins/aks-desktop/src/components/MetricsTab/hooks/usePrometheusMetrics.ts Outdated
@illume
Copy link
Copy Markdown
Collaborator

illume commented Mar 2, 2026

@skoeva can you please check the changes in here relating to ScalingTab? I don't know if they conflict with yours?

Copy link
Copy Markdown
Collaborator

@illume illume left a comment

Choose a reason for hiding this comment

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

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?

@illume illume requested a review from Copilot March 2, 2026 16:23
@illume illume marked this pull request as draft March 2, 2026 16:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 from metricsError. This can result in a warning with an empty message and also hides Prometheus fetch errors once deployments are loaded. Consider (1) rendering error ?? metricsError and (2) surfacing metricsError even when deployments exist (e.g., inline alert above charts). Also Metrics Unavailable is currently hard-coded instead of translated via t(...).
  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.

Comment thread plugins/aks-desktop/src/components/Metrics/hooks/useDeployments.ts
Comment thread plugins/aks-desktop/src/components/Metrics/hooks/useDeployments.ts
@skoeva
Copy link
Copy Markdown
Collaborator

skoeva commented Mar 2, 2026

@skoeva can you please check the changes in here relating to ScalingTab? I don't know if they conflict with yours?

@illume they only involve import statements from the MetricsTab code, there shouldn't be any conflict

@tejhan tejhan force-pushed the metricsTabComponentHookExtractionAndDocumentation3 branch from dcb5f40 to fa0adba Compare March 7, 2026 01:53
@tejhan tejhan marked this pull request as ready for review March 7, 2026 01:55
Copilot AI review requested due to automatic review settings March 7, 2026 01:55
Copilot AI review requested due to automatic review settings March 17, 2026 22:37
@tejhan tejhan force-pushed the metricsTabComponentHookExtractionAndDocumentation3 branch from 1877344 to e02935f Compare March 17, 2026 22:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 30 out of 30 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread plugins/aks-desktop/src/components/Metrics/hooks/usePrometheusMetrics.ts Outdated
Comment thread plugins/aks-desktop/src/components/Metrics/hooks/useCardMetrics.ts Outdated
Comment thread plugins/aks-desktop/src/components/Metrics/hooks/useCardMetrics.ts
@tejhan tejhan force-pushed the metricsTabComponentHookExtractionAndDocumentation3 branch from e02935f to 2898454 Compare March 17, 2026 22:55
Copilot AI review requested due to automatic review settings March 18, 2026 13:57
@tejhan tejhan force-pushed the metricsTabComponentHookExtractionAndDocumentation3 branch from 2898454 to 3ee4636 Compare March 18, 2026 13:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 30 out of 30 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tejhan tejhan force-pushed the metricsTabComponentHookExtractionAndDocumentation3 branch from 3ee4636 to 10e9951 Compare March 30, 2026 20:38
Copilot AI review requested due to automatic review settings March 30, 2026 20:47
@tejhan tejhan force-pushed the metricsTabComponentHookExtractionAndDocumentation3 branch from 10e9951 to 386f880 Compare March 30, 2026 20:47
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 30 out of 47 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

plugins/aks-desktop/src/utils/prometheus/getPrometheusEndpoint.tsx:14

  • The TSDoc describes only a successful return value, but this function throws in multiple failure cases (e.g., when Azure Monitor Metrics isn't enabled, no matching rule group is found, JSON parse fails, etc.). Please document the thrown error behavior (e.g., add an @throws tag and/or clarify in @returns that errors are thrown).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread plugins/aks-desktop/src/components/Metrics/hooks/useCardMetrics.ts
Comment thread plugins/aks-desktop/src/components/Metrics/hooks/useCardMetrics.ts
@tejhan tejhan force-pushed the metricsTabComponentHookExtractionAndDocumentation3 branch from 386f880 to 1030751 Compare March 30, 2026 21:41
Copilot AI review requested due to automatic review settings March 30, 2026 22:08
@tejhan tejhan force-pushed the metricsTabComponentHookExtractionAndDocumentation3 branch from 1030751 to e4892d6 Compare March 30, 2026 22:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 29 out of 29 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread plugins/aks-desktop/src/components/Metrics/hooks/useCardMetrics.ts Outdated
@tejhan tejhan force-pushed the metricsTabComponentHookExtractionAndDocumentation3 branch from e4892d6 to b1ffb0f Compare March 30, 2026 22:25
…gic into hooks & components; Tests, refactors & documentation.
Copilot AI review requested due to automatic review settings March 30, 2026 22:32
@tejhan tejhan force-pushed the metricsTabComponentHookExtractionAndDocumentation3 branch from b1ffb0f to c5c668e Compare March 30, 2026 22:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 29 out of 29 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

plugins/aks-desktop/src/utils/prometheus/queryPrometheus.tsx:38

  • queryPrometheus runs az account get-access-token on every PromQL query. MetricsTab issues multiple queries per refresh (and Scaling now also uses this util), so this can spawn many az processes every 30s and significantly slow the UI / hit rate limits. Consider acquiring the token once per refresh (or caching tokens per subscription until expiry) and reusing it across queries, or make queryPrometheus accept an already-acquired token.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tejhan tejhan requested review from illume and skoeva April 1, 2026 20:15
Copy link
Copy Markdown
Collaborator

@illume illume left a comment

Choose a reason for hiding this comment

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

Great work, thanks! 🎉

@illume illume dismissed skoeva’s stale review April 8, 2026 09:04

These changes were done quite some time ago.

@illume illume merged commit 26d9694 into Azure:main Apr 8, 2026
20 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.

plugins/aks-desktop: Separate presentation from logic plugins/aks-desktop/src/components/MetricsTab/MetricsTab.tsx MetricsTab

5 participants