-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
clustersynchro: add resource synchro metrics
Signed-off-by: Iceber Gu <[email protected]>
- Loading branch information
Showing
6 changed files
with
504 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package options | ||
|
||
import ( | ||
"github.com/spf13/pflag" | ||
|
||
metricsserver "github.com/clusterpedia-io/clusterpedia/pkg/metrics/server" | ||
"github.com/clusterpedia-io/clusterpedia/pkg/synchromanager/resourcesynchro" | ||
) | ||
|
||
type MetricsOptions struct { | ||
Metrics *metricsserver.Options | ||
|
||
ResourceSynchroMetricsScope string | ||
} | ||
|
||
func NewMetricsOptions() *MetricsOptions { | ||
return &MetricsOptions{ | ||
Metrics: metricsserver.NewOptions(), | ||
ResourceSynchroMetricsScope: resourcesynchro.DefaultMetricsWrapperFactory.Config().Scope(), | ||
} | ||
} | ||
|
||
func (o *MetricsOptions) AddFlags(fs *pflag.FlagSet) { | ||
o.Metrics.AddFlags(fs) | ||
|
||
fs.StringVar(&o.ResourceSynchroMetricsScope, "resource-synchro-metrics-scope", o.ResourceSynchroMetricsScope, "The resource synchronizer's metrics aggregation scope, which supports 'all', 'cluster', 'groupversion.resource', 'cluster.groupversion.resource'") | ||
} | ||
|
||
func (o *MetricsOptions) Validate() []error { | ||
errs := o.Metrics.Validate() | ||
|
||
if _, err := resourcesynchro.ParseToMetricsWrapperConfig(o.ResourceSynchroMetricsScope); err != nil { | ||
errs = append(errs, err) | ||
} | ||
return errs | ||
} | ||
|
||
func (o *MetricsOptions) ServerConfig() metricsserver.Config { | ||
return o.Metrics.Config() | ||
} | ||
|
||
func (o *MetricsOptions) ResourceSynchroConfig() resourcesynchro.MetricsWrapperConfig { | ||
config, err := resourcesynchro.ParseToMetricsWrapperConfig(o.ResourceSynchroMetricsScope) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return config | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
pkg/synchromanager/clustersynchro/default_resource_synchro_metrics.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
package clustersynchro | ||
|
||
import ( | ||
"sync" | ||
|
||
compbasemetrics "k8s.io/component-base/metrics" | ||
"k8s.io/component-base/metrics/legacyregistry" | ||
|
||
"github.com/clusterpedia-io/clusterpedia/pkg/synchromanager/resourcesynchro" | ||
) | ||
|
||
// Note: The current design pattern does not account for the presence of multiple different types of resource synchronizers simultaneously. | ||
// Future updates can be made based on requirements. | ||
|
||
const ( | ||
namespace = "clustersynchro" | ||
subsystem = "resourcesynchro" | ||
) | ||
|
||
var ( | ||
// storagedResourcesTotal records the total number of resources stored in the storage layer. | ||
storagedResourcesTotal *compbasemetrics.GaugeVec | ||
|
||
// resourceAddedCounter records the number of times resources are added to the storage layer. | ||
resourceAddedCounter *compbasemetrics.CounterVec | ||
|
||
// resourceUpdatedCounter records the number of times resources are updated in the storage layer. | ||
resourceUpdatedCounter *compbasemetrics.CounterVec | ||
|
||
// resourceDeletedCounter records the number of times resources are deleted from the storage layer. | ||
resourceDeletedCounter *compbasemetrics.CounterVec | ||
|
||
// resourceFailedCounter records the number of times resource operations fail. | ||
resourceFailedCounter *compbasemetrics.CounterVec | ||
|
||
// resourceDroppedCounter records the number of times resources are dropped. | ||
resourceDroppedCounter *compbasemetrics.CounterVec | ||
|
||
// resourceMaxRetryGauge provides the maximum number of retries during resource operations. | ||
resourceMaxRetryGauge *compbasemetrics.GaugeVec | ||
|
||
// resourceStorageDuration records the time interval from when a resource is fetched from the queue to when it is processed. | ||
resourceStorageDuration *compbasemetrics.HistogramVec | ||
) | ||
|
||
var resourceSynchroMetrics = []interface{}{ | ||
storagedResourcesTotal, | ||
resourceAddedCounter, | ||
resourceUpdatedCounter, | ||
resourceDeletedCounter, | ||
resourceFailedCounter, | ||
resourceMaxRetryGauge, | ||
resourceDroppedCounter, | ||
resourceStorageDuration, | ||
} | ||
|
||
var registerOnce sync.Once | ||
|
||
func registerResourceSynchroMetrics() { | ||
registerOnce.Do(func() { | ||
storagedResourcesTotal = resourcesynchro.DefaultMetricsWrapperFactory.NewGaugeVec( | ||
&compbasemetrics.GaugeOpts{ | ||
Namespace: namespace, | ||
Subsystem: subsystem, | ||
Name: "storaged_resource_total", | ||
Help: "Number of resources stored in the storage layer.", | ||
StabilityLevel: compbasemetrics.ALPHA, | ||
}, | ||
) | ||
|
||
resourceAddedCounter = resourcesynchro.DefaultMetricsWrapperFactory.NewCounterVec( | ||
&compbasemetrics.CounterOpts{ | ||
Namespace: namespace, | ||
Subsystem: subsystem, | ||
Name: "resource_added_total", | ||
Help: "Number of times resources are deleted from the storage layer.", | ||
StabilityLevel: compbasemetrics.ALPHA, | ||
}, | ||
) | ||
|
||
resourceUpdatedCounter = resourcesynchro.DefaultMetricsWrapperFactory.NewCounterVec( | ||
&compbasemetrics.CounterOpts{ | ||
Namespace: namespace, | ||
Subsystem: subsystem, | ||
Name: "resource_updated_total", | ||
Help: "Number of times resources are updated in the storage layer.", | ||
StabilityLevel: compbasemetrics.ALPHA, | ||
}, | ||
) | ||
|
||
resourceDeletedCounter = resourcesynchro.DefaultMetricsWrapperFactory.NewCounterVec( | ||
&compbasemetrics.CounterOpts{ | ||
Namespace: namespace, | ||
Subsystem: subsystem, | ||
Name: "resource_deleted_total", | ||
Help: "Number of times resources are deleted from the storage layer.", | ||
StabilityLevel: compbasemetrics.ALPHA, | ||
}, | ||
) | ||
|
||
resourceFailedCounter = resourcesynchro.DefaultMetricsWrapperFactory.NewCounterVec( | ||
&compbasemetrics.CounterOpts{ | ||
Namespace: namespace, | ||
Subsystem: subsystem, | ||
Name: "resource_failed_total", | ||
Help: "Number of times resource operations fail.", | ||
StabilityLevel: compbasemetrics.ALPHA, | ||
}, | ||
) | ||
|
||
resourceMaxRetryGauge = resourcesynchro.DefaultMetricsWrapperFactory.NewGaugeVec( | ||
&compbasemetrics.GaugeOpts{ | ||
Namespace: namespace, | ||
Subsystem: subsystem, | ||
Name: "resource_max_retry_total", | ||
Help: "The maximum number of retries during resource operations.", | ||
StabilityLevel: compbasemetrics.ALPHA, | ||
}, | ||
) | ||
|
||
resourceDroppedCounter = resourcesynchro.DefaultMetricsWrapperFactory.NewCounterVec( | ||
&compbasemetrics.CounterOpts{ | ||
Namespace: namespace, | ||
Subsystem: subsystem, | ||
Name: "failed_resource_total", | ||
Help: "Number of times resources are dropped.", | ||
StabilityLevel: compbasemetrics.ALPHA, | ||
}, | ||
) | ||
|
||
resourceStorageDuration = resourcesynchro.DefaultMetricsWrapperFactory.NewHistogramVec( | ||
&compbasemetrics.HistogramOpts{ | ||
Namespace: namespace, | ||
Subsystem: subsystem, | ||
Name: "storage_duration_seconds", | ||
Help: "The time interval from when a resource is fetched from the queue to when it is processed.", | ||
StabilityLevel: compbasemetrics.ALPHA, | ||
Buckets: []float64{0.025, 0.05, 0.1, 0.2, 0.4, 0.6, 1.0, 1.5, 3, 5, 8, 15}, | ||
}, | ||
) | ||
|
||
resourceSynchroMetrics = []interface{}{ | ||
storagedResourcesTotal, | ||
resourceAddedCounter, | ||
resourceUpdatedCounter, | ||
resourceDeletedCounter, | ||
resourceFailedCounter, | ||
resourceMaxRetryGauge, | ||
resourceDroppedCounter, | ||
resourceStorageDuration, | ||
} | ||
for _, m := range resourceSynchroMetrics { | ||
legacyregistry.MustRegister(m.(compbasemetrics.Registerable)) | ||
} | ||
}) | ||
} |
Oops, something went wrong.