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

Refactor Summaries #759

Merged
merged 11 commits into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions cmd/skywire-cli/commands/visor/pk.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ var pkCmd = &cobra.Command{
Run: func(_ *cobra.Command, _ []string) {

client := rpcClient()
summary, err := client.Summary()
overview, err := client.Overview()
if err != nil {
logger.Fatal("Failed to connect:", err)
}

fmt.Println(summary.PubKey)
fmt.Println(overview.PubKey)
},
}
4 changes: 2 additions & 2 deletions cmd/skywire-cli/commands/visor/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ var buildInfoCmd = &cobra.Command{
Short: "Obtains version and build info of the node",
Run: func(_ *cobra.Command, _ []string) {
client := rpcClient()
summary, err := client.Summary()
overview, err := client.Overview()
if err != nil {
log.Fatal("Failed to connect:", err)
}

if _, err := summary.BuildInfo.WriteTo(os.Stdout); err != nil {
if _, err := overview.BuildInfo.WriteTo(os.Stdout); err != nil {
log.Fatal("Failed to output build info:", err)
}
},
Expand Down
62 changes: 32 additions & 30 deletions pkg/visor/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (

// API represents visor API.
type API interface {
Overview() (*Overview, error)
Summary() (*Summary, error)
ExtraSummary() (*ExtraSummary, error)

Health() (*HealthInfo, error)
Uptime() (float64, error)
Expand Down Expand Up @@ -78,8 +78,8 @@ type HealthCheckable interface {
Health(ctx context.Context) (int, error)
}

// Summary provides a summary of a Skywire Visor.
type Summary struct {
// Overview provides a overview of a Skywire Visor.
ersonp marked this conversation as resolved.
Show resolved Hide resolved
type Overview struct {
PubKey cipher.PubKey `json:"local_pk"`
BuildInfo *buildinfo.Info `json:"build_info"`
AppProtoVersion string `json:"app_protocol_version"`
Expand All @@ -89,17 +89,17 @@ type Summary struct {
LocalIP string `json:"local_ip"`
}

// Summary implements API.
func (v *Visor) Summary() (*Summary, error) {
var summaries []*TransportSummary
// Overview implements API.
func (v *Visor) Overview() (*Overview, error) {
var tSummaries []*TransportSummary
if v == nil {
panic("v is nil")
}
if v.tpM == nil {
panic("tpM is nil")
}
v.tpM.WalkTransports(func(tp *transport.ManagedTransport) bool {
summaries = append(summaries,
tSummaries = append(tSummaries,
newTransportSummary(v.tpM, tp, true, v.router.SetupIsTrusted(tp.Remote())))
return true
})
Expand All @@ -114,38 +114,40 @@ func (v *Visor) Summary() (*Summary, error) {
return nil, fmt.Errorf("failed to get IPs of interface %s: %w", defaultNetworkIfc, err)
}

summary := &Summary{
overview := &Overview{
PubKey: v.conf.PK,
BuildInfo: buildinfo.Get(),
AppProtoVersion: supportedProtocolVersion,
Apps: v.appL.AppStates(),
Transports: summaries,
Transports: tSummaries,
RoutesCount: v.router.RoutesCount(),
}

if len(localIPs) > 0 {
// should be okay to have the first one, in the case of
// active network interface, there's usually just a single IP
summary.LocalIP = localIPs[0].String()
overview.LocalIP = localIPs[0].String()
}

return summary, nil
return overview, nil
}

// ExtraSummary provides an extra summary of a Skywire Visor.
type ExtraSummary struct {
Summary *Summary `json:"summary"`
Dmsg []dmsgtracker.DmsgClientSummary `json:"dmsg"`
Health *HealthInfo `json:"health"`
Uptime float64 `json:"uptime"`
Routes []routingRuleResp `json:"routes"`
// Summary provides an summary of a Skywire Visor.
type Summary struct {
*NetworkStats
Overview *Overview `json:"overview"`
Health *HealthInfo `json:"health"`
Uptime float64 `json:"uptime"`
Routes []routingRuleResp `json:"routes"`
IsHypervisor bool `json:"is_hypervisor,omitempty"`
DmsgStats *dmsgtracker.DmsgClientSummary `json:"dmsg_stats"`
}

// ExtraSummary implements API.
func (v *Visor) ExtraSummary() (*ExtraSummary, error) {
summary, err := v.Summary()
// Summary implements API.
func (v *Visor) Summary() (*Summary, error) {
overview, err := v.Overview()
if err != nil {
return nil, fmt.Errorf("summary")
return nil, fmt.Errorf("overview")
}

health, err := v.Health()
Expand All @@ -172,14 +174,14 @@ func (v *Visor) ExtraSummary() (*ExtraSummary, error) {
})
}

extraSummary := &ExtraSummary{
Summary: summary,
Health: health,
Uptime: uptime,
Routes: extraRoutes,
summary := &Summary{
Overview: overview,
Health: health,
Uptime: uptime,
Routes: extraRoutes,
}

return extraSummary, nil
return summary, nil
}

// collectHealthStats for given services and return health statuses
Expand Down Expand Up @@ -456,12 +458,12 @@ func (v *Visor) GetAppStats(appName string) (appserver.AppStats, error) {

// GetAppConnectionsSummary implements API.
func (v *Visor) GetAppConnectionsSummary(appName string) ([]appserver.ConnectionSummary, error) {
summary, err := v.procM.ConnectionsSummary(appName)
cSummary, err := v.procM.ConnectionsSummary(appName)
if err != nil {
return nil, err
}

return summary, nil
return cSummary, nil
}

// TransportTypes implements API.
Expand Down
Loading