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
38 changes: 23 additions & 15 deletions pkg/cvo/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"time"

"github.com/prometheus/client_golang/prometheus"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/sets"
Expand Down Expand Up @@ -286,28 +287,35 @@ func (m *operatorMetrics) Collect(ch chan<- prometheus.Metric) {
ch <- g
}

installer, err := m.optr.cmConfigLister.Get(internal.InstallerConfigMap)
if err == nil {
version := "<missing>"
invoker := "<missing>"

if v, ok := installer.Data["version"]; ok {
version = v
}
if i, ok := installer.Data["invoker"]; ok {
invoker = i
}

g := m.clusterInstaller.WithLabelValues("openshift-install", version, invoker)
g.Set(1.0)
ch <- g
if installer, err := m.optr.cmConfigLister.Get(internal.InstallerConfigMap); err == nil {
ch <- gaugeFromInstallConfigMap(installer, m.clusterInstaller, "openshift-install")
} else if !apierrors.IsNotFound(err) {
} else if manifests, err := m.optr.cmConfigLister.Get(internal.ManifestsConfigMap); err == nil {
ch <- gaugeFromInstallConfigMap(manifests, m.clusterInstaller, "other")
} else if apierrors.IsNotFound(err) {
g := m.clusterInstaller.WithLabelValues("", "", "")
g.Set(1.0)
ch <- g
}
}

func gaugeFromInstallConfigMap(cm *corev1.ConfigMap, gauge *prometheus.GaugeVec, installType string) prometheus.Gauge {
version := "<missing>"
invoker := "<missing>"

if v, ok := cm.Data["version"]; ok {
version = v
}
if i, ok := cm.Data["invoker"]; ok {
invoker = i
}

g := gauge.WithLabelValues(installType, version, invoker)
g.Set(1.0)

return g
}

// mostRecentTimestamp finds the most recent change recorded to the status and
// returns the seconds since the epoch.
func mostRecentTimestamp(cv *configv1.ClusterVersion) int64 {
Expand Down
50 changes: 49 additions & 1 deletion pkg/cvo/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ func Test_operatorMetrics_Collect(t *testing.T) {
},
},
{
name: "collects openshift-install info",
name: "collects legacy openshift-install info",
optr: &Operator{
releaseVersion: "0.0.2",
releaseImage: "test/image:1",
Expand All @@ -424,6 +424,54 @@ func Test_operatorMetrics_Collect(t *testing.T) {
expectMetric(t, metrics[1], 1, map[string]string{"type": "openshift-install", "version": "v0.0.2", "invoker": "jane"})
},
},
{
name: "collects openshift-install info",
optr: &Operator{
releaseVersion: "0.0.2",
releaseImage: "test/image:1",
releaseCreated: time.Unix(3, 0),
cmConfigLister: &cmConfigLister{
Items: []*corev1.ConfigMap{
{
ObjectMeta: metav1.ObjectMeta{Name: "openshift-install"},
Data: map[string]string{"version": "v0.0.2", "invoker": "jane"},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "openshift-install-manifests"},
Data: map[string]string{"version": "v0.0.1", "invoker": "bill"},
},
},
},
},
wants: func(t *testing.T, metrics []prometheus.Metric) {
if len(metrics) != 2 {
t.Fatalf("Unexpected metrics %s", spew.Sdump(metrics))
}
expectMetric(t, metrics[0], 3, map[string]string{"type": "current", "version": "0.0.2", "image": "test/image:1"})
expectMetric(t, metrics[1], 1, map[string]string{"type": "openshift-install", "version": "v0.0.2", "invoker": "jane"})
},
},
{
name: "collects openshift-install-manifests info",
optr: &Operator{
releaseVersion: "0.0.2",
releaseImage: "test/image:1",
releaseCreated: time.Unix(3, 0),
cmConfigLister: &cmConfigLister{
Items: []*corev1.ConfigMap{{
ObjectMeta: metav1.ObjectMeta{Name: "openshift-install-manifests"},
Data: map[string]string{"version": "v0.0.1", "invoker": "bill"},
}},
},
},
wants: func(t *testing.T, metrics []prometheus.Metric) {
if len(metrics) != 2 {
t.Fatalf("Unexpected metrics %s", spew.Sdump(metrics))
}
expectMetric(t, metrics[0], 3, map[string]string{"type": "current", "version": "0.0.2", "image": "test/image:1"})
expectMetric(t, metrics[1], 1, map[string]string{"type": "other", "version": "v0.0.1", "invoker": "bill"})
},
},
{
name: "collects empty openshift-install info",
optr: &Operator{
Expand Down
1 change: 1 addition & 0 deletions pkg/internal/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ package internal
const (
ConfigNamespace = "openshift-config"
InstallerConfigMap = "openshift-install"
ManifestsConfigMap = "openshift-install-manifests"
)