mirror of
https://github.com/grafana/grafana.git
synced 2026-02-03 20:49:50 -05:00
Snapshots MT: Update k8s client to fetch dashboard data (#117031)
This commit is contained in:
parent
7fa3effcbf
commit
a9c4631946
1 changed files with 29 additions and 28 deletions
|
|
@ -1,8 +1,8 @@
|
|||
import { lastValueFrom, map } from 'rxjs';
|
||||
import { lastValueFrom } from 'rxjs';
|
||||
|
||||
import { config, getBackendSrv, FetchResponse } from '@grafana/runtime';
|
||||
import { config, getBackendSrv } from '@grafana/runtime';
|
||||
import { contextSrv } from 'app/core/services/context_srv';
|
||||
import { DashboardDTO, SnapshotSpec } from 'app/types/dashboard';
|
||||
import { DashboardDataDTO, DashboardDTO } from 'app/types/dashboard';
|
||||
|
||||
import { getAPINamespace } from '../../../api/utils';
|
||||
|
||||
|
|
@ -82,11 +82,12 @@ interface DashboardSnapshotList {
|
|||
items: K8sSnapshotResource[];
|
||||
}
|
||||
|
||||
interface K8sDashboardSnapshot {
|
||||
// Response from the /dashboard subresource - returns a Dashboard with raw dashboard data in spec
|
||||
interface K8sDashboardSubresource {
|
||||
apiVersion: string;
|
||||
kind: 'Snapshot';
|
||||
kind: 'Dashboard';
|
||||
metadata: K8sMetadata;
|
||||
spec: SnapshotSpec;
|
||||
spec: DashboardDataDTO;
|
||||
}
|
||||
|
||||
class K8sAPI implements DashboardSnapshotSrv {
|
||||
|
|
@ -128,32 +129,32 @@ class K8sAPI implements DashboardSnapshotSrv {
|
|||
const token = `??? TODO, get anon token for snapshots (${contextSrv.user?.name}) ???`;
|
||||
headers['Authorization'] = `Bearer ${token}`;
|
||||
}
|
||||
return lastValueFrom(
|
||||
getBackendSrv()
|
||||
.fetch<K8sDashboardSnapshot>({
|
||||
|
||||
// Fetch both snapshot metadata and dashboard content in parallel
|
||||
const [snapshotResponse, dashboardResponse] = await Promise.all([
|
||||
lastValueFrom(
|
||||
getBackendSrv().fetch<K8sSnapshotResource>({
|
||||
url: this.url + '/' + uid,
|
||||
method: 'GET',
|
||||
headers: headers,
|
||||
})
|
||||
.pipe(
|
||||
map((response: FetchResponse<K8sDashboardSnapshot>) => {
|
||||
return {
|
||||
dashboard: response.data.spec.dashboard,
|
||||
meta: {
|
||||
isSnapshot: true,
|
||||
canSave: false,
|
||||
canEdit: false,
|
||||
canAdmin: false,
|
||||
canStar: false,
|
||||
canShare: false,
|
||||
canDelete: false,
|
||||
isFolder: false,
|
||||
provisioned: false,
|
||||
},
|
||||
};
|
||||
})
|
||||
)
|
||||
);
|
||||
),
|
||||
lastValueFrom(
|
||||
getBackendSrv().fetch<K8sDashboardSubresource>({
|
||||
url: this.url + '/' + uid + '/dashboard',
|
||||
method: 'GET',
|
||||
headers: headers,
|
||||
})
|
||||
),
|
||||
]);
|
||||
|
||||
return {
|
||||
dashboard: dashboardResponse.data.spec,
|
||||
meta: {
|
||||
isSnapshot: true,
|
||||
k8s: snapshotResponse.data.metadata,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue