MCPcopy
hub / github.com/grafana/grafana / processCheckRetry

Function processCheckRetry

apps/advisor/pkg/app/utils.go:109–189  ·  view source on GitHub ↗
(ctx context.Context, log logging.Logger, client resource.Client, typesClient resource.Client, obj resource.Object, check checks.Check)

Source from the content-addressed store, hash-verified

107}
108
109func processCheckRetry(ctx context.Context, log logging.Logger, client resource.Client, typesClient resource.Client, obj resource.Object, check checks.Check) error {
110 status := checks.GetStatusAnnotation(obj)
111 if status == "" || status == checks.StatusAnnotationError {
112 // Check not processed yet or errored
113 log.Debug("Check not processed yet or errored, skipping retry", "check", obj.GetName(), "status", status)
114 return nil
115 }
116 // Get the item to retry from the annotation
117 itemToRetry := checks.GetRetryAnnotation(obj)
118 if itemToRetry == "" {
119 // No item to retry, nothing to do
120 log.Debug("No item to retry, skipping retry", "check", obj.GetName())
121 return nil
122 } else {
123 log.Debug("Item to retry found", "check", obj.GetName(), "item", itemToRetry)
124 }
125 c, ok := obj.(*advisorv0alpha1.Check)
126 if !ok {
127 return fmt.Errorf("invalid object type")
128 }
129 // Get the items to check
130 err := check.Init(ctx)
131 if err != nil {
132 return fmt.Errorf("error initializing check: %w", err)
133 }
134 failures := []advisorv0alpha1.CheckReportFailure{}
135 item, err := check.Item(ctx, itemToRetry)
136 if err != nil {
137 setErr := checks.SetStatusAnnotation(ctx, client, obj, checks.StatusAnnotationError)
138 if setErr != nil {
139 return setErr
140 }
141 return fmt.Errorf("error getting item for check: %w", err)
142 }
143 if item != nil {
144 // Get the check type
145 var checkType resource.Object
146 checkType, err = typesClient.Get(ctx, resource.Identifier{
147 Namespace: obj.GetNamespace(),
148 Name: check.ID(),
149 })
150 if err != nil {
151 return err
152 }
153 // Run the steps
154 steps, err := filterSteps(checkType, check.Steps())
155 if err != nil {
156 return err
157 }
158 failures, err = runStepsInParallel(ctx, log, &c.Spec, steps, []any{item})
159 if err != nil {
160 setErr := checks.SetStatusAnnotation(ctx, client, obj, checks.StatusAnnotationError)
161 if setErr != nil {
162 return setErr
163 }
164 return fmt.Errorf("error running steps: %w", err)
165 }
166 }

Calls 15

GetStatusAnnotationFunction · 0.92
GetRetryAnnotationFunction · 0.92
SetStatusAnnotationFunction · 0.92
SetStatusFunction · 0.92
DeleteAnnotationsFunction · 0.92
SetAnnotationsFunction · 0.92
filterStepsFunction · 0.85
runStepsInParallelFunction · 0.85
waitForRetryAnnotationFunction · 0.85
DebugMethod · 0.65
GetNameMethod · 0.65
ErrorfMethod · 0.65