Plan: Per-User Resampling Preferences with Policy-Based Configuration
Context
Resampling is currently configured via explicit numerical parameters in config.json (minimum-points, resolutions, trigger). The resampling algorithm isn't configurable at all from the frontend. Users should be able to control two things from the UI settings:
Resampling policy (low/medium/high) — controls how aggressively data is downsampled, replacing the explicit resolutions/minimum-points/trigger numbers with automatic computation based on job duration and metric frequency
Resampling algorithm (LTTB/AVERAGE/SIMPLE) — controls which downsampling method is used
Both are persisted per-user. Zoom-to-refine continues to work, dynamically recomputing resolution from the visible time window.
Design
Policy mechanics
A policy defines a target datapoint count. The resolution is computed dynamically:
Policy
Target points
Use case
Low
~200
Fast rendering, overview
Medium
~500
Balanced (default)
High
~1000
Maximum detail
Resolution computation (new helper function):
code
targetResolution = ceil(duration / targetPoints)
// Round up to nearest multiple of metric frequency
resolution = ceil(targetResolution / frequency) * frequency
// If totalPoints <= targetPoints, no resampling (resolution = 0)
Medium (500): resolution = ceil(86400/500) = 173 → round to 180s (3×60)
High (1000): resolution = ceil(86400/1000) = 87 → round to 120s (2×60)
Example (60s frequency, 2h job = 120 points):
All policies: 120 ≤ 200, no resampling at any level
Zoom refinement
Currently the frontend zoom uses and to pick the next resolution level. With policies, this changes to:
Assistant
I'll start by reading the key files I need to understand before implementing.
Assistant
Let me read more context files in parallel.
Assistant
Let me read more key files in parallel.
Assistant
Now let me check one more thing - how config.tmpl passes resampleConfig to the settings page.
Assistant
Good, I have a complete picture now. Let me implement all the changes. I'll work in parallel where possible.
Assistant
Now let me write the test file and update the remaining files in parallel.
Assistant
Now update the resolvers. First, let me check what imports are at the top of schema.resolvers.go.
Assistant
Good, metricdispatch and repository are already imported. Now update the JobMetrics resolver.
Assistant
Now update the NodeMetricsList resolver.
Assistant
Now I need to add the helper functions. Let me find a good place for them — I'll add them at the end of the file or create a small helper file in the graph package.
Assistant
I'll create a separate file for these helpers since schema.resolvers.go is auto-generated.
Assistant
Now let me update the frontend files. First, update MetricPlot.svelte to support policy-based dynamic resolution.
Assistant
Let me fix the type issue in the resolver first.
Assistant
Now update the MetricPlot.svelte derived values and setScale hook.
Assistant
Now update the setScale hook to support dynamic resolution computation.
Assistant
I also need to check what frequency variable refers to in this file — it might be the native metric timestep. Let me check the MetricPlot around line 459 where resampleConfig is also referenced.
Assistant
The timestep prop is the native metric timestep. Now I'll update the setScale hook to support both array-based and policy-based resolution computation.
Assistant
Now update the route handler to pass policy-derived resample config. Let me read how the Resampling field is currently set.
Assistant
I need to augment the Resampling config that's passed to the page to include targetPoints when a user has a policy set. Let me update the route handler.
Assistant
I need to modify the route setup to derive policy-based resampling config from user preferences. The Resampling field is *config.ResampleConfig, and I need to add TargetPoints to that struct. Let me update the ResampleConfig struct.
Assistant
Now update the route handler to merge user's policy into the resampling config.
Assistant
Now add the resamplingForUser helper function and import metricdispatch.
Assistant
Now add the resamplingForUser function. Let me find the end of the file to add it.
Assistant
Now update the frontend settings UI — add the two new settings cards to PlotRenderOptions.svelte.
Assistant
Now add the two new cards before the closing </Row>.
Assistant
Now let's build and test.
Assistant
Backend compiles. Now run the tests.
Assistant
All tests pass. Let me run the full test suite.
Assistant
All tests pass. Here's a summary of what was implemented:
Changes Made
New files
internal/metricdispatch/resamplepolicy.go — Policy constants (low/medium/high) with target points (200/500/1000) and ComputeResolution() helper that dynamically computes resampling resolution from duration, frequency, and target points
internal/metricdispatch/resamplepolicy_test.go — Tests covering all policies, edge cases, and the examples from the plan
internal/graph/resample.go — Resolver helpers resolveResolutionFromPolicy() and resolveResampleAlgo() that read user preferences from the config DB
Modified files
— Added field to for policy-derived configs
resampleConfig.trigger
resampleConfig.resolutions
The trigger is derived from the policy's target points (e.g., trigger = targetPoints / 4, so ~50/125/250)
Instead of picking from a fixed resolutions array, the frontend computes the new resolution dynamically: newRes = ceil(visibleWindowDuration / targetPoints / frequency) * frequency
The resampleConfig passed to the frontend changes from {trigger, resolutions, minimumPoints} to {targetPoints, trigger} — both derived from the policy
Implicit: if totalPoints ≤ targetPoints, skip resampling
trigger: 30
Derived from targetPoints (targetPoints / 4)
No algo choice
Per-user resampleAlgo setting
The global EnableResampling config still acts as the on/off switch — if not configured, no resampling happens at all. But the explicit numerical parameters become optional overrides; the policy takes precedence when set.
Implementation Steps
Step 1: Add policy constants and resolution computation helper
New file: internal/metricdispatch/resamplepolicy.go
go
type ResamplePolicy string
const (
ResamplePolicyLow ResamplePolicy = "low"
ResamplePolicyMedium ResamplePolicy = "medium"
ResamplePolicyHigh ResamplePolicy = "high"
)
func TargetPointsForPolicy(policy ResamplePolicy) int
func ComputeResolution(duration int64, frequency int64, targetPoints int) int
ComputeResolution returns 0 (no resampling) when total points ≤ target, otherwise the rounded resolution in seconds.
Keep the trigger check: if (numX <= trigger && timestep !== frequency)
The frequency (native metric timestep) becomes the floor — never request finer than native
This is backward-compatible: if resampleConfig has old-style resolutions array, use the existing logic.
Step 5: Pass policy-derived config to frontend
In route handlers (where Page.Resampling is set): When a user has a policy, compute targetPoints and trigger from the policy and include them in the ResampleConfig passed to the template.
Key files to check: search for where Page.Resampling is populated.
Help text: "Controls how many data points are shown in metric plots. Low = fast overview (~200 points), Medium = balanced (~500), High = maximum detail (~1000)."
Resample Algorithm card:
Radio buttons: Default, LTTB, Average, Simple
Key: plotConfiguration_resampleAlgo
Help text: "Algorithm used when downsampling time-series data. LTTB preserves visual shape, Average smooths data, Simple picks every Nth point."
Both cards shown only when resampling is globally enabled (check resampleConfig via context — thread it as prop from UserSettings.svelte).
Files to Modify
File
Change
internal/metricdispatch/resamplepolicy.go
NEW — policy constants + ComputeResolution() helper
web/web.go
Add ResampleAlgo/ResamplePolicy to PlotConfiguration + UIDefaultsMap
internal/graph/schema.resolvers.go
Read user policy/algo preferences; compute resolution from policy
web/frontend/src/generic/plots/MetricPlot.svelte
Dynamic resolution computation on zoom (alongside existing array-based logic)
cc-lib resampler — called with computed values, no API change needed
config.jsonEnableResampling — still the global on/off switch; explicit values remain as fallback
Verification
go build ./cmd/cc-backend — compiles
go test ./internal/metricdispatch/... — test ComputeResolution() with various durations/frequencies/policies
go test ./... — all existing tests pass
Manual: set policy to "low", load a long job → verify fewer datapoints in response (check timestep field)
Manual: zoom into a plot → verify it refetches at finer resolution
Manual: set algo to "average", verify resampled data uses averaging
Manual: no preferences set → verify identical behavior to current (backward compat)
If you need specific details from before exiting plan mode (like exact code snippets, error messages, or content you generated), read the full transcript at: /Users/jan/.claude/projects/-Users-jan-tmp-cc-backend/6f9f7d00-7153-46bb-97c8-ea14c48ceb2f.jsonl
internal/config/config.go
TargetPoints
ResampleConfig
web/web.go — Added ResampleAlgo/ResamplePolicy to PlotConfiguration struct and UIDefaultsMap
internal/graph/schema.resolvers.go — JobMetrics and NodeMetricsList resolvers now check user policy/algo preferences before falling back to global config
internal/routerconfig/routes.go — Added resamplingForUser() that builds a policy-derived ResampleConfig with targetPoints and trigger when a user has a policy set
web/frontend/src/generic/plots/MetricPlot.svelte — Zoom handler now supports dynamic resolution computation from targetPoints (policy-based) alongside existing array-based logic
web/frontend/src/config/user/PlotRenderOptions.svelte — Two new settings cards (Resample Policy and Resample Algorithm) shown only when resampling is globally enabled