mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
K8s: Fix get dashboard by plugin id (#99509)
This commit is contained in:
parent
d192a44469
commit
6284dd61ae
@ -952,11 +952,26 @@ func (dr *DashboardServiceImpl) UnprovisionDashboard(ctx context.Context, dashbo
|
|||||||
|
|
||||||
func (dr *DashboardServiceImpl) GetDashboardsByPluginID(ctx context.Context, query *dashboards.GetDashboardsByPluginIDQuery) ([]*dashboards.Dashboard, error) {
|
func (dr *DashboardServiceImpl) GetDashboardsByPluginID(ctx context.Context, query *dashboards.GetDashboardsByPluginIDQuery) ([]*dashboards.Dashboard, error) {
|
||||||
if dr.features.IsEnabledGlobally(featuremgmt.FlagKubernetesCliDashboards) {
|
if dr.features.IsEnabledGlobally(featuremgmt.FlagKubernetesCliDashboards) {
|
||||||
return dr.searchDashboardsThroughK8s(ctx, &dashboards.FindPersistedDashboardsQuery{
|
dashs, err := dr.searchDashboardsThroughK8s(ctx, &dashboards.FindPersistedDashboardsQuery{
|
||||||
OrgId: query.OrgID,
|
OrgId: query.OrgID,
|
||||||
ProvisionedRepo: pluginIDRepoName,
|
ProvisionedRepo: pluginIDRepoName,
|
||||||
ProvisionedPath: query.PluginID,
|
ProvisionedPath: query.PluginID,
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// search only returns the metadata, need to get the dashboard.Data too
|
||||||
|
results := make([]*dashboards.Dashboard, len(dashs))
|
||||||
|
for i, d := range dashs {
|
||||||
|
dash, err := dr.GetDashboard(ctx, &dashboards.GetDashboardQuery{OrgID: d.OrgID, UID: d.UID})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
results[i] = dash
|
||||||
|
}
|
||||||
|
|
||||||
|
return results, nil
|
||||||
}
|
}
|
||||||
return dr.dashboardStore.GetDashboardsByPluginID(ctx, query)
|
return dr.dashboardStore.GetDashboardsByPluginID(ctx, query)
|
||||||
}
|
}
|
||||||
|
@ -1020,6 +1020,15 @@ func TestGetDashboardsByPluginID(t *testing.T) {
|
|||||||
PluginID: "testing",
|
PluginID: "testing",
|
||||||
OrgID: 1,
|
OrgID: 1,
|
||||||
}
|
}
|
||||||
|
uidUnstructured := &unstructured.Unstructured{Object: map[string]any{
|
||||||
|
"metadata": map[string]any{
|
||||||
|
"name": "uid1",
|
||||||
|
},
|
||||||
|
"spec": map[string]any{
|
||||||
|
"title": "Dashboard 1",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
|
||||||
t.Run("Should fallback to dashboard store if Kubernetes feature flags are not enabled", func(t *testing.T) {
|
t.Run("Should fallback to dashboard store if Kubernetes feature flags are not enabled", func(t *testing.T) {
|
||||||
service.features = featuremgmt.WithFeatures()
|
service.features = featuremgmt.WithFeatures()
|
||||||
fakeStore.On("GetDashboardsByPluginID", mock.Anything, mock.Anything).Return([]*dashboards.Dashboard{}, nil).Once()
|
fakeStore.On("GetDashboardsByPluginID", mock.Anything, mock.Anything).Return([]*dashboards.Dashboard{}, nil).Once()
|
||||||
@ -1030,6 +1039,7 @@ func TestGetDashboardsByPluginID(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("Should use Kubernetes client if feature flags are enabled", func(t *testing.T) {
|
t.Run("Should use Kubernetes client if feature flags are enabled", func(t *testing.T) {
|
||||||
ctx, k8sCliMock := setupK8sDashboardTests(service)
|
ctx, k8sCliMock := setupK8sDashboardTests(service)
|
||||||
|
k8sCliMock.On("Get", mock.Anything, "uid", mock.Anything, mock.Anything).Return(uidUnstructured, nil)
|
||||||
k8sCliMock.On("Search", mock.Anything, mock.Anything, mock.MatchedBy(func(req *resource.ResourceSearchRequest) bool {
|
k8sCliMock.On("Search", mock.Anything, mock.Anything, mock.MatchedBy(func(req *resource.ResourceSearchRequest) bool {
|
||||||
return req.Options.Fields[0].Key == "repo.name" && req.Options.Fields[0].Values[0] == "plugin" &&
|
return req.Options.Fields[0].Key == "repo.name" && req.Options.Fields[0].Values[0] == "plugin" &&
|
||||||
req.Options.Fields[1].Key == "repo.path" && req.Options.Fields[1].Values[0] == "testing"
|
req.Options.Fields[1].Key == "repo.path" && req.Options.Fields[1].Values[0] == "testing"
|
||||||
|
Loading…
Reference in New Issue
Block a user