Skip to content

Commit

Permalink
OBSDA-553: add provider name to cluster_infrastructure_provider when …
Browse files Browse the repository at this point in the history
…platform external

Signed-off-by: Riccardo Piccoli <rpiccoli@redhat.com>
  • Loading branch information
rccrdpccl committed Feb 7, 2024
1 parent 6080a80 commit 8561852
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions pkg/operator/configmetrics/configmetrics.go
Expand Up @@ -19,7 +19,7 @@ func Register(configInformer configinformers.SharedInformerFactory) {
cloudProvider: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "cluster_infrastructure_provider",
Help: "Reports whether the cluster is configured with an infrastructure provider. type is unset if no cloud provider is recognized or set to the constant used by the Infrastructure config. region is set when the cluster clearly identifies a region within the provider. The value is 1 if a cloud provider is set or 0 if it is unset.",
}, []string{"type", "region"}),
}, []string{"type", "region", "external"}),
featuregateLister: configInformer.Config().V1().FeatureGates().Lister(),
featureSet: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "cluster_feature_set",
Expand Down Expand Up @@ -49,11 +49,22 @@ func (m *configMetrics) Create(version *semver.Version) bool {

// Describe reports the metadata for metrics to the prometheus collector.
func (m *configMetrics) Describe(ch chan<- *prometheus.Desc) {
ch <- m.cloudProvider.WithLabelValues("", "").Desc()
ch <- m.cloudProvider.WithLabelValues("", "", "").Desc()
ch <- m.featureSet.WithLabelValues("").Desc()
ch <- m.proxyEnablement.WithLabelValues("").Desc()
}

// Returns external platform name if present, empty string otherwise
func getExternalPlatformName(infra *configv1.Infrastructure) string {
if infra == nil {
return ""
}
if infra.Spec.PlatformSpec.External == nil {
return ""
}
return infra.Spec.PlatformSpec.External.PlatformName
}

// Collect calculates metrics from the cached config and reports them to the prometheus collector.
func (m *configMetrics) Collect(ch chan<- prometheus.Metric) {
if infra, err := m.infrastructureLister.Get("cluster"); err == nil {
Expand All @@ -64,14 +75,18 @@ func (m *configMetrics) Collect(ch chan<- prometheus.Metric) {
// it is illegal to set type to empty string, so let the default case handle
// empty string (so we can detect it) while preserving the constant None here
case status.Type == configv1.NonePlatformType:
g = m.cloudProvider.WithLabelValues(string(status.Type), "")
g = m.cloudProvider.WithLabelValues(string(status.Type), "", "")
value = 0
case status.AWS != nil:
g = m.cloudProvider.WithLabelValues(string(status.Type), status.AWS.Region)
g = m.cloudProvider.WithLabelValues(string(status.Type), status.AWS.Region, "")
case status.GCP != nil:
g = m.cloudProvider.WithLabelValues(string(status.Type), status.GCP.Region)
g = m.cloudProvider.WithLabelValues(string(status.Type), status.GCP.Region, "")
case status.Type == configv1.ExternalPlatformType:
// Third party providers can integrate with external platform.
platformName := getExternalPlatformName(infra)
g = m.cloudProvider.WithLabelValues(string(status.Type), "", platformName)
default:
g = m.cloudProvider.WithLabelValues(string(status.Type), "")
g = m.cloudProvider.WithLabelValues(string(status.Type), "", "")
}
g.Set(value)
ch <- g
Expand Down

0 comments on commit 8561852

Please sign in to comment.