From 0db2d89598adacf1a04bf3d10e699bf35e330a5b Mon Sep 17 00:00:00 2001 From: Kirill Sushkov Date: Wed, 29 Nov 2023 17:59:47 +0100 Subject: [PATCH] add reconcilation metrics with feature flag(implemented for ProvisionedProduct only) Signed-off-by: Kirill Sushkov --- cmd/provider/main.go | 2 +- .../servicecatalog/provisionedproduct/setup.go | 2 +- pkg/utils/metrics/setup.go | 18 ++++++++---------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/cmd/provider/main.go b/cmd/provider/main.go index 85badcfd52..4244529087 100644 --- a/cmd/provider/main.go +++ b/cmd/provider/main.go @@ -56,7 +56,7 @@ func main() { namespace = app.Flag("namespace", "Namespace used to set as default scope in default secret store config.").Default("crossplane-system").Envar("POD_NAMESPACE").String() enableExternalSecretStores = app.Flag("enable-external-secret-stores", "Enable support for ExternalSecretStores.").Default("false").Envar("ENABLE_EXTERNAL_SECRET_STORES").Bool() enableManagementPolicies = app.Flag("enable-management-policies", "Enable support for Management Policies.").Default("false").Envar("ENABLE_MANAGEMENT_POLICIES").Bool() - enablePrometheusMetricsGroupReconciliation = app.Flag("enable-prom-metric-group-reconciliation", "Enable prometheus reconciliation metrics").Default("false").Envar("ENABLE_PROM_METRIC_GROUP_RECONCILIATION").Bool() + enablePrometheusMetricsGroupReconciliation = app.Flag("enable-prom-metrics-group-reconciliation", "Enable prometheus reconciliation metrics").Default("false").Envar("ENABLE_PROM_METRIC_GROUP_RECONCILIATION").Bool() ) kingpin.MustParse(app.Parse(os.Args[1:])) diff --git a/pkg/controller/servicecatalog/provisionedproduct/setup.go b/pkg/controller/servicecatalog/provisionedproduct/setup.go index 2c8a03cfe9..332f88c39f 100644 --- a/pkg/controller/servicecatalog/provisionedproduct/setup.go +++ b/pkg/controller/servicecatalog/provisionedproduct/setup.go @@ -455,10 +455,10 @@ func (c *custom) getProductID(productName *string) (string, error) { if output == nil { // DescribeProvisioningArtifact method fits much better, but it has a bug - it returns nothing if a product is a part of imported portfolio o, err := c.client.DescribeProduct(&input) - output = o if c.metrics.enabled { c.metrics.observe.Inc() } + output = o if err != nil { return "", errors.Wrap(err, errCouldNotLookupProduct) } diff --git a/pkg/utils/metrics/setup.go b/pkg/utils/metrics/setup.go index d661c5ba98..ee54884ea5 100644 --- a/pkg/utils/metrics/setup.go +++ b/pkg/utils/metrics/setup.go @@ -3,7 +3,7 @@ package metrics import ( "github.com/crossplane/crossplane-runtime/pkg/feature" "github.com/prometheus/client_golang/prometheus" - k8smetrics "sigs.k8s.io/controller-runtime/pkg/metrics" + "sigs.k8s.io/controller-runtime/pkg/metrics" "github.com/crossplane-contrib/provider-aws/pkg/features" ) @@ -31,21 +31,19 @@ type metric interface { } // SetupMetrics will register the known Prometheus metrics with controller-runtime's metrics registry -func SetupMetrics(ff *feature.Flags) error { - metrics := []metric{ +func SetupMetrics(flags *feature.Flags) error { + metricsList := []metric{ metricAWSAPICalls, } - reconciliationMetrics := []metric{ + reconciliationMetricsList := []metric{ MetricAWSAPICallsRec, MetricManagedResRec, } - - if ff.Enabled(features.EnableReconciliationMetrics) { - metrics = append(metrics, reconciliationMetrics...) + if flags.Enabled(features.EnableReconciliationMetrics) { + metricsList = append(metricsList, reconciliationMetricsList...) } - - for _, m := range metrics { - err := k8smetrics.Registry.Register(m) + for _, m := range metricsList { + err := metrics.Registry.Register(m) if err != nil { return err }