Skip to content

Commit

Permalink
Add metric for UpgradeConfig.Spec.PinVersionWindow (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
bastjan authored Oct 3, 2024
1 parent 82dd9a6 commit 89143cc
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 23 deletions.
68 changes: 45 additions & 23 deletions controllers/upgrade_information_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,6 @@ var jobStartBeforeDesc = prometheus.NewDesc(
nil,
)

var upgradeConfigInfoDesc = prometheus.NewDesc(
MetricsNamespace+"_upgradeconfig_info",
"Information about the upgradeconfig object",
[]string{
"upgradeconfig",
"cron",
"location",
"suspended",
},
nil,
)

var upgradeSuspensionWindowInfoDesc = prometheus.NewDesc(
MetricsNamespace+"_upgradesuspensionwindow_info",
"Information about the upgradesuspensionwindow object",
Expand Down Expand Up @@ -130,6 +118,27 @@ var upgradeSuspensionWindowMatchingConfigsDesc = prometheus.NewDesc(
nil,
)

var upgradeConfigInfoDesc = prometheus.NewDesc(
MetricsNamespace+"_upgradeconfig_info",
"Information about the upgradeconfig object",
[]string{
"upgradeconfig",
"cron",
"location",
"suspended",
},
nil,
)

var upgradeConfigPinVersionWindowDesc = prometheus.NewDesc(
MetricsNamespace+"_upgradeconfig_pin_version_window_seconds",
"The value of the pinVersionWindow field of the upgradeconfig.",
[]string{
"upgradeconfig",
},
nil,
)

var upgradeConfigNextPossibleScheduleDesc = prometheus.NewDesc(
MetricsNamespace+"_upgradeconfig_next_possible_schedule_timestamp_seconds",
"The value of the time field of the next possible schedule for an upgrade.",
Expand Down Expand Up @@ -160,6 +169,7 @@ func (*UpgradeInformationCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- jobStartAfterDesc
ch <- jobStartBeforeDesc
ch <- upgradeConfigInfoDesc
ch <- upgradeConfigPinVersionWindowDesc
ch <- upgradeConfigNextPossibleScheduleDesc
ch <- upgradeSuspensionWindowInfoDesc
ch <- upgradeSuspensionWindowStartDesc
Expand Down Expand Up @@ -216,10 +226,11 @@ func (m *UpgradeInformationCollector) Collect(ch chan<- prometheus.Metric) {

var windows managedupgradev1beta1.UpgradeSuspensionWindowList
if err := m.Client.List(ctx, &windows); err != nil {
ch <- prometheus.NewInvalidMetric(upgradeSuspensionWindowInfoDesc, fmt.Errorf("failed to list upgrade suspension windows: %w", err))
ch <- prometheus.NewInvalidMetric(upgradeSuspensionWindowStartDesc, fmt.Errorf("failed to list upgrade suspension windows: %w", err))
ch <- prometheus.NewInvalidMetric(upgradeSuspensionWindowEndDesc, fmt.Errorf("failed to list upgrade suspension windows: %w", err))
ch <- prometheus.NewInvalidMetric(upgradeSuspensionWindowMatchingConfigsDesc, fmt.Errorf("failed to list upgrade suspension windows: %w", err))
ferr := fmt.Errorf("failed to list upgrade suspension windows: %w", err)
ch <- prometheus.NewInvalidMetric(upgradeSuspensionWindowInfoDesc, ferr)
ch <- prometheus.NewInvalidMetric(upgradeSuspensionWindowStartDesc, ferr)
ch <- prometheus.NewInvalidMetric(upgradeSuspensionWindowEndDesc, ferr)
ch <- prometheus.NewInvalidMetric(upgradeSuspensionWindowMatchingConfigsDesc, ferr)
} else {
for _, window := range windows.Items {
ch <- prometheus.MustNewConstMetric(
Expand Down Expand Up @@ -255,7 +266,10 @@ func (m *UpgradeInformationCollector) Collect(ch chan<- prometheus.Metric) {

var configs managedupgradev1beta1.UpgradeConfigList
if err := m.Client.List(ctx, &configs); err != nil {
ch <- prometheus.NewInvalidMetric(upgradeConfigNextPossibleScheduleDesc, fmt.Errorf("failed to list upgrade jobs: %w", err))
ferr := fmt.Errorf("failed to list upgrade configs: %w", err)
ch <- prometheus.NewInvalidMetric(upgradeConfigInfoDesc, ferr)
ch <- prometheus.NewInvalidMetric(upgradeConfigPinVersionWindowDesc, ferr)
ch <- prometheus.NewInvalidMetric(upgradeConfigNextPossibleScheduleDesc, ferr)
} else {
for _, config := range configs.Items {
ch <- prometheus.MustNewConstMetric(
Expand All @@ -267,6 +281,12 @@ func (m *UpgradeInformationCollector) Collect(ch chan<- prometheus.Metric) {
config.Spec.Schedule.Location,
strconv.FormatBool(config.Spec.Schedule.Suspend),
)
ch <- prometheus.MustNewConstMetric(
upgradeConfigPinVersionWindowDesc,
prometheus.GaugeValue,
float64(config.Spec.PinVersionWindow.Seconds()),
config.Name,
)
for i, nps := range config.Status.NextPossibleSchedules {
ch <- prometheus.MustNewConstMetric(
upgradeConfigNextPossibleScheduleDesc,
Expand All @@ -282,17 +302,19 @@ func (m *UpgradeInformationCollector) Collect(ch chan<- prometheus.Metric) {

var jobs managedupgradev1beta1.UpgradeJobList
if err := m.Client.List(ctx, &jobs); err != nil {
ch <- prometheus.NewInvalidMetric(jobStateDesc, fmt.Errorf("failed to list upgrade jobs: %w", err))
ch <- prometheus.NewInvalidMetric(jobStartAfterDesc, fmt.Errorf("failed to list upgrade jobs: %w", err))
ch <- prometheus.NewInvalidMetric(jobStartBeforeDesc, fmt.Errorf("failed to list upgrade jobs: %w", err))
ferr := fmt.Errorf("failed to list upgrade jobs: %w", err)
ch <- prometheus.NewInvalidMetric(jobStateDesc, ferr)
ch <- prometheus.NewInvalidMetric(jobStartAfterDesc, ferr)
ch <- prometheus.NewInvalidMetric(jobStartBeforeDesc, ferr)
return
}

var jobsHooks managedupgradev1beta1.UpgradeJobHookList
if err := m.Client.List(ctx, &jobsHooks); err != nil {
ch <- prometheus.NewInvalidMetric(jobStateDesc, fmt.Errorf("failed to list upgrade job hooks: %w", err))
ch <- prometheus.NewInvalidMetric(jobStartAfterDesc, fmt.Errorf("failed to list upgrade jobs: %w", err))
ch <- prometheus.NewInvalidMetric(jobStartBeforeDesc, fmt.Errorf("failed to list upgrade jobs: %w", err))
ferr := fmt.Errorf("failed to list upgrade job hooks: %w", err)
ch <- prometheus.NewInvalidMetric(jobStateDesc, ferr)
ch <- prometheus.NewInvalidMetric(jobStartAfterDesc, ferr)
ch <- prometheus.NewInvalidMetric(jobStartBeforeDesc, ferr)
return
}

Expand Down
6 changes: 6 additions & 0 deletions controllers/upgrade_information_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ openshift_upgrade_controller_upgradesuspensionwindow_end_timestamp_seconds{upgra
func Test_UpgradeConfigMetric(t *testing.T) {
expectedMetricNames := []string{
"openshift_upgrade_controller_upgradeconfig_info",
"openshift_upgrade_controller_upgradeconfig_pin_version_window_seconds",
"openshift_upgrade_controller_upgradeconfig_next_possible_schedule_timestamp_seconds",
}

Expand All @@ -340,6 +341,7 @@ func Test_UpgradeConfigMetric(t *testing.T) {
IsoWeek: "@odd",
Location: "UTC",
},
PinVersionWindow: metav1.Duration{Duration: time.Hour},
},
Status: managedupgradev1beta1.UpgradeConfigStatus{
NextPossibleSchedules: []managedupgradev1beta1.NextPossibleSchedule{
Expand All @@ -365,6 +367,10 @@ func Test_UpgradeConfigMetric(t *testing.T) {
# TYPE openshift_upgrade_controller_upgradeconfig_info gauge
openshift_upgrade_controller_upgradeconfig_info{cron="0 22 * * *",location="UTC",suspended="false",upgradeconfig="myconfig"} 1
# HELP openshift_upgrade_controller_upgradeconfig_pin_version_window_seconds The value of the pinVersionWindow field of the upgradeconfig.
# TYPE openshift_upgrade_controller_upgradeconfig_pin_version_window_seconds gauge
openshift_upgrade_controller_upgradeconfig_pin_version_window_seconds{upgradeconfig="myconfig"} 3600
# HELP openshift_upgrade_controller_upgradeconfig_next_possible_schedule_timestamp_seconds The value of the time field of the next possible schedule for an upgrade.
# TYPE openshift_upgrade_controller_upgradeconfig_next_possible_schedule_timestamp_seconds gauge
openshift_upgrade_controller_upgradeconfig_next_possible_schedule_timestamp_seconds{n="0",timestamp="2022-12-04T22:45:00Z",upgradeconfig="myconfig"} 1.6701939e+09
Expand Down

0 comments on commit 89143cc

Please sign in to comment.