mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-06 13:26:26 +00:00
Initialize schedule Prometheus metrics to have them created beforehand (see https://prometheus.io/docs/practices/instrumentation/#avoid-missing-metrics)
Signed-off-by: Alex Lemaresquier <alex+github@lemaresquier.org>
This commit is contained in:
@@ -656,6 +656,7 @@ func (s *server) runControllers(config *api.Config) error {
|
|||||||
s.sharedInformerFactory.Ark().V1().Schedules(),
|
s.sharedInformerFactory.Ark().V1().Schedules(),
|
||||||
config.ScheduleSyncPeriod.Duration,
|
config.ScheduleSyncPeriod.Duration,
|
||||||
s.logger,
|
s.logger,
|
||||||
|
s.metrics,
|
||||||
)
|
)
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ import (
|
|||||||
arkv1client "github.com/heptio/ark/pkg/generated/clientset/versioned/typed/ark/v1"
|
arkv1client "github.com/heptio/ark/pkg/generated/clientset/versioned/typed/ark/v1"
|
||||||
informers "github.com/heptio/ark/pkg/generated/informers/externalversions/ark/v1"
|
informers "github.com/heptio/ark/pkg/generated/informers/externalversions/ark/v1"
|
||||||
listers "github.com/heptio/ark/pkg/generated/listers/ark/v1"
|
listers "github.com/heptio/ark/pkg/generated/listers/ark/v1"
|
||||||
|
"github.com/heptio/ark/pkg/metrics"
|
||||||
kubeutil "github.com/heptio/ark/pkg/util/kube"
|
kubeutil "github.com/heptio/ark/pkg/util/kube"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -55,6 +56,7 @@ type scheduleController struct {
|
|||||||
syncPeriod time.Duration
|
syncPeriod time.Duration
|
||||||
clock clock.Clock
|
clock clock.Clock
|
||||||
logger logrus.FieldLogger
|
logger logrus.FieldLogger
|
||||||
|
metrics *metrics.ServerMetrics
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewScheduleController(
|
func NewScheduleController(
|
||||||
@@ -64,6 +66,7 @@ func NewScheduleController(
|
|||||||
schedulesInformer informers.ScheduleInformer,
|
schedulesInformer informers.ScheduleInformer,
|
||||||
syncPeriod time.Duration,
|
syncPeriod time.Duration,
|
||||||
logger logrus.FieldLogger,
|
logger logrus.FieldLogger,
|
||||||
|
metrics *metrics.ServerMetrics,
|
||||||
) *scheduleController {
|
) *scheduleController {
|
||||||
if syncPeriod < time.Minute {
|
if syncPeriod < time.Minute {
|
||||||
logger.WithField("syncPeriod", syncPeriod).Info("Provided schedule sync period is too short. Setting to 1 minute")
|
logger.WithField("syncPeriod", syncPeriod).Info("Provided schedule sync period is too short. Setting to 1 minute")
|
||||||
@@ -80,6 +83,7 @@ func NewScheduleController(
|
|||||||
syncPeriod: syncPeriod,
|
syncPeriod: syncPeriod,
|
||||||
clock: clock.RealClock{},
|
clock: clock.RealClock{},
|
||||||
logger: logger,
|
logger: logger,
|
||||||
|
metrics: metrics,
|
||||||
}
|
}
|
||||||
|
|
||||||
c.syncHandler = c.processSchedule
|
c.syncHandler = c.processSchedule
|
||||||
@@ -106,6 +110,10 @@ func NewScheduleController(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.queue.Add(key)
|
c.queue.Add(key)
|
||||||
|
scheduleName := schedule.GetName()
|
||||||
|
c.logger.Info("Creating schedule ", scheduleName)
|
||||||
|
//Init Prometheus metrics to 0 to have them flowing up
|
||||||
|
metrics.InitSchedule(scheduleName)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import (
|
|||||||
api "github.com/heptio/ark/pkg/apis/ark/v1"
|
api "github.com/heptio/ark/pkg/apis/ark/v1"
|
||||||
"github.com/heptio/ark/pkg/generated/clientset/versioned/fake"
|
"github.com/heptio/ark/pkg/generated/clientset/versioned/fake"
|
||||||
informers "github.com/heptio/ark/pkg/generated/informers/externalversions"
|
informers "github.com/heptio/ark/pkg/generated/informers/externalversions"
|
||||||
|
"github.com/heptio/ark/pkg/metrics"
|
||||||
"github.com/heptio/ark/pkg/util/collections"
|
"github.com/heptio/ark/pkg/util/collections"
|
||||||
arktest "github.com/heptio/ark/pkg/util/test"
|
arktest "github.com/heptio/ark/pkg/util/test"
|
||||||
)
|
)
|
||||||
@@ -129,6 +130,7 @@ func TestProcessSchedule(t *testing.T) {
|
|||||||
sharedInformers.Ark().V1().Schedules(),
|
sharedInformers.Ark().V1().Schedules(),
|
||||||
time.Duration(0),
|
time.Duration(0),
|
||||||
logger,
|
logger,
|
||||||
|
metrics.NewServerMetrics(),
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@@ -106,6 +106,18 @@ func (m *ServerMetrics) RegisterAllMetrics() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *ServerMetrics) InitSchedule(scheduleName string) {
|
||||||
|
if c, ok := m.metrics[backupAttemptCount].(*prometheus.CounterVec); ok {
|
||||||
|
c.WithLabelValues(scheduleName).Set(0)
|
||||||
|
}
|
||||||
|
if c, ok := m.metrics[backupSuccessCount].(*prometheus.CounterVec); ok {
|
||||||
|
c.WithLabelValues(scheduleName).Set(0)
|
||||||
|
}
|
||||||
|
if c, ok := m.metrics[backupFailureCount].(*prometheus.CounterVec); ok {
|
||||||
|
c.WithLabelValues(scheduleName).Set(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// SetBackupTarballSizeBytesGauge records the size, in bytes, of a backup tarball.
|
// SetBackupTarballSizeBytesGauge records the size, in bytes, of a backup tarball.
|
||||||
func (m *ServerMetrics) SetBackupTarballSizeBytesGauge(backupSchedule string, size int64) {
|
func (m *ServerMetrics) SetBackupTarballSizeBytesGauge(backupSchedule string, size int64) {
|
||||||
if g, ok := m.metrics[backupTarballSizeBytesGauge].(*prometheus.GaugeVec); ok {
|
if g, ok := m.metrics[backupTarballSizeBytesGauge].(*prometheus.GaugeVec); ok {
|
||||||
|
|||||||
Reference in New Issue
Block a user