Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup node VM #763

Merged
merged 2 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions cmd/skywire-visor/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package commands

import (
"context"
"embed"
"fmt"
"io"
"io/fs"
"io/ioutil"
"net/http"
_ "net/http/pprof" // nolint:gosec // https://golang.org/doc/diagnostics.html#profiling
Expand All @@ -13,9 +15,6 @@ import (
"syscall"
"time"

"embed"
"io/fs"

"github.com/pkg/profile"
"github.com/skycoin/dmsg/buildinfo"
"github.com/skycoin/dmsg/cmdutil"
Expand Down
4 changes: 3 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9 h1:sYNJzB4J8toYPQTM6pAkcm
golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
Expand Down Expand Up @@ -328,6 +327,7 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand All @@ -354,10 +354,12 @@ google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
Expand Down
13 changes: 2 additions & 11 deletions pkg/setup/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,10 @@ func (sn *Node) Serve(ctx context.Context, m setupmetrics.Metrics) error {
// * Intermediary rules are broadcasted to the intermediary routers.
// * Edge rules are broadcasted to the responding router.
// * Edge rules is returned (to the initiating router).
func CreateRouteGroup(ctx context.Context, dialer snet.Dialer, biRt routing.BidirectionalRoute) (resp routing.EdgeRules, err error) {
start := time.Now()
func CreateRouteGroup(ctx context.Context, dialer snet.Dialer, biRt routing.BidirectionalRoute, metrics setupmetrics.Metrics) (resp routing.EdgeRules, err error) {
log := logging.MustGetLogger(fmt.Sprintf("request:%s->%s", biRt.Desc.SrcPK(), biRt.Desc.DstPK()))
log.Info("Processing request.")
defer func() {
elapsed := time.Since(start)
log := log.WithField("elapsed", elapsed)
if err != nil {
log.WithError(err).Warn("Request processed with error.")
} else {
log.Info("Request processed successfully.")
}
}()
defer metrics.RecordRoute()(&err)

// Ensure bi routes input is valid.
if err = biRt.Check(); err != nil {
Expand Down
6 changes: 5 additions & 1 deletion pkg/setup/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/skycoin/skywire/pkg/routing"
"github.com/skycoin/skywire/pkg/setup/setupmetrics"
)

func TestMain(m *testing.M) {
Expand Down Expand Up @@ -74,11 +75,14 @@ func TestCreateRouteGroup(t *testing.T) {
// arrange: mock dialer
dialer := newMockDialer(t, routers)

// arrange: mock dialer
metrics := setupmetrics.NewEmpty()

// arrange: bidirectional route input
biRt := biRouteFromKeys(tc.fwdPKs, tc.revPKs, tc.SrcPort, tc.DstPort)

// act
resp, err := CreateRouteGroup(context.TODO(), dialer, biRt)
resp, err := CreateRouteGroup(context.TODO(), dialer, biRt, metrics)
if err == nil {
// if successful, inject response (response edge rules) to responding router
var ok bool
Expand Down
2 changes: 1 addition & 1 deletion pkg/setup/rpc_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (g *RPCGateway) DialRouteGroup(route routing.BidirectionalRoute, rules *rou
}
}()

initRules, err := CreateRouteGroup(ctx, g.Dialer, route)
initRules, err := CreateRouteGroup(ctx, g.Dialer, route, g.Metrics)
if err != nil {
return err
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/setup/setupmetrics/empty.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ type Empty struct{}
func (Empty) RecordRequest() func(*routing.EdgeRules, *error) {
return func(*routing.EdgeRules, *error) {}
}

// RecordRoute implements `Metrics`.
func (Empty) RecordRoute() func(*error) {
return func(*error) {}
}
20 changes: 20 additions & 0 deletions pkg/setup/setupmetrics/victoria_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ import (
// Metrics collects metrics in prometheus format.
type Metrics interface {
RecordRequest() func(*routing.EdgeRules, *error)
RecordRoute() func(*error)
}

// VictoriaMetrics implements `Metrics` using Victoria Metrics.
type VictoriaMetrics struct {
activeRequests *metricsutil.VictoriaMetricsIntGaugeWrapper
reqDurationsFailed *metrics.Histogram
reqDurationsSuccesses *metrics.Histogram
routesSetup *metricsutil.VictoriaMetricsIntGaugeWrapper
routesSetupFailed *metricsutil.VictoriaMetricsIntGaugeWrapper
routesSetupDuration *metrics.Histogram
}

// NewVictoriaMetrics returns the Victoria Metrics implementation of Metrics.
Expand All @@ -27,6 +31,9 @@ func NewVictoriaMetrics() *VictoriaMetrics {
activeRequests: metricsutil.NewVictoriaMetricsIntGauge("active_request_count"),
reqDurationsFailed: metrics.GetOrCreateHistogram("request_durations{success=\"true\"}"),
reqDurationsSuccesses: metrics.GetOrCreateHistogram("request_durations{success=\"false\"}"),
routesSetup: metricsutil.NewVictoriaMetricsIntGauge("no_of_route_setups"),
routesSetupFailed: metricsutil.NewVictoriaMetricsIntGauge("no_of_failed_route_setups"),
routesSetupDuration: metrics.GetOrCreateHistogram("route_setup_duration{success=\"true\"}"),
}
}

Expand All @@ -45,3 +52,16 @@ func (m *VictoriaMetrics) RecordRequest() func(rules *routing.EdgeRules, err *er
m.activeRequests.Dec()
}
}

// RecordRoute implements `Metrics`.
func (m *VictoriaMetrics) RecordRoute() func(err *error) {
start := time.Now()
m.routesSetup.Inc()

return func(err *error) {
m.routesSetupDuration.UpdateDuration(start)
if *err != nil {
m.routesSetupFailed.Inc()
}
}
}
3 changes: 1 addition & 2 deletions pkg/visor/hypervisorconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package hypervisorconfig
import (
"encoding/hex"
"encoding/json"
"io/fs"
"log"
"net/http"
"os"
"path/filepath"
"time"

"io/fs"

"github.com/skycoin/dmsg/cipher"

"github.com/skycoin/skywire/pkg/skyenv"
Expand Down