Skip to content

Commit

Permalink
pass config to getPredictedValuesFromSignals (gocrane#347)
Browse files Browse the repository at this point in the history
  • Loading branch information
yufeiyu authored and chenkaiyue committed Jun 11, 2022
1 parent 3760c3a commit f4299f4
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pkg/prediction/percentile/prediction.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ func generateSamplesFromWindow(value float64, start time.Time, end time.Time, st
return result
}

func (p *percentilePrediction) getPredictedValuesFromSignals(queryExpr string, signals map[string]*aggregateSignal) []*common.TimeSeries {
func (p *percentilePrediction) getPredictedValuesFromSignals(queryExpr string, signals map[string]*aggregateSignal, cfg *internalConfig) []*common.TimeSeries {
var predictedTimeSeriesList []*common.TimeSeries

cfg := p.a.GetConfig(queryExpr)
if cfg == nil {
cfg = p.a.GetConfig(queryExpr)
}
estimator := NewPercentileEstimator(cfg.percentile)
estimator = WithMargin(cfg.marginFraction, estimator)
estimator = WithTargetUtilization(cfg.targetUtilization, estimator)
Expand Down Expand Up @@ -112,7 +114,7 @@ func (p *percentilePrediction) getPredictedValues(ctx context.Context, namer met
return predictedTimeSeriesList
}
if signals != nil && status == prediction.StatusReady {
return p.getPredictedValuesFromSignals(queryExpr, signals)
return p.getPredictedValuesFromSignals(queryExpr, signals, nil)
}
select {
case <-ctx.Done():
Expand Down Expand Up @@ -141,7 +143,7 @@ func (p *percentilePrediction) QueryRealtimePredictedValuesOnce(_ context.Contex

signals, status := p.a.GetSignals(queryExpr)
if signals != nil && status == prediction.StatusReady {
return p.getPredictedValuesFromSignals(queryExpr, signals), nil
return p.getPredictedValuesFromSignals(queryExpr, signals, nil), nil
} else {
// namer metric query is firstly registered by this caller
// we first fetch history data to construct the histogram model, then get estimation.
Expand Down Expand Up @@ -193,7 +195,7 @@ func (p *percentilePrediction) process(namer metricnaming.MetricNamer, config co
}
}

return p.getPredictedValuesFromSignals(queryExpr, signals), nil
return p.getPredictedValuesFromSignals(queryExpr, signals, cfg), nil
}

func NewPrediction(realtimeProvider providers.RealTime, historyProvider providers.History) prediction.Interface {
Expand Down

0 comments on commit f4299f4

Please sign in to comment.