Skip to content

Commit

Permalink
remove XRStateMetrics
Browse files Browse the repository at this point in the history
Signed-off-by: ezgidemirel <ezgidemirel91@gmail.com>
  • Loading branch information
ezgidemirel committed Apr 18, 2024
1 parent aa7264b commit 39473aa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 183 deletions.
22 changes: 14 additions & 8 deletions pkg/controller/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ type Options struct {
// determine whether it has work to do.
PollInterval time.Duration

// PollStateMetricInterval at which each controller should record state
PollStateMetricInterval time.Duration

// MaxConcurrentReconciles for each controller.
MaxConcurrentReconciles int

Expand All @@ -67,11 +64,8 @@ type Options struct {
// ESSOptions for External Secret Stores.
ESSOptions *ESSOptions

// MetricsRecorder to use for recording metrics.
MRMetrics managed.MetricRecorder

// StateMetrics to use for recording state metrics.
StateMetrics *statemetrics.MRStateMetrics
// MetricOptions for recording metrics.
MetricOptions *MetricOptions
}

// ForControllerRuntime extracts options for controller-runtime.
Expand All @@ -90,3 +84,15 @@ type ESSOptions struct {
TLSConfig *tls.Config
TLSSecretName *string
}

// MetricOptions for recording metrics.
type MetricOptions struct {
// PollStateMetricInterval at which each controller should record state
PollStateMetricInterval time.Duration

// MetricsRecorder to use for recording metrics.
MRMetrics managed.MetricRecorder

// MRStateMetrics to use for recording state metrics.
MRStateMetrics *statemetrics.MRStateMetrics
}
20 changes: 11 additions & 9 deletions pkg/reconciler/managed/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func NewMRMetricRecorder() *MRMetricRecorder {
return &MRMetricRecorder{
mrDetected: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Subsystem: subSystem,
Name: "managed_resource_time_to_first_reconcile_seconds",
Name: "managed_resource_first_time_to_reconcile_seconds",
Help: "The time it took for a managed resource to be detected by the controller",
Buckets: kmetrics.ExponentialBuckets(10e-9, 10, 10),
}, []string{"gvk"}),
Expand Down Expand Up @@ -109,8 +109,7 @@ func (r *MRMetricRecorder) recordUnchanged(name string) {

func (r *MRMetricRecorder) recordFirstTimeReconciled(managed resource.Managed) {
if managed.GetCondition(xpv1.TypeSynced).Status == corev1.ConditionUnknown {
r.mrDetected.WithLabelValues("gvk", managed.GetObjectKind().GroupVersionKind().String()).
Observe(time.Since(managed.GetCreationTimestamp().Time).Seconds())
r.mrDetected.With(getLabels(managed)).Observe(time.Since(managed.GetCreationTimestamp().Time).Seconds())
r.firstObservation.Store(managed.GetName(), time.Now()) // this is the first time we reconciled on this resource
}
}
Expand All @@ -126,15 +125,13 @@ func (r *MRMetricRecorder) recordDrift(managed resource.Managed) {
return
}

r.mrDrift.WithLabelValues("gvk", managed.GetObjectKind().GroupVersionKind().String()).
Observe(time.Since(lt).Seconds())
r.mrDrift.With(getLabels(managed)).Observe(time.Since(lt).Seconds())

r.lastObservation.Store(name, time.Now())
}

func (r *MRMetricRecorder) recordDeleted(managed resource.Managed) {
r.mrDeletion.WithLabelValues("gvk", managed.GetObjectKind().GroupVersionKind().String()).
Observe(time.Since(managed.GetDeletionTimestamp().Time).Seconds())
r.mrDeletion.With(getLabels(managed)).Observe(time.Since(managed.GetDeletionTimestamp().Time).Seconds())
}

func (r *MRMetricRecorder) recordFirstTimeReady(managed resource.Managed) {
Expand All @@ -145,8 +142,7 @@ func (r *MRMetricRecorder) recordFirstTimeReady(managed resource.Managed) {
if !ok {
return
}
r.mrFirstTimeReady.WithLabelValues("gvk", managed.GetObjectKind().GroupVersionKind().String()).
Observe(time.Since(managed.GetCreationTimestamp().Time).Seconds())
r.mrFirstTimeReady.With(getLabels(managed)).Observe(time.Since(managed.GetCreationTimestamp().Time).Seconds())
r.firstObservation.Delete(managed.GetName())
}
}
Expand Down Expand Up @@ -174,3 +170,9 @@ func (r *NopMetricRecorder) recordDrift(_ resource.Managed) {}
func (r *NopMetricRecorder) recordDeleted(_ resource.Managed) {}

func (r *NopMetricRecorder) recordFirstTimeReady(_ resource.Managed) {}

func getLabels(r resource.Managed) prometheus.Labels {
return prometheus.Labels{
"gvk": r.GetObjectKind().GroupVersionKind().String(),
}
}
166 changes: 0 additions & 166 deletions pkg/statemetrics/xr_state_metrics.go

This file was deleted.

0 comments on commit 39473aa

Please sign in to comment.