Skip to content

Commit

Permalink
reuse core log
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed Oct 31, 2022
1 parent 04b7e5e commit 23ab442
Show file tree
Hide file tree
Showing 33 changed files with 222 additions and 206 deletions.
35 changes: 13 additions & 22 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,19 @@ import (
"github.com/projecteru2/agent/types"
"github.com/projecteru2/agent/utils"
"github.com/projecteru2/agent/version"
"github.com/projecteru2/core/log"

"github.com/jinzhu/configor"
log "github.com/sirupsen/logrus"
zerolog "github.com/rs/zerolog/log"
cli "github.com/urfave/cli/v2"
_ "go.uber.org/automaxprocs"
)

func setupLogLevel(l string) error {
level, err := log.ParseLevel(l)
if err != nil {
return err
}
log.SetLevel(level)
log.SetOutput(os.Stdout)
return nil
}

func initConfig(c *cli.Context) *types.Config {
config := &types.Config{}

if err := configor.Load(config, c.String("config")); err != nil {
log.Fatalf("[main] load config failed %v", err)
log.Fatalf(c.Context, err, "[main] load config failed %v", err)
}

config.Prepare(c)
Expand All @@ -48,8 +39,8 @@ func initConfig(c *cli.Context) *types.Config {
func serve(c *cli.Context) error {
rand.Seed(time.Now().UnixNano())

if err := setupLogLevel(c.String("log-level")); err != nil {
log.Fatal(err)
if err := log.SetupLog(c.String("log-level")); err != nil {
zerolog.Fatal().Err(err).Send()
}

config := initConfig(c)
Expand All @@ -74,7 +65,7 @@ func serve(c *cli.Context) error {
_ = utils.Pool.Submit(func() {
defer wg.Done()
if err := workloadsManager.Run(ctx); err != nil {
log.Errorf("[agent] workload manager err: %v, exiting", err)
log.Error(c.Context, err, "[agent] workload manager failed")
errChan <- err
}
})
Expand All @@ -86,7 +77,7 @@ func serve(c *cli.Context) error {
_ = utils.Pool.Submit(func() {
defer wg.Done()
if err := nodeManager.Run(ctx); err != nil {
log.Errorf("[agent] node manager err: %v, exiting", err)
log.Error(c.Context, err, "[agent] node manager failed")
errChan <- err
}
})
Expand All @@ -97,15 +88,15 @@ func serve(c *cli.Context) error {
_ = utils.Pool.Submit(func() {
select {
case <-ctx.Done():
log.Info("[agent] Agent exiting")
case <-errChan:
log.Error("[agent] Got error, exiting")
log.Info(c.Context, "[agent] Agent exiting")
case err := <-errChan:
log.Error(c.Context, err, "[agent] Got error, exiting")
cancel()
case sig := <-signalChan:
log.Infof("[agent] Agent caught system signal %v", sig)
log.Infof(c.Context, "[agent] Agent caught system signal %v", sig)
if sig != syscall.SIGUSR1 {
if err := nodeManager.Exit(); err != nil {
log.Errorf("[agent] node manager exits with err: %v", err)
log.Error(c.Context, err, "[agent] node manager exits with err")
}
}
cancel()
Expand Down Expand Up @@ -245,6 +236,6 @@ func main() {
Action: serve,
}
if err := app.Run(os.Args); err != nil {
log.Errorf("Error running agent: %v", err)
zerolog.Fatal().Err(err).Send()
}
}
8 changes: 4 additions & 4 deletions api/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
"github.com/projecteru2/agent/manager/workload"
"github.com/projecteru2/agent/types"
"github.com/projecteru2/agent/version"
"github.com/projecteru2/core/log"

"github.com/bmizerany/pat"
"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"
)

// JSON define a json
Expand Down Expand Up @@ -57,7 +57,7 @@ func (h *Handler) log(w http.ResponseWriter, req *http.Request) {
if hijack, ok := w.(http.Hijacker); ok {
conn, buf, err := hijack.Hijack()
if err != nil {
log.Errorf("[apiLog] connect failed %v", err)
log.Error(req.Context(), err, "[apiLog] connect failed")
return
}
defer conn.Close()
Expand Down Expand Up @@ -98,13 +98,13 @@ func (h *Handler) Serve() {

http.Handle("/", restfulAPIServer)
http.Handle("/metrics", promhttp.Handler())
log.Infof("[apiServe] http api started %s", h.config.API.Addr)
log.Infof(nil, "[apiServe] http api started %s", h.config.API.Addr) //nolint

server := &http.Server{
Addr: h.config.API.Addr,
ReadHeaderTimeout: 3 * time.Second,
}
if err := server.ListenAndServe(); err != nil {
log.Errorf("http api failed %s", err)
log.Error(nil, err, "http api start failed") //nolint
}
}
10 changes: 9 additions & 1 deletion common/error.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package common

import "errors"
import "github.com/pkg/errors"

// ErrNotImplemented .
var (
Expand All @@ -25,4 +25,12 @@ var (
ErrSyscallFailed = errors.New("syscall fail, Not a syscall.Stat_t")
// ErrDevNotFound .
ErrDevNotFound = errors.New("device not found")
// ErrJournalDisable .
ErrJournalDisable = errors.New("journal disabled")
// ErrInvaildContainer .
ErrInvaildContainer = errors.New("invaild container")
// ErrGetLockFailed .
ErrGetLockFailed = errors.New("get lock failed")
// ErrInvaildVM .
ErrInvaildVM = errors.New("invaild vm")
)
9 changes: 6 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ require (
github.com/jinzhu/configor v1.2.1
github.com/panjf2000/ants/v2 v2.5.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/projecteru2/core v0.0.0-20221011033901-ff9e2848a9e1
github.com/pkg/errors v0.9.1
github.com/projecteru2/core v0.0.0-20221027062222-5e76472a0774
github.com/projecteru2/libyavirt v0.0.0-20220621042712-95cdc6363b1c
github.com/prometheus/client_golang v1.13.0
github.com/rs/zerolog v1.28.0
github.com/shirou/gopsutil v3.20.11+incompatible
github.com/sirupsen/logrus v1.9.0
github.com/stretchr/testify v1.8.0
github.com/urfave/cli/v2 v2.17.1
go.uber.org/automaxprocs v1.5.1
Expand All @@ -42,17 +43,19 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/juju/errors v1.0.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/stretchr/objx v0.4.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
go.uber.org/zap v1.23.0 // indirect
Expand Down
18 changes: 16 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnht
github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf h1:iW4rZ826su+pqaw19uhpSCzhj44qo35pNgKFGqzDKkU=
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cornelk/hashmap v1.0.8 h1:nv0AWgw02n+iDcawr5It4CjQIAcdMMKRrs10HOJYlrc=
github.com/cornelk/hashmap v1.0.8/go.mod h1:RfZb7JO3RviW/rT6emczVuC/oxpdz4UsSB2LJSclR1k=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
Expand Down Expand Up @@ -118,6 +119,7 @@ github.com/go-ole/go-ole v0.0.0-20180213002836-a1ec82a652eb/go.mod h1:7FAglXiTm7
github.com/go-ping/ping v0.0.0-20210407214646-e4e642a95741 h1:b0sLP++Tsle+s57tqg5sUk1/OQsC6yMCciVeqNzOcwU=
github.com/go-ping/ping v0.0.0-20210407214646-e4e642a95741/go.mod h1:35JbSyV/BYqHwwRA6Zr1uVDm1637YlNOU61wI797NPI=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
Expand Down Expand Up @@ -205,6 +207,12 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/matttproud/golang_protobuf_extensions v1.0.2 h1:hAHbPm5IJGijwng3PWk09JkG9WeqChjprR5s9bBZ+OM=
github.com/matttproud/golang_protobuf_extensions v1.0.2/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
Expand Down Expand Up @@ -236,8 +244,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g=
github.com/projecteru2/core v0.0.0-20221011033901-ff9e2848a9e1 h1:/HOTU06kNTYVKXCI9G4ks6Vp23ItwGo5m7MmyRqpuP4=
github.com/projecteru2/core v0.0.0-20221011033901-ff9e2848a9e1/go.mod h1:193eVQXbJKmemk4aYY1k7679JE5kEKi+5CBBYFbrOnM=
github.com/projecteru2/core v0.0.0-20221027062222-5e76472a0774 h1:hVUfTHt/IXDNWOCXIJeyAlHpWQDVYvpOMlkcKte/768=
github.com/projecteru2/core v0.0.0-20221027062222-5e76472a0774/go.mod h1:Z2unoE5X/P8RrYa8PsMGbTlmEgZWgxOl8W3DRwR17Bw=
github.com/projecteru2/libyavirt v0.0.0-20220621042712-95cdc6363b1c h1:bsQMtiuDy3vH/+2Bm4o+0dSqhHGrzvNfoHW9C/7Tyqw=
github.com/projecteru2/libyavirt v0.0.0-20220621042712-95cdc6363b1c/go.mod h1:M4iuzX/GsUF8cnkZujoJ8OWULi0+fuwg0D4Zahhzco0=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
Expand Down Expand Up @@ -267,6 +275,9 @@ github.com/prometheus/procfs v0.8.0 h1:ODq8ZFEaYeCaZOJlZZdJA2AbQR98dSHSM1KW/You5
github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0uaxHdg830/4=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.28.0 h1:MirSo27VyNi7RJYP3078AA1+Cyzd2GB66qy3aUHvsWY=
github.com/rs/zerolog v1.28.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shirou/gopsutil v3.20.11+incompatible h1:LJr4ZQK4mPpIV5gOa4jCOKOGb4ty4DZO54I4FGqIpto=
Expand Down Expand Up @@ -440,9 +451,12 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20221006211917-84dc82d7e875 h1:AzgQNqF+FKwyQ5LbVrVqOcuuFB67N47F9+htZYH0wFM=
golang.org/x/sys v0.0.0-20221006211917-84dc82d7e875/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand Down
5 changes: 2 additions & 3 deletions logs/enc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"sync"

"github.com/projecteru2/agent/common"
"github.com/projecteru2/agent/types"

"github.com/coreos/go-systemd/journal"
Expand Down Expand Up @@ -41,8 +42,6 @@ func (e *StreamEncoder) Close() error {
return e.wt.Close()
}

var errJournalDisabled = fmt.Errorf("journal disabled")

// JournalEncoder .
type JournalEncoder struct {
sync.Mutex
Expand All @@ -51,7 +50,7 @@ type JournalEncoder struct {
// CreateJournalEncoder .
func CreateJournalEncoder() (*JournalEncoder, error) {
if !journal.Enabled() {
return nil, errJournalDisabled
return nil, common.ErrJournalDisable
}
return &JournalEncoder{}, nil
}
Expand Down
26 changes: 13 additions & 13 deletions logs/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/projecteru2/agent/types"
"github.com/projecteru2/agent/utils"

log "github.com/sirupsen/logrus"
"github.com/projecteru2/core/log"
)

// Discard .
Expand Down Expand Up @@ -64,15 +64,15 @@ func NewWriter(ctx context.Context, addr string, stdout bool) (writer *Writer, e

switch {
case err == common.ErrInvalidScheme:
log.Infof("[writer] create an empty writer for %s success", addr)
log.Infof(ctx, "[writer] create an empty writer for %s success", addr)
writer.enc = NewStreamEncoder(discard{})
case err == errJournalDisabled:
case err == common.ErrJournalDisable:
return nil, err
case err != nil:
log.Errorf("[writer] failed to create writer encoder for %s, err: %v, will retry", addr, err)
log.Errorf(ctx, err, "[writer] failed to create writer encoder for %s, will retry", addr)
writer.needReconnect = true
default:
log.Infof("[writer] create writer for %s success", addr)
log.Infof(ctx, "[writer] create writer for %s success", addr)
}

_ = utils.Pool.Submit(func() { writer.keepalive(ctx) })
Expand All @@ -82,7 +82,7 @@ func NewWriter(ctx context.Context, addr string, stdout bool) (writer *Writer, e
// Write write log to remote
func (w *Writer) Write(logline *types.Log) error {
if w.stdout {
log.Info(logline)
log.Info(nil, logline) //nolint
}
if len(w.addr) == 0 && len(w.scheme) == 0 {
return nil
Expand All @@ -109,7 +109,7 @@ func (w *Writer) close() error {
w.enc = nil
}
})
log.Infof("[writer] writer for %s closed", w.addr)
log.Infof(nil, "[writer] writer for %s closed", w.addr) //nolint
return err
}

Expand Down Expand Up @@ -159,7 +159,7 @@ func (w *Writer) createEncoder() (enc Encoder, err error) {
case "journal":
enc, err = CreateJournalEncoder()
default:
log.Errorf("[writer] Invalid scheme: %s", w.scheme)
log.Errorf(nil, err, "[writer] Invalid scheme: %s", w.scheme) //nolint
err = common.ErrInvalidScheme
}
return enc, err
Expand All @@ -174,17 +174,17 @@ func (w *Writer) reconnect() {
return
}

log.Debugf("[writer] Reconnecting to %s...", w.addr)
log.Debugf(nil, "[writer] Reconnecting to %s...", w.addr) //nolint
enc, err := w.createEncoder()
if err == nil {
w.withLock(func() {
w.enc = enc
w.needReconnect = false
})
log.Debugf("[writer] Connect to %s successfully", w.addr)
log.Debugf(nil, "[writer] Connect to %s successfully", w.addr) //nolint
return
}
log.Warnf("[writer] Failed to connect to %s: %s", w.addr, err)
log.Warnf(nil, "[writer] Failed to connect to %s: %s", w.addr, err) //nolint
}

func (w *Writer) keepalive(ctx context.Context) {
Expand All @@ -198,7 +198,7 @@ func (w *Writer) keepalive(ctx context.Context) {
// leave some time for the pending writing
time.Sleep(CloseWaitInterval)
if err := w.close(); err != nil {
log.Errorf("[keepalive] failed to close writer %s, err: %s", w.addr, err)
log.Errorf(nil, err, "[keepalive] failed to close writer %s", w.addr) //nolint
}
return
}
Expand All @@ -207,7 +207,7 @@ func (w *Writer) keepalive(ctx context.Context) {

func (w *Writer) checkError(err error) {
if err != nil && err != common.ErrConnecting {
log.Errorf("[writer] Sending log failed %s", err)
log.Error(nil, err, "[writer] Sending log failed") //nolint
w.withLock(func() {
if w.enc != nil {
w.enc.Close()
Expand Down
3 changes: 2 additions & 1 deletion logs/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"
"time"

"github.com/projecteru2/agent/common"
"github.com/projecteru2/agent/types"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -39,7 +40,7 @@ func TestNewWriterWithJournal(t *testing.T) {
defer cancel()
addr := "journal://system"
enc, err := CreateJournalEncoder()
if err == errJournalDisabled {
if err == common.ErrJournalDisable {
return
}
assert.NoError(t, err)
Expand Down
Loading

0 comments on commit 23ab442

Please sign in to comment.