Skip to content

Commit

Permalink
refactor: move to zerolog
Browse files Browse the repository at this point in the history
  • Loading branch information
sapk committed Dec 2, 2018
1 parent 728351d commit 683e022
Show file tree
Hide file tree
Showing 42 changed files with 5,821 additions and 57 deletions.
4 changes: 2 additions & 2 deletions gluster/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package driver
import (
"fmt"

"github.com/rs/zerolog/log"
"github.com/sapk/docker-volume-helpers/basic"
"github.com/sapk/docker-volume-helpers/driver"

"github.com/docker/go-plugins-helpers/volume"
"github.com/sirupsen/logrus"
)

var (
Expand All @@ -24,7 +24,7 @@ type GlusterDriver = basic.Driver

//Init start all needed deps and serve response to API call
func Init(root string, mountUniqName bool) *GlusterDriver {
logrus.Debugf("Init gluster driver at %s, UniqName: %v", root, mountUniqName)
log.Debug().Msgf("Init gluster driver at %s, UniqName: %v", root, mountUniqName)
config := basic.DriverConfig{
Version: CfgVersion,
Root: root,
Expand Down
17 changes: 9 additions & 8 deletions gluster/gluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (
"path/filepath"

"github.com/docker/go-plugins-helpers/volume"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/sapk/docker-volume-gluster/gluster/driver"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -66,19 +67,19 @@ func Init() {
rootCmd.Long = fmt.Sprintf(longHelp, Version, Branch, Commit, BuildTime)
rootCmd.AddCommand(versionCmd, daemonCmd)
if err := rootCmd.Execute(); err != nil {
logrus.Fatal(err)
log.Fatal().Err(err)
}
}

//DaemonStart Start the deamon
func DaemonStart(cmd *cobra.Command, args []string) {
d := driver.Init(BaseDir, mountUniqName)
logrus.Debug(d)
log.Debug().Msg(d)
h := volume.NewHandler(d)
logrus.Debug(h)
log.Debug().Msg(h)
err := h.ServeUnix(PluginAlias, 0)
if err != nil {
logrus.Debug(err)
log.Debug().Err(err)
}
}

Expand All @@ -91,9 +92,9 @@ func setupFlags() {

func setupLogger(cmd *cobra.Command, args []string) {
if verbose, _ := cmd.Flags().GetBool(VerboseFlag); verbose {
logrus.SetLevel(logrus.DebugLevel)
logrus.Debugf("Debug mode on")
zerolog.SetGlobalLevel(zerolog.DebugLevel)
log.Debug().Msg("Debug mode on")
} else {
logrus.SetLevel(logrus.InfoLevel)
zerolog.SetGlobalLevel(zerolog.InfoLevel)
}
}
61 changes: 31 additions & 30 deletions gluster/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import (
"time"

"github.com/docker/go-plugins-helpers/volume"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/sapk/docker-volume-gluster/gluster"
"github.com/sapk/docker-volume-gluster/gluster/driver"
"github.com/sirupsen/logrus"
)

const timeInterval = 2 * time.Second
Expand Down Expand Up @@ -45,67 +46,67 @@ func setupPlugin() {
gluster.PluginAlias = "gluster-local-integration"
gluster.BaseDir = filepath.Join(volume.DefaultDockerRootDirectory, gluster.PluginAlias)
driver.CfgFolder = "/etc/docker-volumes/" + gluster.PluginAlias
logrus.Print(cmd("rm", os.Environ(), "-rf", driver.CfgFolder))
logrus.SetLevel(logrus.DebugLevel)
log.Print(cmd("rm", os.Environ(), "-rf", driver.CfgFolder))
zerolog.SetGlobalLevel(zerolog.DebugLevel)

gluster.DaemonStart(nil, []string{})
time.Sleep(timeInterval)
//logrus.Print(cmd("docker", "plugin", "ls"))
logrus.Print(cmd("docker", os.Environ(), "info", "-f", "{{.Plugins.Volume}}"))
//log.Print(cmd("docker", "plugin", "ls"))
log.Print(cmd("docker", os.Environ(), "info", "-f", "{{.Plugins.Volume}}"))
}

func setupManagedPlugin() {
//Build custom integration docker plugin
env := os.Environ()
env = append(env, fmt.Sprintf("PLUGIN_USER=%s", "testing"))
logrus.Print(cmd("make", env, "--directory=../../", "docker-plugin"))
logrus.Print(cmd("make", env, "--directory=../../", "docker-plugin-enable"))
log.Print(cmd("make", env, "--directory=../../", "docker-plugin"))
log.Print(cmd("make", env, "--directory=../../", "docker-plugin-enable"))
}

func cleanManagedPlugin() {
logrus.Print(cmd("docker", os.Environ(), "plugin", "disable", "testing/plugin-gluster"))
logrus.Print(cmd("docker", os.Environ(), "plugin", "rm", "testing/plugin-gluster"))
log.Print(cmd("docker", os.Environ(), "plugin", "disable", "testing/plugin-gluster"))
log.Print(cmd("docker", os.Environ(), "plugin", "rm", "testing/plugin-gluster"))
}

func setupGlusterCluster() {
logrus.Print(dockerCompose("up", "-d"))
log.Print(dockerCompose("up", "-d"))
time.Sleep(timeInterval)
nodes := []string{"node-1", "node-2", "node-3"}

for _, n := range nodes {
time.Sleep(timeInterval)
logrus.Print(dockerCompose("exec", "-T", n, "mkdir", "-p", "/brick"))
log.Print(dockerCompose("exec", "-T", n, "mkdir", "-p", "/brick"))
}

time.Sleep(timeInterval)
IPs := getGlusterClusterContainersIPs()
for _, ip := range IPs[1:] {
time.Sleep(timeInterval)
logrus.Print(dockerCompose("exec", "-T", "node-1", "gluster", "peer", "probe", ip))
log.Print(dockerCompose("exec", "-T", "node-1", "gluster", "peer", "probe", ip))
}

time.Sleep(timeInterval)
logrus.Print(dockerCompose("exec", "-T", "node-1", "gluster", "pool", "list"))
logrus.Print(dockerCompose("exec", "-T", "node-1", "gluster", "peer", "status"))
log.Print(dockerCompose("exec", "-T", "node-1", "gluster", "pool", "list"))
log.Print(dockerCompose("exec", "-T", "node-1", "gluster", "peer", "status"))
time.Sleep(timeInterval)

logrus.Print(dockerCompose("exec", "-T", "node-1", "gluster", "volume", "create", "test-replica", "replica", "3", IPs[0]+":/brick/replica", IPs[1]+":/brick/replica", IPs[2]+":/brick/replica"))
log.Print(dockerCompose("exec", "-T", "node-1", "gluster", "volume", "create", "test-replica", "replica", "3", IPs[0]+":/brick/replica", IPs[1]+":/brick/replica", IPs[2]+":/brick/replica"))
time.Sleep(timeInterval)
logrus.Print(dockerCompose("exec", "-T", "node-1", "gluster", "volume", "create", "test-distributed", IPs[0]+":/brick/distributed", IPs[1]+":/brick/distributed", IPs[2]+":/brick/distributed"))
log.Print(dockerCompose("exec", "-T", "node-1", "gluster", "volume", "create", "test-distributed", IPs[0]+":/brick/distributed", IPs[1]+":/brick/distributed", IPs[2]+":/brick/distributed"))

time.Sleep(timeInterval)
logrus.Print(dockerCompose("exec", "-T", "node-1", "gluster", "volume", "start", "test-replica"))
log.Print(dockerCompose("exec", "-T", "node-1", "gluster", "volume", "start", "test-replica"))
time.Sleep(timeInterval)
logrus.Print(dockerCompose("exec", "-T", "node-1", "gluster", "volume", "start", "test-distributed"))
log.Print(dockerCompose("exec", "-T", "node-1", "gluster", "volume", "start", "test-distributed"))
time.Sleep(timeInterval)
}

func cleanGlusterCluster() {
logrus.Print("Cleaning up")
logrus.Print(dockerCompose("down"))
//logrus.Print(cmd("docker", "volume", "rm", "-f", "glustercluster_brick-node-2", "glustercluster_brick-node-1", "glustercluster_brick-node-3", "glustercluster_state-node-1", "glustercluster_state-node-2", "glustercluster_state-node-3"))
// extra clean up logrus.Print(cmd("docker", "volume", "prune", "-f"))
// full extra clean up logrus.Print(cmd("docker", "system", "prune", "-af"))
log.Print("Cleaning up")
log.Print(dockerCompose("down"))
//log.Print(cmd("docker", "volume", "rm", "-f", "glustercluster_brick-node-2", "glustercluster_brick-node-1", "glustercluster_brick-node-3", "glustercluster_state-node-1", "glustercluster_state-node-2", "glustercluster_state-node-3"))
// extra clean up log.Print(cmd("docker", "volume", "prune", "-f"))
// full extra clean up log.Print(cmd("docker", "system", "prune", "-af"))
}

func dockerCompose(arg ...string) (string, error) {
Expand Down Expand Up @@ -207,41 +208,41 @@ func TestIntegration(t *testing.T) {

for _, tc := range testCases {
t.Run("Create volume for "+tc.name, func(t *testing.T) {
logrus.Print(cmd("docker", os.Environ(), "volume", "create", "--driver", tc.driver, "--opt", "voluri=\""+strings.Join(tc.servers, ",")+":"+tc.volume+"\"", tc.id))
log.Print(cmd("docker", os.Environ(), "volume", "create", "--driver", tc.driver, "--opt", "voluri=\""+strings.Join(tc.servers, ",")+":"+tc.volume+"\"", tc.id))
time.Sleep(timeInterval)
})
time.Sleep(3 * timeInterval)
//TODO test volume exist
}

logrus.Print(cmd("docker", os.Environ(), "volume", "ls"))
log.Print(cmd("docker", os.Environ(), "volume", "ls"))

for i, tc := range testCases {
t.Run("Test volume "+tc.name, func(t *testing.T) {
out, err := cmd("docker", os.Environ(), "run", "--rm", "-t", "-v", tc.id+":/mnt", "alpine", "/bin/ls", "/mnt")
logrus.Println(out)
log.Println(out)
if err != nil {
t.Errorf("Failed to list mounted volume : %v", err)
}
if !strings.Contains(tc.name, "double") && !strings.Contains(tc.name, "managed") {
out, err = cmd("docker", os.Environ(), "run", "--rm", "-t", "-v", tc.id+":/mnt", "alpine", "/bin/cp", "/etc/hostname", "/mnt/container")
logrus.Println(out)
log.Println(out)
if err != nil {
t.Errorf("Failed to write inside mounted volume : %v", err)
}
out, err = cmd("docker", os.Environ(), "run", "--rm", "-t", "-v", tc.id+":/mnt", "alpine", "/bin/mkdir", "/mnt/subdir")
logrus.Println(out)
log.Println(out)
if err != nil {
t.Errorf("Failed to create dir inside mounted volume : %v", err)
}
out, err = cmd("docker", os.Environ(), "run", "--rm", "-t", "-v", tc.id+":/mnt", "alpine", "/bin/cp", "/etc/hostname", "/mnt/subdir/container")
logrus.Println(out)
log.Println(out)
if err != nil {
t.Errorf("Failed to write inside mounted volume : %v", err)
}
}
testCases[i].hostname, err = cmd("docker", os.Environ(), "run", "--rm", "-t", "-v", tc.id+":/mnt", "alpine", "/bin/cat", "/mnt/container")
logrus.Println(out)
log.Println(out)
if err != nil {
t.Errorf("Failed to read from mounted volume : %v", err)
}
Expand Down
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ require (
github.com/docker/go-plugins-helpers v0.0.0-20181025120712-1e6269c305b8
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/kr/pty v1.1.3 // indirect
github.com/mitchellh/mapstructure v1.1.2 // indirect
github.com/sapk/docker-volume-helpers v0.0.0-20180326195556-7a90a1c14fd6
github.com/sirupsen/logrus v1.2.0
github.com/rs/zerolog v1.11.0
github.com/sapk/docker-volume-helpers v0.0.0-20181202155618-910e680a34fd
github.com/spf13/cast v1.3.0 // indirect
github.com/spf13/cobra v0.0.3
github.com/spf13/pflag v1.0.3 // indirect
github.com/spf13/viper v1.2.1 // indirect
golang.org/x/crypto v0.0.0-20181112202954-3d3f9f413869 // indirect
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a
golang.org/x/sys v0.0.0-20181116161606-93218def8b18 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
Expand Down
16 changes: 4 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
Expand All @@ -33,10 +30,10 @@ github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
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/sapk/docker-volume-helpers v0.0.0-20180326195556-7a90a1c14fd6 h1:7lYPwcPlelvMgjUklzUVtqQpjqye4tfF+abrPOfB9WY=
github.com/sapk/docker-volume-helpers v0.0.0-20180326195556-7a90a1c14fd6/go.mod h1:Sn42NciYjOR7TRoe8PF5NlRjAgrkuzLqJiGlXJ0gPac=
github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/rs/zerolog v1.11.0 h1:DRuq/S+4k52uJzBQciUcofXx45GrMC6yrEbb/CoK6+M=
github.com/rs/zerolog v1.11.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU=
github.com/sapk/docker-volume-helpers v0.0.0-20181202155618-910e680a34fd h1:eOMaPG9hfxUexZVDJ9n9f38CTuPj3ozYr0pNQfOVYyY=
github.com/sapk/docker-volume-helpers v0.0.0-20181202155618-910e680a34fd/go.mod h1:Sn42NciYjOR7TRoe8PF5NlRjAgrkuzLqJiGlXJ0gPac=
github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/cast v1.2.0 h1:HHl1DSRbEQN2i8tJmtS6ViPyHx35+p51amrdsiTCrkg=
Expand All @@ -52,15 +49,10 @@ github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/viper v1.2.1 h1:bIcUwXqLseLF3BDAZduuNfekWG87ibtFxi59Bq+oI9M=
github.com/spf13/viper v1.2.1/go.mod h1:P4AexN0a+C9tGAnUFNwDMYYZv3pjFuvmeiMyKRaNVlI=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181112202954-3d3f9f413869 h1:kkXA53yGe04D0adEYJwEVQjeBppL01Exg+fnMjfUraU=
golang.org/x/crypto v0.0.0-20181112202954-3d3f9f413869/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a h1:gOpx8G595UYyvj8UK4+OFyY4rx037g3fmfhe5SasG3U=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180906133057-8cf3aee42992/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181116161606-93218def8b18 h1:Wh+XCfg3kNpjhdq2LXrsiOProjtQZKme5XUx7VcxwAw=
golang.org/x/sys v0.0.0-20181116161606-93218def8b18/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down
25 changes: 25 additions & 0 deletions vendor/github.com/rs/zerolog/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions vendor/github.com/rs/zerolog/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/rs/zerolog/CNAME

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions vendor/github.com/rs/zerolog/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 683e022

Please sign in to comment.