refactored large func

This commit is contained in:
2026-06-25 14:16:35 +02:00
parent e1291d1d92
commit d60983411e

View File

@@ -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
}