Advisor: Replace Error naming with Failure (#100262)
This commit is contained in:
@@ -75,7 +75,7 @@ func (s *uidValidationStep) Description() string {
|
||||
return "Check if the UID of each data source is valid."
|
||||
}
|
||||
|
||||
func (s *uidValidationStep) Run(ctx context.Context, obj *advisor.CheckSpec, i any) (*advisor.CheckReportError, error) {
|
||||
func (s *uidValidationStep) Run(ctx context.Context, obj *advisor.CheckSpec, i any) (*advisor.CheckReportFailure, error) {
|
||||
ds, ok := i.(*datasources.DataSource)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid item type %T", i)
|
||||
@@ -83,8 +83,8 @@ func (s *uidValidationStep) Run(ctx context.Context, obj *advisor.CheckSpec, i a
|
||||
// Data source UID validation
|
||||
err := util.ValidateUID(ds.UID)
|
||||
if err != nil {
|
||||
return checks.NewCheckReportError(
|
||||
advisor.CheckReportErrorSeverityLow,
|
||||
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(),
|
||||
@@ -111,7 +111,7 @@ func (s *healthCheckStep) ID() string {
|
||||
return "health-check"
|
||||
}
|
||||
|
||||
func (s *healthCheckStep) Run(ctx context.Context, obj *advisor.CheckSpec, i any) (*advisor.CheckReportError, error) {
|
||||
func (s *healthCheckStep) Run(ctx context.Context, obj *advisor.CheckSpec, i any) (*advisor.CheckReportFailure, error) {
|
||||
ds, ok := i.(*datasources.DataSource)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid item type %T", i)
|
||||
@@ -132,8 +132,8 @@ func (s *healthCheckStep) Run(ctx context.Context, obj *advisor.CheckSpec, i any
|
||||
}
|
||||
resp, err := s.PluginClient.CheckHealth(ctx, req)
|
||||
if err != nil || resp.Status != backend.HealthStatusOk {
|
||||
return checks.NewCheckReportError(
|
||||
advisor.CheckReportErrorSeverityHigh,
|
||||
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>"+
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
func TestCheck_Run(t *testing.T) {
|
||||
t.Run("should return no errors when all datasources are healthy", func(t *testing.T) {
|
||||
t.Run("should return no failures when all datasources are healthy", func(t *testing.T) {
|
||||
datasources := []*datasources.DataSource{
|
||||
{UID: "valid-uid-1", Type: "prometheus", Name: "Prometheus"},
|
||||
{UID: "valid-uid-2", Type: "mysql", Name: "MySQL"},
|
||||
@@ -33,23 +33,23 @@ func TestCheck_Run(t *testing.T) {
|
||||
ctx := identity.WithRequester(context.Background(), &user.SignedInUser{})
|
||||
items, err := check.Items(ctx)
|
||||
assert.NoError(t, err)
|
||||
errs := []advisor.CheckReportError{}
|
||||
failures := []advisor.CheckReportFailure{}
|
||||
for _, step := range check.Steps() {
|
||||
for _, item := range items {
|
||||
stepErr, err := step.Run(ctx, &advisor.CheckSpec{}, item)
|
||||
stepFailures, err := step.Run(ctx, &advisor.CheckSpec{}, item)
|
||||
assert.NoError(t, err)
|
||||
if stepErr != nil {
|
||||
errs = append(errs, *stepErr)
|
||||
if stepFailures != nil {
|
||||
failures = append(failures, *stepFailures)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 2, len(items))
|
||||
assert.Empty(t, errs)
|
||||
assert.Empty(t, failures)
|
||||
})
|
||||
|
||||
t.Run("should return errors when datasource UID is invalid", func(t *testing.T) {
|
||||
t.Run("should return failures when datasource UID is invalid", func(t *testing.T) {
|
||||
datasources := []*datasources.DataSource{
|
||||
{UID: "invalid uid", Type: "prometheus", Name: "Prometheus"},
|
||||
}
|
||||
@@ -67,24 +67,24 @@ func TestCheck_Run(t *testing.T) {
|
||||
ctx := identity.WithRequester(context.Background(), &user.SignedInUser{})
|
||||
items, err := check.Items(ctx)
|
||||
assert.NoError(t, err)
|
||||
errs := []advisor.CheckReportError{}
|
||||
failures := []advisor.CheckReportFailure{}
|
||||
for _, step := range check.Steps() {
|
||||
for _, item := range items {
|
||||
stepErr, err := step.Run(ctx, &advisor.CheckSpec{}, item)
|
||||
stepFailures, err := step.Run(ctx, &advisor.CheckSpec{}, item)
|
||||
assert.NoError(t, err)
|
||||
if stepErr != nil {
|
||||
errs = append(errs, *stepErr)
|
||||
if stepFailures != nil {
|
||||
failures = append(failures, *stepFailures)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 1, len(items))
|
||||
assert.Len(t, errs, 1)
|
||||
assert.Equal(t, "Invalid UID 'invalid uid' for data source Prometheus", errs[0].Reason)
|
||||
assert.Len(t, failures, 1)
|
||||
assert.Equal(t, "Invalid UID 'invalid uid' for data source Prometheus", failures[0].Reason)
|
||||
})
|
||||
|
||||
t.Run("should return errors when datasource health check fails", func(t *testing.T) {
|
||||
t.Run("should return failures when datasource health check fails", func(t *testing.T) {
|
||||
datasources := []*datasources.DataSource{
|
||||
{UID: "valid-uid-1", Type: "prometheus", Name: "Prometheus"},
|
||||
}
|
||||
@@ -102,21 +102,21 @@ func TestCheck_Run(t *testing.T) {
|
||||
ctx := identity.WithRequester(context.Background(), &user.SignedInUser{})
|
||||
items, err := check.Items(ctx)
|
||||
assert.NoError(t, err)
|
||||
errs := []advisor.CheckReportError{}
|
||||
failures := []advisor.CheckReportFailure{}
|
||||
for _, step := range check.Steps() {
|
||||
for _, item := range items {
|
||||
stepErr, err := step.Run(ctx, &advisor.CheckSpec{}, item)
|
||||
stepFailures, err := step.Run(ctx, &advisor.CheckSpec{}, item)
|
||||
assert.NoError(t, err)
|
||||
if stepErr != nil {
|
||||
errs = append(errs, *stepErr)
|
||||
if stepFailures != nil {
|
||||
failures = append(failures, *stepFailures)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 1, len(items))
|
||||
assert.Len(t, errs, 1)
|
||||
assert.Equal(t, "Health check failed for Prometheus", errs[0].Reason)
|
||||
assert.Len(t, failures, 1)
|
||||
assert.Equal(t, "Health check failed for Prometheus", failures[0].Reason)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user