Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: reduce nested level #224

Merged
merged 1 commit into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,27 @@ func (tc *Controller) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Res
p := &predictionapi.TimeSeriesPrediction{}
err := tc.Client.Get(ctx, req.NamespacedName, p)
if err != nil {
if errors.IsNotFound(err) {
if last, ok := tc.tsPredictionMap.Load(req.NamespacedName.String()); ok {
if tsp, ok := last.(*predictionapi.TimeSeriesPrediction); ok {
err := tc.removeTimeSeriesPrediction(tsp)
if err != nil {
return ctrl.Result{Requeue: true}, err
}
return ctrl.Result{}, nil
}
return ctrl.Result{}, fmt.Errorf("assert tsp failed for tsp %v in map", req.String())
}
if !errors.IsNotFound(err) {
klog.V(4).Infof("Failed to get TimeSeriesPrediction %v err: %v", klog.KObj(p), err)
return ctrl.Result{Requeue: true}, err
}

last, ok := tc.tsPredictionMap.Load(req.NamespacedName.String())
if !ok {
klog.V(4).Infof("Failed to load exist tsp %v", req.String())
return ctrl.Result{}, nil
}
klog.V(4).Infof("Failed to get TimeSeriesPrediction %v err: %v", klog.KObj(p), err)
return ctrl.Result{Requeue: true}, err

tsp, ok := last.(*predictionapi.TimeSeriesPrediction)
if !ok {
return ctrl.Result{}, fmt.Errorf("assert tsp failed for tsp %v in map", req.String())
}

err := tc.removeTimeSeriesPrediction(tsp)
if err != nil {
return ctrl.Result{Requeue: true}, err
}
return ctrl.Result{}, nil
}

return tc.syncTimeSeriesPrediction(ctx, p)
Expand All @@ -98,25 +103,28 @@ func (tc *Controller) syncTimeSeriesPrediction(ctx context.Context, tsp *predict
return ctrl.Result{}, err
}

last, ok := tc.tsPredictionMap.Load(key)
if !ok { // first time created or system start
c.WithApiConfigs(tsp.Spec.PredictionMetrics)
} else {
if old, ok := last.(*predictionapi.TimeSeriesPrediction); ok {
// predictor need a interface to query the config and then diff.
// now just diff the cache in the controller to decide, it can not cover all the cases when users modify the spec
for _, oldMetricConf := range old.Spec.PredictionMetrics {
if !ExistsPredictionMetric(oldMetricConf, tsp.Spec.PredictionMetrics) {
c.DeleteApiConfig(&oldMetricConf)
}
}
for _, newMetricConf := range tsp.Spec.PredictionMetrics {
c.WithApiConfig(&newMetricConf)
}
} else {
func() {
last, ok := tc.tsPredictionMap.Load(key)
if !ok { // first time created or system start
c.WithApiConfigs(tsp.Spec.PredictionMetrics)
return
}
}
old, ok := last.(*predictionapi.TimeSeriesPrediction)
if !ok {
c.WithApiConfigs(tsp.Spec.PredictionMetrics)
return
}
// predictor need an interface to query the config and then diff.
// now just diff the cache in the controller to decide, it can not cover all the cases when users modify the spec
for _, oldMetricConf := range old.Spec.PredictionMetrics {
if !ExistsPredictionMetric(oldMetricConf, tsp.Spec.PredictionMetrics) {
c.DeleteApiConfig(&oldMetricConf)
}
}
for _, newMetricConf := range tsp.Spec.PredictionMetrics {
c.WithApiConfig(&newMetricConf)
}
}()

tc.tsPredictionMap.Store(key, tsp)

Expand Down
1 change: 0 additions & 1 deletion pkg/prediction/dsp/prediction.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ func preProcessTimeSeriesList(tsList []*common.TimeSeries, config *internalConfi
for ts := range tsCh {
tsList = append(tsList, ts)
}
wg.Wait()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate wait here


return tsList, nil
}
Expand Down