diff --git a/controllers/upgrade_information_collector.go b/controllers/upgrade_information_collector.go index a795352..fdcd870 100644 --- a/controllers/upgrade_information_collector.go +++ b/controllers/upgrade_information_collector.go @@ -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", @@ -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.", @@ -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 @@ -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( @@ -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( @@ -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, @@ -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 } diff --git a/controllers/upgrade_information_collector_test.go b/controllers/upgrade_information_collector_test.go index 63cefc1..36be238 100644 --- a/controllers/upgrade_information_collector_test.go +++ b/controllers/upgrade_information_collector_test.go @@ -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", } @@ -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{ @@ -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