-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/advanced error handling #294
base: master
Are you sure you want to change the base?
Changes from all commits
df47b2e
fb9a94d
b1e3a10
39ec778
8f0930e
7cee7e2
093e16f
f6cc7e0
4684028
6584bce
2d89e3f
d539a7a
0f5d73a
03df3e1
702e632
2467994
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,8 +189,10 @@ func (aiService *AppinsightsMonitorService) GetByName(monitorName string) (*mode | |
log.Println("AppInsights Monitor's GetByName method has been called") | ||
webtest, err := aiService.insightsClient.Get(aiService.ctx, aiService.resourceGroup, monitorName) | ||
if err != nil { | ||
// if not found let's mark it as non-error | ||
if webtest.Response.StatusCode == http.StatusNotFound { | ||
return nil, fmt.Errorf("Application Insights WebTest %s was not found in Resource Group %s", monitorName, aiService.resourceGroup) | ||
log.Printf("Application Insights WebTest %s was not found in Resource Group %s", monitorName, aiService.resourceGroup) | ||
return nil, nil | ||
Comment on lines
+194
to
+195
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we removing this error from here ? |
||
} | ||
return nil, fmt.Errorf("Error retrieving Application Insights WebTests %s (Resource Group %s): %v", monitorName, aiService.resourceGroup, err) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,8 +60,9 @@ func (service *MonitorService) GetByName(name string) (monitor *models.Monitor, | |
return &localMonitor, nil | ||
} | ||
} | ||
|
||
return nil, fmt.Errorf("Unable to locate monitor with name %v", name) | ||
// monitor not found and no errors raised | ||
log.Printf("There is no gcloud MonitorService with name %s found.", name) | ||
return nil, nil | ||
Comment on lines
+64
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we removing this error from here ? |
||
} | ||
|
||
func (service *MonitorService) GetAll() (monitors []models.Monitor) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ type PingdomMonitorService struct { | |
client *pingdom.Client | ||
} | ||
|
||
func (monitor *PingdomMonitorService) Equal(oldMonitor models.Monitor, newMonitor models.Monitor) bool { | ||
func (service *PingdomMonitorService) Equal(oldMonitor models.Monitor, newMonitor models.Monitor) bool { | ||
// TODO: Retrieve oldMonitor config and compare it here | ||
return false | ||
} | ||
|
@@ -45,21 +45,23 @@ func (service *PingdomMonitorService) Setup(p config.Provider) { | |
BaseURL: service.url, | ||
}) | ||
if err != nil { | ||
log.Println("Error Seting Up Monitor Service: ", err.Error()) | ||
log.Println("Error Setting Up Monitor Service: ", err.Error()) | ||
} | ||
} | ||
|
||
func (service *PingdomMonitorService) GetByName(name string) (*models.Monitor, error) { | ||
var match *models.Monitor | ||
|
||
monitors := service.GetAll() | ||
monitors, err := service.GetAllWithAPIErrorHandler() | ||
if err != nil { | ||
return nil, fmt.Errorf("error received while getting all Pingdom monitors: %s", err.Error()) | ||
} | ||
for _, mon := range monitors { | ||
if mon.Name == name { | ||
return &mon, nil | ||
} | ||
} | ||
|
||
return match, fmt.Errorf("Unable to locate monitor with name %v", name) | ||
// neither error and any matched monitor | ||
log.Printf("There is no PingdomMonitorService with name %s found.", name) | ||
return nil, nil | ||
Comment on lines
+63
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we removing this error from here ? |
||
} | ||
|
||
func (service *PingdomMonitorService) GetAll() []models.Monitor { | ||
|
@@ -82,6 +84,26 @@ func (service *PingdomMonitorService) GetAll() []models.Monitor { | |
return monitors | ||
} | ||
|
||
// Function that gets all monitors with an error handling to avoid duplicate checks creation | ||
func (service *PingdomMonitorService) GetAllWithAPIErrorHandler() ([]models.Monitor, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know how this function can avoid duplication compared with the existing GetAll() one? |
||
var monitors []models.Monitor | ||
|
||
checks, err := service.client.Checks.List() | ||
if err != nil { | ||
return nil, err | ||
} | ||
for _, mon := range checks { | ||
newMon := models.Monitor{ | ||
URL: mon.Hostname, | ||
ID: fmt.Sprintf("%v", mon.ID), | ||
Name: mon.Name, | ||
} | ||
monitors = append(monitors, newMon) | ||
} | ||
|
||
return monitors, nil | ||
} | ||
|
||
func (service *PingdomMonitorService) Add(m models.Monitor) { | ||
httpCheck := service.createHttpCheck(m) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ package statuscake | |
import ( | ||
"bytes" | ||
"encoding/json" | ||
"errors" | ||
"io/ioutil" | ||
"net/http" | ||
"net/url" | ||
|
@@ -202,8 +201,8 @@ func (service *StatusCakeMonitorService) GetByName(name string) (*models.Monitor | |
return &monitor, nil | ||
} | ||
} | ||
errorString := "GetByName Request failed for name: " + name | ||
return nil, errors.New(errorString) | ||
log.Printf("There is no StatusCakeMonitorService with name %s found.", name) | ||
return nil, nil | ||
Comment on lines
+204
to
+205
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we removing this error from here ? |
||
} | ||
|
||
// GetAll function will fetch all monitors | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's unable to create a monitor this will be an endless re-conciliation loop !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But if it was only the API call error? E.g. API has returned 500 code, and we would be able to add this monitor on the next iteration?