Skip to content

Commit

Permalink
chore: Add missing operator metrics (#5751)
Browse files Browse the repository at this point in the history
Co-authored-by: csuzhangxc <csuzhangxc@gmail.com>
  • Loading branch information
ti-chi-bot and csuzhangxc authored Sep 25, 2024
1 parent 29f6519 commit 6320ae0
Show file tree
Hide file tree
Showing 17 changed files with 168 additions and 14 deletions.
5 changes: 5 additions & 0 deletions cmd/br-federation-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ func main() {

initMetrics := func(c Controller) {
metrics.ActiveWorkers.WithLabelValues(c.Name()).Set(0)
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelSuccess).Add(0)
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelError).Add(0)
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelRequeue).Add(0)
metrics.ReconcileErrors.WithLabelValues(c.Name()).Add(0)
metrics.WorkerCount.WithLabelValues(c.Name()).Set(float64(cliCfg.Workers))
}

// Initialize all controllers
Expand Down
5 changes: 5 additions & 0 deletions cmd/controller-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ func main() {

initMetrics := func(c Controller) {
metrics.ActiveWorkers.WithLabelValues(c.Name()).Set(0)
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelSuccess).Add(0)
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelError).Add(0)
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelRequeue).Add(0)
metrics.ReconcileErrors.WithLabelValues(c.Name()).Add(0)
metrics.WorkerCount.WithLabelValues(c.Name()).Set(float64(cliCfg.Workers))
}

// Initialize all controllers
Expand Down
12 changes: 11 additions & 1 deletion pkg/controller/autoscaler/tidbcluster_autoscaler_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,21 @@ func (c *Controller) processNextWorkItem() bool {
return true
}

func (c *Controller) sync(key string) error {
func (c *Controller) sync(key string) (err error) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
metrics.ReconcileTime.WithLabelValues(c.Name()).Observe(duration.Seconds())

if err == nil {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelSuccess).Inc()
} else if perrors.Find(err, controller.IsRequeueError) != nil {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelRequeue).Inc()
} else {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelError).Inc()
metrics.ReconcileErrors.WithLabelValues(c.Name()).Inc()
}

klog.V(4).Infof("Finished syncing TidbClusterAutoScaler %q (%v)", key, duration)
}()

Expand Down
12 changes: 11 additions & 1 deletion pkg/controller/backup/backup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,21 @@ func (c *Controller) processNextWorkItem() bool {
}

// sync syncs the given backup.
func (c *Controller) sync(key string) error {
func (c *Controller) sync(key string) (err error) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
metrics.ReconcileTime.WithLabelValues(c.Name()).Observe(duration.Seconds())

if err == nil {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelSuccess).Inc()
} else if perrors.Find(err, controller.IsRequeueError) != nil {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelRequeue).Inc()
} else {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelError).Inc()
metrics.ReconcileErrors.WithLabelValues(c.Name()).Inc()
}

klog.V(4).Infof("Finished syncing Backup %q (%v)", key, duration)
}()

Expand Down
12 changes: 11 additions & 1 deletion pkg/controller/backupschedule/backup_schedule_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,21 @@ func (c *Controller) processNextWorkItem() bool {
}

// sync syncs the given backupSchedule.
func (c *Controller) sync(key string) error {
func (c *Controller) sync(key string) (err error) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
metrics.ReconcileTime.WithLabelValues(c.Name()).Observe(duration.Seconds())

if err == nil {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelSuccess).Inc()
} else if perrors.Find(err, controller.IsRequeueError) != nil {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelRequeue).Inc()
} else {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelError).Inc()
metrics.ReconcileErrors.WithLabelValues(c.Name()).Inc()
}

klog.V(4).Infof("Finished syncing BackupSchedule %q (%v)", key, duration)
}()

Expand Down
12 changes: 11 additions & 1 deletion pkg/controller/dmcluster/dm_cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,21 @@ func (c *Controller) processNextWorkItem() bool {
}

// sync syncs the given dmcluster.
func (c *Controller) sync(key string) error {
func (c *Controller) sync(key string) (err error) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
metrics.ReconcileTime.WithLabelValues(c.Name()).Observe(duration.Seconds())

if err == nil {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelSuccess).Inc()
} else if perrors.Find(err, controller.IsRequeueError) != nil {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelRequeue).Inc()
} else {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelError).Inc()
metrics.ReconcileErrors.WithLabelValues(c.Name()).Inc()
}

klog.V(4).Infof("Finished syncing DMCluster %q (%v)", key, duration)
}()

Expand Down
12 changes: 11 additions & 1 deletion pkg/controller/fedvolumebackup/fed_volume_backup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,21 @@ func (c *Controller) processNextWorkItem() bool {
}

// sync syncs the given VolumeBackup.
func (c *Controller) sync(key string) error {
func (c *Controller) sync(key string) (err error) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
metrics.ReconcileTime.WithLabelValues(c.Name()).Observe(duration.Seconds())

if err == nil {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelSuccess).Inc()
} else if perrors.Find(err, controller.IsRequeueError) != nil {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelRequeue).Inc()
} else {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelError).Inc()
metrics.ReconcileErrors.WithLabelValues(c.Name()).Inc()
}

klog.V(4).Infof("Finished syncing VolumeBackup %q (%v)", key, duration)
}()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,21 @@ func (c *Controller) processNextWorkItem() bool {
}

// sync syncs the given VolumeBackupSchedule.
func (c *Controller) sync(key string) error {
func (c *Controller) sync(key string) (err error) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
metrics.ReconcileTime.WithLabelValues(c.Name()).Observe(duration.Seconds())

if err == nil {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelSuccess).Inc()
} else if perrors.Find(err, controller.IsRequeueError) != nil {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelRequeue).Inc()
} else {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelError).Inc()
metrics.ReconcileErrors.WithLabelValues(c.Name()).Inc()
}

klog.V(4).Infof("Finished syncing VolumeBackupSchedule %q (%v)", key, duration)
}()

Expand Down
12 changes: 11 additions & 1 deletion pkg/controller/fedvolumerestore/fed_volume_restore_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,21 @@ func (c *Controller) processNextWorkItem() bool {
}

// sync syncs the given VolumeRestore.
func (c *Controller) sync(key string) error {
func (c *Controller) sync(key string) (err error) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
metrics.ReconcileTime.WithLabelValues(c.Name()).Observe(duration.Seconds())

if err == nil {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelSuccess).Inc()
} else if perrors.Find(err, controller.IsRequeueError) != nil {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelRequeue).Inc()
} else {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelError).Inc()
metrics.ReconcileErrors.WithLabelValues(c.Name()).Inc()
}

klog.V(4).Infof("Finished syncing VolumeRestore %q (%v)", key, duration)
}()

Expand Down
12 changes: 11 additions & 1 deletion pkg/controller/restore/restore_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,21 @@ func (c *Controller) processNextWorkItem() bool {
}

// sync syncs the given restore.
func (c *Controller) sync(key string) error {
func (c *Controller) sync(key string) (err error) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
metrics.ReconcileTime.WithLabelValues(c.Name()).Observe(duration.Seconds())

if err == nil {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelSuccess).Inc()
} else if perrors.Find(err, controller.IsRequeueError) != nil {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelRequeue).Inc()
} else {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelError).Inc()
metrics.ReconcileErrors.WithLabelValues(c.Name()).Inc()
}

klog.V(4).Infof("Finished syncing Restore %q (%v)", key, duration)
}()

Expand Down
12 changes: 11 additions & 1 deletion pkg/controller/tidbcluster/pod_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (c *PodController) processNextWorkItem() bool {
return true
}

func (c *PodController) sync(key string) (reconcile.Result, error) {
func (c *PodController) sync(key string) (result reconcile.Result, err error) {
ns, name, err := cache.SplitMetaNamespaceKey(key)
if err != nil {
return reconcile.Result{}, err
Expand Down Expand Up @@ -213,6 +213,16 @@ func (c *PodController) sync(key string) (reconcile.Result, error) {
defer func() {
duration := time.Since(startTime)
metrics.ReconcileTime.WithLabelValues(c.Name()).Observe(duration.Seconds())

if err == nil {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelSuccess).Inc()
} else if perrors.Find(err, controller.IsRequeueError) != nil {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelRequeue).Inc()
} else {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelError).Inc()
metrics.ReconcileErrors.WithLabelValues(c.Name()).Inc()
}

klog.V(4).Infof("Finished syncing TidbCluster pod %q (%v)", key, duration)
}()

Expand Down
12 changes: 11 additions & 1 deletion pkg/controller/tidbcluster/tidb_cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,21 @@ func (c *Controller) processNextWorkItem() bool {
}

// sync syncs the given tidbcluster.
func (c *Controller) sync(key string) error {
func (c *Controller) sync(key string) (err error) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
metrics.ReconcileTime.WithLabelValues(c.Name()).Observe(duration.Seconds())

if err == nil {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelSuccess).Inc()
} else if perrors.Find(err, controller.IsRequeueError) != nil {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelRequeue).Inc()
} else {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelError).Inc()
metrics.ReconcileErrors.WithLabelValues(c.Name()).Inc()
}

klog.V(4).Infof("Finished syncing TidbCluster %q (%v)", key, duration)
}()

Expand Down
12 changes: 11 additions & 1 deletion pkg/controller/tidbdashboard/tidb_dashboard_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,21 @@ func (c *Controller) processNextWorkItem() bool {
return true
}

func (c *Controller) sync(key string) error {
func (c *Controller) sync(key string) (err error) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
metrics.ReconcileTime.WithLabelValues(c.Name()).Observe(duration.Seconds())

if err == nil {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelSuccess).Inc()
} else if perrors.Find(err, controller.IsRequeueError) != nil {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelRequeue).Inc()
} else {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelError).Inc()
metrics.ReconcileErrors.WithLabelValues(c.Name()).Inc()
}

klog.V(4).Infof("Finished syncing TidbDashboard %s (%v)", key, duration)
}()

Expand Down
12 changes: 11 additions & 1 deletion pkg/controller/tidbinitializer/tidb_initializer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,21 @@ func (c *Controller) processNextWorkItem() bool {
return true
}

func (c *Controller) sync(key string) error {
func (c *Controller) sync(key string) (err error) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
metrics.ReconcileTime.WithLabelValues(c.Name()).Observe(duration.Seconds())

if err == nil {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelSuccess).Inc()
} else if perrors.Find(err, controller.IsRequeueError) != nil {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelRequeue).Inc()
} else {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelError).Inc()
metrics.ReconcileErrors.WithLabelValues(c.Name()).Inc()
}

klog.V(4).Infof("Finished syncing TiDBInitializer %q (%v)", key, duration)
}()

Expand Down
12 changes: 11 additions & 1 deletion pkg/controller/tidbmonitor/tidb_monitor_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,21 @@ func (c *Controller) processNextWorkItem() bool {
return true
}

func (c *Controller) sync(key string) error {
func (c *Controller) sync(key string) (err error) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
metrics.ReconcileTime.WithLabelValues(c.Name()).Observe(duration.Seconds())

if err == nil {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelSuccess).Inc()
} else if perrors.Find(err, controller.IsRequeueError) != nil {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelRequeue).Inc()
} else {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelError).Inc()
metrics.ReconcileErrors.WithLabelValues(c.Name()).Inc()
}

klog.V(4).Infof("Finished syncing TidbMonitor %q (%v)", key, duration)
}()

Expand Down
12 changes: 11 additions & 1 deletion pkg/controller/tidbngmonitoring/tidb_ng_monitoring_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,21 @@ func (c *Controller) processNextWorkItem() bool {
return true
}

func (c *Controller) sync(key string) error {
func (c *Controller) sync(key string) (err error) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
metrics.ReconcileTime.WithLabelValues(c.Name()).Observe(duration.Seconds())

if err == nil {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelSuccess).Inc()
} else if perrors.Find(err, controller.IsRequeueError) != nil {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelRequeue).Inc()
} else {
metrics.ReconcileTotal.WithLabelValues(c.Name(), metrics.LabelError).Inc()
metrics.ReconcileErrors.WithLabelValues(c.Name()).Inc()
}

klog.V(4).Infof("Finished syncing TidbNGMonitoring %s (%v)", key, duration)
}()

Expand Down
4 changes: 4 additions & 0 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const (
LabelNamespace = "namespace"
LabelName = "name"
LabelComponent = "component"

LabelError = "error"
LabelRequeue = "requeue"
LabelSuccess = "success"
)

var (
Expand Down

0 comments on commit 6320ae0

Please sign in to comment.