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:
@@ -4,7 +4,11 @@
|
||||
// license that can be found in the LICENSE file.
|
||||
package metricdispatch
|
||||
|
||||
import "math"
|
||||
import (
|
||||
"math"
|
||||
|
||||
"github.com/ClusterCockpit/cc-backend/internal/config"
|
||||
)
|
||||
|
||||
type ResamplePolicy string
|
||||
|
||||
@@ -14,18 +18,12 @@ const (
|
||||
ResamplePolicyHigh ResamplePolicy = "high"
|
||||
)
|
||||
|
||||
// TargetPointsForPolicy returns the target number of data points for a given policy.
|
||||
// TargetPointsForPolicy returns the target number of data points for a given
|
||||
// policy. The table lives in the config package so that the requested
|
||||
// resolution and the resampler's MinimumRequiredPoints threshold can never
|
||||
// diverge.
|
||||
func TargetPointsForPolicy(policy ResamplePolicy) int {
|
||||
switch policy {
|
||||
case ResamplePolicyLow:
|
||||
return 200
|
||||
case ResamplePolicyMedium:
|
||||
return 500
|
||||
case ResamplePolicyHigh:
|
||||
return 1000
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
return config.TargetPointsForPolicy(string(policy))
|
||||
}
|
||||
|
||||
// ComputeResolution computes the resampling resolution in seconds for a given
|
||||
|
||||
Reference in New Issue
Block a user