Skip to content

Commit

Permalink
Merge pull request #30 from mrpalide/fix/improve-monitor-logic
Browse files Browse the repository at this point in the history
Fix VPN and Public Visor monitor services
  • Loading branch information
jdknives authored Nov 20, 2023
2 parents f2b804f + 30d6c03 commit 115d627
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Install Requirements
run: |
GO111MODULES=off; go mod vendor
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.50.1
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.52.1
- name: Setup SSH Key Build and run e2e
run : |
make e2e-build
Expand Down
30 changes: 1 addition & 29 deletions cmd/public-visor-monitor/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
package commands

import (
"bytes"
"context"
"io"
"log"
"os"
"path/filepath"
"time"

cc "github.com/ivanpirog/coloredcobra"
Expand All @@ -16,7 +13,6 @@ import (
"github.com/skycoin/skywire-utilities/pkg/cmdutil"
"github.com/skycoin/skywire-utilities/pkg/logging"
"github.com/skycoin/skywire-utilities/pkg/tcpproxy"
"github.com/skycoin/skywire/pkg/visor/visorconfig"
"github.com/spf13/cobra"

"github.com/skycoin/skywire-services/pkg/public-visor-monitor/api"
Expand Down Expand Up @@ -70,7 +66,7 @@ var RootCmd = &cobra.Command{

logging.SetLevel(lvl)

conf := initConfig(confPath, visorBuildInfo, mLogger)
conf := api.InitConfig(confPath, mLogger)

srvURLs := api.ServicesURLs{
SD: conf.Launcher.ServiceDisc,
Expand Down Expand Up @@ -110,30 +106,6 @@ var RootCmd = &cobra.Command{
},
}

func initConfig(confPath string, visorBuildInfo *buildinfo.Info, mLog *logging.MasterLogger) *visorconfig.V1 {
log := mLog.PackageLogger("public_visor_monitor:config")
var r io.Reader

if confPath != "" {
log.WithField("filepath", confPath).Info()
f, err := os.ReadFile(filepath.Clean(confPath))
if err != nil {
log.WithError(err).Fatal("Failed to read config file.")
}
r = bytes.NewReader(f)
}

conf, compat, err := visorconfig.Parse(log, r, confPath, visorBuildInfo)
if err != nil {
log.WithError(err).Fatal("Failed to read in config.")
}
if !compat {
log.Fatalf("failed to start skywire - config version is incompatible")
}

return conf
}

// Execute executes root CLI command.
func Execute() {
cc.Init(&cc.Config{
Expand Down
30 changes: 1 addition & 29 deletions cmd/vpn-monitor/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
package commands

import (
"bytes"
"context"
"fmt"
"io"
"log"
"os"
"path/filepath"
"time"

cc "github.com/ivanpirog/coloredcobra"
Expand All @@ -17,7 +14,6 @@ import (
"github.com/skycoin/skywire-utilities/pkg/cmdutil"
"github.com/skycoin/skywire-utilities/pkg/logging"
"github.com/skycoin/skywire-utilities/pkg/tcpproxy"
"github.com/skycoin/skywire/pkg/visor/visorconfig"
"github.com/spf13/cobra"

"github.com/skycoin/skywire-services/pkg/vpn-monitor/api"
Expand Down Expand Up @@ -62,7 +58,7 @@ var RootCmd = &cobra.Command{
}

mLogger := logging.NewMasterLogger()
conf := initConfig(confPath, visorBuildInfo, mLogger)
conf := api.InitConfig(confPath, mLogger)

fmt.Println(conf.Version)

Expand Down Expand Up @@ -104,30 +100,6 @@ var RootCmd = &cobra.Command{
},
}

func initConfig(confPath string, visorBuildInfo *buildinfo.Info, mLog *logging.MasterLogger) *visorconfig.V1 {
log := mLog.PackageLogger("vpn_monitor:config")
var r io.Reader

if confPath != "" {
log.WithField("filepath", confPath).Info()
f, err := os.ReadFile(filepath.Clean(confPath))
if err != nil {
log.WithError(err).Fatal("Failed to read config file.")
}
r = bytes.NewReader(f)
}

conf, compat, err := visorconfig.Parse(log, r, confPath, visorBuildInfo)
if err != nil {
log.WithError(err).Fatal("Failed to read in config.")
}
if !compat {
log.Fatalf("failed to start skywire - config version is incompatible")
}

return conf
}

// Execute executes root CLI command.
func Execute() {
cc.Init(&cc.Config{
Expand Down
2 changes: 1 addition & 1 deletion docker/images/skywire-visor/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ARG image_tag=e2e

ARG base=alpine
FROM golang:alpine3.13 as builder
FROM golang:alpine3.17 as builder

ARG BUILDINFO_LDFLAGS
ARG CGO_ENABLED=0
Expand Down
1 change: 1 addition & 0 deletions pkg/dmsg-monitor/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ func InitConfig(confPath string, mLog *logging.MasterLogger) *visorconfig.V1 {
conf.Launcher.BinPath = oldConf.Launcher.BinPath
conf.Launcher.ServerAddr = oldConf.Launcher.ServerAddr
conf.CLIAddr = oldConf.CLIAddr
conf.Transport.TransportSetupPKs = oldConf.Transport.TransportSetupPKs

// following services are not needed
conf.STCP = nil
Expand Down
1 change: 1 addition & 0 deletions pkg/network-monitor/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ func InitConfig(confPath string, mLog *logging.MasterLogger) *visorconfig.V1 {
conf.Launcher.BinPath = oldConf.Launcher.BinPath
conf.Launcher.ServerAddr = oldConf.Launcher.ServerAddr
conf.CLIAddr = oldConf.CLIAddr
conf.Transport.TransportSetupPKs = oldConf.Transport.TransportSetupPKs

// following services are not needed
conf.STCP = nil
Expand Down
63 changes: 63 additions & 0 deletions pkg/public-visor-monitor/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"github.com/skycoin/skywire-utilities/pkg/cipher"
"github.com/skycoin/skywire-utilities/pkg/httputil"
"github.com/skycoin/skywire-utilities/pkg/logging"
utilenv "github.com/skycoin/skywire-utilities/pkg/skyenv"
"github.com/skycoin/skywire/pkg/app/appserver"
"github.com/skycoin/skywire/pkg/servicedisc"
"github.com/skycoin/skywire/pkg/transport/network"
"github.com/skycoin/skywire/pkg/visor"
Expand Down Expand Up @@ -279,3 +281,64 @@ func (api *API) startVisor(ctx context.Context, conf *visorconfig.V1) {
}
api.Visor = v
}

// InitConfig to initialize config
func InitConfig(confPath string, mLog *logging.MasterLogger) *visorconfig.V1 {
log := mLog.PackageLogger("public_visor_monitor:config")
log.Info("Reading config from file.")
log.WithField("filepath", confPath).Info()

oldConf, err := visorconfig.ReadFile(confPath)
if err != nil {
log.WithError(err).Fatal("Failed to read config file.")
}
var testEnv bool
if oldConf.Dmsg.Discovery == utilenv.TestDmsgDiscAddr {
testEnv = true
}
// have same services as old config
services := &visorconfig.Services{
DmsgDiscovery: oldConf.Dmsg.Discovery,
TransportDiscovery: oldConf.Transport.Discovery,
AddressResolver: oldConf.Transport.AddressResolver,
RouteFinder: oldConf.Routing.RouteFinder,
RouteSetupNodes: oldConf.Routing.RouteSetupNodes,
UptimeTracker: oldConf.UptimeTracker.Addr,
ServiceDiscovery: oldConf.Launcher.ServiceDisc,
}
// update old config
conf, err := visorconfig.MakeDefaultConfig(mLog, &oldConf.SK, false, false, testEnv, false, false, confPath, "", services)
if err != nil {
log.WithError(err).Fatal("Failed to create config.")
}

// have the same apps that the old config had
var newConfLauncherApps []appserver.AppConfig
for _, app := range conf.Launcher.Apps {
for _, oldApp := range oldConf.Launcher.Apps {
if app.Name == oldApp.Name {
newConfLauncherApps = append(newConfLauncherApps, app)
}
}
}
conf.Launcher.Apps = newConfLauncherApps

conf.Version = oldConf.Version
conf.LocalPath = oldConf.LocalPath
conf.Launcher.BinPath = oldConf.Launcher.BinPath
conf.Launcher.ServerAddr = oldConf.Launcher.ServerAddr
conf.CLIAddr = oldConf.CLIAddr
conf.Transport.TransportSetupPKs = oldConf.Transport.TransportSetupPKs

// following services are not needed
conf.STCP = nil
conf.Dmsgpty = nil
conf.Transport.PublicAutoconnect = false

// save the config file
if err := conf.Flush(); err != nil {
log.WithError(err).Fatal("Failed to flush config to file.")
}

return conf
}
62 changes: 62 additions & 0 deletions pkg/vpn-monitor/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/skycoin/skywire-utilities/pkg/cipher"
"github.com/skycoin/skywire-utilities/pkg/httputil"
"github.com/skycoin/skywire-utilities/pkg/logging"
utilenv "github.com/skycoin/skywire-utilities/pkg/skyenv"
"github.com/skycoin/skywire/pkg/app/appserver"
"github.com/skycoin/skywire/pkg/servicedisc"
"github.com/skycoin/skywire/pkg/skyenv"
Expand Down Expand Up @@ -353,3 +354,64 @@ func RunVpnClient(v *visor.Visor, serverPK cipher.PubKey, appName string) ([]app

return sum, nil
}

// InitConfig to initialize config
func InitConfig(confPath string, mLog *logging.MasterLogger) *visorconfig.V1 {
log := mLog.PackageLogger("vpn_monitor:config")
log.Info("Reading config from file.")
log.WithField("filepath", confPath).Info()

oldConf, err := visorconfig.ReadFile(confPath)
if err != nil {
log.WithError(err).Fatal("Failed to read config file.")
}
var testEnv bool
if oldConf.Dmsg.Discovery == utilenv.TestDmsgDiscAddr {
testEnv = true
}
// have same services as old config
services := &visorconfig.Services{
DmsgDiscovery: oldConf.Dmsg.Discovery,
TransportDiscovery: oldConf.Transport.Discovery,
AddressResolver: oldConf.Transport.AddressResolver,
RouteFinder: oldConf.Routing.RouteFinder,
RouteSetupNodes: oldConf.Routing.RouteSetupNodes,
UptimeTracker: oldConf.UptimeTracker.Addr,
ServiceDiscovery: oldConf.Launcher.ServiceDisc,
}
// update old config
conf, err := visorconfig.MakeDefaultConfig(mLog, &oldConf.SK, false, false, testEnv, false, false, confPath, "", services)
if err != nil {
log.WithError(err).Fatal("Failed to create config.")
}

// have the same apps that the old config had
var newConfLauncherApps []appserver.AppConfig
for _, app := range conf.Launcher.Apps {
for _, oldApp := range oldConf.Launcher.Apps {
if app.Name == oldApp.Name {
newConfLauncherApps = append(newConfLauncherApps, app)
}
}
}
conf.Launcher.Apps = newConfLauncherApps

conf.Version = oldConf.Version
conf.LocalPath = oldConf.LocalPath
conf.Launcher.BinPath = oldConf.Launcher.BinPath
conf.Launcher.ServerAddr = oldConf.Launcher.ServerAddr
conf.CLIAddr = oldConf.CLIAddr
conf.Transport.TransportSetupPKs = oldConf.Transport.TransportSetupPKs

// following services are not needed
conf.STCP = nil
conf.Dmsgpty = nil
conf.Transport.PublicAutoconnect = false

// save the config file
if err := conf.Flush(); err != nil {
log.WithError(err).Fatal("Failed to flush config to file.")
}

return conf
}

0 comments on commit 115d627

Please sign in to comment.