mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2026-08-31 00:47:15 +02:00
fix: unify resample policy target-points table
The policy -> target-points mapping existed twice with different values: internal/config (300/600/1000) fed the resampler's MinimumRequiredPoints threshold, while internal/metricdispatch (200/500/1000) fed the requested resolution and the frontend target point count. Because the threshold was larger than the target, the resampler refused to downsample series whose length fell between the two numbers, silently dropping the resolution the backend had asked for. With the medium policy that covered every series between 500 and 600 points. Move the table into internal/config as the single source of truth (import direction rules out the reverse, since metricdispatch already imports config) and keep the 200/500/1000 values, which already drove the requested resolution. metricdispatch.TargetPointsForPolicy now delegates to it, so MinimumRequiredPoints equals the target and resampling happens exactly when a series exceeds it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
+28
-11
@@ -171,24 +171,41 @@ func Init(mainConfig json.RawMessage) {
|
||||
cclog.Abortf("Config Init: Could not decode config file '%s'.\nError: %s\n", mainConfig, err.Error())
|
||||
}
|
||||
|
||||
if Keys.EnableResampling != nil {
|
||||
policy := Keys.EnableResampling.DefaultPolicy
|
||||
if policy == "" {
|
||||
policy = "medium"
|
||||
}
|
||||
resampler.SetMinimumRequiredPoints(targetPointsForPolicy(policy))
|
||||
}
|
||||
initResampler()
|
||||
}
|
||||
|
||||
func targetPointsForPolicy(policy string) int {
|
||||
// initResampler aligns the resampler's MinimumRequiredPoints threshold with the
|
||||
// configured policy's target point count. The resampler must be allowed to act
|
||||
// exactly when a series is longer than that target; a different threshold here
|
||||
// silently drops resample requests for a band of job durations.
|
||||
func initResampler() {
|
||||
if Keys.EnableResampling == nil {
|
||||
return
|
||||
}
|
||||
|
||||
policy := Keys.EnableResampling.DefaultPolicy
|
||||
if policy == "" {
|
||||
policy = DefaultResamplePolicy
|
||||
}
|
||||
resampler.SetMinimumRequiredPoints(TargetPointsForPolicy(policy))
|
||||
}
|
||||
|
||||
// DefaultResamplePolicy is used when no resample policy is configured.
|
||||
const DefaultResamplePolicy = "medium"
|
||||
|
||||
// TargetPointsForPolicy returns the target number of data points for a resample
|
||||
// policy. This is the single source of truth: it feeds both the requested
|
||||
// resolution (via metricdispatch.ComputeResolution) and the resampler's
|
||||
// MinimumRequiredPoints threshold. Unknown or empty policies return 0.
|
||||
func TargetPointsForPolicy(policy string) int {
|
||||
switch policy {
|
||||
case "low":
|
||||
return 300
|
||||
return 200
|
||||
case "medium":
|
||||
return 600
|
||||
return 500
|
||||
case "high":
|
||||
return 1000
|
||||
default:
|
||||
return 600
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user