mirror of
https://github.com/cloudnative-pg/plugin-barman-cloud.git
synced 2026-01-12 05:33:11 +01:00
feat: return 404 for missing WAL files
The plugin now returns a 404 status code when a requested WAL file does not exist in the object store. This prevents misleading log entries such as "Error while handling gRPC request" for expected missing-file scenarios. Signed-off-by: Leonardo Cecchi <leonardo.cecchi@enterprisedb.com>
This commit is contained in:
parent
65a0d11ec8
commit
e5a0aeed34
@ -1,16 +1,14 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
// walNotFoundError is raised when a WAL file has not been found in the object store
|
import (
|
||||||
type walNotFoundError struct{}
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/status"
|
||||||
|
)
|
||||||
|
|
||||||
func newWALNotFoundError() *walNotFoundError { return &walNotFoundError{} }
|
// newWALNotFoundError returns a error that states that a
|
||||||
|
// certain WAL file has not been found. This error is
|
||||||
// ShouldPrintStackTrace tells whether the sidecar log stream should contain the stack trace
|
// compatible with GRPC status codes, resulting in a 404
|
||||||
func (e walNotFoundError) ShouldPrintStackTrace() bool {
|
// being used as a response code.
|
||||||
return false
|
func newWALNotFoundError(walName string) error {
|
||||||
}
|
return status.Errorf(codes.NotFound, "wal %q not found", walName)
|
||||||
|
|
||||||
// Error implements the error interface
|
|
||||||
func (e walNotFoundError) Error() string {
|
|
||||||
return "WAL file not found"
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,8 @@ import (
|
|||||||
"github.com/cloudnative-pg/machinery/pkg/fileutils"
|
"github.com/cloudnative-pg/machinery/pkg/fileutils"
|
||||||
walUtils "github.com/cloudnative-pg/machinery/pkg/fileutils/wals"
|
walUtils "github.com/cloudnative-pg/machinery/pkg/fileutils/wals"
|
||||||
"github.com/cloudnative-pg/machinery/pkg/log"
|
"github.com/cloudnative-pg/machinery/pkg/log"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/status"
|
||||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
@ -350,7 +352,7 @@ func (w WALServiceImplementation) restoreFromBarmanObjectStore(
|
|||||||
// The failure has already been logged in walRestorer.RestoreList method
|
// The failure has already been logged in walRestorer.RestoreList method
|
||||||
if walStatus[0].Err != nil {
|
if walStatus[0].Err != nil {
|
||||||
if errors.Is(walStatus[0].Err, barmanRestorer.ErrWALNotFound) {
|
if errors.Is(walStatus[0].Err, barmanRestorer.ErrWALNotFound) {
|
||||||
return newWALNotFoundError()
|
return newWALNotFoundError(walStatus[0].WalName)
|
||||||
}
|
}
|
||||||
|
|
||||||
return walStatus[0].Err
|
return walStatus[0].Err
|
||||||
@ -458,7 +460,7 @@ func gatherWALFilesToRestore(walName string, parallel int) (walList []string, er
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ErrEndOfWALStreamReached is returned when end of WAL is detected in the cloud archive.
|
// ErrEndOfWALStreamReached is returned when end of WAL is detected in the cloud archive.
|
||||||
var ErrEndOfWALStreamReached = errors.New("end of WAL reached")
|
var ErrEndOfWALStreamReached = status.Errorf(codes.NotFound, "end of WAL reached")
|
||||||
|
|
||||||
// checkEndOfWALStreamFlag returns ErrEndOfWALStreamReached if the flag is set in the restorer.
|
// checkEndOfWALStreamFlag returns ErrEndOfWALStreamReached if the flag is set in the restorer.
|
||||||
func checkEndOfWALStreamFlag(walRestorer *barmanRestorer.WALRestorer) error {
|
func checkEndOfWALStreamFlag(walRestorer *barmanRestorer.WALRestorer) error {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user