Skip to content

Commit

Permalink
send sentry for log.Error (#295)
Browse files Browse the repository at this point in the history
  • Loading branch information
jschwinger233 authored Dec 11, 2020
1 parent f648b90 commit 8b52f0b
Show file tree
Hide file tree
Showing 61 changed files with 317 additions and 91 deletions.
2 changes: 1 addition & 1 deletion client/interceptor/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"

"github.com/cenkalti/backoff/v4"
log "github.com/sirupsen/logrus"
"github.com/projecteru2/core/log"

"google.golang.org/grpc"
)
Expand Down
2 changes: 1 addition & 1 deletion client/resolver/eru/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"strings"

"github.com/projecteru2/core/client/servicediscovery"
"github.com/projecteru2/core/log"
"github.com/projecteru2/core/types"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc/resolver"
)

Expand Down
2 changes: 1 addition & 1 deletion client/servicediscovery/eru_service_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (

"github.com/projecteru2/core/auth"
"github.com/projecteru2/core/client/interceptor"
"github.com/projecteru2/core/log"
pb "github.com/projecteru2/core/rpc/gen"
"github.com/projecteru2/core/types"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc"
)

Expand Down
2 changes: 1 addition & 1 deletion client/servicediscovery/resolver.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package servicediscovery

import (
log "github.com/sirupsen/logrus"
"github.com/projecteru2/core/log"

"google.golang.org/grpc/resolver"
)
Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"time"

enginetypes "github.com/projecteru2/core/engine/types"
"github.com/projecteru2/core/log"
"github.com/projecteru2/core/types"
log "github.com/sirupsen/logrus"
)

// BuildImage will build image
Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/calcium.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/projecteru2/core/cluster"
"github.com/projecteru2/core/discovery"
"github.com/projecteru2/core/discovery/helium"
"github.com/projecteru2/core/log"
"github.com/projecteru2/core/scheduler"
complexscheduler "github.com/projecteru2/core/scheduler/complex"
"github.com/projecteru2/core/source"
Expand All @@ -14,7 +15,6 @@ import (
"github.com/projecteru2/core/store"
"github.com/projecteru2/core/store/etcdv3"
"github.com/projecteru2/core/types"
log "github.com/sirupsen/logrus"
)

// Calcium implement the cluster
Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/capacity.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"context"

"github.com/pkg/errors"
"github.com/projecteru2/core/log"
"github.com/projecteru2/core/resources"
resourcetypes "github.com/projecteru2/core/resources/types"
"github.com/projecteru2/core/strategy"
"github.com/projecteru2/core/types"
log "github.com/sirupsen/logrus"
)

// CalculateCapacity calculates capacity
Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"sync"

"github.com/projecteru2/core/cluster"
"github.com/projecteru2/core/log"
"github.com/projecteru2/core/types"
"github.com/projecteru2/core/utils"
log "github.com/sirupsen/logrus"
)

// ControlWorkload control workloads status
Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"sync"

"github.com/projecteru2/core/log"
"github.com/projecteru2/core/types"
log "github.com/sirupsen/logrus"
)

// Copy uses VirtualizationCopyFrom cp to copy specified things and send to remote
Expand Down
4 changes: 2 additions & 2 deletions cluster/calcium/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
"github.com/projecteru2/core/metrics"
resourcetypes "github.com/projecteru2/core/resources/types"

"github.com/projecteru2/core/log"
"github.com/projecteru2/core/types"
"github.com/projecteru2/core/utils"
"github.com/sanity-io/litter"
log "github.com/sirupsen/logrus"
)

// CreateWorkload use options to create workloads
Expand Down Expand Up @@ -116,7 +116,7 @@ func (c *Calcium) doCreateWorkloads(ctx context.Context, opts *types.DeployOptio
}
}()

return ch, err
return ch, errors.WithStack(err)
}

func (c *Calcium) doDeployWorkloads(ctx context.Context, ch chan *types.CreateWorkloadMessage, opts *types.DeployOptions, plans []resourcetypes.ResourcePlans, deployMap map[string]int) (_ map[string][]int, err error) {
Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/dissociate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package calcium
import (
"context"

"github.com/projecteru2/core/log"
"github.com/projecteru2/core/store"
"github.com/projecteru2/core/types"
"github.com/projecteru2/core/utils"
log "github.com/sirupsen/logrus"
)

// DissociateWorkload dissociate workload from eru, return it resource but not modity it
Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"strconv"

enginetypes "github.com/projecteru2/core/engine/types"
"github.com/projecteru2/core/log"
"github.com/projecteru2/core/types"
log "github.com/sirupsen/logrus"
)

// ExecuteWorkload executes commands in running workloads
Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (

"github.com/projecteru2/core/engine"
enginetypes "github.com/projecteru2/core/engine/types"
"github.com/projecteru2/core/log"
"github.com/projecteru2/core/types"
"github.com/projecteru2/core/utils"
log "github.com/sirupsen/logrus"
"golang.org/x/net/context"
)

Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"sync"

"github.com/projecteru2/core/log"
"github.com/projecteru2/core/types"
log "github.com/sirupsen/logrus"
)

// RemoveImage remove images
Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/lambda.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"sync"

enginetypes "github.com/projecteru2/core/engine/types"
"github.com/projecteru2/core/log"
"github.com/projecteru2/core/strategy"
"github.com/projecteru2/core/types"
"github.com/projecteru2/core/utils"
log "github.com/sirupsen/logrus"
)

const exitDataPrefix = "[exitcode] "
Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

"github.com/projecteru2/core/cluster"
"github.com/projecteru2/core/lock"
"github.com/projecteru2/core/log"
"github.com/projecteru2/core/types"
log "github.com/sirupsen/logrus"
)

func (c *Calcium) doLock(ctx context.Context, name string, timeout time.Duration) (lock.DistributedLock, error) {
Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package calcium
import (
"context"

"github.com/projecteru2/core/log"
"github.com/projecteru2/core/types"
"github.com/sanity-io/litter"
log "github.com/sirupsen/logrus"
)

// AddNode adds a node
Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/projecteru2/core/store"
"github.com/projecteru2/core/utils"

"github.com/projecteru2/core/log"
"github.com/projecteru2/core/types"
log "github.com/sirupsen/logrus"
)

// RemoveWorkload remove workloads
Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"sync"

enginetypes "github.com/projecteru2/core/engine/types"
"github.com/projecteru2/core/log"
"github.com/projecteru2/core/types"
"github.com/projecteru2/core/utils"
log "github.com/sirupsen/logrus"
)

// ReplaceWorkload replace workloads with same resource
Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"

"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/projecteru2/core/log"

resourcetypes "github.com/projecteru2/core/resources/types"
"github.com/projecteru2/core/strategy"
Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"sync"

"github.com/projecteru2/core/engine"
"github.com/projecteru2/core/log"
"github.com/projecteru2/core/types"
log "github.com/sirupsen/logrus"
)

// Send send files to workload
Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"sync"
"time"

"github.com/projecteru2/core/log"
"github.com/projecteru2/core/types"
"github.com/projecteru2/core/utils"
log "github.com/sirupsen/logrus"
)

// WatchServiceStatus returns chan of available service address
Expand Down
36 changes: 23 additions & 13 deletions core.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ import (
"net/http"
_ "net/http/pprof" // nolint
"os"
"time"

"github.com/getsentry/sentry-go"
"github.com/projecteru2/core/auth"
"github.com/projecteru2/core/cluster/calcium"
"github.com/projecteru2/core/log"
"github.com/projecteru2/core/metrics"
"github.com/projecteru2/core/rpc"
pb "github.com/projecteru2/core/rpc/gen"
"github.com/projecteru2/core/utils"
"github.com/projecteru2/core/version"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/sethvargo/go-signalcontext"
log "github.com/sirupsen/logrus"
cli "github.com/urfave/cli/v2"
"google.golang.org/grpc"

Expand All @@ -28,20 +30,22 @@ var (
embeddedStorage bool
)

func setupLog(l string) error {
level, err := log.ParseLevel(l)
if err != nil {
return err
func setupSentry(dsn string) (func(), error) {
if dsn == "" {
return nil, nil
}
log.SetLevel(level)

formatter := &log.TextFormatter{
TimestampFormat: "2006-01-02 15:04:05",
FullTimestamp: true,
sentryDefer := func() {
defer sentry.Flush(2 * time.Second)
err := recover()
if err != nil {
sentry.CaptureMessage(fmt.Sprintf("%+v", err))
panic(err)
}
}
log.SetFormatter(formatter)
log.SetOutput(os.Stdout)
return nil
return sentryDefer, sentry.Init(sentry.ClientOptions{
Dsn: dsn,
})
}

func serve(c *cli.Context) error {
Expand All @@ -50,10 +54,16 @@ func serve(c *cli.Context) error {
log.Fatalf("[main] %v", err)
}

if err := setupLog(config.LogLevel); err != nil {
if err := log.SetupLog(config.LogLevel); err != nil {
log.Fatalf("[main] %v", err)
}

if sentryDefer, err := setupSentry(config.SentryDSN); err != nil {
log.Warnf("[main] sentry %v", err)
} else if sentryDefer != nil {
defer sentryDefer()
}

if err := metrics.InitMetrics(config); err != nil {
log.Fatalf("[main] %v", err)
}
Expand Down
1 change: 1 addition & 0 deletions core.yaml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ profile: ":12346"
global_timeout: 300s
lock_timeout: 30s
cert_path: "/etc/eru/tls"
sentry_dsn: "https://[email protected]/0"

auth:
username: admin
Expand Down
2 changes: 1 addition & 1 deletion discovery/helium/helium.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"time"

"github.com/google/uuid"
"github.com/projecteru2/core/log"
"github.com/projecteru2/core/store"
"github.com/projecteru2/core/types"
log "github.com/sirupsen/logrus"
)

// Helium .
Expand Down
2 changes: 1 addition & 1 deletion engine/docker/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (

"github.com/projecteru2/core/engine/types"
enginetypes "github.com/projecteru2/core/engine/types"
"github.com/projecteru2/core/log"
coresource "github.com/projecteru2/core/source"
coretypes "github.com/projecteru2/core/types"
"github.com/projecteru2/core/utils"
log "github.com/sirupsen/logrus"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion engine/docker/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/docker/go-units"
"github.com/pkg/errors"

log "github.com/sirupsen/logrus"
"github.com/projecteru2/core/log"

dockertypes "github.com/docker/docker/api/types"
dockercontainer "github.com/docker/docker/api/types/container"
Expand Down
2 changes: 1 addition & 1 deletion engine/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/docker/go-connections/tlsconfig"
"github.com/projecteru2/core/engine"
enginetypes "github.com/projecteru2/core/engine/types"
"github.com/projecteru2/core/log"
coretypes "github.com/projecteru2/core/types"
log "github.com/sirupsen/logrus"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion engine/docker/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
corecluster "github.com/projecteru2/core/cluster"
"github.com/projecteru2/core/engine"
enginetypes "github.com/projecteru2/core/engine/types"
"github.com/projecteru2/core/log"
"github.com/projecteru2/core/types"
coretypes "github.com/projecteru2/core/types"
log "github.com/sirupsen/logrus"

"github.com/docker/distribution/reference"
dockertypes "github.com/docker/docker/api/types"
Expand Down
2 changes: 1 addition & 1 deletion engine/docker/tarfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"os"
"path/filepath"

log "github.com/sirupsen/logrus"
"github.com/projecteru2/core/log"
)

func withTarfileDump(target string, content io.Reader, f func(target, tarfile string) error) error {
Expand Down
2 changes: 1 addition & 1 deletion engine/systemd/systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
coretypes "github.com/projecteru2/core/types"
"golang.org/x/crypto/ssh"

log "github.com/sirupsen/logrus"
"github.com/projecteru2/core/log"
)

const (
Expand Down
Loading

0 comments on commit 8b52f0b

Please sign in to comment.