Skip to content

Commit e57f170

Browse files
committed
metrics: include upi installs in cluster_installer
This is a follow-on to c147732, which added the cluster_installer series originally. Recently, the installer started injecting a new ConfigMap (openshift-install-manifests), which includes information about the manifest generation stage of the install. Because this phase always happens, this ConfigMap is included in every cluster created by this newer installer. We can now look at the presence of this new ConfigMap and the absence of the openshift-install ConfigMap to determine that the cluster was installed using UPI. We can additionally look at its contents to determine information about the installer.
1 parent 294dc15 commit e57f170

File tree

3 files changed

+73
-16
lines changed

3 files changed

+73
-16
lines changed

pkg/cvo/metrics.go

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"time"
55

66
"github.com/prometheus/client_golang/prometheus"
7+
corev1 "k8s.io/api/core/v1"
78
apierrors "k8s.io/apimachinery/pkg/api/errors"
89
"k8s.io/apimachinery/pkg/labels"
910
"k8s.io/apimachinery/pkg/util/sets"
@@ -286,28 +287,35 @@ func (m *operatorMetrics) Collect(ch chan<- prometheus.Metric) {
286287
ch <- g
287288
}
288289

289-
installer, err := m.optr.cmConfigLister.Get(internal.InstallerConfigMap)
290-
if err == nil {
291-
version := "<missing>"
292-
invoker := "<missing>"
293-
294-
if v, ok := installer.Data["version"]; ok {
295-
version = v
296-
}
297-
if i, ok := installer.Data["invoker"]; ok {
298-
invoker = i
299-
}
300-
301-
g := m.clusterInstaller.WithLabelValues("openshift-install", version, invoker)
302-
g.Set(1.0)
303-
ch <- g
290+
if installer, err := m.optr.cmConfigLister.Get(internal.InstallerConfigMap); err == nil {
291+
ch <- gaugeFromInstallConfigMap(installer, m.clusterInstaller, "openshift-install")
292+
} else if !apierrors.IsNotFound(err) {
293+
} else if manifests, err := m.optr.cmConfigLister.Get(internal.ManifestsConfigMap); err == nil {
294+
ch <- gaugeFromInstallConfigMap(manifests, m.clusterInstaller, "other")
304295
} else if apierrors.IsNotFound(err) {
305296
g := m.clusterInstaller.WithLabelValues("", "", "")
306297
g.Set(1.0)
307298
ch <- g
308299
}
309300
}
310301

302+
func gaugeFromInstallConfigMap(cm *corev1.ConfigMap, gauge *prometheus.GaugeVec, installType string) prometheus.Gauge {
303+
version := "<missing>"
304+
invoker := "<missing>"
305+
306+
if v, ok := cm.Data["version"]; ok {
307+
version = v
308+
}
309+
if i, ok := cm.Data["invoker"]; ok {
310+
invoker = i
311+
}
312+
313+
g := gauge.WithLabelValues(installType, version, invoker)
314+
g.Set(1.0)
315+
316+
return g
317+
}
318+
311319
// mostRecentTimestamp finds the most recent change recorded to the status and
312320
// returns the seconds since the epoch.
313321
func mostRecentTimestamp(cv *configv1.ClusterVersion) int64 {

pkg/cvo/metrics_test.go

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ func Test_operatorMetrics_Collect(t *testing.T) {
404404
},
405405
},
406406
{
407-
name: "collects openshift-install info",
407+
name: "collects legacy openshift-install info",
408408
optr: &Operator{
409409
releaseVersion: "0.0.2",
410410
releaseImage: "test/image:1",
@@ -424,6 +424,54 @@ func Test_operatorMetrics_Collect(t *testing.T) {
424424
expectMetric(t, metrics[1], 1, map[string]string{"type": "openshift-install", "version": "v0.0.2", "invoker": "jane"})
425425
},
426426
},
427+
{
428+
name: "collects openshift-install info",
429+
optr: &Operator{
430+
releaseVersion: "0.0.2",
431+
releaseImage: "test/image:1",
432+
releaseCreated: time.Unix(3, 0),
433+
cmConfigLister: &cmConfigLister{
434+
Items: []*corev1.ConfigMap{
435+
{
436+
ObjectMeta: metav1.ObjectMeta{Name: "openshift-install"},
437+
Data: map[string]string{"version": "v0.0.2", "invoker": "jane"},
438+
},
439+
{
440+
ObjectMeta: metav1.ObjectMeta{Name: "openshift-install-manifests"},
441+
Data: map[string]string{"version": "v0.0.1", "invoker": "bill"},
442+
},
443+
},
444+
},
445+
},
446+
wants: func(t *testing.T, metrics []prometheus.Metric) {
447+
if len(metrics) != 2 {
448+
t.Fatalf("Unexpected metrics %s", spew.Sdump(metrics))
449+
}
450+
expectMetric(t, metrics[0], 3, map[string]string{"type": "current", "version": "0.0.2", "image": "test/image:1"})
451+
expectMetric(t, metrics[1], 1, map[string]string{"type": "openshift-install", "version": "v0.0.2", "invoker": "jane"})
452+
},
453+
},
454+
{
455+
name: "collects openshift-install-manifests info",
456+
optr: &Operator{
457+
releaseVersion: "0.0.2",
458+
releaseImage: "test/image:1",
459+
releaseCreated: time.Unix(3, 0),
460+
cmConfigLister: &cmConfigLister{
461+
Items: []*corev1.ConfigMap{{
462+
ObjectMeta: metav1.ObjectMeta{Name: "openshift-install-manifests"},
463+
Data: map[string]string{"version": "v0.0.1", "invoker": "bill"},
464+
}},
465+
},
466+
},
467+
wants: func(t *testing.T, metrics []prometheus.Metric) {
468+
if len(metrics) != 2 {
469+
t.Fatalf("Unexpected metrics %s", spew.Sdump(metrics))
470+
}
471+
expectMetric(t, metrics[0], 3, map[string]string{"type": "current", "version": "0.0.2", "image": "test/image:1"})
472+
expectMetric(t, metrics[1], 1, map[string]string{"type": "other", "version": "v0.0.1", "invoker": "bill"})
473+
},
474+
},
427475
{
428476
name: "collects empty openshift-install info",
429477
optr: &Operator{

pkg/internal/constants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ package internal
33
const (
44
ConfigNamespace = "openshift-config"
55
InstallerConfigMap = "openshift-install"
6+
ManifestsConfigMap = "openshift-install-manifests"
67
)

0 commit comments

Comments
 (0)