Advisor: Allow to retry checks for a single element (#104279)
This commit is contained in:
@@ -62,6 +62,17 @@ func (c *check) Items(ctx context.Context) ([]any, error) {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (c *check) Item(ctx context.Context, id string) (any, error) {
|
||||
requester, err := identity.GetRequester(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return c.DatasourceSvc.GetDataSource(ctx, &datasources.GetDataSourceQuery{
|
||||
UID: id,
|
||||
OrgID: requester.GetOrgID(),
|
||||
})
|
||||
}
|
||||
|
||||
func (c *check) ID() string {
|
||||
return CheckID
|
||||
}
|
||||
@@ -113,6 +124,7 @@ func (s *uidValidationStep) Run(ctx context.Context, obj *advisor.CheckSpec, i a
|
||||
advisor.CheckReportFailureSeverityLow,
|
||||
s.ID(),
|
||||
fmt.Sprintf("%s (%s)", ds.Name, ds.UID),
|
||||
ds.UID,
|
||||
[]advisor.CheckErrorLink{},
|
||||
), nil
|
||||
}
|
||||
@@ -181,6 +193,7 @@ func (s *healthCheckStep) Run(ctx context.Context, obj *advisor.CheckSpec, i any
|
||||
advisor.CheckReportFailureSeverityHigh,
|
||||
s.ID(),
|
||||
ds.Name,
|
||||
ds.UID,
|
||||
[]advisor.CheckErrorLink{
|
||||
{
|
||||
Message: "Fix me",
|
||||
@@ -241,6 +254,7 @@ func (s *missingPluginStep) Run(ctx context.Context, obj *advisor.CheckSpec, i a
|
||||
advisor.CheckReportFailureSeverityHigh,
|
||||
s.ID(),
|
||||
ds.Name,
|
||||
ds.UID,
|
||||
links,
|
||||
), nil
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ import (
|
||||
type Check interface {
|
||||
// ID returns the unique identifier of the check
|
||||
ID() string
|
||||
// Item returns the item that will be checked
|
||||
Item(ctx context.Context, id string) (any, error)
|
||||
// Items returns the list of items that will be checked
|
||||
Items(ctx context.Context) ([]any, error)
|
||||
// Steps returns the list of steps that will be executed
|
||||
|
||||
@@ -61,6 +61,14 @@ func (c *check) Items(ctx context.Context) ([]any, error) {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (c *check) Item(ctx context.Context, id string) (any, error) {
|
||||
p, exists := c.PluginStore.Plugin(ctx, id)
|
||||
if !exists {
|
||||
return nil, fmt.Errorf("plugin %s not found", id)
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (c *check) Steps() []checks.Step {
|
||||
return []checks.Step{
|
||||
&deprecationStep{
|
||||
@@ -118,6 +126,7 @@ func (s *deprecationStep) Run(ctx context.Context, _ *advisor.CheckSpec, it any)
|
||||
return checks.NewCheckReportFailure(
|
||||
advisor.CheckReportFailureSeverityHigh,
|
||||
s.ID(),
|
||||
p.Name,
|
||||
p.ID,
|
||||
[]advisor.CheckErrorLink{
|
||||
{
|
||||
@@ -190,6 +199,7 @@ func (s *updateStep) Run(ctx context.Context, _ *advisor.CheckSpec, i any) (*adv
|
||||
return checks.NewCheckReportFailure(
|
||||
advisor.CheckReportFailureSeverityLow,
|
||||
s.ID(),
|
||||
p.Name,
|
||||
p.ID,
|
||||
[]advisor.CheckErrorLink{
|
||||
{
|
||||
|
||||
@@ -33,7 +33,7 @@ func TestRun(t *testing.T) {
|
||||
{
|
||||
name: "Deprecated plugin",
|
||||
plugins: []pluginstore.Plugin{
|
||||
{JSONData: plugins.JSONData{ID: "plugin1", Info: plugins.Info{Version: "1.0.0"}}},
|
||||
{JSONData: plugins.JSONData{ID: "plugin1", Name: "Plugin 1", Info: plugins.Info{Version: "1.0.0"}}},
|
||||
},
|
||||
pluginInfo: map[string]*repo.PluginInfo{
|
||||
"plugin1": {Status: "deprecated"},
|
||||
@@ -45,7 +45,8 @@ func TestRun(t *testing.T) {
|
||||
{
|
||||
Severity: advisor.CheckReportFailureSeverityHigh,
|
||||
StepID: "deprecation",
|
||||
Item: "plugin1",
|
||||
Item: "Plugin 1",
|
||||
ItemID: "plugin1",
|
||||
Links: []advisor.CheckErrorLink{
|
||||
{
|
||||
Url: "/plugins/plugin1",
|
||||
@@ -58,7 +59,7 @@ func TestRun(t *testing.T) {
|
||||
{
|
||||
name: "Plugin with update",
|
||||
plugins: []pluginstore.Plugin{
|
||||
{JSONData: plugins.JSONData{ID: "plugin2", Info: plugins.Info{Version: "1.0.0"}}},
|
||||
{JSONData: plugins.JSONData{ID: "plugin2", Name: "Plugin 2", Info: plugins.Info{Version: "1.0.0"}}},
|
||||
},
|
||||
pluginInfo: map[string]*repo.PluginInfo{
|
||||
"plugin2": {Status: "active"},
|
||||
@@ -70,7 +71,8 @@ func TestRun(t *testing.T) {
|
||||
{
|
||||
Severity: advisor.CheckReportFailureSeverityLow,
|
||||
StepID: "update",
|
||||
Item: "plugin2",
|
||||
Item: "Plugin 2",
|
||||
ItemID: "plugin2",
|
||||
Links: []advisor.CheckErrorLink{
|
||||
{
|
||||
Url: "/plugins/plugin2?page=version-history",
|
||||
@@ -83,7 +85,7 @@ func TestRun(t *testing.T) {
|
||||
{
|
||||
name: "Plugin with update (non semver)",
|
||||
plugins: []pluginstore.Plugin{
|
||||
{JSONData: plugins.JSONData{ID: "plugin2", Info: plugins.Info{Version: "alpha"}}},
|
||||
{JSONData: plugins.JSONData{ID: "plugin2", Name: "Plugin 2", Info: plugins.Info{Version: "alpha"}}},
|
||||
},
|
||||
pluginInfo: map[string]*repo.PluginInfo{
|
||||
"plugin2": {Status: "active"},
|
||||
@@ -95,7 +97,8 @@ func TestRun(t *testing.T) {
|
||||
{
|
||||
Severity: advisor.CheckReportFailureSeverityLow,
|
||||
StepID: "update",
|
||||
Item: "plugin2",
|
||||
Item: "Plugin 2",
|
||||
ItemID: "plugin2",
|
||||
Links: []advisor.CheckErrorLink{
|
||||
{
|
||||
Url: "/plugins/plugin2?page=version-history",
|
||||
@@ -108,7 +111,7 @@ func TestRun(t *testing.T) {
|
||||
{
|
||||
name: "Plugin pinned",
|
||||
plugins: []pluginstore.Plugin{
|
||||
{JSONData: plugins.JSONData{ID: "plugin3", Info: plugins.Info{Version: "1.0.0"}}},
|
||||
{JSONData: plugins.JSONData{ID: "plugin3", Name: "Plugin 3", Info: plugins.Info{Version: "1.0.0"}}},
|
||||
},
|
||||
pluginInfo: map[string]*repo.PluginInfo{
|
||||
"plugin3": {Status: "active"},
|
||||
@@ -122,7 +125,7 @@ func TestRun(t *testing.T) {
|
||||
{
|
||||
name: "Managed plugin",
|
||||
plugins: []pluginstore.Plugin{
|
||||
{JSONData: plugins.JSONData{ID: "plugin4", Info: plugins.Info{Version: "1.0.0"}}},
|
||||
{JSONData: plugins.JSONData{ID: "plugin4", Name: "Plugin 4", Info: plugins.Info{Version: "1.0.0"}}},
|
||||
},
|
||||
pluginInfo: map[string]*repo.PluginInfo{
|
||||
"plugin4": {Status: "active"},
|
||||
@@ -136,7 +139,7 @@ func TestRun(t *testing.T) {
|
||||
{
|
||||
name: "Provisioned plugin",
|
||||
plugins: []pluginstore.Plugin{
|
||||
{JSONData: plugins.JSONData{ID: "plugin5", Info: plugins.Info{Version: "1.0.0"}}},
|
||||
{JSONData: plugins.JSONData{ID: "plugin5", Name: "Plugin 5", Info: plugins.Info{Version: "1.0.0"}}},
|
||||
},
|
||||
pluginInfo: map[string]*repo.PluginInfo{
|
||||
"plugin5": {Status: "active"},
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
const (
|
||||
TypeLabel = "advisor.grafana.app/type"
|
||||
StatusAnnotation = "advisor.grafana.app/status"
|
||||
RetryAnnotation = "advisor.grafana.app/retry"
|
||||
StatusAnnotationError = "error"
|
||||
StatusAnnotationProcessed = "processed"
|
||||
)
|
||||
@@ -22,12 +23,14 @@ func NewCheckReportFailure(
|
||||
severity advisor.CheckReportFailureSeverity,
|
||||
stepID string,
|
||||
item string,
|
||||
itemID string,
|
||||
links []advisor.CheckErrorLink,
|
||||
) *advisor.CheckReportFailure {
|
||||
return &advisor.CheckReportFailure{
|
||||
Severity: severity,
|
||||
StepID: stepID,
|
||||
Item: item,
|
||||
ItemID: itemID,
|
||||
Links: links,
|
||||
}
|
||||
}
|
||||
@@ -47,6 +50,10 @@ func GetStatusAnnotation(obj resource.Object) string {
|
||||
return obj.GetAnnotations()[StatusAnnotation]
|
||||
}
|
||||
|
||||
func GetRetryAnnotation(obj resource.Object) string {
|
||||
return obj.GetAnnotations()[RetryAnnotation]
|
||||
}
|
||||
|
||||
func SetStatusAnnotation(ctx context.Context, client resource.Client, obj resource.Object, status string) error {
|
||||
annotations := obj.GetAnnotations()
|
||||
if annotations == nil {
|
||||
|
||||
Reference in New Issue
Block a user