MCPcopy Create free account
hub / github.com/cortexproject/cortex / getCasErrorCode

Function getCasErrorCode

pkg/ring/kv/metrics.go:27–43  ·  view source on GitHub ↗

getCasErrorCode converts the provided CAS error into the code that should be used to track the operation in metrics.

(err error)

Source from the content-addressed store, hash-verified

25// getCasErrorCode converts the provided CAS error into the code that should be used to track the operation
26// in metrics.
27func getCasErrorCode(err error) string {
28 if err == nil {
29 return "200"
30 }
31 if resp, ok := httpgrpc.HTTPResponseFromError(err); ok {
32 return strconv.Itoa(int(resp.GetCode()))
33 }
34
35 // If the error has been returned to abort the CAS operation, then we shouldn't
36 // consider it an error when tracking metrics.
37 var casAborted interface{ IsOperationAborted() bool }
38 if errors.As(err, &casAborted) && casAborted.IsOperationAborted() {
39 return "200"
40 }
41
42 return "500"
43}
44
45type metrics struct {
46 c Client

Callers 1

TestGetCasErrorCodeFunction · 0.85

Calls 2

GetCodeMethod · 0.80
IsOperationAbortedMethod · 0.45

Tested by 1

TestGetCasErrorCodeFunction · 0.68