// ComputeStep computes the step size for a window
ComputeStep computes the step size for a window
// ComputeStep computes the step size for a window
func (p *PrometheusClient) ComputeStep(ctx context.Context, start, end time.Time) time.Duration {
	step := 5 * time.Second
	diff := end.Sub(start)
	if diff <= 10*time.Minute { 
		step = 5 * time.Second
	} else if diff <= 30*time.Minute { 
		step = 10 * time.Second
	} else if diff > 30*time.Minute && diff <= time.Hour { 
		step = 20 * time.Second
	} else if diff > 1*time.Hour && diff <= 3*time.Hour { 
		step = 1 * time.Minute
	} else if diff > 3*time.Hour && diff <= 6*time.Hour { 
		step = 2 * time.Minute
	} else if diff > 6*time.Hour && diff <= 1*24*time.Hour { 
		step = 8 * time.Minute
	} else if diff > 1*24*time.Hour && diff <= 2*24*time.Hour { 
		step = 16 * time.Minute
	} else if diff > 2*24*time.Hour && diff <= 4*24*time.Hour { 
		step = 32 * time.Minute
	} else if diff > 4*24*time.Hour && diff <= 7*24*time.Hour { 
		step = 56 * time.Minute
	} else if diff > 7*24*time.Hour && diff <= 15*24*time.Hour { 
		step = 2 * time.Hour
	} else if diff > 15*24*time.Hour && diff <= 1*30*24*time.Hour { 
		step = 4 * time.Hour
	} else if diff > 1*30*24*time.Hour && diff <= 3*30*24*time.Hour { 
		step = 12 * time.Hour
	} else if diff > 3*30*24*time.Hour && diff <= 6*30*24*time.Hour { 
		step = 1 * 24 * time.Hour
	} else if diff > 6*30*24*time.Hour && diff <= 1*12*30*24*time.Hour { 
		step = 2 * 24 * time.Hour
	} else if diff > 1*12*30*24*time.Hour && diff <= 2*12*30*24*time.Hour { 
		step = 4 * 24 * time.Hour
	} else if diff > 2*12*30*24*time.Hour && diff <= 5*12*30*24*time.Hour { 
		step = 10 * 24 * time.Hour
	} else {
		step = 30 * 24 * time.Hour
	}
	return step
}
func ( p * PrometheusClient ) ComputeStep ( ctx context . Context , start , end time . Time ) time . Duration { step := 5 * time . Second diff := end . Sub ( start ) if diff <= 10 * time . Minute { step = 5 * time . Second } else if diff <= 30 * time . Minute { step = 10 * time . Second } else if diff > 30 * time . Minute && diff <= time . Hour { step = 20 * time . Second } else if diff > 1 * time . Hour && diff <= 3 * time . Hour { step = 1 * time . Minute } else if diff > 3 * time . Hour && diff <= 6 * time . Hour { step = 2 * time . Minute } else if diff > 6 * time . Hour && diff <= 1 * 24 * time . Hour { step = 8 * time . Minute } else if diff > 1 * 24 * time . Hour && diff <= 2 * 24 * time . Hour { step = 16 * time . Minute } else if diff > 2 * 24 * time . Hour && diff <= 4 * 24 * time . Hour { step = 32 * time . Minute } else if diff > 4 * 24 * time . Hour && diff <= 7 * 24 * time . Hour { step = 56 * time . Minute } else if diff > 7 * 24 * time . Hour && diff <= 15 * 24 * time . Hour { step = 2 * time . Hour } else if diff > 15 * 24 * time . Hour && diff <= 1 * 30 * 24 * time . Hour { step = 4 * time . Hour } else if diff > 1 * 30 * 24 * time . Hour && diff <= 3 * 30 * 24 * time . Hour { step = 12 * time . Hour } else if diff > 3 * 30 * 24 * time . Hour && diff <= 6 * 30 * 24 * time . Hour { step = 1 * 24 * time . Hour } else if diff > 6 * 30 * 24 * time . Hour && diff <= 1 * 12 * 30 * 24 * time . Hour { step = 2 * 24 * time . Hour } else if diff > 1 * 12 * 30 * 24 * time . Hour && diff <= 2 * 12 * 30 * 24 * time . Hour { step = 4 * 24 * time . Hour } else if diff > 2 * 12 * 30 * 24 * time . Hour && diff <= 5 * 12 * 30 * 24 * time . Hour { step = 10 * 24 * time . Hour } else { step = 30 * 24 * time . Hour } return step }
ComputeStep computes the step size for a window
ComputeStep computes the step size for a window
// all calc. here are approx. // 10 mins // 30 mins // 60 mins/1hr // 3 time.Hour // 6 time.Hour // 24 time.Hour/1 day // 2 24*time.Hour // 4 24*time.Hour // 7 24*time.Hour // 15 24*time.Hour // 30 24*time.Hour/1 month // 3 months // 6 months // 1 year/12 months // 2 years // 5 years