Skip to content

Commit

Permalink
Merge pull request #670 from Altinity/zerolog
Browse files Browse the repository at this point in the history
[WIP] try switch to Zerolog
  • Loading branch information
Slach authored Aug 3, 2024
2 parents 0a3a9f2 + a26d40a commit 418f8f4
Show file tree
Hide file tree
Showing 48 changed files with 871 additions and 1,212 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ name: Build
on:
pull_request:
branches:
- master
- "*"

push:
branches:
- "*"
- master

jobs:
build:
Expand Down
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ IMPROVEMENTS
- improve support for `use_embedded_backup_restore: true`, applied ugly workaround in test to avoid https://github.com/ClickHouse/ClickHouse/issues/43971, and applied restore workaround to resolve https://github.com/ClickHouse/ClickHouse/issues/42709
- migrate to `clickhouse-go/v2`, fix [540](https://github.com/Altinity/clickhouse-backup/issues/540), close [562](https://github.com/Altinity/clickhouse-backup/pull/562)
- add documentation for `AWS_ARN_ROLE` and `AWS_WEB_IDENTITY_TOKEN_FILE`, fix [563](https://github.com/Altinity/clickhouse-backup/issues/563)
- migrate from `apex/log` to `rs/zerolog`, fix RaceConditions, fix [624](https://github.com/Altinity/clickhouse-backup/issues/624),see details https://github.com/apex/log/issues/103

BUG FIXES
- hotfix wrong empty files when disk_mapping contains don't exist during creation, affected 2.2.7 version, look details [676](https://github.com/Altinity/clickhouse-backup/issues/676#issue-1771732489)
Expand Down
23 changes: 17 additions & 6 deletions cmd/clickhouse-backup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ package main
import (
"context"
"fmt"
stdlog "log"
"os"
"strings"

"github.com/apex/log"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/rs/zerolog/pkgerrors"
"github.com/urfave/cli"

"github.com/Altinity/clickhouse-backup/v2/pkg/backup"
"github.com/Altinity/clickhouse-backup/v2/pkg/config"
"github.com/Altinity/clickhouse-backup/v2/pkg/logcli"
"github.com/Altinity/clickhouse-backup/v2/pkg/server"
"github.com/Altinity/clickhouse-backup/v2/pkg/status"
)
Expand All @@ -23,7 +25,16 @@ var (
)

func main() {
log.SetHandler(logcli.New(os.Stderr))
zerolog.TimeFieldFormat = zerolog.TimeFormatUnixMs
zerolog.ErrorStackMarshaler = pkgerrors.MarshalStack
consoleWriter := zerolog.ConsoleWriter{Out: os.Stderr, NoColor: true, TimeFormat: "2006-01-02 15:04:05.000"}
//diodeWriter := diode.NewWriter(consoleWriter, 4096, 10*time.Millisecond, func(missed int) {
// fmt.Printf("Logger Dropped %d messages", missed)
//})
log.Logger = zerolog.New(zerolog.SyncWriter(consoleWriter)).With().Timestamp().Caller().Logger()
//zerolog.SetGlobalLevel(zerolog.Disabled)
//log.Logger = zerolog.New(os.Stdout).With().Timestamp().Caller().Logger()
stdlog.SetOutput(log.Logger)
cliapp := cli.NewApp()
cliapp.Name = "clickhouse-backup"
cliapp.Usage = "Tool for easy backup of ClickHouse with cloud support"
Expand Down Expand Up @@ -499,11 +510,11 @@ func main() {
Action: func(c *cli.Context) error {
b := backup.NewBackuper(config.GetConfigFromCli(c))
if c.Args().Get(1) == "" {
log.Errorf("Backup name must be defined")
log.Err(fmt.Errorf("backup name must be defined")).Send()
cli.ShowCommandHelpAndExit(c, c.Command.Name, 1)
}
if c.Args().Get(0) != "local" && c.Args().Get(0) != "remote" {
log.Errorf("Unknown command '%s'\n", c.Args().Get(0))
log.Err(fmt.Errorf("Unknown command '%s'\n", c.Args().Get(0))).Send()
cli.ShowCommandHelpAndExit(c, c.Command.Name, 1)
}
return b.Delete(c.Args().Get(0), c.Args().Get(1), c.Int("command-id"))
Expand Down Expand Up @@ -639,6 +650,6 @@ func main() {
},
}
if err := cliapp.Run(os.Args); err != nil {
log.Fatal(err.Error())
log.Fatal().Err(err).Send()
}
}
10 changes: 7 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
// wrong INSERT syntax, wait when resolve https://github.com/ClickHouse/clickhouse-go/issues/1345
github.com/ClickHouse/clickhouse-go/v2 v2.23.2
github.com/antchfx/xmlquery v1.4.1
github.com/apex/log v1.9.0
github.com/aws/aws-sdk-go-v2 v1.30.1
github.com/aws/aws-sdk-go-v2/config v1.27.23
github.com/aws/aws-sdk-go-v2/credentials v1.17.23
Expand All @@ -20,7 +19,6 @@ require (
github.com/djherbis/buffer v1.2.0
github.com/djherbis/nio/v3 v3.0.1
github.com/eapache/go-resiliency v1.6.0
github.com/go-logfmt/logfmt v0.6.0
github.com/go-zookeeper/zk v1.0.3
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/google/uuid v1.6.0
Expand Down Expand Up @@ -49,7 +47,11 @@ require (
gopkg.in/yaml.v3 v3.0.1
)

require golang.org/x/text v0.16.0
require (
github.com/apex/log v1.9.0
github.com/rs/zerolog v1.33.0
golang.org/x/text v0.16.0
)

require (
cloud.google.com/go v0.115.0 // indirect
Expand Down Expand Up @@ -104,7 +106,9 @@ require (
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/klauspost/pgzip v1.2.5 // indirect
github.com/kr/fs v0.1.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-ieproxy v0.0.1 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/mozillazg/go-httpheader v0.2.1 // indirect
github.com/nwaples/rardecode/v2 v2.0.0-beta.2 // indirect
Expand Down
Loading

0 comments on commit 418f8f4

Please sign in to comment.