1
1
package watch
2
2
3
3
import (
4
+ "fmt"
4
5
"time"
5
6
6
7
log "github.com/sirupsen/logrus"
@@ -11,16 +12,18 @@ import (
11
12
// From https://golang.org/src/time/format.go
12
13
const GCPSnapshotTimestampLayout string = "2006-01-02T15:04:05Z07:00"
13
14
14
- func Watch (gsc * snapshot.GCPSnapClient , retentionHours , intervalSecs int ) {
15
+ func Watch (gsc * snapshot.GCPSnapClient , watchInterval , retentionHours , intervalSecs int ) {
15
16
16
17
for t := time .Tick (time .Second * 60 ); ; <- t {
17
18
18
19
retentionStart := time .Now ().Add (- time .Duration (retentionHours ) * time .Hour )
19
20
lastAcceptedCreation := time .Now ().Add (time .Duration (- intervalSecs ) * time .Second )
21
+
20
22
log .WithFields (log.Fields {
21
- "Retention Start" : retentionStart ,
23
+ "Watch Interval in secs" : watchInterval ,
24
+ "Retention Period Start" : retentionStart ,
22
25
"last accepted snap time" : lastAcceptedCreation ,
23
- }).Info ("Initiating watch cycle" )
26
+ }).Info ("Initiating new disk watch cycle" )
24
27
25
28
// Get disks
26
29
disks , err := gsc .GetDiskList ()
@@ -30,7 +33,7 @@ func Watch(gsc *snapshot.GCPSnapClient, retentionHours, intervalSecs int) {
30
33
}
31
34
32
35
for _ , disk := range disks {
33
- log .Info ("Checking disk: " , disk .Name )
36
+ log .Debug ("Checking disk: " , disk .Name )
34
37
35
38
// Get snapshots per disk created by the snapshotter
36
39
snaps , err := gsc .ListClientCreatedSnapshots (disk .SelfLink )
@@ -93,11 +96,12 @@ func deleteSnapshots(gsc *snapshot.GCPSnapClient, sl []compute.Snapshot) error {
93
96
}
94
97
95
98
func createSnapshot (gsc * snapshot.GCPSnapClient , d compute.Disk ) error {
96
- log .Info ( "Taking snapshot of disk: " , d .Name )
99
+ log .Debug ( "Attempt to take snapshot of disk: " , d .Name )
97
100
op , err := gsc .CreateSnapshot (d .Name , d .Zone )
98
101
if err != nil {
99
102
return err
100
103
}
104
+ log .Info (fmt .Sprintf ("New snapshot of disk: %v operation: %v" , d .Name , op ))
101
105
102
106
// Create snapshot is a zonal operation!!!
103
107
go pollZonalOperation (gsc , op , d .Zone )
@@ -109,8 +113,7 @@ func pollZonalOperation(gsc *snapshot.GCPSnapClient, operation, zone string) {
109
113
for {
110
114
status , err := gsc .GetZonalOperationStatus (operation , zone )
111
115
if err != nil {
112
- log .Info ("Operation failed: " , operation )
113
- log .Error (err )
116
+ log .Error ("Operation failed: " , operation , err )
114
117
break
115
118
}
116
119
if status == "DONE" {
@@ -125,8 +128,7 @@ func pollGlobalOperation(gsc *snapshot.GCPSnapClient, operation string) {
125
128
for {
126
129
status , err := gsc .GetGlobalOperationStatus (operation )
127
130
if err != nil {
128
- log .Info ("Operation failed: " , operation )
129
- log .Error (err )
131
+ log .Error ("Operation failed: " , operation , err )
130
132
break
131
133
}
132
134
if status == "DONE" {
0 commit comments