func GetMetricsDuration() int {
	return globalObjectTracker.GetMetricsDuration()
}
GetMetricsDuration function returns current metricsDuration
of package-scoped internal variable of type *ObjectTracker.
It is safe to call this function from multiple go routines
with another go routines calling SetMetricsDuration function.
package declarative
import (
	"context"
	"sync"
	"time"
	"github.com/prometheus/client_golang/prometheus"
	"k8s.io/apimachinery/pkg/api/meta"
	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
	"k8s.io/apimachinery/pkg/runtime/schema"
	"k8s.io/apimachinery/pkg/util/errors"
	"k8s.io/client-go/util/workqueue"
	"sigs.k8s.io/controller-runtime/pkg/event"
	"sigs.k8s.io/controller-runtime/pkg/handler"
	"sigs.k8s.io/controller-runtime/pkg/manager"
	"sigs.k8s.io/controller-runtime/pkg/predicate"
	"sigs.k8s.io/controller-runtime/pkg/reconcile"
	"sigs.k8s.io/controller-runtime/pkg/source"
	"sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/declarative/pkg/manifest"
)
const emptyNamespace = "_Empty_"
const clusterScoped = "_Cluster_"
const (
	Declarative = "declarative_reconciler"
)
const (
	ReconcileCount   = "reconcile_count"
	ReconcileFailure = "reconcile_failure_count"
	ManagedObjectsRecord = "managed_objects_record"
)
var metricsRegisterOnce *sync.Once = &sync.Once{}
var (
	reconcileCount = prometheus.NewCounterVec(prometheus.CounterOpts{
		Subsystem: Declarative,
		Name:      ReconcileCount,
		Help:      "How many times reconciliation of K8s objects managed by declarative reconciler occurs",
	}, []string{"group_version_kind", "namespace", "name"})
	reconcileFailure = prometheus.NewCounterVec(prometheus.CounterOpts{
		Subsystem: Declarative,
		Name:      ReconcileFailure,
		Help:      "How many times reconciliation failure of K8s objects managed by declarative reconciler occurs",
	}, []string{"group_version_kind", "namespace", "name"})
	managedObjectsRecord = prometheus.NewGaugeVec(prometheus.GaugeOpts{
		Subsystem: Declarative,
		Name:      ManagedObjectsRecord,
		Help:      "Track the number of objects in manifest",
	}, []string{"group_version_kind", "namespace", "name"})
)
var metricsList = []prometheus.Collector{reconcileCount, reconcileFailure, managedObjectsRecord}
func gvkString(gvk schema.GroupVersionKind) string {
	if len(gvk.Group) == 0 && gvk.Version == "v1" {
		return gvk.Version + "/" + gvk.Kind
	}
	return gvk.Group + "/" + gvk.Version + "/" + gvk.Kind
}
func namespaced(mgr manager.Manager, gvk schema.GroupVersionKind) (bool, error) {
	mapping, err := mgr.GetRESTMapper().RESTMapping(gvk.GroupKind(), gvk.Version)
	if err != nil {
		return false, err
	}
	if mapping.Scope.Name() == meta.RESTScopeNameNamespace {
		return true, nil
	} else {
		return false, nil
	}
}
type reconcileMetrics struct {
	groupVersionKind           string
	reconcileCounterVec        *prometheus.CounterVec
	reconcileFailureCounterVec *prometheus.CounterVec
}
func reconcileMetricsFor(gvk schema.GroupVersionKind) reconcileMetrics {
	return reconcileMetrics{groupVersionKind: gvkString(gvk),
		reconcileCounterVec: reconcileCount, reconcileFailureCounterVec: reconcileFailure}
}
func (rm *reconcileMetrics) reconcileWith(req reconcile.Request) {
	rm.reconcileCounterVec.WithLabelValues(rm.groupVersionKind, req.Namespace, req.Name).Inc()
}
func (rm *reconcileMetrics) reconcileFailedWith(req reconcile.Request, _ reconcile.Result, err error) {
	if err != nil {
		rm.reconcileFailureCounterVec.WithLabelValues(rm.groupVersionKind, req.Namespace, req.Name).Inc()
	}
}
type objectRecorder struct {
	groupVersionKind string
	gaugeVec         *prometheus.GaugeVec
}
func objectRecorderFor(gvk schema.GroupVersionKind) objectRecorder {
	return objectRecorder{groupVersionKind: gvkString(gvk), gaugeVec: managedObjectsRecord}
}
func (or objectRecorder) Set(namespace, name string, num float64) {
	if namespace == emptyNamespace || namespace == clusterScoped {
		or.gaugeVec.WithLabelValues(or.groupVersionKind, "", name).Set(num)
	} else {
		or.gaugeVec.WithLabelValues(or.groupVersionKind, namespace, name).Set(num)
	}
}
func (or objectRecorder) Unset(namespace, name string) {
	if namespace == emptyNamespace || namespace == clusterScoped {
		or.gaugeVec.DeleteLabelValues(or.groupVersionKind, "", name)
	} else {
		or.gaugeVec.DeleteLabelValues(or.groupVersionKind, namespace, name)
	}
}
var globalObjectTracker *ObjectTracker = NewObjectTracker()