mirror of
https://github.com/beclab/Olares
synced 2026-04-21 13:37:46 +00:00
backup: add log level, set resty debug env (#2895)
* fix: add debug mode * backup: add log level
This commit is contained in:
parent
317e1f2ca5
commit
dd4b4dbc72
9 changed files with 44 additions and 32 deletions
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
|
||||
{{ $backupVersion := "0.3.62" }}
|
||||
{{ $backupVersion := "0.3.63" }}
|
||||
{{ $backup_server_rootpath := printf "%s%s" .Values.rootPath "/rootfs/backup-server" }}
|
||||
|
||||
{{- $backup_nats_secret := (lookup "v1" "Secret" .Release.Namespace "backup-nats-secret") -}}
|
||||
|
|
@ -157,6 +157,8 @@ spec:
|
|||
command:
|
||||
- /backup-server
|
||||
- apiserver
|
||||
- --log-level
|
||||
- info
|
||||
resources:
|
||||
requests:
|
||||
cpu: 20m
|
||||
|
|
@ -206,6 +208,8 @@ spec:
|
|||
command:
|
||||
- /backup-server
|
||||
- controller
|
||||
- --log-level
|
||||
- info
|
||||
resources:
|
||||
requests:
|
||||
cpu: 20m
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import (
|
|||
"olares.com/backup-server/pkg/constant"
|
||||
"olares.com/backup-server/pkg/integration"
|
||||
"olares.com/backup-server/pkg/signals"
|
||||
pkgutil "olares.com/backup-server/pkg/util"
|
||||
"olares.com/backup-server/pkg/util/log"
|
||||
"olares.com/backup-server/pkg/watchers"
|
||||
"olares.com/backup-server/pkg/watchers/systemenv"
|
||||
|
|
@ -59,6 +60,10 @@ func Run(o *options.ServerRunOptions, ctx context.Context) error {
|
|||
errCh := make(chan error)
|
||||
defer close(errCh)
|
||||
|
||||
constant.InitDebugMode()
|
||||
pkgutil.InitRestyClient(constant.DebugMode)
|
||||
|
||||
|
||||
go func() {
|
||||
if err := run(o, ictx); err != nil {
|
||||
errCh <- err
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import (
|
|||
"olares.com/backup-server/pkg/controllers"
|
||||
"olares.com/backup-server/pkg/handlers"
|
||||
"olares.com/backup-server/pkg/integration"
|
||||
pkgutil "olares.com/backup-server/pkg/util"
|
||||
"olares.com/backup-server/pkg/util/log"
|
||||
"olares.com/backup-server/pkg/watchers"
|
||||
"olares.com/backup-server/pkg/watchers/notification"
|
||||
|
|
@ -78,7 +79,10 @@ func addFlags(fs *pflag.FlagSet) {
|
|||
}
|
||||
|
||||
func Run() error {
|
||||
log.InitLog("debug")
|
||||
log.InitLog(logLevel)
|
||||
|
||||
constant.InitDebugMode()
|
||||
pkgutil.InitRestyClient(constant.DebugMode)
|
||||
|
||||
f, err := client.NewFactory()
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ var (
|
|||
SyncServerURL string
|
||||
OlaresRemoteService string = DefaultSyncServerURL
|
||||
NodeName string = os.Getenv("NODE_NAME")
|
||||
DebugMode bool
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -199,3 +200,10 @@ func ReloadEnvDependantVars() error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func InitDebugMode() {
|
||||
d := os.Getenv(EnvIntegrationDebug)
|
||||
if d == "1" {
|
||||
DebugMode = true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-resty/resty/v2"
|
||||
"olares.com/backup-server/pkg/constant"
|
||||
"olares.com/backup-server/pkg/util"
|
||||
"olares.com/backup-server/pkg/util/log"
|
||||
)
|
||||
|
||||
|
|
@ -52,14 +52,12 @@ func (app *AppHandler) StartAppBackup(parentCtx context.Context, backupId, snaps
|
|||
|
||||
var result *BackupAppResponse
|
||||
|
||||
client := resty.New().SetTimeout(15 * time.Second).SetDebug(true)
|
||||
|
||||
data := map[string]string{
|
||||
"backup_id": backupId,
|
||||
"snapshot_id": snapshotId,
|
||||
}
|
||||
|
||||
resp, err := client.R().
|
||||
resp, err := util.RestClient.R().
|
||||
SetContext(ctx).
|
||||
SetHeaders(headers).
|
||||
SetFormData(data).
|
||||
|
|
@ -92,9 +90,7 @@ func (app *AppHandler) GetAppBackupStatus(parentCtx context.Context, backupId, s
|
|||
"X-BFL-USER": app.owner,
|
||||
}
|
||||
|
||||
client := resty.New().SetTimeout(15 * time.Second).SetDebug(true)
|
||||
|
||||
resp, err := client.R().
|
||||
resp, err := util.RestClient.R().
|
||||
SetContext(parentCtx).
|
||||
SetHeaders(headers).
|
||||
SetResult(&result).
|
||||
|
|
@ -142,8 +138,7 @@ func (app *AppHandler) SendBackupResult(parentCtx context.Context, backupId, sna
|
|||
"message": msg,
|
||||
}
|
||||
|
||||
client := resty.New().SetTimeout(15 * time.Second).SetDebug(true)
|
||||
resp, err := client.R().
|
||||
resp, err := util.RestClient.R().
|
||||
SetContext(ctx).
|
||||
SetHeaders(headers).
|
||||
SetFormData(data).
|
||||
|
|
@ -176,15 +171,13 @@ func (app *AppHandler) StartAppRestore(parentCtx context.Context, restoreId stri
|
|||
return fmt.Errorf("start restore, json convert error: %v, metadata: %s", err, metadata)
|
||||
}
|
||||
|
||||
client := resty.New().SetTimeout(15 * time.Second).SetDebug(true)
|
||||
|
||||
data := map[string]interface{}{
|
||||
"restore_id": restoreId,
|
||||
"restic_snapshot_id": resticSnapshotId,
|
||||
"data": md,
|
||||
}
|
||||
|
||||
resp, err := client.R().
|
||||
resp, err := util.RestClient.R().
|
||||
SetContext(ctx).
|
||||
SetHeaders(headers).
|
||||
SetBody(data).
|
||||
|
|
@ -219,9 +212,7 @@ func (app *AppHandler) GetAppRestoreStatus(parentCtx context.Context, restoreId
|
|||
"X-BFL-USER": app.owner,
|
||||
}
|
||||
|
||||
client := resty.New().SetTimeout(15 * time.Second).SetDebug(true)
|
||||
|
||||
resp, err := client.R().
|
||||
resp, err := util.RestClient.R().
|
||||
SetContext(ctx).
|
||||
SetHeaders(headers).
|
||||
SetResult(&result).
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/emicklei/go-restful/v3"
|
||||
"github.com/go-resty/resty/v2"
|
||||
"github.com/pkg/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
|
|
@ -69,7 +68,6 @@ func GetBackupPassword(ctx context.Context, owner string, backupName string, tok
|
|||
return true
|
||||
}, func() error {
|
||||
settingsUrl := fmt.Sprintf("http://settings.user-system-%s:28080/api/backup/password", owner)
|
||||
client := resty.New().SetTimeout(15 * time.Second).SetDebug(true)
|
||||
|
||||
req := &proxyRequest{
|
||||
Op: "getAccount",
|
||||
|
|
@ -80,7 +78,7 @@ func GetBackupPassword(ctx context.Context, owner string, backupName string, tok
|
|||
}
|
||||
|
||||
log.Info("fetch password from settings, ", settingsUrl)
|
||||
resp, err := client.R().SetContext(ctx).
|
||||
resp, err := util.RestClient.R().SetContext(ctx).
|
||||
SetHeader(restful.HEADER_ContentType, restful.MIME_JSON).
|
||||
SetHeader("Authorization", fmt.Sprintf("Bearer %s", token)).
|
||||
SetBody(req).
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
|
@ -37,15 +36,9 @@ type authToken struct {
|
|||
}
|
||||
|
||||
func NewIntegrationManager(factory client.Factory) {
|
||||
var debug = false
|
||||
d := os.Getenv(constant.EnvIntegrationDebug)
|
||||
if d == "1" {
|
||||
debug = true
|
||||
}
|
||||
|
||||
IntegrationService = &Integration{
|
||||
Factory: factory,
|
||||
rest: resty.New().SetTimeout(20 * time.Second).SetDebug(debug),
|
||||
rest: resty.New().SetTimeout(20 * time.Second).SetDebug(constant.DebugMode),
|
||||
OlaresTokens: make(map[string]*SpaceToken),
|
||||
authToken: make(map[string]*authToken),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ func NotifyBackup(ctx context.Context, cloudApiUrl string, backup *Backup) error
|
|||
var result *Response
|
||||
client := resty.New().SetTimeout(15 * time.Second).
|
||||
SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true}).
|
||||
SetDebug(true)
|
||||
SetDebug(constant.DebugMode)
|
||||
|
||||
resp, err := client.R().
|
||||
SetContext(ctx).
|
||||
|
|
@ -155,7 +155,7 @@ func NotifySnapshot(ctx context.Context, cloudApiUrl string, snapshot *Snapshot)
|
|||
var headers = make(map[string]string)
|
||||
headers[restful.HEADER_ContentType] = "application/x-www-form-urlencoded"
|
||||
|
||||
result, err := httpx.Post[Response](ctx, url, headers, data, true)
|
||||
result, err := httpx.Post[Response](ctx, url, headers, data, constant.DebugMode)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -189,7 +189,7 @@ func NotifyStopBackup(ctx context.Context, cloudApiUrl string, userId, token, ba
|
|||
var headers = make(map[string]string)
|
||||
headers[restful.HEADER_ContentType] = "application/x-www-form-urlencoded"
|
||||
|
||||
result, err := httpx.Post[Response](ctx, url, headers, data, true)
|
||||
result, err := httpx.Post[Response](ctx, url, headers, data, constant.DebugMode)
|
||||
if err != nil {
|
||||
log.Errorf("[notify] delete backup record failed: %v", err)
|
||||
return err
|
||||
|
|
@ -228,7 +228,7 @@ func CheckCloudStorageQuotaAndPermission(ctx context.Context, cloudApiUrl string
|
|||
var headers = make(map[string]string)
|
||||
headers[restful.HEADER_ContentType] = "application/x-www-form-urlencoded"
|
||||
|
||||
result, err = httpx.Post[Usage](ctx, url, headers, data, true)
|
||||
result, err = httpx.Post[Usage](ctx, url, headers, data, constant.DebugMode)
|
||||
if err != nil {
|
||||
log.Errorf("[notify] check backup usage failed: %v", err)
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import (
|
|||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/go-resty/resty/v2"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
|
|
@ -22,6 +23,14 @@ const (
|
|||
DateFormat = "2006-01-02 15:04:05"
|
||||
)
|
||||
|
||||
|
||||
var RestClient *resty.Client
|
||||
|
||||
func InitRestyClient(debugMode bool) {
|
||||
RestClient = resty.New().SetTimeout(20 * time.Second).SetDebug(debugMode)
|
||||
}
|
||||
|
||||
|
||||
func TrimLineBreak(s string) string {
|
||||
return strings.TrimRight(s, "\r\n")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue