diff --git a/pkg/es/ilm_forecast.go b/pkg/es/ilm_forecast.go index dc29014..0b92a8d 100644 --- a/pkg/es/ilm_forecast.go +++ b/pkg/es/ilm_forecast.go @@ -35,6 +35,7 @@ import ( var ( matchDuration = regexp.MustCompile(`(\d+)([dhms])`) + IlmPhaseOrder = []string{"hot", "warm", "cold", "frozen", "delete"} ) type NextPhase struct { @@ -161,6 +162,7 @@ func virtualAge(phase *PhaseData) time.Duration { return time.Duration(virtualAge) * time.Second } +// Retrieve all index, ilm-explain and ilm-policies in parallel func getIlmPhaseData(conf *cfg.Config) ([]PhaseData, error) { responses := make(chan apiResponse, 3) wg := &sync.WaitGroup{} @@ -254,10 +256,7 @@ func getIlmPhaseData(conf *cfg.Config) ([]PhaseData, error) { return list, nil } -func findNextPhase(policy types.IlmPolicy, currentPhase string) *NextPhase { - // phase list to determine which comes next - order := []string{"hot", "warm", "cold", "frozen", "delete"} - +func registerPhases(policy types.IlmPolicy, currentPhase string) (map[string]*types.Phase, int) { // register phases configured in the policy phases := map[string]*types.Phase{ "hot": nil, @@ -271,7 +270,7 @@ func findNextPhase(policy types.IlmPolicy, currentPhase string) *NextPhase { start := 0 // register phases - for idx, phase := range order { + for idx, phase := range IlmPhaseOrder { switch phase { case "hot": if policy.Phases.Hot != nil { @@ -304,11 +303,18 @@ func findNextPhase(policy types.IlmPolicy, currentPhase string) *NextPhase { } } + return phases, start +} + +func findNextPhase(policy types.IlmPolicy, currentPhase string) *NextPhase { + // phase list to determine which comes next + phases, start := registerPhases(policy, currentPhase) + nextPhase := &NextPhase{} // finally determine which phase comes next // exception: hot, where we look for rollover rules - for idx, phase := range order { + for idx, phase := range IlmPhaseOrder { if idx < start { continue }