-
Notifications
You must be signed in to change notification settings - Fork 5
Add prom for failover res #669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
umswmayj
wants to merge
4
commits into
main
Choose a base branch
from
add-prom-for-failover-res
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| // Copyright SAP SE | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package failover | ||
|
|
||
| import ( | ||
| "github.com/prometheus/client_golang/prometheus" | ||
| ) | ||
|
|
||
| var azLabel = []string{"availability_zone"} | ||
|
|
||
| // FailoverMonitor provides Prometheus metrics for the failover reconciliation controller. | ||
| type FailoverMonitor struct { | ||
| reconciliationRuns *prometheus.CounterVec | ||
| reconciliationDuration *prometheus.HistogramVec | ||
| totalVMs *prometheus.GaugeVec | ||
| totalReservations *prometheus.GaugeVec | ||
| vmsMissingFailover *prometheus.GaugeVec | ||
| vmsProcessed *prometheus.CounterVec | ||
| reservationsNeeded *prometheus.CounterVec | ||
| reservationsReused *prometheus.CounterVec | ||
| reservationsCreated *prometheus.CounterVec | ||
| reservationsFailed *prometheus.CounterVec | ||
| reservationsUpdated *prometheus.CounterVec | ||
| reservationsDeleted *prometheus.CounterVec | ||
| } | ||
|
|
||
| // NewFailoverMonitor creates a new monitor with Prometheus metrics. | ||
| func NewFailoverMonitor() *FailoverMonitor { | ||
| m := &FailoverMonitor{ | ||
| reconciliationRuns: prometheus.NewCounterVec(prometheus.CounterOpts{ | ||
| Name: "cortex_failover_reconciliation_runs_total", | ||
| Help: "Total number of failover periodic reconciliation runs since pod restart", | ||
| }, azLabel), | ||
| reconciliationDuration: prometheus.NewHistogramVec(prometheus.HistogramOpts{ | ||
| Name: "cortex_failover_reconciliation_duration_seconds", | ||
| Help: "Duration of failover periodic reconciliation cycles", | ||
| Buckets: []float64{0.1, 0.25, 0.5, 1, 2.5, 5, 10, 30, 60}, | ||
| }, azLabel), | ||
| totalVMs: prometheus.NewGaugeVec(prometheus.GaugeOpts{ | ||
| Name: "cortex_failover_reconciliation_total_vms", | ||
| Help: "Total number of VMs seen during the last reconciliation", | ||
| }, azLabel), | ||
| totalReservations: prometheus.NewGaugeVec(prometheus.GaugeOpts{ | ||
| Name: "cortex_failover_reconciliation_total_reservations", | ||
| Help: "Total number of failover reservations during the last reconciliation", | ||
| }, azLabel), | ||
| vmsMissingFailover: prometheus.NewGaugeVec(prometheus.GaugeOpts{ | ||
| Name: "cortex_failover_reconciliation_vms_missing_failover", | ||
| Help: "Number of VMs missing required failover reservations during the last reconciliation", | ||
| }, azLabel), | ||
| vmsProcessed: prometheus.NewCounterVec(prometheus.CounterOpts{ | ||
| Name: "cortex_failover_reconciliation_vms_processed_total", | ||
| Help: "Total number of VMs processed across all reconciliation cycles since pod restart", | ||
| }, azLabel), | ||
| reservationsNeeded: prometheus.NewCounterVec(prometheus.CounterOpts{ | ||
| Name: "cortex_failover_reconciliation_reservations_needed_total", | ||
| Help: "Total number of reservations needed across all reconciliation cycles since pod restart", | ||
| }, azLabel), | ||
| reservationsReused: prometheus.NewCounterVec(prometheus.CounterOpts{ | ||
| Name: "cortex_failover_reconciliation_reservations_reused_total", | ||
| Help: "Total number of reservations reused across all reconciliation cycles since pod restart", | ||
| }, azLabel), | ||
| reservationsCreated: prometheus.NewCounterVec(prometheus.CounterOpts{ | ||
| Name: "cortex_failover_reconciliation_reservations_created_total", | ||
| Help: "Total number of reservations created across all reconciliation cycles since pod restart", | ||
| }, azLabel), | ||
| reservationsFailed: prometheus.NewCounterVec(prometheus.CounterOpts{ | ||
| Name: "cortex_failover_reconciliation_reservations_failed_total", | ||
| Help: "Total number of failed reservation attempts across all reconciliation cycles since pod restart", | ||
| }, azLabel), | ||
| reservationsUpdated: prometheus.NewCounterVec(prometheus.CounterOpts{ | ||
| Name: "cortex_failover_reconciliation_reservations_updated_total", | ||
| Help: "Total number of reservation allocation updates across all reconciliation cycles since pod restart", | ||
| }, azLabel), | ||
| reservationsDeleted: prometheus.NewCounterVec(prometheus.CounterOpts{ | ||
| Name: "cortex_failover_reconciliation_reservations_deleted_total", | ||
| Help: "Total number of empty reservations deleted across all reconciliation cycles since pod restart", | ||
| }, azLabel), | ||
| } | ||
|
|
||
| // Pre-initialize the aggregate label so metrics appear even before the first reconciliation. | ||
| m.preInitialize("") | ||
|
|
||
| return m | ||
| } | ||
|
|
||
| func (m *FailoverMonitor) preInitialize(az string) { | ||
| m.reconciliationRuns.WithLabelValues(az) | ||
| m.reconciliationDuration.WithLabelValues(az) | ||
| m.totalVMs.WithLabelValues(az) | ||
| m.totalReservations.WithLabelValues(az) | ||
| m.vmsMissingFailover.WithLabelValues(az) | ||
| m.vmsProcessed.WithLabelValues(az) | ||
| m.reservationsNeeded.WithLabelValues(az) | ||
| m.reservationsReused.WithLabelValues(az) | ||
| m.reservationsCreated.WithLabelValues(az) | ||
| m.reservationsFailed.WithLabelValues(az) | ||
| m.reservationsUpdated.WithLabelValues(az) | ||
| m.reservationsDeleted.WithLabelValues(az) | ||
| } | ||
|
|
||
| // RecordReconciliation records all metrics from a single reconciliation cycle. | ||
| // The availabilityZone parameter allows future per-AZ reporting; pass "" for aggregate. | ||
| func (m *FailoverMonitor) RecordReconciliation(summary reconcileSummary, availabilityZone string) { | ||
| m.reconciliationRuns.WithLabelValues(availabilityZone).Inc() | ||
| m.reconciliationDuration.WithLabelValues(availabilityZone).Observe(summary.duration.Seconds()) | ||
| m.totalVMs.WithLabelValues(availabilityZone).Set(float64(summary.totalVMs)) | ||
| m.totalReservations.WithLabelValues(availabilityZone).Set(float64(summary.totalReservations)) | ||
| m.vmsMissingFailover.WithLabelValues(availabilityZone).Set(float64(summary.vmsMissingFailover)) | ||
| m.vmsProcessed.WithLabelValues(availabilityZone).Add(float64(summary.vmsProcessed)) | ||
| m.reservationsNeeded.WithLabelValues(availabilityZone).Add(float64(summary.reservationsNeeded)) | ||
| m.reservationsReused.WithLabelValues(availabilityZone).Add(float64(summary.totalReused)) | ||
| m.reservationsCreated.WithLabelValues(availabilityZone).Add(float64(summary.totalCreated)) | ||
| m.reservationsFailed.WithLabelValues(availabilityZone).Add(float64(summary.totalFailed)) | ||
| m.reservationsUpdated.WithLabelValues(availabilityZone).Add(float64(summary.reservationsUpdated)) | ||
| m.reservationsDeleted.WithLabelValues(availabilityZone).Add(float64(summary.reservationsDeleted)) | ||
| } | ||
|
|
||
| // Describe implements prometheus.Collector. | ||
| func (m *FailoverMonitor) Describe(ch chan<- *prometheus.Desc) { | ||
| m.reconciliationRuns.Describe(ch) | ||
| m.reconciliationDuration.Describe(ch) | ||
| m.totalVMs.Describe(ch) | ||
| m.totalReservations.Describe(ch) | ||
| m.vmsMissingFailover.Describe(ch) | ||
| m.vmsProcessed.Describe(ch) | ||
| m.reservationsNeeded.Describe(ch) | ||
| m.reservationsReused.Describe(ch) | ||
| m.reservationsCreated.Describe(ch) | ||
| m.reservationsFailed.Describe(ch) | ||
| m.reservationsUpdated.Describe(ch) | ||
| m.reservationsDeleted.Describe(ch) | ||
| } | ||
|
|
||
| // Collect implements prometheus.Collector. | ||
| func (m *FailoverMonitor) Collect(ch chan<- prometheus.Metric) { | ||
| m.reconciliationRuns.Collect(ch) | ||
| m.reconciliationDuration.Collect(ch) | ||
| m.totalVMs.Collect(ch) | ||
| m.totalReservations.Collect(ch) | ||
| m.vmsMissingFailover.Collect(ch) | ||
| m.vmsProcessed.Collect(ch) | ||
| m.reservationsNeeded.Collect(ch) | ||
| m.reservationsReused.Collect(ch) | ||
| m.reservationsCreated.Collect(ch) | ||
| m.reservationsFailed.Collect(ch) | ||
| m.reservationsUpdated.Collect(ch) | ||
| m.reservationsDeleted.Collect(ch) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
totalReservationsis underreported after reservation creation.On Line 334,
summary.totalReservations = len(failoverReservations)uses the pre-creation slice size. Since step 6 can create reservations, the logged/recorded total will be too low.🔧 Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents