mirror of
https://github.com/chrislusf/seaweedfs
synced 2024-06-03 01:00:04 +02:00
Compare commits
2 commits
a6eb21d41a
...
5dc299a52d
Author | SHA1 | Date | |
---|---|---|---|
5dc299a52d | |||
c8922b9c2e |
|
@ -10,8 +10,10 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
sentryhttp "github.com/getsentry/sentry-go/http"
|
||||||
"google.golang.org/grpc/reflection"
|
"google.golang.org/grpc/reflection"
|
||||||
|
|
||||||
|
"github.com/getsentry/sentry-go"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/filer"
|
"github.com/seaweedfs/seaweedfs/weed/filer"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/pb"
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
||||||
|
@ -264,6 +266,7 @@ func (fo *FilerOptions) startFiler() {
|
||||||
AllowedOrigins: strings.Split(*fo.allowedOrigins, ","),
|
AllowedOrigins: strings.Split(*fo.allowedOrigins, ","),
|
||||||
})
|
})
|
||||||
if nfs_err != nil {
|
if nfs_err != nil {
|
||||||
|
sentry.CaptureException(nfs_err)
|
||||||
glog.Fatalf("Filer startup error: %v", nfs_err)
|
glog.Fatalf("Filer startup error: %v", nfs_err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,16 +275,21 @@ func (fo *FilerOptions) startFiler() {
|
||||||
glog.V(0).Infoln("Start Seaweed filer server", util.Version(), "public at", publicListeningAddress)
|
glog.V(0).Infoln("Start Seaweed filer server", util.Version(), "public at", publicListeningAddress)
|
||||||
publicListener, localPublicListener, e := util.NewIpAndLocalListeners(*fo.bindIp, *fo.publicPort, 0)
|
publicListener, localPublicListener, e := util.NewIpAndLocalListeners(*fo.bindIp, *fo.publicPort, 0)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
|
sentry.CaptureException(e)
|
||||||
glog.Fatalf("Filer server public listener error on port %d:%v", *fo.publicPort, e)
|
glog.Fatalf("Filer server public listener error on port %d:%v", *fo.publicPort, e)
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
if e := http.Serve(publicListener, publicVolumeMux); e != nil {
|
if e := http.Serve(publicListener, publicVolumeMux); e != nil {
|
||||||
|
localHub := sentry.CurrentHub().Clone()
|
||||||
|
localHub.CaptureException(e)
|
||||||
glog.Fatalf("Volume server fail to serve public: %v", e)
|
glog.Fatalf("Volume server fail to serve public: %v", e)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
if localPublicListener != nil {
|
if localPublicListener != nil {
|
||||||
go func() {
|
go func() {
|
||||||
if e := http.Serve(localPublicListener, publicVolumeMux); e != nil {
|
if e := http.Serve(localPublicListener, publicVolumeMux); e != nil {
|
||||||
|
localHub := sentry.CurrentHub().Clone()
|
||||||
|
localHub.CaptureException(e)
|
||||||
glog.Errorf("Volume server fail to serve public: %v", e)
|
glog.Errorf("Volume server fail to serve public: %v", e)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
@ -294,6 +302,7 @@ func (fo *FilerOptions) startFiler() {
|
||||||
time.Duration(10)*time.Second,
|
time.Duration(10)*time.Second,
|
||||||
)
|
)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
|
sentry.CaptureException(e)
|
||||||
glog.Fatalf("Filer listener error: %v", e)
|
glog.Fatalf("Filer listener error: %v", e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,6 +310,7 @@ func (fo *FilerOptions) startFiler() {
|
||||||
grpcPort := *fo.portGrpc
|
grpcPort := *fo.portGrpc
|
||||||
grpcL, grpcLocalL, err := util.NewIpAndLocalListeners(*fo.bindIp, grpcPort, 0)
|
grpcL, grpcLocalL, err := util.NewIpAndLocalListeners(*fo.bindIp, grpcPort, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
sentry.CaptureException(err)
|
||||||
glog.Fatalf("failed to listen on grpc port %d: %v", grpcPort, err)
|
glog.Fatalf("failed to listen on grpc port %d: %v", grpcPort, err)
|
||||||
}
|
}
|
||||||
grpcS := pb.NewGrpcServer(security.LoadServerTLS(util.GetViper(), "grpc.filer"))
|
grpcS := pb.NewGrpcServer(security.LoadServerTLS(util.GetViper(), "grpc.filer"))
|
||||||
|
@ -311,19 +321,22 @@ func (fo *FilerOptions) startFiler() {
|
||||||
}
|
}
|
||||||
go grpcS.Serve(grpcL)
|
go grpcS.Serve(grpcL)
|
||||||
|
|
||||||
httpS := &http.Server{Handler: defaultMux}
|
httpS := &http.Server{Handler: sentryhttp.New(sentryhttp.Options{}).Handle(defaultMux)}
|
||||||
if runtime.GOOS != "windows" {
|
if runtime.GOOS != "windows" {
|
||||||
localSocket := *fo.localSocket
|
localSocket := *fo.localSocket
|
||||||
if localSocket == "" {
|
if localSocket == "" {
|
||||||
localSocket = fmt.Sprintf("/tmp/seaweedfs-filer-%d.sock", *fo.port)
|
localSocket = fmt.Sprintf("/tmp/seaweedfs-filer-%d.sock", *fo.port)
|
||||||
}
|
}
|
||||||
if err := os.Remove(localSocket); err != nil && !os.IsNotExist(err) {
|
if err := os.Remove(localSocket); err != nil && !os.IsNotExist(err) {
|
||||||
|
sentry.CaptureException(err)
|
||||||
glog.Fatalf("Failed to remove %s, error: %s", localSocket, err.Error())
|
glog.Fatalf("Failed to remove %s, error: %s", localSocket, err.Error())
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
// start on local unix socket
|
// start on local unix socket
|
||||||
filerSocketListener, err := net.Listen("unix", localSocket)
|
filerSocketListener, err := net.Listen("unix", localSocket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
localHub := sentry.CurrentHub().Clone()
|
||||||
|
localHub.CaptureException(err)
|
||||||
glog.Fatalf("Failed to listen on %s: %v", localSocket, err)
|
glog.Fatalf("Failed to listen on %s: %v", localSocket, err)
|
||||||
}
|
}
|
||||||
httpS.Serve(filerSocketListener)
|
httpS.Serve(filerSocketListener)
|
||||||
|
@ -332,11 +345,14 @@ func (fo *FilerOptions) startFiler() {
|
||||||
if filerLocalListener != nil {
|
if filerLocalListener != nil {
|
||||||
go func() {
|
go func() {
|
||||||
if err := httpS.Serve(filerLocalListener); err != nil {
|
if err := httpS.Serve(filerLocalListener); err != nil {
|
||||||
|
localHub := sentry.CurrentHub().Clone()
|
||||||
|
localHub.CaptureException(e)
|
||||||
glog.Errorf("Filer Fail to serve: %v", e)
|
glog.Errorf("Filer Fail to serve: %v", e)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
if err := httpS.Serve(filerListener); err != nil {
|
if err := httpS.Serve(filerListener); err != nil {
|
||||||
|
sentry.CaptureException(err)
|
||||||
glog.Fatalf("Filer Fail to serve: %v", e)
|
glog.Fatalf("Filer Fail to serve: %v", e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ import (
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
|
||||||
|
sentryhttp "github.com/getsentry/sentry-go/http"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/s3api"
|
"github.com/seaweedfs/seaweedfs/weed/s3api"
|
||||||
stats_collect "github.com/seaweedfs/seaweedfs/weed/stats"
|
stats_collect "github.com/seaweedfs/seaweedfs/weed/stats"
|
||||||
|
@ -236,7 +237,8 @@ func (s3opt *S3Options) startS3Server() bool {
|
||||||
glog.Fatalf("S3 API Server startup error: %v", s3ApiServer_err)
|
glog.Fatalf("S3 API Server startup error: %v", s3ApiServer_err)
|
||||||
}
|
}
|
||||||
|
|
||||||
httpS := &http.Server{Handler: router}
|
sentryHandler := sentryhttp.New(sentryhttp.Options{})
|
||||||
|
httpS := &http.Server{Handler: sentryHandler.Handle(router)}
|
||||||
|
|
||||||
if *s3opt.portGrpc == 0 {
|
if *s3opt.portGrpc == 0 {
|
||||||
*s3opt.portGrpc = 10000 + *s3opt.port
|
*s3opt.portGrpc = 10000 + *s3opt.port
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
sentryhttp "github.com/getsentry/sentry-go/http"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/collectors"
|
"github.com/prometheus/client_golang/prometheus/collectors"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
|
@ -337,7 +338,8 @@ func StartMetricsServer(ip string, port int) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
http.Handle("/metrics", promhttp.HandlerFor(Gather, promhttp.HandlerOpts{}))
|
http.Handle("/metrics", promhttp.HandlerFor(Gather, promhttp.HandlerOpts{}))
|
||||||
log.Fatal(http.ListenAndServe(JoinHostPort(ip, port), nil))
|
handler := sentryhttp.New(sentryhttp.Options{}).Handle(http.DefaultServeMux)
|
||||||
|
log.Fatal(http.ListenAndServe(JoinHostPort(ip, port), handler))
|
||||||
}
|
}
|
||||||
|
|
||||||
func SourceName(port uint32) string {
|
func SourceName(port uint32) string {
|
||||||
|
|
22
weed/weed.go
22
weed/weed.go
|
@ -51,14 +51,13 @@ func main() {
|
||||||
glog.MaxFileCount = 5
|
glog.MaxFileCount = 5
|
||||||
flag.Usage = usage
|
flag.Usage = usage
|
||||||
|
|
||||||
err := sentry.Init(sentry.ClientOptions{
|
err := initSentry()
|
||||||
SampleRate: 0.1,
|
// Sentry does not return error for empty or unreachable DSN
|
||||||
EnableTracing: true,
|
// Provided DSN might be incorrect, so let's terminate program because we will call sentry later
|
||||||
TracesSampleRate: 0.1,
|
|
||||||
ProfilesSampleRate: 0.1,
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "sentry.Init: %v", err)
|
fmt.Fprintf(os.Stderr, "sentry.Init: %v", err)
|
||||||
|
setExitStatus(1)
|
||||||
|
exit()
|
||||||
}
|
}
|
||||||
// Flush buffered events before the program terminates.
|
// Flush buffered events before the program terminates.
|
||||||
// Set the timeout to the maximum duration the program can afford to wait.
|
// Set the timeout to the maximum duration the program can afford to wait.
|
||||||
|
@ -128,12 +127,23 @@ var helpTemplate = `{{if .Runnable}}Usage: weed {{.UsageLine}}
|
||||||
{{.Long}}
|
{{.Long}}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
func initSentry() error {
|
||||||
|
return sentry.Init(sentry.ClientOptions{
|
||||||
|
SampleRate: 0.1,
|
||||||
|
EnableTracing: true,
|
||||||
|
TracesSampleRate: 0.1,
|
||||||
|
ProfilesSampleRate: 0.1,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// tmpl executes the given template text on data, writing the result to w.
|
// tmpl executes the given template text on data, writing the result to w.
|
||||||
func tmpl(w io.Writer, text string, data interface{}) {
|
func tmpl(w io.Writer, text string, data interface{}) {
|
||||||
t := template.New("top")
|
t := template.New("top")
|
||||||
t.Funcs(template.FuncMap{"trim": strings.TrimSpace, "capitalize": capitalize})
|
t.Funcs(template.FuncMap{"trim": strings.TrimSpace, "capitalize": capitalize})
|
||||||
template.Must(t.Parse(text))
|
template.Must(t.Parse(text))
|
||||||
if err := t.Execute(w, data); err != nil {
|
if err := t.Execute(w, data); err != nil {
|
||||||
|
sentry.CaptureException(err)
|
||||||
|
sentry.Flush(2 * time.Second)
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
25
weed/weed_test.go
Normal file
25
weed/weed_test.go
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestInitSentryNoDSN(t *testing.T) {
|
||||||
|
assert.Nil(t, initSentry())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestInitSentryEmptyDSN(t *testing.T) {
|
||||||
|
t.Setenv("SENTRY_DSN", "")
|
||||||
|
assert.Nil(t, initSentry())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestInitSentryTestDSN(t *testing.T) {
|
||||||
|
t.Setenv("SENTRY_DSN", "https://example@example.com/123")
|
||||||
|
assert.Nil(t, initSentry())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestInitSentryInvalidDSN(t *testing.T) {
|
||||||
|
t.Setenv("SENTRY_DSN", "https://example.com")
|
||||||
|
assert.NotNil(t, initSentry())
|
||||||
|
}
|
Loading…
Reference in a new issue