use fork of roll so that we don't crash on 429 errors

This commit is contained in:
Jesse Duffield 2019-06-29 20:50:24 +10:00
parent c57b7122df
commit 4856a3d872
8 changed files with 36 additions and 30 deletions

34
Gopkg.lock generated
View file

@ -105,14 +105,6 @@
revision = "a6af135bd4e28680facf08a3d206b454abc877a4"
version = "v1.0.1"
[[projects]]
branch = "master"
digest = "1:d457d39e88f678ed14ac29517c3d74927a48dbc6a9f073fa241cf364a68cbe5c"
name = "github.com/heroku/rollrus"
packages = ["."]
pruneopts = "NUT"
revision = "fc0cef2ff331aebb24cd4e9ded7e20650f3d7006"
[[projects]]
digest = "1:aaa38889f11896ee3644d77e17dc7764cc47f5f3d3b488268df2af2b52541c5f"
name = "github.com/imdario/mergo"
@ -145,6 +137,22 @@
pruneopts = "NUT"
revision = "02db52c7e406c7abec44c717a173c7715e4c1b62"
[[projects]]
branch = "master"
digest = "1:7429d1589cc1454e9e97ba48cb7c5025a085b32eae4d3163c517e3e5d6c7a7a0"
name = "github.com/jesseduffield/roll"
packages = ["."]
pruneopts = "NUT"
revision = "695be2e62b007ecef6644383f0ee9504c1f5cbb9"
[[projects]]
branch = "master"
digest = "1:ec8982ff49a9ebdd7d7dfe320258ad19a07baafb5eeba7f41b31ee2072d1bba9"
name = "github.com/jesseduffield/rollrus"
packages = ["."]
pruneopts = "NUT"
revision = "7086c0b1b1bd21ef1f502e914ff2505a68c7d638"
[[projects]]
branch = "master"
digest = "1:e0306e92cef41d02af05a9f88395ec49c94f0255d54ca88ee3c02ae8f5806ee3"
@ -256,14 +264,6 @@
revision = "f35b8ab0b5a2cef36673838d662e249dd9c94686"
version = "v1.2.2"
[[projects]]
branch = "master"
digest = "1:e42372d3f4921ec35df07f9b23239631e9d28580f7c1edcca212bc6daddc68fe"
name = "github.com/stvp/roll"
packages = ["."]
pruneopts = "NUT"
revision = "3627a5cbeaeaa68023abd02bb8687925265f2f63"
[[projects]]
digest = "1:cd5ffc5bda4e0296ab3e4de90dbb415259c78e45e7fab13694b14cde8ab74541"
name = "github.com/tcnksm/go-gitconfig"
@ -326,11 +326,11 @@
"github.com/docker/docker/client",
"github.com/fatih/color",
"github.com/go-errors/errors",
"github.com/heroku/rollrus",
"github.com/imdario/mergo",
"github.com/jesseduffield/asciigraph",
"github.com/jesseduffield/gocui",
"github.com/jesseduffield/pty",
"github.com/jesseduffield/rollrus",
"github.com/jesseduffield/yaml",
"github.com/mcuadros/go-lookup",
"github.com/mgutz/str",

View file

@ -48,3 +48,7 @@
[[constraint]]
branch = "v2"
name = "github.com/jesseduffield/yaml"
[[constraint]]
branch = "master"
name = "github.com/jesseduffield/roll"

View file

@ -6,8 +6,8 @@ import (
"os"
"path/filepath"
"github.com/heroku/rollrus"
"github.com/jesseduffield/lazydocker/pkg/config"
"github.com/jesseduffield/rollrus"
"github.com/sirupsen/logrus"
)

View file

@ -203,7 +203,8 @@ func (c *rollbarClient) send(item map[string]interface{}) (uuid string, err erro
resp, err := http.Post(Endpoint, "application/json", bytes.NewReader(jsonBody))
if err != nil {
return "", err
// If something goes wrong it really does not matter
return "", nil
}
defer func() {
io.Copy(ioutil.Discard, resp.Body)
@ -211,7 +212,8 @@ func (c *rollbarClient) send(item map[string]interface{}) (uuid string, err erro
}()
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("Rollbar returned %s", resp.Status)
// If something goes wrong it really does not matter
return "", nil
}
// Extract UUID from JSON response

View file

@ -1,4 +1,4 @@
// Package rollrus combines github.com/stvp/roll with github.com/sirupsen/logrus
// Package rollrus combines github.com/jesseduffield/roll with github.com/sirupsen/logrus
// via logrus.Hook mechanism, so that whenever logrus' logger.Error/f(),
// logger.Fatal/f() or logger.Panic/f() are used the messages are
// intercepted and sent to rollbar.
@ -22,9 +22,9 @@ import (
"os"
"time"
"github.com/jesseduffield/roll"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/stvp/roll"
)
var defaultTriggerLevels = []logrus.Level{
@ -37,7 +37,7 @@ var defaultTriggerLevels = []logrus.Level{
type Hook struct {
roll.Client
triggers []logrus.Level
ignoredErrors map[error]struct{}
ignoredErrors []error
ignoreErrorFunc func(error) bool
ignoreFunc func(error, map[string]string) bool
@ -78,12 +78,10 @@ func WithMinLevel(level logrus.Level) OptionFunc {
}
// WithIgnoredErrors is an OptionFunc that whitelists certain errors to prevent
// them from firing.
// them from firing. See https://golang.org/ref/spec#Comparison_operators
func WithIgnoredErrors(errors ...error) OptionFunc {
return func(h *Hook) {
for _, e := range errors {
h.ignoredErrors[e] = struct{}{}
}
h.ignoredErrors = append(h.ignoredErrors, errors...)
}
}
@ -120,7 +118,7 @@ func NewHookForLevels(token string, env string, levels []logrus.Level) *Hook {
return &Hook{
Client: roll.New(token, env),
triggers: levels,
ignoredErrors: make(map[error]struct{}),
ignoredErrors: make([]error, 0),
ignoreErrorFunc: func(error) bool { return false },
ignoreFunc: func(error, map[string]string) bool { return false },
}
@ -179,8 +177,10 @@ func (r *Hook) Levels() []logrus.Level {
// returned by Levels().
func (r *Hook) Fire(entry *logrus.Entry) error {
trace, cause := extractError(entry)
if _, ok := r.ignoredErrors[cause]; ok {
return nil
for _, ie := range r.ignoredErrors {
if ie == cause {
return nil
}
}
if r.ignoreErrorFunc(cause) {