storj: remove storj/private/version
package which was moved to
`storj/private` repo Change-Id: I81c3f5b9d5e4fe7bca760999eb045ee9734e5e2e
This commit is contained in:
parent
bdec51658e
commit
fdf40a7526
@ -22,9 +22,9 @@ import (
|
|||||||
"storj.io/common/rpc"
|
"storj.io/common/rpc"
|
||||||
"storj.io/private/cfgstruct"
|
"storj.io/private/cfgstruct"
|
||||||
"storj.io/private/process"
|
"storj.io/private/process"
|
||||||
|
"storj.io/private/version"
|
||||||
"storj.io/storj/certificate/certificateclient"
|
"storj.io/storj/certificate/certificateclient"
|
||||||
"storj.io/storj/pkg/revocation"
|
"storj.io/storj/pkg/revocation"
|
||||||
"storj.io/storj/private/version"
|
|
||||||
"storj.io/storj/private/version/checker"
|
"storj.io/storj/private/version/checker"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -9,8 +9,8 @@ import (
|
|||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
|
||||||
"storj.io/private/process"
|
"storj.io/private/process"
|
||||||
|
"storj.io/private/version"
|
||||||
"storj.io/storj/pkg/revocation"
|
"storj.io/storj/pkg/revocation"
|
||||||
"storj.io/storj/private/version"
|
|
||||||
"storj.io/storj/satellite"
|
"storj.io/storj/satellite"
|
||||||
"storj.io/storj/satellite/metainfo"
|
"storj.io/storj/satellite/metainfo"
|
||||||
"storj.io/storj/satellite/satellitedb"
|
"storj.io/storj/satellite/satellitedb"
|
||||||
|
@ -10,8 +10,8 @@ import (
|
|||||||
|
|
||||||
"storj.io/common/context2"
|
"storj.io/common/context2"
|
||||||
"storj.io/private/process"
|
"storj.io/private/process"
|
||||||
|
"storj.io/private/version"
|
||||||
"storj.io/storj/pkg/revocation"
|
"storj.io/storj/pkg/revocation"
|
||||||
"storj.io/storj/private/version"
|
|
||||||
"storj.io/storj/satellite"
|
"storj.io/storj/satellite"
|
||||||
"storj.io/storj/satellite/accounting/live"
|
"storj.io/storj/satellite/accounting/live"
|
||||||
"storj.io/storj/satellite/metainfo"
|
"storj.io/storj/satellite/metainfo"
|
||||||
|
@ -9,8 +9,8 @@ import (
|
|||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
|
||||||
"storj.io/private/process"
|
"storj.io/private/process"
|
||||||
|
"storj.io/private/version"
|
||||||
"storj.io/storj/pkg/revocation"
|
"storj.io/storj/pkg/revocation"
|
||||||
"storj.io/storj/private/version"
|
|
||||||
"storj.io/storj/satellite"
|
"storj.io/storj/satellite"
|
||||||
"storj.io/storj/satellite/metainfo"
|
"storj.io/storj/satellite/metainfo"
|
||||||
"storj.io/storj/satellite/satellitedb"
|
"storj.io/storj/satellite/satellitedb"
|
||||||
|
@ -21,10 +21,10 @@ import (
|
|||||||
"storj.io/common/storj"
|
"storj.io/common/storj"
|
||||||
"storj.io/private/cfgstruct"
|
"storj.io/private/cfgstruct"
|
||||||
"storj.io/private/process"
|
"storj.io/private/process"
|
||||||
|
"storj.io/private/version"
|
||||||
"storj.io/storj/cmd/satellite/reports"
|
"storj.io/storj/cmd/satellite/reports"
|
||||||
"storj.io/storj/pkg/cache"
|
"storj.io/storj/pkg/cache"
|
||||||
"storj.io/storj/pkg/revocation"
|
"storj.io/storj/pkg/revocation"
|
||||||
"storj.io/storj/private/version"
|
|
||||||
"storj.io/storj/satellite"
|
"storj.io/storj/satellite"
|
||||||
"storj.io/storj/satellite/accounting/live"
|
"storj.io/storj/satellite/accounting/live"
|
||||||
"storj.io/storj/satellite/metainfo"
|
"storj.io/storj/satellite/metainfo"
|
||||||
|
@ -10,8 +10,8 @@ import (
|
|||||||
|
|
||||||
"storj.io/common/context2"
|
"storj.io/common/context2"
|
||||||
"storj.io/private/process"
|
"storj.io/private/process"
|
||||||
|
"storj.io/private/version"
|
||||||
"storj.io/storj/pkg/revocation"
|
"storj.io/storj/pkg/revocation"
|
||||||
"storj.io/storj/private/version"
|
|
||||||
"storj.io/storj/satellite"
|
"storj.io/storj/satellite"
|
||||||
"storj.io/storj/satellite/metainfo"
|
"storj.io/storj/satellite/metainfo"
|
||||||
"storj.io/storj/satellite/orders"
|
"storj.io/storj/satellite/orders"
|
||||||
|
@ -33,7 +33,7 @@ import (
|
|||||||
"storj.io/common/sync2"
|
"storj.io/common/sync2"
|
||||||
"storj.io/private/cfgstruct"
|
"storj.io/private/cfgstruct"
|
||||||
"storj.io/private/process"
|
"storj.io/private/process"
|
||||||
"storj.io/storj/private/version"
|
"storj.io/private/version"
|
||||||
"storj.io/storj/private/version/checker"
|
"storj.io/storj/private/version/checker"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ import (
|
|||||||
"storj.io/common/pb"
|
"storj.io/common/pb"
|
||||||
"storj.io/common/rpc"
|
"storj.io/common/rpc"
|
||||||
"storj.io/private/process"
|
"storj.io/private/process"
|
||||||
"storj.io/storj/private/version"
|
"storj.io/private/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
const contactWindow = time.Hour * 2
|
const contactWindow = time.Hour * 2
|
||||||
|
@ -20,8 +20,8 @@ import (
|
|||||||
"storj.io/common/storj"
|
"storj.io/common/storj"
|
||||||
"storj.io/private/cfgstruct"
|
"storj.io/private/cfgstruct"
|
||||||
"storj.io/private/process"
|
"storj.io/private/process"
|
||||||
|
"storj.io/private/version"
|
||||||
"storj.io/storj/pkg/revocation"
|
"storj.io/storj/pkg/revocation"
|
||||||
"storj.io/storj/private/version"
|
|
||||||
"storj.io/storj/storagenode"
|
"storj.io/storj/storagenode"
|
||||||
"storj.io/storj/storagenode/storagenodedb"
|
"storj.io/storj/storagenode/storagenodedb"
|
||||||
)
|
)
|
||||||
|
1
go.mod
1
go.mod
@ -5,7 +5,6 @@ go 1.13
|
|||||||
require (
|
require (
|
||||||
github.com/alessio/shellescape v0.0.0-20190409004728-b115ca0f9053
|
github.com/alessio/shellescape v0.0.0-20190409004728-b115ca0f9053
|
||||||
github.com/alicebob/miniredis/v2 v2.11.1
|
github.com/alicebob/miniredis/v2 v2.11.1
|
||||||
github.com/blang/semver v3.5.1+incompatible
|
|
||||||
github.com/btcsuite/btcutil v1.0.1
|
github.com/btcsuite/btcutil v1.0.1
|
||||||
github.com/cheggaaa/pb/v3 v3.0.1
|
github.com/cheggaaa/pb/v3 v3.0.1
|
||||||
github.com/fatih/color v1.7.0
|
github.com/fatih/color v1.7.0
|
||||||
|
@ -23,9 +23,9 @@ import (
|
|||||||
"storj.io/common/rpc"
|
"storj.io/common/rpc"
|
||||||
"storj.io/common/storj"
|
"storj.io/common/storj"
|
||||||
"storj.io/private/debug"
|
"storj.io/private/debug"
|
||||||
|
"storj.io/private/version"
|
||||||
"storj.io/storj/pkg/revocation"
|
"storj.io/storj/pkg/revocation"
|
||||||
"storj.io/storj/pkg/server"
|
"storj.io/storj/pkg/server"
|
||||||
"storj.io/storj/private/version"
|
|
||||||
versionchecker "storj.io/storj/private/version/checker"
|
versionchecker "storj.io/storj/private/version/checker"
|
||||||
"storj.io/storj/satellite"
|
"storj.io/storj/satellite"
|
||||||
"storj.io/storj/satellite/accounting"
|
"storj.io/storj/satellite/accounting"
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"storj.io/storj/private/version"
|
"storj.io/private/version"
|
||||||
"storj.io/storj/private/version/checker"
|
"storj.io/storj/private/version/checker"
|
||||||
"storj.io/storj/versioncontrol"
|
"storj.io/storj/versioncontrol"
|
||||||
)
|
)
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
"github.com/spacemonkeygo/monkit/v3"
|
"github.com/spacemonkeygo/monkit/v3"
|
||||||
"github.com/zeebo/errs"
|
"github.com/zeebo/errs"
|
||||||
|
|
||||||
"storj.io/storj/private/version"
|
"storj.io/private/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
"go.uber.org/zap/zaptest"
|
"go.uber.org/zap/zaptest"
|
||||||
|
|
||||||
"storj.io/common/testcontext"
|
"storj.io/common/testcontext"
|
||||||
"storj.io/storj/private/version"
|
"storj.io/private/version"
|
||||||
"storj.io/storj/private/version/checker"
|
"storj.io/storj/private/version/checker"
|
||||||
"storj.io/storj/versioncontrol"
|
"storj.io/storj/versioncontrol"
|
||||||
)
|
)
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
|
||||||
"storj.io/common/sync2"
|
"storj.io/common/sync2"
|
||||||
"storj.io/storj/private/version"
|
"storj.io/private/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config contains the necessary Information to check the Software Version
|
// Config contains the necessary Information to check the Software Version
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
// Copyright (C) 2019 Storj Labs, Inc.
|
|
||||||
// See LICENSE for copying information.
|
|
||||||
|
|
||||||
package version
|
|
||||||
|
|
||||||
import (
|
|
||||||
"hash/crc32"
|
|
||||||
"sync/atomic"
|
|
||||||
|
|
||||||
"github.com/spacemonkeygo/monkit/v3"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Stats implements the monkit.StatSource interface
|
|
||||||
func (info *Info) Stats(cb func(key monkit.SeriesKey, field string, val float64)) {
|
|
||||||
key := monkit.NewSeriesKey("version_info")
|
|
||||||
|
|
||||||
if info.Release {
|
|
||||||
cb(key, "release", 1)
|
|
||||||
} else {
|
|
||||||
cb(key, "release", 0)
|
|
||||||
}
|
|
||||||
if !info.Timestamp.IsZero() {
|
|
||||||
cb(key, "timestamp", float64(info.Timestamp.Unix()))
|
|
||||||
}
|
|
||||||
crc := atomic.LoadUint32(&info.commitHashCRC)
|
|
||||||
if crc == 0 {
|
|
||||||
c := crc32.NewIEEE()
|
|
||||||
_, err := c.Write([]byte(buildCommitHash))
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
atomic.StoreUint32(&info.commitHashCRC, c.Sum32())
|
|
||||||
}
|
|
||||||
cb(key, "commit", float64(crc))
|
|
||||||
cb(key, "major", float64(info.Version.Major))
|
|
||||||
cb(key, "minor", float64(info.Version.Minor))
|
|
||||||
cb(key, "patch", float64(info.Version.Patch))
|
|
||||||
}
|
|
@ -1,270 +0,0 @@
|
|||||||
// Copyright (C) 2019 Storj Labs, Inc.
|
|
||||||
// See LICENSE for copying information.
|
|
||||||
|
|
||||||
package version
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"crypto/hmac"
|
|
||||||
"crypto/sha256"
|
|
||||||
"encoding/hex"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"math/big"
|
|
||||||
"reflect"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/blang/semver"
|
|
||||||
"github.com/zeebo/errs"
|
|
||||||
|
|
||||||
"storj.io/common/pb"
|
|
||||||
"storj.io/common/storj"
|
|
||||||
)
|
|
||||||
|
|
||||||
const quote = byte('"')
|
|
||||||
|
|
||||||
var (
|
|
||||||
// VerError is the error class for version-related errors.
|
|
||||||
VerError = errs.Class("version error")
|
|
||||||
|
|
||||||
// the following fields are set by linker flags. if any of them
|
|
||||||
// are set and fail to parse, the program will fail to start
|
|
||||||
buildTimestamp string // unix seconds since epoch
|
|
||||||
buildCommitHash string
|
|
||||||
buildVersion string // semantic version format
|
|
||||||
buildRelease string // true/false
|
|
||||||
|
|
||||||
// Build is a struct containing all relevant build information associated with the binary
|
|
||||||
Build Info
|
|
||||||
)
|
|
||||||
|
|
||||||
// Info is the versioning information for a binary
|
|
||||||
type Info struct {
|
|
||||||
// sync/atomic cache
|
|
||||||
commitHashCRC uint32
|
|
||||||
|
|
||||||
Timestamp time.Time `json:"timestamp,omitempty"`
|
|
||||||
CommitHash string `json:"commitHash,omitempty"`
|
|
||||||
Version SemVer `json:"version"`
|
|
||||||
Release bool `json:"release,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// SemVer represents a semantic version.
|
|
||||||
// TODO: replace with semver.Version
|
|
||||||
type SemVer struct {
|
|
||||||
semver.Version
|
|
||||||
}
|
|
||||||
|
|
||||||
// OldSemVer represents a semantic version.
|
|
||||||
// NB: this will be deprecated in favor of `SemVer`; these structs marshal to JSON differently.
|
|
||||||
type OldSemVer struct {
|
|
||||||
Major int64 `json:"major"`
|
|
||||||
Minor int64 `json:"minor"`
|
|
||||||
Patch int64 `json:"patch"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// AllowedVersions provides the Minimum SemVer per Service.
|
|
||||||
// TODO: I don't think this name is representative of what this struct now holds.
|
|
||||||
type AllowedVersions struct {
|
|
||||||
Satellite OldSemVer
|
|
||||||
Storagenode OldSemVer
|
|
||||||
Uplink OldSemVer
|
|
||||||
Gateway OldSemVer
|
|
||||||
Identity OldSemVer
|
|
||||||
|
|
||||||
Processes Processes `json:"processes"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Processes describes versions for each binary.
|
|
||||||
// TODO: this name is inconsistent with the versioncontrol server pkg's analogue, `Versions`.
|
|
||||||
type Processes struct {
|
|
||||||
Satellite Process `json:"satellite"`
|
|
||||||
Storagenode Process `json:"storagenode"`
|
|
||||||
StoragenodeUpdater Process `json:"storagenode-updater"`
|
|
||||||
Uplink Process `json:"uplink"`
|
|
||||||
Gateway Process `json:"gateway"`
|
|
||||||
Identity Process `json:"identity"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process versions for specific binary.
|
|
||||||
type Process struct {
|
|
||||||
Minimum Version `json:"minimum"`
|
|
||||||
Suggested Version `json:"suggested"`
|
|
||||||
Rollout Rollout `json:"rollout"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Version represents version and download URL for binary.
|
|
||||||
type Version struct {
|
|
||||||
Version string `json:"version"`
|
|
||||||
URL string `json:"url"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rollout represents the state of a version rollout.
|
|
||||||
type Rollout struct {
|
|
||||||
Seed RolloutBytes `json:"seed"`
|
|
||||||
Cursor RolloutBytes `json:"cursor"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// RolloutBytes implements json un/marshalling using hex de/encoding.
|
|
||||||
type RolloutBytes [32]byte
|
|
||||||
|
|
||||||
// MarshalJSON hex-encodes RolloutBytes and pre/appends JSON string literal quotes.
|
|
||||||
func (rb RolloutBytes) MarshalJSON() ([]byte, error) {
|
|
||||||
zeroRolloutBytes := RolloutBytes{}
|
|
||||||
if bytes.Equal(rb[:], zeroRolloutBytes[:]) {
|
|
||||||
return []byte{quote, quote}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
hexBytes := make([]byte, hex.EncodedLen(len(rb)))
|
|
||||||
hex.Encode(hexBytes, rb[:])
|
|
||||||
encoded := append([]byte{quote}, hexBytes...)
|
|
||||||
encoded = append(encoded, quote)
|
|
||||||
return encoded, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON drops the JSON string literal quotes and hex-decodes RolloutBytes .
|
|
||||||
func (rb *RolloutBytes) UnmarshalJSON(b []byte) error {
|
|
||||||
if _, err := hex.Decode(rb[:], b[1:len(b)-1]); err != nil {
|
|
||||||
return VerError.Wrap(err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewSemVer parses a given version and returns an instance of SemVer or
|
|
||||||
// an error if unable to parse the version.
|
|
||||||
func NewSemVer(v string) (SemVer, error) {
|
|
||||||
ver, err := semver.ParseTolerant(v)
|
|
||||||
if err != nil {
|
|
||||||
return SemVer{}, VerError.Wrap(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return SemVer{
|
|
||||||
Version: ver,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewOldSemVer parses a given version and returns an instance of OldSemVer or
|
|
||||||
// an error if unable to parse the version.
|
|
||||||
func NewOldSemVer(v string) (OldSemVer, error) {
|
|
||||||
ver, err := NewSemVer(v)
|
|
||||||
if err != nil {
|
|
||||||
return OldSemVer{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return OldSemVer{
|
|
||||||
Major: int64(ver.Major),
|
|
||||||
Minor: int64(ver.Minor),
|
|
||||||
Patch: int64(ver.Patch),
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compare compare two versions, return -1 if compared version is greater, 0 if equal and 1 if less.
|
|
||||||
func (sem *SemVer) Compare(version SemVer) int {
|
|
||||||
return sem.Version.Compare(version.Version)
|
|
||||||
}
|
|
||||||
|
|
||||||
// String converts the SemVer struct to a more easy to handle string
|
|
||||||
func (sem *SemVer) String() (version string) {
|
|
||||||
return fmt.Sprintf("v%d.%d.%d", sem.Major, sem.Minor, sem.Patch)
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsZero checks if the semantic version is its zero value.
|
|
||||||
func (sem SemVer) IsZero() bool {
|
|
||||||
return reflect.ValueOf(sem).IsZero()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (old OldSemVer) String() string {
|
|
||||||
return fmt.Sprintf("v%d.%d.%d", old.Major, old.Minor, old.Patch)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SemVer converts a version struct into a semantic version struct.
|
|
||||||
func (ver *Version) SemVer() (SemVer, error) {
|
|
||||||
return NewSemVer(ver.Version)
|
|
||||||
}
|
|
||||||
|
|
||||||
// New creates Version_Info from a json byte array
|
|
||||||
func New(data []byte) (v Info, err error) {
|
|
||||||
err = json.Unmarshal(data, &v)
|
|
||||||
return v, VerError.Wrap(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsZero checks if the version struct is its zero value.
|
|
||||||
func (info Info) IsZero() bool {
|
|
||||||
return reflect.ValueOf(info).IsZero()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Marshal converts the existing Version Info to any json byte array
|
|
||||||
func (info Info) Marshal() ([]byte, error) {
|
|
||||||
data, err := json.Marshal(info)
|
|
||||||
if err != nil {
|
|
||||||
return nil, VerError.Wrap(err)
|
|
||||||
}
|
|
||||||
return data, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Proto converts an Info struct to a pb.NodeVersion
|
|
||||||
// TODO: shouldn't we just use pb.NodeVersion everywhere? gogoproto will let
|
|
||||||
// us make it match Info.
|
|
||||||
func (info Info) Proto() (*pb.NodeVersion, error) {
|
|
||||||
return &pb.NodeVersion{
|
|
||||||
Version: info.Version.String(),
|
|
||||||
CommitHash: info.CommitHash,
|
|
||||||
Timestamp: info.Timestamp,
|
|
||||||
Release: info.Release,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// PercentageToCursor calculates the cursor value for the given percentage of nodes which should update.
|
|
||||||
func PercentageToCursor(pct int) RolloutBytes {
|
|
||||||
// NB: convert the max value to a number, multiply by the percentage, convert back.
|
|
||||||
var maxInt, maskInt big.Int
|
|
||||||
var maxBytes RolloutBytes
|
|
||||||
for i := 0; i < len(maxBytes); i++ {
|
|
||||||
maxBytes[i] = 255
|
|
||||||
}
|
|
||||||
maxInt.SetBytes(maxBytes[:])
|
|
||||||
maskInt.Div(maskInt.Mul(&maxInt, big.NewInt(int64(pct))), big.NewInt(100))
|
|
||||||
|
|
||||||
var cursor RolloutBytes
|
|
||||||
copy(cursor[:], maskInt.Bytes())
|
|
||||||
|
|
||||||
return cursor
|
|
||||||
}
|
|
||||||
|
|
||||||
// ShouldUpdate checks if for the the given rollout state, a user with the given nodeID should update.
|
|
||||||
func ShouldUpdate(rollout Rollout, nodeID storj.NodeID) bool {
|
|
||||||
hash := hmac.New(sha256.New, rollout.Seed[:])
|
|
||||||
_, err := hash.Write(nodeID[:])
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return bytes.Compare(hash.Sum(nil), rollout.Cursor[:]) <= 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
if buildVersion == "" && buildTimestamp == "" && buildCommitHash == "" && buildRelease == "" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
timestamp, err := strconv.ParseInt(buildTimestamp, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
panic(VerError.Wrap(err))
|
|
||||||
}
|
|
||||||
Build = Info{
|
|
||||||
Timestamp: time.Unix(timestamp, 0),
|
|
||||||
CommitHash: buildCommitHash,
|
|
||||||
Release: strings.ToLower(buildRelease) == "true",
|
|
||||||
}
|
|
||||||
|
|
||||||
sv, err := NewSemVer(buildVersion)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
Build.Version = sv
|
|
||||||
|
|
||||||
if Build.Timestamp.Unix() == 0 || Build.CommitHash == "" {
|
|
||||||
Build.Release = false
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,143 +0,0 @@
|
|||||||
// Copyright (C) 2019 Storj Labs, Inc.
|
|
||||||
// See LICENSE for copying information.
|
|
||||||
|
|
||||||
package version_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"math"
|
|
||||||
"math/rand"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
|
|
||||||
"storj.io/common/storj"
|
|
||||||
"storj.io/storj/private/version"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestInfo_IsZero(t *testing.T) {
|
|
||||||
zeroInfo := version.Info{}
|
|
||||||
require.True(t, zeroInfo.IsZero())
|
|
||||||
|
|
||||||
ver, err := version.NewSemVer("1.2.3")
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
info := version.Info{
|
|
||||||
Version: ver,
|
|
||||||
}
|
|
||||||
require.False(t, info.IsZero())
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSemVer_IsZero(t *testing.T) {
|
|
||||||
zeroVer := version.SemVer{}
|
|
||||||
require.True(t, zeroVer.IsZero())
|
|
||||||
|
|
||||||
ver, err := version.NewSemVer("1.2.3")
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.False(t, ver.IsZero())
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSemVer_Compare(t *testing.T) {
|
|
||||||
version001, err := version.NewSemVer("v0.0.1")
|
|
||||||
require.NoError(t, err)
|
|
||||||
version002, err := version.NewSemVer("v0.0.2")
|
|
||||||
require.NoError(t, err)
|
|
||||||
version030, err := version.NewSemVer("v0.3.0")
|
|
||||||
require.NoError(t, err)
|
|
||||||
version040, err := version.NewSemVer("v0.4.0")
|
|
||||||
require.NoError(t, err)
|
|
||||||
version500, err := version.NewSemVer("v5.0.0")
|
|
||||||
require.NoError(t, err)
|
|
||||||
version600, err := version.NewSemVer("v6.0.0")
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// compare the same values
|
|
||||||
require.True(t, version001.Compare(version001) == 0)
|
|
||||||
require.True(t, version030.Compare(version030) == 0)
|
|
||||||
require.True(t, version500.Compare(version500) == 0)
|
|
||||||
|
|
||||||
require.True(t, version001.Compare(version002) < 0)
|
|
||||||
require.True(t, version030.Compare(version040) < 0)
|
|
||||||
require.True(t, version500.Compare(version600) < 0)
|
|
||||||
require.True(t, version001.Compare(version030) < 0)
|
|
||||||
require.True(t, version030.Compare(version500) < 0)
|
|
||||||
|
|
||||||
require.True(t, version002.Compare(version001) > 0)
|
|
||||||
require.True(t, version040.Compare(version030) > 0)
|
|
||||||
require.True(t, version600.Compare(version500) > 0)
|
|
||||||
require.True(t, version030.Compare(version002) > 0)
|
|
||||||
require.True(t, version600.Compare(version040) > 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRollout_MarshalJSON_UnmarshalJSON(t *testing.T) {
|
|
||||||
var arbitraryRollout version.Rollout
|
|
||||||
for i := 0; i < len(version.RolloutBytes{}); i++ {
|
|
||||||
arbitraryRollout.Seed[i] = byte(i)
|
|
||||||
arbitraryRollout.Cursor[i] = byte(i * 2)
|
|
||||||
}
|
|
||||||
|
|
||||||
scenarios := []struct {
|
|
||||||
name string
|
|
||||||
rollout version.Rollout
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
"arbitrary rollout",
|
|
||||||
arbitraryRollout,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"empty rollout",
|
|
||||||
version.Rollout{},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, scenario := range scenarios {
|
|
||||||
scenario := scenario
|
|
||||||
t.Run(scenario.name, func(t *testing.T) {
|
|
||||||
var actualRollout version.Rollout
|
|
||||||
|
|
||||||
_, err := json.Marshal(actualRollout.Seed)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
jsonRollout, err := json.Marshal(scenario.rollout)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
err = json.Unmarshal(jsonRollout, &actualRollout)
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, scenario.rollout, actualRollout)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestShouldUpdate(t *testing.T) {
|
|
||||||
// NB: total and acceptable tolerance are negatively correlated.
|
|
||||||
total := 10000
|
|
||||||
tolerance := total * 2 / 100 // 2%
|
|
||||||
|
|
||||||
for p := 10; p < 100; p += 10 {
|
|
||||||
var rollouts int
|
|
||||||
percentage := p
|
|
||||||
cursor := version.PercentageToCursor(percentage)
|
|
||||||
|
|
||||||
rollout := version.Rollout{
|
|
||||||
Seed: version.RolloutBytes{},
|
|
||||||
Cursor: cursor,
|
|
||||||
}
|
|
||||||
rand.Read(rollout.Seed[:])
|
|
||||||
|
|
||||||
for i := 0; i < total; i++ {
|
|
||||||
var nodeID storj.NodeID
|
|
||||||
_, err := rand.Read(nodeID[:])
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
if version.ShouldUpdate(rollout, nodeID) {
|
|
||||||
rollouts++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.Condition(t, func() bool {
|
|
||||||
diff := rollouts - (total * percentage / 100)
|
|
||||||
return int(math.Abs(float64(diff))) < tolerance
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
@ -17,8 +17,8 @@ import (
|
|||||||
"storj.io/common/peertls/extensions"
|
"storj.io/common/peertls/extensions"
|
||||||
"storj.io/common/storj"
|
"storj.io/common/storj"
|
||||||
"storj.io/private/debug"
|
"storj.io/private/debug"
|
||||||
|
"storj.io/private/version"
|
||||||
"storj.io/storj/private/lifecycle"
|
"storj.io/storj/private/lifecycle"
|
||||||
"storj.io/storj/private/version"
|
|
||||||
"storj.io/storj/private/version/checker"
|
"storj.io/storj/private/version/checker"
|
||||||
"storj.io/storj/satellite/admin"
|
"storj.io/storj/satellite/admin"
|
||||||
"storj.io/storj/satellite/metainfo"
|
"storj.io/storj/satellite/metainfo"
|
||||||
|
@ -24,12 +24,12 @@ import (
|
|||||||
"storj.io/common/signing"
|
"storj.io/common/signing"
|
||||||
"storj.io/common/storj"
|
"storj.io/common/storj"
|
||||||
"storj.io/private/debug"
|
"storj.io/private/debug"
|
||||||
|
"storj.io/private/version"
|
||||||
"storj.io/storj/pkg/auth/grpcauth"
|
"storj.io/storj/pkg/auth/grpcauth"
|
||||||
"storj.io/storj/pkg/server"
|
"storj.io/storj/pkg/server"
|
||||||
"storj.io/storj/private/lifecycle"
|
"storj.io/storj/private/lifecycle"
|
||||||
"storj.io/storj/private/post"
|
"storj.io/storj/private/post"
|
||||||
"storj.io/storj/private/post/oauth2"
|
"storj.io/storj/private/post/oauth2"
|
||||||
"storj.io/storj/private/version"
|
|
||||||
"storj.io/storj/private/version/checker"
|
"storj.io/storj/private/version/checker"
|
||||||
"storj.io/storj/satellite/accounting"
|
"storj.io/storj/satellite/accounting"
|
||||||
"storj.io/storj/satellite/console"
|
"storj.io/storj/satellite/console"
|
||||||
|
@ -21,8 +21,8 @@ import (
|
|||||||
"storj.io/common/signing"
|
"storj.io/common/signing"
|
||||||
"storj.io/common/storj"
|
"storj.io/common/storj"
|
||||||
"storj.io/private/debug"
|
"storj.io/private/debug"
|
||||||
|
"storj.io/private/version"
|
||||||
"storj.io/storj/private/lifecycle"
|
"storj.io/storj/private/lifecycle"
|
||||||
"storj.io/storj/private/version"
|
|
||||||
version_checker "storj.io/storj/private/version/checker"
|
version_checker "storj.io/storj/private/version/checker"
|
||||||
"storj.io/storj/satellite/accounting"
|
"storj.io/storj/satellite/accounting"
|
||||||
"storj.io/storj/satellite/accounting/reportedrollup"
|
"storj.io/storj/satellite/accounting/reportedrollup"
|
||||||
|
@ -19,8 +19,8 @@ import (
|
|||||||
"storj.io/common/rpc"
|
"storj.io/common/rpc"
|
||||||
"storj.io/common/storj"
|
"storj.io/common/storj"
|
||||||
"storj.io/private/debug"
|
"storj.io/private/debug"
|
||||||
|
"storj.io/private/version"
|
||||||
"storj.io/storj/private/lifecycle"
|
"storj.io/storj/private/lifecycle"
|
||||||
"storj.io/storj/private/version"
|
|
||||||
version_checker "storj.io/storj/private/version/checker"
|
version_checker "storj.io/storj/private/version/checker"
|
||||||
"storj.io/storj/satellite/gc"
|
"storj.io/storj/satellite/gc"
|
||||||
"storj.io/storj/satellite/metainfo"
|
"storj.io/storj/satellite/metainfo"
|
||||||
|
@ -21,8 +21,8 @@ import (
|
|||||||
"storj.io/common/signing"
|
"storj.io/common/signing"
|
||||||
"storj.io/common/storj"
|
"storj.io/common/storj"
|
||||||
"storj.io/private/debug"
|
"storj.io/private/debug"
|
||||||
|
"storj.io/private/version"
|
||||||
"storj.io/storj/private/lifecycle"
|
"storj.io/storj/private/lifecycle"
|
||||||
"storj.io/storj/private/version"
|
|
||||||
version_checker "storj.io/storj/private/version/checker"
|
version_checker "storj.io/storj/private/version/checker"
|
||||||
"storj.io/storj/satellite/metainfo"
|
"storj.io/storj/satellite/metainfo"
|
||||||
"storj.io/storj/satellite/orders"
|
"storj.io/storj/satellite/orders"
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
|
|
||||||
"storj.io/common/pb"
|
"storj.io/common/pb"
|
||||||
"storj.io/common/storj"
|
"storj.io/common/storj"
|
||||||
"storj.io/storj/private/version"
|
"storj.io/private/version"
|
||||||
"storj.io/storj/satellite/overlay"
|
"storj.io/storj/satellite/overlay"
|
||||||
"storj.io/storj/satellite/satellitedb/dbx"
|
"storj.io/storj/satellite/satellitedb/dbx"
|
||||||
)
|
)
|
||||||
|
@ -28,7 +28,7 @@ fi
|
|||||||
|
|
||||||
echo Running "go $@"
|
echo Running "go $@"
|
||||||
exec go "$1" -ldflags \
|
exec go "$1" -ldflags \
|
||||||
"-s -w -X storj.io/storj/private/version.buildTimestamp=$TIMESTAMP
|
"-s -w -X storj.io/private/version.buildTimestamp=$TIMESTAMP
|
||||||
-X storj.io/storj/private/version.buildCommitHash=$COMMIT
|
-X storj.io/private/version.buildCommitHash=$COMMIT
|
||||||
-X storj.io/storj/private/version.buildVersion=$VERSION
|
-X storj.io/private/version.buildVersion=$VERSION
|
||||||
-X storj.io/storj/private/version.buildRelease=$RELEASE" "${@:2}"
|
-X storj.io/private/version.buildRelease=$RELEASE" "${@:2}"
|
||||||
|
@ -13,8 +13,8 @@ import (
|
|||||||
|
|
||||||
"storj.io/common/memory"
|
"storj.io/common/memory"
|
||||||
"storj.io/common/storj"
|
"storj.io/common/storj"
|
||||||
|
"storj.io/private/version"
|
||||||
"storj.io/storj/private/date"
|
"storj.io/storj/private/date"
|
||||||
"storj.io/storj/private/version"
|
|
||||||
"storj.io/storj/private/version/checker"
|
"storj.io/storj/private/version/checker"
|
||||||
"storj.io/storj/storagenode/bandwidth"
|
"storj.io/storj/storagenode/bandwidth"
|
||||||
"storj.io/storj/storagenode/contact"
|
"storj.io/storj/storagenode/contact"
|
||||||
|
@ -24,9 +24,9 @@ import (
|
|||||||
"storj.io/common/signing"
|
"storj.io/common/signing"
|
||||||
"storj.io/common/storj"
|
"storj.io/common/storj"
|
||||||
"storj.io/private/debug"
|
"storj.io/private/debug"
|
||||||
|
"storj.io/private/version"
|
||||||
"storj.io/storj/pkg/server"
|
"storj.io/storj/pkg/server"
|
||||||
"storj.io/storj/private/lifecycle"
|
"storj.io/storj/private/lifecycle"
|
||||||
"storj.io/storj/private/version"
|
|
||||||
"storj.io/storj/private/version/checker"
|
"storj.io/storj/private/version/checker"
|
||||||
"storj.io/storj/satellite/overlay"
|
"storj.io/storj/satellite/overlay"
|
||||||
"storj.io/storj/storage"
|
"storj.io/storj/storage"
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
|
|
||||||
"storj.io/common/errs2"
|
"storj.io/common/errs2"
|
||||||
"storj.io/storj/private/version"
|
"storj.io/private/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
// seedLength is the number of bytes in a rollout seed.
|
// seedLength is the number of bytes in a rollout seed.
|
||||||
|
Loading…
Reference in New Issue
Block a user