From ed482219c60099b6c4435d0679f17b6f984355c4 Mon Sep 17 00:00:00 2001 From: Stephanie Hingtgen Date: Fri, 3 Oct 2025 03:52:13 -0600 Subject: [PATCH] Provisioning: Specify managed by git sync (#111969) * Provisioning: Specify managed by git sync * linter * Update public/app/features/provisioning/Wizard/hooks/useResourceStats.ts Co-authored-by: Alex Khomenko * Update public/app/features/provisioning/Shared/RepositoryList.tsx Co-authored-by: Alex Khomenko * Update public/app/features/provisioning/Wizard/hooks/useResourceStats.ts Co-authored-by: Alex Khomenko * Update public/app/features/provisioning/Shared/RepositoryList.tsx Co-authored-by: Alex Khomenko * fix frontend lint --------- Co-authored-by: Alex Khomenko Co-authored-by: Ryan McKinley --- .../provisioning/Shared/RepositoryList.tsx | 4 +- .../Wizard/hooks/useResourceStats.ts | 41 +++++++++++++++---- public/locales/en-US/grafana.json | 6 +-- 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/public/app/features/provisioning/Shared/RepositoryList.tsx b/public/app/features/provisioning/Shared/RepositoryList.tsx index be7ff34c074..c84a3e7e6dd 100644 --- a/public/app/features/provisioning/Shared/RepositoryList.tsx +++ b/public/app/features/provisioning/Shared/RepositoryList.tsx @@ -43,13 +43,13 @@ export function RepositoryList({ items }: Props) { i18nKey="provisioning.folder-repository-list.partial-managed" values={{ managedCount, resourceCount }} > - {{ managedCount }}/{{ resourceCount }} resources managed. + {{ managedCount }}/{{ resourceCount }} resources managed by Git sync. {unmanagedCount > 0 && ( <> {' '} - {{ count: unmanagedCount }} resources aren't managed as code yet. + {{ count: unmanagedCount }} resources aren't managed by Git sync. )} diff --git a/public/app/features/provisioning/Wizard/hooks/useResourceStats.ts b/public/app/features/provisioning/Wizard/hooks/useResourceStats.ts index 4afc252e0e5..49573b4e793 100644 --- a/public/app/features/provisioning/Wizard/hooks/useResourceStats.ts +++ b/public/app/features/provisioning/Wizard/hooks/useResourceStats.ts @@ -11,24 +11,27 @@ import { useGetRepositoryFilesQuery, useGetResourceStatsQuery, } from 'app/api/clients/provisioning/v0alpha1'; +import { ManagerKind } from 'app/features/apiserver/types'; function getManagedCount(managed?: ManagerStats[]) { let totalCount = 0; // Loop through each managed repository managed?.forEach((manager) => { - // Loop through stats inside each manager and sum up the counts - manager.stats.forEach((stat) => { - if (stat.group === 'folder.grafana.app' || stat.group === 'dashboard.grafana.app') { - totalCount += stat.count; - } - }); + if (manager.kind === ManagerKind.Repo) { + // Loop through stats inside each manager and sum up the counts + manager.stats.forEach((stat) => { + if (stat.group === 'folder.grafana.app' || stat.group === 'dashboard.grafana.app') { + totalCount += stat.count; + } + }); + } }); return totalCount; } -function getResourceCount(stats?: ResourceCount[]) { +function getResourceCount(stats?: ResourceCount[], managed?: ManagerStats[]) { let counts: string[] = []; let resourceCount = 0; @@ -46,6 +49,26 @@ function getResourceCount(stats?: ResourceCount[]) { } }); + managed?.forEach((manager) => { + if (manager.kind !== ManagerKind.Repo) { + manager.stats.forEach((stat) => { + switch (stat.group) { + case 'folders': + case 'folder.grafana.app': + resourceCount += stat.count; + counts.push(t('provisioning.bootstrap-step.folders-count', '{{count}} folder', { count: stat.count })); + break; + case 'dashboard.grafana.app': + resourceCount += stat.count; + counts.push( + t('provisioning.bootstrap-step.dashboards-count', '{{count}} dashboard', { count: stat.count }) + ); + break; + } + }); + } + }); + return { counts, resourceCount, @@ -92,7 +115,9 @@ export function useResourceStats(repoName?: string, isLegacyStorage?: boolean, s return { // managed does not exist in response when first time connecting to a repo managedCount: getManagedCount(resourceStatsQuery.data?.managed), - unmanagedCount: getResourceCount(resourceStatsQuery.data?.unmanaged).resourceCount, + // "unmanaged" means unmanaged by git sync. it may still be managed by other means, like terraform, plugins, file provisioning, etc. + unmanagedCount: getResourceCount(resourceStatsQuery.data?.unmanaged, resourceStatsQuery.data?.managed) + .resourceCount, }; }, [resourceStatsQuery.data]); diff --git a/public/locales/en-US/grafana.json b/public/locales/en-US/grafana.json index d86e265b519..38084055225 100644 --- a/public/locales/en-US/grafana.json +++ b/public/locales/en-US/grafana.json @@ -11353,10 +11353,10 @@ "all-resources-managed_one": "All {{count}} resource is managed", "all-resources-managed_other": "All {{count}} resources are managed", "no-results-matching-your-query": "No results matching your query", - "partial-managed": "{{managedCount}}/{{resourceCount}} resources managed.", + "partial-managed": "{{managedCount}}/{{resourceCount}} resources managed by Git sync.", "placeholder-search": "Search", - "unmanaged-resources_one": "{{count}} resource isn't managed as code yet.", - "unmanaged-resources_other": "{{count}} resources aren't managed as code yet." + "unmanaged-resources_one": "{{count}} resource isn't managed by git sync.", + "unmanaged-resources_other": "{{count}} resources aren't managed by git sync." }, "get-default-values": { "title": {