cloudflare/pint

Public

mirrored from https://github.com/cloudflare/pintAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
f06e37dc774cc7b4e5d1b30c65fe14537992badc

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

internal/promapi/errors.go

52lines · modecode

1package promapi
2
3import (
4 "errors"
5 "net"
6 "strings"
7 "syscall"
8 "time"
9
10 v1 "github.com/prometheus/client_golang/api/prometheus/v1"
11)
12
13func IsUnavailableError(err error) bool {
14 var apiErr *v1.Error
15 if ok := errors.As(err, &apiErr); ok {
16 return apiErr.Type == v1.ErrServer
17 }
18
19 return true
20}
21
22func CanRetryError(err error, delta time.Duration) (time.Duration, bool) {
23 if errors.Is(err, syscall.ECONNREFUSED) {
24 return delta, false
25 }
26
27 var neterr net.Error
28 if ok := errors.As(err, &neterr); ok && neterr.Timeout() {
29 return delta / 2, true
30 }
31
32 var apiErr *v1.Error
33 if ok := errors.As(err, &apiErr); ok {
34 switch apiErr.Type {
35 case v1.ErrBadData:
36 case v1.ErrTimeout:
37 return delta / 2, true
38 case v1.ErrCanceled:
39 case v1.ErrExec:
40 if strings.Contains(apiErr.Msg, "query processing would load too many samples into memory in ") {
41 return (delta / 4) * 3, true
42 }
43 return delta / 2, true
44 case v1.ErrBadResponse:
45 case v1.ErrServer:
46 case v1.ErrClient:
47 return delta / 2, true
48 }
49 }
50
51 return delta, false
52}
53