Advisor: Redefine check properties (#100874)

This commit is contained in:
Andres Martinez Gotor
2025-02-19 15:11:55 +01:00
committed by GitHub
parent 9f49f4ce36
commit a24fd1b722
15 changed files with 177 additions and 71 deletions
@@ -12,6 +12,7 @@ import (
"github.com/grafana/grafana/pkg/services/datasources"
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginstore"
"github.com/grafana/grafana/pkg/util"
"k8s.io/klog/v2"
)
type check struct {
@@ -72,7 +73,12 @@ func (s *uidValidationStep) Title() string {
}
func (s *uidValidationStep) Description() string {
return "Check if the UID of each data source is valid."
return "Checks if the UID of a data source is valid."
}
func (s *uidValidationStep) Resolution() string {
return "Check the <a href='https://grafana.com/docs/grafana/latest/upgrade-guide/upgrade-v11.2/#grafana-data-source-uid-format-enforcement'" +
"target=_blank>documentation</a> for more information or delete the data source and create a new one."
}
func (s *uidValidationStep) Run(ctx context.Context, obj *advisor.CheckSpec, i any) (*advisor.CheckReportFailure, error) {
@@ -85,10 +91,9 @@ func (s *uidValidationStep) Run(ctx context.Context, obj *advisor.CheckSpec, i a
if err != nil {
return checks.NewCheckReportFailure(
advisor.CheckReportFailureSeverityLow,
fmt.Sprintf("Invalid UID '%s' for data source %s", ds.UID, ds.Name),
"Check the <a href='https://grafana.com/docs/grafana/latest/upgrade-guide/upgrade-v11.2/#grafana-data-source-uid-format-enforcement' target=_blank>documentation</a> for more information.",
s.ID(),
ds.UID,
fmt.Sprintf("%s (%s)", ds.Name, ds.UID),
[]advisor.CheckErrorLink{},
), nil
}
return nil, nil
@@ -104,7 +109,11 @@ func (s *healthCheckStep) Title() string {
}
func (s *healthCheckStep) Description() string {
return "Check if all data sources are healthy."
return "Checks if a data sources is healthy."
}
func (s *healthCheckStep) Resolution() string {
return "Go to the data source configuration page and address the issues reported."
}
func (s *healthCheckStep) ID() string {
@@ -124,7 +133,9 @@ func (s *healthCheckStep) Run(ctx context.Context, obj *advisor.CheckSpec, i any
}
pCtx, err := s.PluginContextProvider.GetWithDataSource(ctx, ds.Type, requester, ds)
if err != nil {
return nil, fmt.Errorf("failed to get plugin context: %w", err)
// Unable to check health check
klog.Error("Failed to get plugin context", "datasource_uid", ds.UID, "error", err)
return nil, nil
}
req := &backend.CheckHealthRequest{
PluginContext: pCtx,
@@ -134,12 +145,14 @@ func (s *healthCheckStep) Run(ctx context.Context, obj *advisor.CheckSpec, i any
if err != nil || resp.Status != backend.HealthStatusOk {
return checks.NewCheckReportFailure(
advisor.CheckReportFailureSeverityHigh,
fmt.Sprintf("Health check failed for %s", ds.Name),
fmt.Sprintf(
"Go to the <a href='/connections/datasources/edit/%s'>data source configuration</a>"+
" and address the issues reported.", ds.UID),
s.ID(),
ds.UID,
ds.Name,
[]advisor.CheckErrorLink{
{
Message: "Fix me",
Url: fmt.Sprintf("/connections/datasources/edit/%s", ds.UID),
},
},
), nil
}
return nil, nil
@@ -81,7 +81,7 @@ func TestCheck_Run(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, 1, len(items))
assert.Len(t, failures, 1)
assert.Equal(t, "Invalid UID 'invalid uid' for data source Prometheus", failures[0].Reason)
assert.Equal(t, "uid-validation", failures[0].StepID)
})
t.Run("should return failures when datasource health check fails", func(t *testing.T) {
@@ -116,7 +116,7 @@ func TestCheck_Run(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, 1, len(items))
assert.Len(t, failures, 1)
assert.Equal(t, "Health check failed for Prometheus", failures[0].Reason)
assert.Equal(t, "health-check", failures[0].StepID)
})
}