forked from stolostron/thanos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Recover from panics in Series calls (thanos-io#6077)
* Recover from panics in Series calls This commit adds panic recovery for Series calls in all Store servers. Signed-off-by: Filip Petkovski <[email protected]> * Apply error suggestion Signed-off-by: Filip Petkovski <[email protected]> --------- Signed-off-by: Filip Petkovski <[email protected]>
- Loading branch information
1 parent
830da2b
commit 6507a04
Showing
10 changed files
with
106 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) The Thanos Authors. | ||
// Licensed under the Apache License 2.0. | ||
|
||
package store | ||
|
||
import ( | ||
"fmt" | ||
"runtime" | ||
|
||
"github.com/go-kit/log" | ||
"github.com/go-kit/log/level" | ||
"github.com/pkg/errors" | ||
|
||
"github.com/thanos-io/thanos/pkg/store/storepb" | ||
) | ||
|
||
type recoverableStoreServer struct { | ||
logger log.Logger | ||
storepb.StoreServer | ||
} | ||
|
||
func NewRecoverableStoreServer(logger log.Logger, storeServer storepb.StoreServer) *recoverableStoreServer { | ||
return &recoverableStoreServer{logger: logger, StoreServer: storeServer} | ||
} | ||
|
||
func (r *recoverableStoreServer) Series(request *storepb.SeriesRequest, srv storepb.Store_SeriesServer) error { | ||
defer r.recover(srv) | ||
return r.StoreServer.Series(request, srv) | ||
} | ||
|
||
func (r *recoverableStoreServer) recover(srv storepb.Store_SeriesServer) { | ||
e := recover() | ||
if e == nil { | ||
return | ||
} | ||
|
||
switch err := e.(type) { | ||
case runtime.Error: | ||
// Print the stack trace but do not inhibit the running application. | ||
buf := make([]byte, 64<<10) | ||
buf = buf[:runtime.Stack(buf, false)] | ||
|
||
level.Error(r.logger).Log("msg", "runtime panic in TSDB Series server", "err", err.Error(), "stacktrace", string(buf)) | ||
if err := srv.Send(storepb.NewWarnSeriesResponse(err)); err != nil { | ||
level.Error(r.logger).Log("err", err) | ||
} | ||
default: | ||
if err := srv.Send(storepb.NewWarnSeriesResponse(errors.New(fmt.Sprintf("unknown error while processing Series: %v", e)))); err != nil { | ||
level.Error(r.logger).Log("err", err) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) The Thanos Authors. | ||
// Licensed under the Apache License 2.0. | ||
|
||
package store | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/efficientgo/core/testutil" | ||
"github.com/go-kit/log" | ||
|
||
"github.com/thanos-io/thanos/pkg/store/storepb" | ||
) | ||
|
||
func TestRecoverableServer(t *testing.T) { | ||
logger := log.NewNopLogger() | ||
store := NewRecoverableStoreServer(logger, &panicStoreServer{}) | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
srv := storepb.NewInProcessStream(ctx, 1) | ||
|
||
testutil.Ok(t, store.Series(&storepb.SeriesRequest{}, srv)) | ||
} | ||
|
||
type panicStoreServer struct { | ||
storepb.StoreServer | ||
} | ||
|
||
func (m *panicStoreServer) Series(_ *storepb.SeriesRequest, _ storepb.Store_SeriesServer) error { | ||
panic("something went wrong.") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters