Skip to content

Commit be9db87

Browse files
committed
for loops are hard and less Errorf
1 parent 15c65fe commit be9db87

4 files changed

Lines changed: 16 additions & 13 deletions

File tree

checks/checks.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func (c *Client) CheckRegexAgainstRow(query, regex string) bool {
6868

6969
cols, err := rows.Columns()
7070
if err != nil {
71+
log.WithError(err).Error("Could not return the columns name")
7172
return false
7273
}
7374

@@ -108,11 +109,9 @@ func (c *Client) CheckRegexAgainstRow(query, regex string) bool {
108109
"regex": regex,
109110
"result": result,
110111
}).Info("Found a match")
111-
return value
112-
} else {
113-
return false
112+
return true
114113
}
115114
}
116115
}
117-
return true
116+
return false
118117
}

cmd/check/main.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func validate(destination checks.DefaultChecks, doc checks.Doc) error {
6666
if err != nil {
6767
log.WithFields(log.Fields{
6868
"RDS Instance": instance.Name,
69-
}).Errorf("Could not get snapshots: %s", err)
69+
}).WithError(err).Error("Could not get snapshots")
7070
return err
7171
}
7272
for _, snapshot := range snapshots {
@@ -77,7 +77,7 @@ func validate(destination checks.DefaultChecks, doc checks.Doc) error {
7777
log.WithFields(log.Fields{
7878
"RDS Instance": instance.Name,
7979
"Snapshot": *snapshot.DBSnapshotIdentifier,
80-
}).Errorf("Could not get snapshots: %s", err)
80+
}).WithError(err).Error("Could not get snapshots")
8181
return err
8282
}
8383
}
@@ -118,7 +118,7 @@ func caseReady(destination checks.DefaultChecks, snapshot *rds.DBSnapshot) error
118118
if err != nil {
119119
log.WithFields(log.Fields{
120120
"RDS Instance": *snapshot.DBInstanceIdentifier,
121-
}).Errorf("Could not create Database Subnet Group: %s", err)
121+
}).WithError(err).Error("Could not create Database Subnet Group")
122122
err = destination.UpdateTag(snapshot, "Status", "alarm")
123123
if err != nil {
124124
return err
@@ -138,7 +138,7 @@ func caseRestore(destination checks.DefaultChecks, snapshot *rds.DBSnapshot, ins
138138
log.WithFields(log.Fields{
139139
"Snapshot": *snapshot.DBSnapshotIdentifier,
140140
"RDS Instance": *snapshot.DBInstanceIdentifier + "-" + *snapshot.DBSnapshotIdentifier,
141-
}).Errorf("Could not create rds instance from snapshot: %s", err)
141+
}).WithError(err).Error("Could not create rds instance from snapshot")
142142
errors := destination.UpdateTag(snapshot, "Status", "alarm")
143143
if errors != nil {
144144
return err
@@ -227,7 +227,7 @@ func caseVerify(destination checks.DefaultChecks, snapshot *rds.DBSnapshot, inst
227227
"DB Name": *dbInfo.DBName,
228228
"Query": query.Query,
229229
"Regex": query.Regex,
230-
}).Errorf("Query matched failed: %s", err)
230+
}).WithError(err).Error("Query matched failed")
231231
errors := destination.UpdateTag(snapshot, "Status", "alarm")
232232
if errors != nil {
233233
return err
@@ -262,7 +262,7 @@ func caseClean(destination checks.DefaultChecks, snapshot *rds.DBSnapshot) error
262262
if err != nil {
263263
log.WithFields(log.Fields{
264264
"RDS Instance": *snapshot.DBInstanceIdentifier + "-" + *snapshot.DBSnapshotIdentifier,
265-
}).Errorf("Could not delete the rds instance: %s", err)
265+
}).WithError(err).Error("Could not delete the rds instance")
266266
return err
267267
}
268268

@@ -286,7 +286,7 @@ func caseTested(destination checks.DefaultChecks, snapshot *rds.DBSnapshot) erro
286286
if err != nil {
287287
log.WithFields(log.Fields{
288288
"RDS Instance": *snapshot.DBInstanceIdentifier,
289-
}).Errorf("Could not delete database subnet group: %s", err)
289+
}).WithError(err).Error("Could not delete database subnet group")
290290
return err
291291
}
292292
return nil

cmd/check/main_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ var singleInstance = &checks.Instances{
3434
Query: "SELECT tablename FROM pg_catalog.pg_tables;",
3535
Regex: "^pg_statistic$",
3636
},
37+
checks.Queries{
38+
Query: "SELECT tablename FROM pg_catalog.pg_tables;",
39+
Regex: "^pg_test$",
40+
},
3741
},
3842
}
3943

cmd/copy/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func copy(source checks.DefaultChecks, destination checks.DefaultChecks) error {
4646
log.WithFields(log.Fields{
4747
"RDS Instance": instance.Name,
4848
"AWS Region": config.AWSRegionSource,
49-
}).Errorf("Could not get snapshots: %s", err)
49+
}).WithError(err).Error("Could not get snapshots")
5050
return err
5151
}
5252
for _, snapshot := range snapshots {
@@ -92,7 +92,7 @@ func copy(source checks.DefaultChecks, destination checks.DefaultChecks) error {
9292
log.WithFields(log.Fields{
9393
"RDS Instance": instance.Name,
9494
"AWS Region": instance.Destination,
95-
}).Errorf("Could not get snapshots: %s", err)
95+
}).WithError(err).Error("Could not get snapshots")
9696
return err
9797
}
9898
for _, snapshot := range snapshots {

0 commit comments

Comments
 (0)