cloudflare/pint

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.13.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

internal/promapi/errors.go

69lines · 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
13type Error struct {
14 err error
15 isStrict bool
16}
17
18func (e *Error) Unwrap() error {
19 return e.err
20}
21
22func (e *Error) Error() string {
23 return e.err.Error()
24}
25
26func (e *Error) IsStrict() bool {
27 return e.isStrict
28}
29
30func IsUnavailableError(err error) bool {
31 var apiErr *v1.Error
32 if ok := errors.As(err, &apiErr); ok {
33 return apiErr.Type == v1.ErrServer
34 }
35
36 return true
37}
38
39func CanRetryError(err error, delta time.Duration) (time.Duration, bool) {
40 if errors.Is(err, syscall.ECONNREFUSED) {
41 return delta, false
42 }
43
44 var neterr net.Error
45 if ok := errors.As(err, &neterr); ok && neterr.Timeout() {
46 return delta / 2, true
47 }
48
49 var apiErr *v1.Error
50 if ok := errors.As(err, &apiErr); ok {
51 switch apiErr.Type {
52 case v1.ErrBadData:
53 case v1.ErrTimeout:
54 return delta / 2, true
55 case v1.ErrCanceled:
56 case v1.ErrExec:
57 if strings.Contains(apiErr.Msg, "query processing would load too many samples into memory in ") {
58 return (delta / 4) * 3, true
59 }
60 return delta / 2, true
61 case v1.ErrBadResponse:
62 case v1.ErrServer:
63 case v1.ErrClient:
64 return delta / 2, true
65 }
66 }
67
68 return delta, false
69}
70