Skip to content

Commit

Permalink
add --include-versions flag to skywire-cli log command
Browse files Browse the repository at this point in the history
  • Loading branch information
mrpalide committed Jun 11, 2023
1 parent 5111778 commit 9140738
Show file tree
Hide file tree
Showing 14 changed files with 1,297 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.USERNAME }}
password: ${{ secrets.TOKEN }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: actions/checkout@v3
- name: deploy to docker
run: |
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ lint-windows: ## Run linters. Use make install-linters-windows first

test: ## Run tests
-go clean -testcache &>/dev/null
${OPTS} go test ${TEST_OPTS} ./internal/... ./pkg/...
${OPTS} go test ${TEST_OPTS} ./internal/... ./pkg/... ./cmd/...
${OPTS} go test ${TEST_OPTS}

test-windows: ## Run tests on windows
@go clean -testcache
${OPTS} go test ${TEST_OPTS} ./internal/... ./pkg/...
${OPTS} go test ${TEST_OPTS} ./internal/... ./pkg/... ./cmd/...

install-linters: ## Install linters
- VERSION=latest ./ci_scripts/install-golangci-lint.sh
Expand Down
77 changes: 77 additions & 0 deletions cmd/skywire-cli/commands/config/gen_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package cliconfig

import (
"os"
"os/exec"
"runtime"
"testing"

"github.com/bitfield/script"
)

var (
shell string
)

func init() {
switch runtime.GOOS {
case "windows":
if _, err := exec.LookPath("bash"); err == nil {
shell = "bash"
} else if _, err := exec.LookPath("powershell"); err == nil {
shell = "powershell"
} else {
panic("Required binaries 'bash' and 'powershell' not found")
}
case "linux", "darwin":
if _, err := exec.LookPath("bash"); err != nil {
panic("Required binary 'bash' not found")
}
shell = "bash"
default:
panic("Unsupported operating system: " + runtime.GOOS)
}
}

// Reference Issue https://github.com/skycoin/skywire/issues/1606

func TestConfigGenCmdFunc(t *testing.T) {
tests := []struct {
name string
command string
expectedErr bool
}{
{
name: "first config gen -r",
command: "config gen -r -o test-config.json",
expectedErr: false,
},
{
name: "second config gen -r",
command: "config gen -r -o test-config.json",
expectedErr: false,
},
{
name: "config gen -rf",
command: "config gen -rf -o test-config.json",
expectedErr: true,
},
}
_ = os.Remove("test-config.json") //nolint
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
_, err := script.Exec(shell + ` -c "go run ../../skywire-cli.go ` + test.command + `"`).Stdout()
if err != nil {
if !test.expectedErr {
t.Fatalf("Expected error: %v, but got: %v", test.expectedErr, err)
}
}
if err == nil {
if test.expectedErr {
t.Fatalf("Expected error: %v, but got: %v", test.expectedErr, err)
}
}
})
}
_ = os.Remove("test-config.json") //nolint
}
25 changes: 24 additions & 1 deletion cmd/skywire-cli/commands/log/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import (
"math/rand"
"net/http"
"os"
"strings"
"sync"
"time"

"github.com/hashicorp/go-version"
"github.com/skycoin/dmsg/pkg/dmsgget"
"github.com/skycoin/dmsg/pkg/dmsghttp"
"github.com/spf13/cobra"
Expand All @@ -37,6 +39,7 @@ var (
logOnly bool
surveyOnly bool
deleteOnErrors bool
incVer string
)

func init() {
Expand All @@ -46,6 +49,7 @@ func init() {
logCmd.Flags().BoolVarP(&surveyOnly, "survey", "v", false, "fetch only surveys")
logCmd.Flags().BoolVarP(&deleteOnErrors, "clean", "c", false, "delete files and folders on errors")
logCmd.Flags().StringVar(&minv, "minv", "v1.3.4", "minimum version for get logs, default is 1.3.4")
logCmd.Flags().StringVar(&incVer, "include-versions", "", "list of version that not satisfy our minimum version condition, but we want include them")
logCmd.Flags().IntVarP(&duration, "duration", "n", 1, "numberof days before today to fetch transport logs for")
logCmd.Flags().BoolVar(&allVisors, "all", false, "consider all visors ; no version filtering")
logCmd.Flags().IntVar(&batchSize, "batchSize", 50, "number of visor in each batch, default is 50")
Expand Down Expand Up @@ -128,12 +132,22 @@ var logCmd = &cobra.Command{
dmsgC.EnsureAndObtainSession(ctx, server.PK) //nolint
}

minimumVersion, _ := version.NewVersion(minv) //nolint
incVerList := strings.Split(incVer, ",")

start := time.Now()
var bulkFolders []string
// Get visors data
var wg sync.WaitGroup
for _, v := range uptimes {
if !allVisors && v.Version < minv {
visorVersion, err := version.NewVersion(v.Version) //nolint
includeV := contains(incVerList, v.Version)
if err != nil && !includeV {
log.Warnf("The version %s for visor %s is not valid", v.Version, v.PubKey)
continue
}
if !allVisors && visorVersion.LessThan(minimumVersion) && !includeV {
log.Warnf("The version %s for visor %s does not satisfy our minimum version condition", v.Version, v.PubKey)
continue
}
wg.Add(1)
Expand Down Expand Up @@ -259,3 +273,12 @@ func getAllDMSGServers() []dmsgServer {
type dmsgServer struct {
PK cipher.PubKey `json:"static"`
}

func contains(s []string, str string) bool {
for _, v := range s {
if v == str {
return true
}
}
return false
}
2 changes: 1 addition & 1 deletion cmd/skywire-cli/commands/visor/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var pk string
func init() {
RootCmd.AddCommand(pkCmd)
pkCmd.Flags().StringVarP(&path, "input", "i", "", "path of input config file.")
pkCmd.Flags().BoolVarP(&pkg, "pkg", "p", false, "read from "+fmt.Sprintf("%s", visorconfig.PackageConfig())) //nolint
pkCmd.Flags().BoolVarP(&pkg, "pkg", "p", false, "read from "+fmt.Sprintf("%v", visorconfig.PackageConfig())) //nolint
pkCmd.Flags().BoolVarP(&web, "http", "w", false, "serve public key via http")
pkCmd.Flags().StringVarP(&webPort, "prt", "x", "7998", "serve public key via http")
RootCmd.AddCommand(summaryCmd)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ require (
github.com/gin-gonic/gin v1.9.1
github.com/go-chi/chi/v5 v5.0.8-0.20220103230436-7dbe9a0bd10f
github.com/gocarina/gocsv v0.0.0-20220927221512-ad3251f9fa25
github.com/hashicorp/go-version v1.6.0
github.com/ivanpirog/coloredcobra v1.0.0
github.com/james-barrow/golang-ipc v0.0.0-20210227130457-95e7cc81f5e2
github.com/jaypipes/ghw v0.10.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerX
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
Expand Down
45 changes: 45 additions & 0 deletions vendor/github.com/hashicorp/go-version/CHANGELOG.md

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

Loading

0 comments on commit 9140738

Please sign in to comment.