Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/skycoin/skywire-services
Browse files Browse the repository at this point in the history
…into develop
  • Loading branch information
jdknives committed Jul 10, 2023
2 parents c6a15ce + ed25005 commit 4e60a7d
Show file tree
Hide file tree
Showing 24 changed files with 172 additions and 85 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ format: dep ## Formats the code. Must have goimports and goimports-reviser insta
goimports -w -local github.com/skycoin/skywire-services ./pkg
goimports -w -local github.com/skycoin/skywire-services ./cmd
goimports -w -local github.com/skycoin/skywire-services ./internal
find . -type f -name '*.go' -not -path "./vendor/*" -exec goimports-reviser -project-name ${PROJECT_BASE} -file-path {} \;
find . -type f -name '*.go' -not -path "./vendor/*" -exec goimports-reviser -project-name ${PROJECT_BASE} {} \;

## : ## _ [Build, install, clean]

Expand Down Expand Up @@ -190,7 +190,7 @@ e2e-help: ## E2E. Show env-vars and useful commands

docker-push-test:
bash ./docker/docker_build.sh test ${BUILD_OPTS_DEPLOY}
bash ./docker/docker_push.sh test
# bash ./docker/docker_push.sh test

docker-push:
bash ./docker/docker_build.sh prod ${BUILD_OPTS_DEPLOY}
Expand Down
25 changes: 17 additions & 8 deletions cmd/address-resolver/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commands

import (
"context"
"fmt"
"log"
"log/syslog"
"os"
Expand Down Expand Up @@ -40,29 +41,31 @@ var (
metricsAddr string
redisURL string
redisPoolSize int
logEnabled bool
syslogAddr string
tag string
logLvl string
testing bool
dmsgDisc string
whitelistKeys string
testEnvironment bool
sk cipher.SecKey
dmsgPort uint16
)

func init() {
rootCmd.Flags().StringVarP(&addr, "addr", "a", ":9093", "address to bind to\033[0m")
rootCmd.Flags().StringVarP(&metricsAddr, "metrics", "m", "", "address to bind metrics API to\033[0m")
rootCmd.Flags().StringVar(&redisURL, "redis", "redis://localhost:6379", "connections string for a redis store\033[0m")
rootCmd.Flags().IntVar(&redisPoolSize, "redis-pool-size", 10, "redis connection pool size\033[0m")
rootCmd.Flags().BoolVarP(&logEnabled, "log", "l", true, "enable request logging\033[0m")
rootCmd.Flags().StringVarP(&logLvl, "loglvl", "l", "info", "set log level one of: info, error, warn, debug, trace, panic")
rootCmd.Flags().StringVar(&syslogAddr, "syslog", "", "syslog server address. E.g. localhost:514\033[0m")
rootCmd.Flags().StringVar(&tag, "tag", "address_resolver", "logging tag\033[0m")
rootCmd.Flags().BoolVarP(&testing, "testing", "t", false, "enable testing to start without redis\033[0m")
rootCmd.Flags().StringVar(&dmsgDisc, "dmsg-disc", "http://dmsgd.skywire.skycoin.com", "url of dmsg-discovery\033[0m")
rootCmd.Flags().StringVar(&whitelistKeys, "whitelist-keys", "", "list of whitelisted keys of network monitor used for deregistration\033[0m")
rootCmd.Flags().BoolVar(&testEnvironment, "test-environment", false, "distinguished between prod and test environment\033[0m")
rootCmd.Flags().Var(&sk, "sk", "dmsg secret key\r")
rootCmd.Flags().Uint16Var(&dmsgPort, "dmsgPort", dmsg.DefaultDmsgHTTPPort, "dmsg port value\r")
var helpflag bool
rootCmd.SetUsageTemplate(help)
rootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for "+rootCmd.Use)
Expand Down Expand Up @@ -101,13 +104,14 @@ var rootCmd = &cobra.Command{
storeConfig.Type = storeconfig.Memory
}

var logger *logging.Logger
if logEnabled {
logger = logging.MustGetLogger(tag)
} else {
logger = nil
logger := logging.MustGetLogger(tag)
lvl, err := logging.LevelFromString(logLvl)
if err != nil {
logger.Fatal("Invalid loglvl detected")
}

logging.SetLevel(lvl)

ctx, cancel := cmdutil.SignalContext(context.Background(), logger)
defer cancel()

Expand Down Expand Up @@ -158,8 +162,13 @@ var rootCmd = &cobra.Command{
m = armetrics.NewVictoriaMetrics()
}

var dmsgAddr string
if !pk.Null() {
dmsgAddr = fmt.Sprintf("%s:%d", pk.Hex(), dmsgPort)
}

enableMetrics := metricsAddr != ""
arAPI := api.New(logger, transportStore, nonceStore, enableMetrics, m)
arAPI := api.New(logger, transportStore, nonceStore, enableMetrics, m, dmsgAddr)

udpListener, err := kcp.Listen(addr)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions cmd/config-bootstrapper/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,12 @@ func readConfig(log *logging.Logger, confPath string) (config api.Config) {
func Execute() {
cc.Init(&cc.Config{
RootCmd: rootCmd,
Headings: cc.HiBlue + cc.Bold, //+ cc.Underline,
Headings: cc.HiBlue + cc.Bold,
Commands: cc.HiBlue + cc.Bold,
CmdShortDescr: cc.HiBlue,
Example: cc.HiBlue + cc.Italic,
ExecName: cc.HiBlue + cc.Bold,
Flags: cc.HiBlue + cc.Bold,
//FlagsDataType: cc.HiBlue,
FlagsDescr: cc.HiBlue,
NoExtraNewlines: true,
NoBottomNewline: true,
Expand Down
25 changes: 16 additions & 9 deletions cmd/dmsg-monitor/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var (
addr string
tag string
syslogAddr string
logLvl string
sleepDeregistration time.Duration
batchSize int
)
Expand All @@ -40,6 +41,7 @@ func init() {
rootCmd.Flags().StringVarP(&utURL, "ut-url", "u", "", "url to uptime tracker visor data.\033[0m")
rootCmd.Flags().StringVar(&tag, "tag", "dmsg_monitor", "logging tag\033[0m")
rootCmd.Flags().StringVar(&syslogAddr, "syslog", "", "syslog server address. E.g. localhost:514\033[0m")
rootCmd.Flags().StringVarP(&logLvl, "loglvl", "l", "info", "set log level one of: info, error, warn, debug, trace, panic")
var helpflag bool
rootCmd.SetUsageTemplate(help)
rootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for "+rootCmd.Use)
Expand All @@ -65,6 +67,12 @@ var rootCmd = &cobra.Command{
}

mLogger := logging.NewMasterLogger()
lvl, err := logging.LevelFromString(logLvl)
if err != nil {
mLogger.Fatal("Invalid log level")
}
logging.SetLevel(lvl)

conf := api.InitConfig(confPath, mLogger)

if dmsgURL == "" {
Expand All @@ -78,7 +86,7 @@ var rootCmd = &cobra.Command{
srvURLs.DMSG = dmsgURL
srvURLs.UT = utURL

logger := mLogger.PackageLogger("dmsg_monitor")
logger := mLogger.PackageLogger(tag)
if syslogAddr != "" {
hook, err := logrussyslog.NewSyslogHook("udp", syslogAddr, syslog.LOG_INFO, tag)
if err != nil {
Expand Down Expand Up @@ -120,14 +128,13 @@ var rootCmd = &cobra.Command{
// Execute executes root CLI command.
func Execute() {
cc.Init(&cc.Config{
RootCmd: rootCmd,
Headings: cc.HiBlue + cc.Bold, //+ cc.Underline,
Commands: cc.HiBlue + cc.Bold,
CmdShortDescr: cc.HiBlue,
Example: cc.HiBlue + cc.Italic,
ExecName: cc.HiBlue + cc.Bold,
Flags: cc.HiBlue + cc.Bold,
//FlagsDataType: cc.HiBlue,
RootCmd: rootCmd,
Headings: cc.HiBlue + cc.Bold,
Commands: cc.HiBlue + cc.Bold,
CmdShortDescr: cc.HiBlue,
Example: cc.HiBlue + cc.Italic,
ExecName: cc.HiBlue + cc.Bold,
Flags: cc.HiBlue + cc.Bold,
FlagsDescr: cc.HiBlue,
NoExtraNewlines: true,
NoBottomNewline: true,
Expand Down
3 changes: 1 addition & 2 deletions cmd/keys-gen/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import (
"fmt"
"log"

cc "github.com/ivanpirog/coloredcobra"
"github.com/skycoin/skywire-utilities/pkg/buildinfo"
"github.com/skycoin/skywire-utilities/pkg/cipher"

cc "github.com/ivanpirog/coloredcobra"
"github.com/spf13/cobra"
)

Expand Down
9 changes: 9 additions & 0 deletions cmd/liveness-checker/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var (
addr string
tag string
syslogAddr string
logLvl string
redisURL string
testing bool
)
Expand All @@ -39,6 +40,7 @@ func init() {
rootCmd.Flags().StringVarP(&confPath, "config", "c", "liveness-checker.json", "config file location.\033[0m")
rootCmd.Flags().StringVar(&tag, "tag", "liveness_checker", "logging tag\033[0m")
rootCmd.Flags().StringVar(&syslogAddr, "syslog", "", "syslog server address. E.g. localhost:514\033[0m")
rootCmd.Flags().StringVarP(&logLvl, "loglvl", "l", "info", "set log level one of: info, error, warn, debug, trace, panic")
rootCmd.Flags().StringVar(&redisURL, "redis", "redis://localhost:6379", "connections string for a redis store\033[0m")
rootCmd.Flags().BoolVarP(&testing, "testing", "t", false, "enable testing to start without redis\033[0m")
var helpflag bool
Expand Down Expand Up @@ -80,6 +82,13 @@ var rootCmd = &cobra.Command{
}

mLogger := logging.NewMasterLogger()
lvl, err := logging.LevelFromString(logLvl)
if err != nil {
mLogger.Fatal("Invalid loglvl detected")
}

logging.SetLevel(lvl)

conf, confAPI := api.InitConfig(confPath, mLogger)

logger := mLogger.PackageLogger(tag)
Expand Down
8 changes: 8 additions & 0 deletions cmd/network-monitor/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var (
addr string
tag string
syslogAddr string
logLvl string
metricsAddr string
redisURL string
testing bool
Expand All @@ -55,6 +56,7 @@ func init() {
rootCmd.Flags().StringVarP(&utURL, "ut-url", "u", "", "url to uptime tracker visor data.\033[0m")
rootCmd.Flags().StringVar(&tag, "tag", "network_monitor", "logging tag\033[0m")
rootCmd.Flags().StringVar(&syslogAddr, "syslog", "", "syslog server address. E.g. localhost:514\033[0m")
rootCmd.Flags().StringVarP(&logLvl, "loglvl", "l", "info", "set log level one of: info, error, warn, debug, trace, panic")
rootCmd.Flags().StringVarP(&metricsAddr, "metrics", "m", "", "address to bind metrics API to\033[0m")
rootCmd.Flags().StringVar(&redisURL, "redis", "redis://localhost:6379", "connections string for a redis store\033[0m")
rootCmd.Flags().BoolVarP(&testing, "testing", "t", false, "enable testing to start without redis\033[0m")
Expand Down Expand Up @@ -104,6 +106,12 @@ var rootCmd = &cobra.Command{
}

mLogger := logging.NewMasterLogger()
lvl, err := logging.LevelFromString(logLvl)
if err != nil {
mLogger.Fatal("Invalid loglvl detected")
}

logging.SetLevel(lvl)
conf := api.InitConfig(confPath, mLogger)

if sdURL == "" {
Expand Down
9 changes: 9 additions & 0 deletions cmd/public-visor-monitor/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var (
confPath string
addr string
tag string
logLvl string
sleepDeregistration time.Duration
)

Expand All @@ -34,6 +35,7 @@ func init() {
rootCmd.Flags().DurationVarP(&sleepDeregistration, "sleep-deregistration", "s", 10, "Sleep time for derigstration process in minutes\033[0m")
rootCmd.Flags().StringVarP(&confPath, "config", "c", "public-visor-monitor.json", "config file location.\033[0m")
rootCmd.Flags().StringVar(&tag, "tag", "public_visor_monitor", "logging tag\033[0m")
rootCmd.Flags().StringVarP(&logLvl, "loglvl", "l", "info", "set log level one of: info, error, warn, debug, trace, panic")
var helpflag bool
rootCmd.SetUsageTemplate(help)
rootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for "+rootCmd.Use)
Expand All @@ -60,6 +62,13 @@ var rootCmd = &cobra.Command{
}

mLogger := logging.NewMasterLogger()
lvl, err := logging.LevelFromString(logLvl)
if err != nil {
mLogger.Fatal("Invalid loglvl detected")
}

logging.SetLevel(lvl)

conf := initConfig(confPath, visorBuildInfo, mLogger)

srvURLs := api.ServicesURLs{
Expand Down
25 changes: 16 additions & 9 deletions cmd/route-finder/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,27 @@ var (
metricsAddr string
pgHost string
pgPort string
logEnabled bool
syslogAddr string
logLvl string
tag string
testing bool
dmsgDisc string
sk cipher.SecKey
dmsgPort uint16
)

func init() {
rootCmd.Flags().StringVarP(&addr, "addr", "a", ":9092", "address to bind to\033[0m")
rootCmd.Flags().StringVarP(&metricsAddr, "metrics", "m", "", "address to bind metrics API to\033[0m")
rootCmd.Flags().BoolVarP(&logEnabled, "log", "l", true, "enable request logging\033[0m")
rootCmd.Flags().StringVar(&pgHost, "pg-host", "localhost", "host of postgres\033[0m")
rootCmd.Flags().StringVar(&pgPort, "pg-port", "5432", "port of postgres\033[0m")
rootCmd.Flags().StringVar(&syslogAddr, "syslog", "", "syslog server address. E.g. localhost:514\033[0m")
rootCmd.Flags().StringVarP(&logLvl, "loglvl", "l", "info", "set log level one of: info, error, warn, debug, trace, panic")
rootCmd.Flags().StringVar(&tag, "tag", "route_finder", "logging tag\033[0m")
rootCmd.Flags().BoolVarP(&testing, "testing", "t", false, "enable testing to start without redis\033[0m")
rootCmd.Flags().StringVar(&dmsgDisc, "dmsg-disc", "http://dmsgd.skywire.skycoin.com", "url of dmsg-discovery\033[0m")
rootCmd.Flags().Var(&sk, "sk", "dmsg secret key\r")
rootCmd.Flags().Uint16Var(&dmsgPort, "dmsgPort", dmsg.DefaultDmsgHTTPPort, "dmsg port value\r")
var helpflag bool
rootCmd.SetUsageTemplate(help)
rootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for "+rootCmd.Use)
Expand All @@ -78,15 +80,15 @@ var rootCmd = &cobra.Command{

memoryStore := true

var logger *logging.Logger
if logEnabled {
logger = logging.MustGetLogger(tag)
} else {
logger = nil
logger := logging.MustGetLogger(tag)
lvl, err := logging.LevelFromString(logLvl)
if err != nil {
logger.Fatal("Invalid loglvl detected")
}

logging.SetLevel(lvl)

var gormDB *gorm.DB
var err error

if !testing {
pgUser, pgPassword, pgDatabase := storeconfig.PostgresCredential()
Expand Down Expand Up @@ -125,8 +127,13 @@ var rootCmd = &cobra.Command{

metricsutil.ServeHTTPMetrics(logger, metricsAddr)

var dmsgAddr string
if !pk.Null() {
dmsgAddr = fmt.Sprintf("%s:%d", pk.Hex(), dmsgPort)
}

enableMetrics := metricsAddr != ""
rfAPI := api.New(transportStore, logger, enableMetrics)
rfAPI := api.New(transportStore, logger, enableMetrics, dmsgAddr)

if logger != nil {
logger.Infof("Listening on %s", addr)
Expand Down
Loading

0 comments on commit 4e60a7d

Please sign in to comment.