metrics: add worker error metrics
This commit introduces the collection of error metrics since it is now possible to differentiate between internal errors and user input errors. Additionally, the error status is reported for job duration metrics.
This commit is contained in:
parent
6c4caec022
commit
290472dfdf
3 changed files with 50 additions and 4 deletions
|
|
@ -34,6 +34,40 @@ type Error struct {
|
|||
Details interface{} `json:"details"`
|
||||
}
|
||||
|
||||
const (
|
||||
JobStatusSuccess = "2xx"
|
||||
JobStatusUserInputError = "4xx"
|
||||
JobStatusInternalError = "5xx"
|
||||
)
|
||||
|
||||
type StatusCode string
|
||||
|
||||
func (s *StatusCode) ToString() string {
|
||||
return string(*s)
|
||||
}
|
||||
|
||||
func GetStatusCode(err *Error) StatusCode {
|
||||
if err == nil {
|
||||
return JobStatusSuccess
|
||||
}
|
||||
switch err.ID {
|
||||
case ErrorDNFDepsolveError:
|
||||
return JobStatusInternalError
|
||||
case ErrorDNFMarkingError:
|
||||
return JobStatusInternalError
|
||||
case ErrorNoDynamicArgs:
|
||||
return JobStatusUserInputError
|
||||
case ErrorInvalidTargetConfig:
|
||||
return JobStatusUserInputError
|
||||
case ErrorSharingTarget:
|
||||
return JobStatusUserInputError
|
||||
case ErrorInvalidTarget:
|
||||
return JobStatusUserInputError
|
||||
default:
|
||||
return JobStatusInternalError
|
||||
}
|
||||
}
|
||||
|
||||
func WorkerClientError(code ClientErrorCode, reason string, details ...interface{}) *Error {
|
||||
return &Error{
|
||||
ID: code,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue