Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 50 additions & 29 deletions gen/api/v1/mpa.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions internal/collector/historical_metrics_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,31 @@ func (c *HistoricalMetricsCollector) fetchContainerPercentiles(ctx context.Conte
sampleCount = int32(countVal)
}

// Pmax queries: max observed value over 24h for spike protection
var cpuPmax, memPmax int64

cpuPmaxQuery := fmt.Sprintf(
`max_over_time(rate(container_cpu_usage_seconds_total{namespace="%s", pod=~"%s", container="%s"}[5m])[24h:%s])`,
workload.Namespace, workload.PodRegex, containerName, historicalStepInterval,
)
cpuPmaxVal, err := c.queryScalar(ctx, cpuPmaxQuery, now)
if err != nil {
c.logger.V(1).Info("CPU pmax query failed", "error", err)
} else {
cpuPmax = int64(cpuPmaxVal * 1000) // Convert cores to millicores
}

memPmaxQuery := fmt.Sprintf(
`max_over_time(container_memory_working_set_bytes{namespace="%s", pod=~"%s", container="%s"}[24h])`,
workload.Namespace, workload.PodRegex, containerName,
)
memPmaxVal, err := c.queryScalar(ctx, memPmaxQuery, now)
if err != nil {
c.logger.V(1).Info("Memory pmax query failed", "error", err)
} else {
memPmax = int64(memPmaxVal)
}

return &gen.ContainerHistoricalMetrics{
ContainerName: containerName,
CpuP50: cpuValues[0.50],
Expand All @@ -199,6 +224,8 @@ func (c *HistoricalMetricsCollector) fetchContainerPercentiles(ctx context.Conte
MemP80: memValues[0.80],
MemP90: memValues[0.90],
MemP99: memValues[0.99],
CpuPmax: cpuPmax,
MemPmax: memPmax,
}, sampleCount
}

Expand Down
3 changes: 3 additions & 0 deletions internal/proto/mpa.proto
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ message ContainerHistoricalMetrics {
int64 disk_p90 = 21;
int64 disk_p95 = 22;
int64 disk_p99 = 23;
// Pmax (max observed over 24h window) for spike protection
int64 cpu_pmax = 24; // max CPU over 24h window (millicores)
int64 mem_pmax = 25; // max memory over 24h window (bytes)
}

// MpaStreamResponse wraps both real-time and historical data on the same stream
Expand Down
3 changes: 3 additions & 0 deletions proto/api/v1/mpa.proto
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ message ContainerHistoricalMetrics {
int64 disk_p90 = 21;
int64 disk_p95 = 22;
int64 disk_p99 = 23;
// Pmax (max observed over 24h window) for spike protection
int64 cpu_pmax = 24; // max CPU over 24h window (millicores)
int64 mem_pmax = 25; // max memory over 24h window (bytes)
}

// MpaStreamResponse wraps both real-time and historical data on the same stream
Expand Down