Skip to content

Commit

Permalink
add reconcilation metrics with feature flag(implemented for Provision…
Browse files Browse the repository at this point in the history
…edProduct only)

Signed-off-by: Kirill Sushkov <[email protected]>
  • Loading branch information
Kirill Sushkov committed Nov 29, 2023
1 parent c05b170 commit 0db2d89
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cmd/provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:]))

Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/servicecatalog/provisionedproduct/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
18 changes: 8 additions & 10 deletions pkg/utils/metrics/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 0db2d89

Please sign in to comment.