Skip to content

Commit

Permalink
feat: added error handling in collector level
Browse files Browse the repository at this point in the history
  • Loading branch information
Hardikl committed Feb 9, 2024
1 parent ba90e7a commit 2026829
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
10 changes: 9 additions & 1 deletion cmd/collectors/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,12 +583,20 @@ func (r *Rest) GetRestData(href string) ([]gjson.Result, error) {

result, err := rest.Fetch(r.Client, href)
if err != nil {
return nil, fmt.Errorf("failed to fetch data: %w", err)
return r.handleError(err, href)
}

return result, nil
}

func (r *Rest) handleError(err error, href string) ([]gjson.Result, error) {
if errs.IsRestErr(err, errs.MetroClusterNotConfigured) {
// MetroCluster is not configured in cluster, return ErrMetroClusterNotConfigured
return nil, fmt.Errorf("polling href=[%s] err: %w", href, errs.New(errs.ErrMetroClusterNotConfigured, err.Error()))
}
return nil, fmt.Errorf("failed to fetch data: %w", err)
}

func (r *Rest) CollectAutoSupport(p *collector.Payload) {
var exporterTypes []string
for _, exporter := range r.Exporters {
Expand Down
2 changes: 2 additions & 0 deletions cmd/poller/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ func (c *AbstractCollector) Start(wg *sync.WaitGroup) {
c.Schedule.SetStandByModeMax(task, 1*time.Hour)
// Log as info since some of these aren't errors
c.Logger.Info().Err(err).Str("task", task.Name).Msg("Entering standby mode")
} else if errors.Is(err, errs.ErrMetroClusterNotConfigured) {
c.Logger.Trace().Err(err).Str("task", task.Name).Msg("MetroCluster is not configured in cluster")
} else {
c.Logger.Error().Err(err).Str("task", task.Name).Send()
}
Expand Down
33 changes: 17 additions & 16 deletions pkg/errs/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,23 @@ type harvestError string
func (e harvestError) Error() string { return string(e) }

const (
ErrAPIRequestRejected = harvestError("API request rejected")
ErrAPIResponse = harvestError("error reading api response")
ErrAttributeNotFound = harvestError("attribute not found")
ErrAuthFailed = harvestError("auth failed")
ErrConfig = harvestError("configuration error")
ErrConnection = harvestError("connection error")
ErrImplement = harvestError("implementation error")
ErrInvalidItem = harvestError("invalid item")
ErrInvalidParam = harvestError("invalid parameter")
ErrMissingParam = harvestError("missing parameter")
ErrNoCollector = harvestError("no collectors")
ErrNoInstance = harvestError("no instances")
ErrNoMetric = harvestError("no metrics")
ErrPanic = harvestError("goroutine panic")
ErrPermissionDenied = harvestError("Permission denied")
ErrWrongTemplate = harvestError("wrong template")
ErrAPIRequestRejected = harvestError("API request rejected")
ErrAPIResponse = harvestError("error reading api response")
ErrAttributeNotFound = harvestError("attribute not found")
ErrAuthFailed = harvestError("auth failed")
ErrConfig = harvestError("configuration error")
ErrConnection = harvestError("connection error")
ErrImplement = harvestError("implementation error")
ErrInvalidItem = harvestError("invalid item")
ErrInvalidParam = harvestError("invalid parameter")
ErrMissingParam = harvestError("missing parameter")
ErrNoCollector = harvestError("no collectors")
ErrNoInstance = harvestError("no instances")
ErrNoMetric = harvestError("no metrics")
ErrPanic = harvestError("goroutine panic")
ErrPermissionDenied = harvestError("Permission denied")
ErrWrongTemplate = harvestError("wrong template")
ErrMetroClusterNotConfigured = harvestError("MetroCluster is not configured in cluster")
)

const (
Expand Down
5 changes: 3 additions & 2 deletions pkg/errs/ontap.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ type OntapRestCode struct {
}

var (
APINotFound = OntapRestCode{"API not found", 3}
TableNotFound = OntapRestCode{"Table is not found", 8585320}
APINotFound = OntapRestCode{"API not found", 3}
TableNotFound = OntapRestCode{"Table is not found", 8585320}
MetroClusterNotConfigured = OntapRestCode{"MetroCluster is not configured in cluster", 2426405}
)

func IsRestErr(err error, sentinel OntapRestCode) bool {
Expand Down

0 comments on commit 2026829

Please sign in to comment.