Skip to content

Commit

Permalink
Merge pull request #760 from skriss/v0.9.3-cherrypicks
Browse files Browse the repository at this point in the history
V0.9.3 cherrypicks
  • Loading branch information
carlisia authored Aug 10, 2018
2 parents 0acd368 + ca8ae18 commit 659a852
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

#### [v0.9.3](https://github.com/heptio/ark/releases/tag/v0.9.3) - 2018-08-10

#### Bug Fixes
* Initalize Prometheus metrics when creating a new schedule (#689, @lemaral)

#### [v0.9.2](https://github.com/heptio/ark/releases/tag/v0.9.2) - 2018-07-26

##### Bug Fixes:
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ func (s *server) runControllers(config *api.Config) error {
s.sharedInformerFactory.Ark().V1().Schedules(),
config.ScheduleSyncPeriod.Duration,
s.logger,
s.metrics,
)
wg.Add(1)
go func() {
Expand Down
8 changes: 8 additions & 0 deletions pkg/controller/schedule_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
arkv1client "github.com/heptio/ark/pkg/generated/clientset/versioned/typed/ark/v1"
informers "github.com/heptio/ark/pkg/generated/informers/externalversions/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"
)

Expand All @@ -55,6 +56,7 @@ type scheduleController struct {
syncPeriod time.Duration
clock clock.Clock
logger logrus.FieldLogger
metrics *metrics.ServerMetrics
}

func NewScheduleController(
Expand All @@ -64,6 +66,7 @@ func NewScheduleController(
schedulesInformer informers.ScheduleInformer,
syncPeriod time.Duration,
logger logrus.FieldLogger,
metrics *metrics.ServerMetrics,
) *scheduleController {
if syncPeriod < time.Minute {
logger.WithField("syncPeriod", syncPeriod).Info("Provided schedule sync period is too short. Setting to 1 minute")
Expand All @@ -80,6 +83,7 @@ func NewScheduleController(
syncPeriod: syncPeriod,
clock: clock.RealClock{},
logger: logger,
metrics: metrics,
}

c.syncHandler = c.processSchedule
Expand All @@ -106,6 +110,10 @@ func NewScheduleController(
return
}
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)
},
},
)
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/schedule_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
api "github.com/heptio/ark/pkg/apis/ark/v1"
"github.com/heptio/ark/pkg/generated/clientset/versioned/fake"
informers "github.com/heptio/ark/pkg/generated/informers/externalversions"
"github.com/heptio/ark/pkg/metrics"
"github.com/heptio/ark/pkg/util/collections"
arktest "github.com/heptio/ark/pkg/util/test"
)
Expand Down Expand Up @@ -129,6 +130,7 @@ func TestProcessSchedule(t *testing.T) {
sharedInformers.Ark().V1().Schedules(),
time.Duration(0),
logger,
metrics.NewServerMetrics(),
)

var (
Expand Down
12 changes: 12 additions & 0 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
func (m *ServerMetrics) SetBackupTarballSizeBytesGauge(backupSchedule string, size int64) {
if g, ok := m.metrics[backupTarballSizeBytesGauge].(*prometheus.GaugeVec); ok {
Expand Down

0 comments on commit 659a852

Please sign in to comment.