@@ -21,8 +21,9 @@ import (
2121 "time"
2222
2323 api "github.com/coreos/etcd-operator/pkg/apis/etcd/v1beta2"
24+ "github.com/coreos/etcd-operator/pkg/backup/metrics"
2425 "github.com/coreos/etcd-operator/pkg/util/constants"
25-
26+ "github.com/prometheus/client_golang/prometheus"
2627 "github.com/sirupsen/logrus"
2728 apierrors "k8s.io/apimachinery/pkg/api/errors"
2829 "k8s.io/apimachinery/pkg/api/meta"
@@ -101,14 +102,17 @@ func (b *Backup) processItem(key string) error {
101102 ctx := context .Background ()
102103 ctx , cancel := context .WithCancel (ctx )
103104 go b .periodicRunnerFunc (ctx , ticker , eb )
104-
105105 // Store cancel function for periodic
106106 b .backupRunnerStore .Store (eb .ObjectMeta .UID , BackupRunner {eb .Spec , cancel })
107107
108108 } else if ! isPeriodic {
109109 // Perform backup
110+ metrics .BackupsAttemptedTotal .With (prometheus .Labels (prometheus.Labels {
111+ "namespace" : eb .ObjectMeta .Namespace ,
112+ "name" : eb .ObjectMeta .Name ,
113+ })).Inc ()
110114 bs , err := b .handleBackup (nil , & eb .Spec , false )
111- // Report backup status
115+ //status of backup
112116 b .reportBackupStatus (bs , err , eb )
113117 }
114118 return err
@@ -195,9 +199,13 @@ func (b *Backup) periodicRunnerFunc(ctx context.Context, t *time.Ticker, eb *api
195199 }
196200 if err == nil {
197201 // Perform backup
202+ metrics .BackupsAttemptedTotal .With (prometheus .Labels (prometheus.Labels {
203+ "namespace" : eb .ObjectMeta .Namespace ,
204+ "name" : eb .ObjectMeta .Name ,
205+ })).Inc ()
198206 bs , err = b .handleBackup (& ctx , & latestEb .Spec , true )
199207 }
200- // Report backup status
208+ //BackupStatus here
201209 b .reportBackupStatus (bs , err , latestEb )
202210 }
203211 }
@@ -213,6 +221,15 @@ func (b *Backup) reportBackupStatus(bs *api.BackupStatus, berr error, eb *api.Et
213221 eb .Status .EtcdRevision = bs .EtcdRevision
214222 eb .Status .EtcdVersion = bs .EtcdVersion
215223 eb .Status .LastSuccessDate = bs .LastSuccessDate
224+ metrics .BackupsSuccessTotal .With (prometheus .Labels (prometheus.Labels {
225+ "namespace" : eb .ObjectMeta .Namespace ,
226+ "name" : eb .ObjectMeta .Name ,
227+ })).Inc ()
228+ metrics .BackupsLastSuccess .With (prometheus .Labels (prometheus.Labels {
229+ "namespace" : eb .ObjectMeta .Namespace ,
230+ "name" : eb .ObjectMeta .Name ,
231+ })).Set (float64 (time .Now ().Unix ()))
232+
216233 }
217234 _ , err := b .backupCRCli .EtcdV1beta2 ().EtcdBackups (b .namespace ).Update (eb )
218235 if err != nil {
@@ -249,7 +266,6 @@ func (b *Backup) handleBackup(parentContext *context.Context, spec *api.BackupSp
249266 if err != nil {
250267 return nil , err
251268 }
252-
253269 // When BackupPolicy.TimeoutInSecond <= 0, use default DefaultBackupTimeout.
254270 backupTimeout := time .Duration (constants .DefaultBackupTimeout )
255271 if spec .BackupPolicy != nil && spec .BackupPolicy .TimeoutInSecond > 0 {
0 commit comments