Skip to content

Commit

Permalink
add uptime tracker code from skywire-ut develop branch
Browse files Browse the repository at this point in the history
  • Loading branch information
0pcom committed Sep 23, 2024
1 parent 54f5d92 commit cda0d17
Show file tree
Hide file tree
Showing 19 changed files with 62 additions and 38 deletions.
25 changes: 11 additions & 14 deletions cmd/uptime-tracker/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ import (
"github.com/skycoin/dmsg/pkg/direct"
"github.com/skycoin/dmsg/pkg/dmsg"
"github.com/skycoin/dmsg/pkg/dmsghttp"
"github.com/skycoin/skywire-ut/internal/pg"
"github.com/skycoin/skywire-ut/internal/utmetrics"
"github.com/skycoin/skywire-ut/pkg/uptime-tracker/api"
"github.com/skycoin/skywire-ut/pkg/uptime-tracker/store"
"github.com/spf13/cobra"
"gorm.io/gorm"

"github.com/skycoin/skywire-utilities/pkg/buildinfo"
"github.com/skycoin/skywire-utilities/pkg/cipher"
"github.com/skycoin/skywire-utilities/pkg/cmdutil"
Expand All @@ -21,13 +28,6 @@ import (
"github.com/skycoin/skywire-utilities/pkg/metricsutil"
"github.com/skycoin/skywire-utilities/pkg/storeconfig"
"github.com/skycoin/skywire-utilities/pkg/tcpproxy"
"github.com/spf13/cobra"
"gorm.io/gorm"

"github.com/skycoin/skywire-services/internal/pg"
"github.com/skycoin/skywire-services/internal/utmetrics"
"github.com/skycoin/skywire-services/pkg/uptime-tracker/api"
"github.com/skycoin/skywire-services/pkg/uptime-tracker/store"
)

const (
Expand All @@ -53,7 +53,6 @@ var (
dmsgDisc string
sk cipher.SecKey
dmsgPort uint16
dmsgServerType string
storeDataCutoff int
storeDataPath string
)
Expand All @@ -77,7 +76,6 @@ func init() {
rootCmd.Flags().StringVar(&dmsgDisc, "dmsg-disc", "http://dmsgd.skywire.skycoin.com", "url of dmsg-discovery")
rootCmd.Flags().Var(&sk, "sk", "dmsg secret key")
rootCmd.Flags().Uint16Var(&dmsgPort, "dmsgPort", dmsg.DefaultDmsgHTTPPort, "dmsg port value\r")
rootCmd.Flags().StringVar(&dmsgServerType, "dmsg-server-type", "", "type of dmsg server on dmsghttp handler")
}

var rootCmd = &cobra.Command{
Expand Down Expand Up @@ -180,15 +178,14 @@ var rootCmd = &cobra.Command{
}()

if !pk.Null() {
servers := dmsghttp.GetServers(ctx, dmsgDisc, dmsgServerType, logger)
servers := dmsghttp.GetServers(ctx, dmsgDisc, logger)

var keys cipher.PubKeys
keys = append(keys, pk)
dClient := direct.NewClient(direct.GetAllEntries(keys, servers), logger)
config := &dmsg.Config{
MinSessions: 0, // listen on all available servers
UpdateInterval: dmsg.DefaultUpdateInterval,
ConnectedServersType: dmsgServerType,
MinSessions: 0, // listen on all available servers
UpdateInterval: dmsg.DefaultUpdateInterval,
}

dmsgDC, closeDmsgDC, err := direct.StartDmsg(ctx, logger, pk, sk, dClient, config)
Expand All @@ -205,7 +202,7 @@ var rootCmd = &cobra.Command{
}
}()

go dmsghttp.UpdateServers(ctx, dClient, dmsgDisc, dmsgDC, dmsgServerType, logger)
go dmsghttp.UpdateServers(ctx, dClient, dmsgDisc, dmsgDC, logger)

go func() {
if err := dmsghttp.ListenAndServe(ctx, sk, utAPI, dClient, dmsg.DefaultDmsgHTTPPort, dmsgDC, logger); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/uptime-tracker/uptime-tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package main

import (
"github.com/skycoin/skywire-services/cmd/uptime-tracker/commands"
"github.com/skycoin/skywire-ut/cmd/uptime-tracker/commands"
)

func main() {
Expand Down
4 changes: 3 additions & 1 deletion internal/armetrics/victoria_metrics.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package armetrics

import "github.com/skycoin/skywire-utilities/pkg/metricsutil"
import (
"github.com/skycoin/skywire-utilities/pkg/metricsutil"
)

// VictoriaMetrics implements `Metrics` using `VictoriaMetrics`.
type VictoriaMetrics struct {
Expand Down
4 changes: 3 additions & 1 deletion internal/config/default_environments_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package config

import "fmt"
import (
"fmt"
)

func ExampleEnvConfig_AddThreeChatVisors() {
globalEnv := &EnvConfig{
Expand Down
4 changes: 3 additions & 1 deletion internal/config/runners.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package config

import "fmt"
import (
"fmt"
)

const (
// DockerRedisCmdTemplate is a template for running dockerized redis
Expand Down
4 changes: 3 additions & 1 deletion internal/lc/data.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Package lc internal/lc/data.go
package lc

import "github.com/skycoin/skywire-utilities/pkg/httputil"
import (
"github.com/skycoin/skywire-utilities/pkg/httputil"
)

// ServiceSummary summary of a visor connection
type ServiceSummary struct {
Expand Down
4 changes: 3 additions & 1 deletion internal/nmmetrics/victoria_metrics.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package nmmetrics

import "github.com/skycoin/skywire-utilities/pkg/metricsutil"
import (
"github.com/skycoin/skywire-utilities/pkg/metricsutil"
)

// VictoriaMetrics implements `Metrics` using `VictoriaMetrics`.
type VictoriaMetrics struct {
Expand Down
4 changes: 3 additions & 1 deletion internal/tpdiscmetrics/empty.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Package tpdiscmetrics internal/tpdiscmetrics/empty.go
package tpdiscmetrics

import "github.com/skycoin/skywire/pkg/transport/network"
import (
"github.com/skycoin/skywire/pkg/transport/network"
)

// NewEmpty constructs new empty metrics.
func NewEmpty() Empty {
Expand Down
4 changes: 3 additions & 1 deletion internal/tpdiscmetrics/metrics.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package tpdiscmetrics

import "github.com/skycoin/skywire/pkg/transport/network"
import (
"github.com/skycoin/skywire/pkg/transport/network"
)

// Metrics collects metrics for metrics tracking system.
type Metrics interface {
Expand Down
4 changes: 3 additions & 1 deletion internal/utmetrics/victoria_metrics.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package utmetrics

import "github.com/skycoin/skywire-utilities/pkg/metricsutil"
import (
"github.com/skycoin/skywire-utilities/pkg/metricsutil"
)

// VictoriaMetrics implements `Metrics` using `VictoriaMetrics`.
type VictoriaMetrics struct {
Expand Down
4 changes: 3 additions & 1 deletion internal/vpn/client_config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package vpn

import "github.com/skycoin/skywire-utilities/pkg/cipher"
import (
"github.com/skycoin/skywire-utilities/pkg/cipher"
)

// ClientConfig is a configuration for VPN client.
type ClientConfig struct {
Expand Down
4 changes: 3 additions & 1 deletion internal/vpn/handshake_status.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package vpn

import "errors"
import (
"errors"
)

// HandshakeStatus is a status of Client/Server handshake.
type HandshakeStatus int
Expand Down
4 changes: 3 additions & 1 deletion internal/vpn/hello.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package vpn

import "net"
import (
"net"
)

// ClientHello is a message sent by client during the Client/Server handshake.
type ClientHello struct {
Expand Down
4 changes: 3 additions & 1 deletion internal/vpn/tun_device.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package vpn

import "io"
import (
"io"
)

// TUNDevice is a wrapper for TUN interface.
type TUNDevice interface {
Expand Down
6 changes: 3 additions & 3 deletions pkg/uptime-tracker/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
"github.com/go-echarts/go-echarts/v2/charts"
"github.com/go-echarts/go-echarts/v2/opts"
"github.com/sirupsen/logrus"
"github.com/skycoin/skywire-ut/internal/utmetrics"
"github.com/skycoin/skywire-ut/pkg/uptime-tracker/store"

"github.com/skycoin/skywire-utilities/pkg/buildinfo"
"github.com/skycoin/skywire-utilities/pkg/cipher"
"github.com/skycoin/skywire-utilities/pkg/geo"
Expand All @@ -29,9 +32,6 @@ import (
"github.com/skycoin/skywire-utilities/pkg/logging"
"github.com/skycoin/skywire-utilities/pkg/metricsutil"
"github.com/skycoin/skywire-utilities/pkg/netutil"

"github.com/skycoin/skywire-services/internal/utmetrics"
"github.com/skycoin/skywire-services/pkg/uptime-tracker/store"
)

const (
Expand Down
10 changes: 5 additions & 5 deletions pkg/uptime-tracker/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import (
"net/http/httptest"
"testing"

"github.com/skycoin/skywire-ut/internal/utmetrics"
"github.com/skycoin/skywire-ut/pkg/uptime-tracker/store"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/skycoin/skywire-utilities/pkg/cipher"
"github.com/skycoin/skywire-utilities/pkg/geo"
"github.com/skycoin/skywire-utilities/pkg/httpauth"
"github.com/skycoin/skywire-utilities/pkg/storeconfig"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/skycoin/skywire-services/internal/utmetrics"
"github.com/skycoin/skywire-services/pkg/uptime-tracker/store"
)

var testPubKey, testSec = cipher.GenerateKeyPair()
Expand Down
3 changes: 2 additions & 1 deletion pkg/uptime-tracker/store/memory_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
"testing"
"time"

"github.com/stretchr/testify/require"

"github.com/skycoin/skywire-utilities/pkg/cipher"
"github.com/skycoin/skywire-utilities/pkg/geo"
"github.com/stretchr/testify/require"
)

func TestMemory(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/uptime-tracker/store/postgres_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
"sync"
"time"

"gorm.io/gorm"

"github.com/skycoin/skywire-utilities/pkg/geo"
"github.com/skycoin/skywire-utilities/pkg/logging"
"gorm.io/gorm"
)

type postgresStore struct {
Expand Down
3 changes: 2 additions & 1 deletion pkg/uptime-tracker/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package store
import (
"time"

"gorm.io/gorm"

"github.com/skycoin/skywire-utilities/pkg/geo"
"github.com/skycoin/skywire-utilities/pkg/logging"
"gorm.io/gorm"
)

const (
Expand Down

0 comments on commit cda0d17

Please sign in to comment.