web/storagenode: minimal allowed version view implemented (#3583)
This commit is contained in:
parent
2502c26154
commit
038ac58600
@ -35,9 +35,10 @@ type Service struct {
|
||||
|
||||
Loop *sync2.Cycle
|
||||
|
||||
checked sync2.Fence
|
||||
mu sync.Mutex
|
||||
allowed bool
|
||||
checked sync2.Fence
|
||||
mu sync.Mutex
|
||||
allowed bool
|
||||
acceptedVersion version.SemVer
|
||||
}
|
||||
|
||||
// NewService creates a Version Check Client with default configuration
|
||||
@ -85,44 +86,57 @@ func (srv *Service) Run(ctx context.Context) (err error) {
|
||||
}
|
||||
|
||||
// IsAllowed returns whether if the Service is allowed to operate or not
|
||||
func (srv *Service) IsAllowed(ctx context.Context) bool {
|
||||
func (srv *Service) IsAllowed(ctx context.Context) (version.SemVer, bool) {
|
||||
if !srv.checked.Wait(ctx) {
|
||||
return false
|
||||
return version.SemVer{}, false
|
||||
}
|
||||
srv.mu.Lock()
|
||||
defer srv.mu.Unlock()
|
||||
return srv.allowed
|
||||
return srv.acceptedVersion, srv.allowed
|
||||
}
|
||||
|
||||
// CheckVersion checks if the client is running latest/allowed code
|
||||
// checkVersion checks if the client is running latest/allowed code
|
||||
func (srv *Service) checkVersion(ctx context.Context) (allowed bool) {
|
||||
defer mon.Task()(&ctx)(nil)
|
||||
var err error
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
var minimum version.SemVer
|
||||
|
||||
defer func() {
|
||||
srv.mu.Lock()
|
||||
srv.allowed = allowed
|
||||
if err == nil {
|
||||
srv.acceptedVersion = minimum
|
||||
}
|
||||
srv.mu.Unlock()
|
||||
srv.checked.Release()
|
||||
}()
|
||||
|
||||
if !srv.info.Release {
|
||||
minimum = srv.info.Version
|
||||
return true
|
||||
}
|
||||
|
||||
minimum, err := srv.client.OldMinimum(ctx, srv.service)
|
||||
minimumOld, err := srv.client.OldMinimum(ctx, srv.service)
|
||||
if err != nil {
|
||||
// Log about the error, but dont crash the service and allow further operation
|
||||
srv.log.Sugar().Errorf("Failed to do periodic version check: %s", err.Error())
|
||||
return true
|
||||
}
|
||||
|
||||
minimum, err = version.NewSemVer(minimumOld.String())
|
||||
if err != nil {
|
||||
srv.log.Sugar().Errorf("failed to convert old sem version to sem version")
|
||||
return true
|
||||
}
|
||||
|
||||
srv.log.Sugar().Debugf("allowed minimum version from control server is: %s", minimum.String())
|
||||
|
||||
if minimum.String() == "" {
|
||||
srv.log.Sugar().Errorf("no version from control server, accepting to run")
|
||||
return true
|
||||
}
|
||||
if isAcceptedVersion(srv.info.Version, minimum) {
|
||||
if isAcceptedVersion(srv.info.Version, minimumOld) {
|
||||
srv.log.Sugar().Infof("running on version %s", srv.info.Version.String())
|
||||
return true
|
||||
}
|
||||
|
@ -120,8 +120,9 @@ type Dashboard struct {
|
||||
LastPingFromID storj.NodeID `json:"lastPingFromID"`
|
||||
LastPingFromAddress string `json:"lastPingFromAddress"`
|
||||
|
||||
Version version.SemVer `json:"version"`
|
||||
UpToDate bool `json:"upToDate"`
|
||||
Version version.SemVer `json:"version"`
|
||||
AllowedVersion version.SemVer `json:"allowedVersion"`
|
||||
UpToDate bool `json:"upToDate"`
|
||||
|
||||
StartedAt time.Time `json:"startedAt"`
|
||||
}
|
||||
@ -134,10 +135,10 @@ func (s *Service) GetDashboardData(ctx context.Context) (_ *Dashboard, err error
|
||||
data.NodeID = s.contact.Local().Id
|
||||
data.Wallet = s.walletAddress
|
||||
data.Version = s.versionInfo.Version
|
||||
data.UpToDate = s.version.IsAllowed(ctx)
|
||||
data.StartedAt = s.startedAt
|
||||
|
||||
data.LastPinged = s.pingStats.WhenLastPinged()
|
||||
data.AllowedVersion, data.UpToDate = s.version.IsAllowed(ctx)
|
||||
|
||||
stats, err := s.reputationDB.All(ctx)
|
||||
if err != nil {
|
||||
|
@ -31,11 +31,11 @@
|
||||
alt="offline status image"
|
||||
/>
|
||||
<p class="title__info__version-title"><b>Node Version</b></p>
|
||||
<p class="title__info__version-value">{{version}}</p>
|
||||
<p class="title__info__version-value">{{info.version}}</p>
|
||||
<VInfo
|
||||
v-if="info.isLastVersion"
|
||||
text="Running the minimal allowed version:"
|
||||
bold-text="v0.0.0"
|
||||
:bold-text="info.allowedVersion"
|
||||
is-custom-position="true"
|
||||
>
|
||||
<div class="version-svg-container">
|
||||
@ -81,16 +81,22 @@ class NodeInfo {
|
||||
public id: string;
|
||||
public status: string;
|
||||
public version: string;
|
||||
public allowedVersion: string;
|
||||
public wallet: string;
|
||||
public isLastVersion: boolean;
|
||||
|
||||
public constructor(id: string, status: string, version: string, wallet: string, isLastVersion: boolean) {
|
||||
public constructor(id: string, status: string, version: string, allowedVersion: string, wallet: string, isLastVersion: boolean) {
|
||||
this.id = id;
|
||||
this.status = status;
|
||||
this.version = version;
|
||||
this.version = this.toVersionString(version);
|
||||
this.allowedVersion = this.toVersionString(allowedVersion);
|
||||
this.wallet = wallet;
|
||||
this.isLastVersion = isLastVersion;
|
||||
}
|
||||
|
||||
private toVersionString(version: string): string {
|
||||
return `v${version}`;
|
||||
}
|
||||
}
|
||||
|
||||
@Component ({
|
||||
@ -109,13 +115,10 @@ export default class SNOContentTitle extends Vue {
|
||||
}
|
||||
|
||||
public get info(): NodeInfo {
|
||||
return this.$store.state.node.info;
|
||||
}
|
||||
const nodeInfo = this.$store.state.node.info;
|
||||
|
||||
public get version(): string {
|
||||
const version = this.$store.state.node.info.version;
|
||||
|
||||
return `v${version}`;
|
||||
return new NodeInfo(nodeInfo.id, nodeInfo.status, nodeInfo.version, nodeInfo.allowedVersion, nodeInfo.wallet,
|
||||
nodeInfo.isLastVersion);
|
||||
}
|
||||
|
||||
public get online(): boolean {
|
||||
|
@ -44,6 +44,7 @@ export const node = {
|
||||
lastPinged: new Date(),
|
||||
startedAt: new Date(),
|
||||
version: '',
|
||||
allowedVersion: '',
|
||||
wallet: '',
|
||||
isLastVersion: false
|
||||
},
|
||||
@ -80,6 +81,7 @@ export const node = {
|
||||
state.info.id = nodeInfo.nodeID;
|
||||
state.info.isLastVersion = nodeInfo.isUpToDate;
|
||||
state.info.version = nodeInfo.version;
|
||||
state.info.allowedVersion = nodeInfo.allowedVersion;
|
||||
state.info.wallet = nodeInfo.wallet;
|
||||
state.utilization.diskSpace.used = nodeInfo.diskSpace.used;
|
||||
state.utilization.diskSpace.remaining = nodeInfo.diskSpace.available - nodeInfo.diskSpace.used;
|
||||
|
@ -11,7 +11,7 @@ import {
|
||||
Metric,
|
||||
Satellite,
|
||||
Satellites,
|
||||
Stamp
|
||||
Stamp,
|
||||
} from '@/storagenode/satellite';
|
||||
|
||||
/**
|
||||
@ -53,7 +53,7 @@ export class SNOApi {
|
||||
const bandwidth: BandwidthInfo = new BandwidthInfo(json.bandwidth.used, json.bandwidth.available);
|
||||
|
||||
return new Dashboard(json.nodeID, json.wallet, satellites, diskSpace, bandwidth,
|
||||
new Date(json.lastPinged), new Date(json.startedAt), json.version, json.upToDate);
|
||||
new Date(json.lastPinged), new Date(json.startedAt), json.version, json.allowedVersion, json.upToDate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -14,6 +14,7 @@ export class Dashboard {
|
||||
public lastPinged: Date,
|
||||
public startedAt: Date,
|
||||
public version: string,
|
||||
public allowedVersion: string,
|
||||
public isUpToDate: boolean) {}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user