Update node.proto to use time.Time instead of timestamp (#2482)

This commit is contained in:
Alexander Leitner 2019-07-08 14:24:42 -04:00 committed by GitHub
parent a554752ce0
commit 19ab9852f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 68 additions and 72 deletions

View File

@ -11,7 +11,6 @@ import (
"strings"
"time"
"github.com/golang/protobuf/ptypes"
"github.com/zeebo/errs"
"gopkg.in/spacemonkeygo/monkit.v2"
@ -115,14 +114,10 @@ func (v Info) Marshal() (data []byte, err error) {
// TODO: shouldn't we just use pb.NodeVersion everywhere? gogoproto will let
// us make it match Info.
func (v Info) Proto() (*pb.NodeVersion, error) {
pbts, err := ptypes.TimestampProto(v.Timestamp)
if err != nil {
return nil, err
}
return &pb.NodeVersion{
Version: v.Version.String(),
CommitHash: v.CommitHash,
Timestamp: pbts,
Timestamp: v.Timestamp,
Release: v.Release,
}, nil
}

View File

@ -8,7 +8,6 @@ import (
"testing"
"time"
"github.com/golang/protobuf/ptypes"
"github.com/stretchr/testify/require"
"storj.io/storj/internal/testrand"
@ -84,7 +83,7 @@ func BenchmarkOverlay(b *testing.B) {
})
b.Run("UpdateNodeInfo", func(b *testing.B) {
now := ptypes.TimestampNow()
now := time.Now()
for i := 0; i < b.N; i++ {
id := all[i%len(all)]
_, err := overlaydb.UpdateNodeInfo(ctx, id, &pb.InfoResponse{

View File

@ -7,14 +7,16 @@ import (
fmt "fmt"
_ "github.com/gogo/protobuf/gogoproto"
proto "github.com/gogo/protobuf/proto"
timestamp "github.com/golang/protobuf/ptypes/timestamp"
_ "github.com/golang/protobuf/ptypes/timestamp"
math "math"
time "time"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
var _ = time.Kitchen
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
@ -367,13 +369,13 @@ func (m *NodeRestrictions) GetFreeDisk() int64 {
// NodeVersion contains
type NodeVersion struct {
Version string `protobuf:"bytes,1,opt,name=version,proto3" json:"version,omitempty"`
CommitHash string `protobuf:"bytes,2,opt,name=commit_hash,json=commitHash,proto3" json:"commit_hash,omitempty"`
Timestamp *timestamp.Timestamp `protobuf:"bytes,3,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
Release bool `protobuf:"varint,4,opt,name=release,proto3" json:"release,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
Version string `protobuf:"bytes,1,opt,name=version,proto3" json:"version,omitempty"`
CommitHash string `protobuf:"bytes,2,opt,name=commit_hash,json=commitHash,proto3" json:"commit_hash,omitempty"`
Timestamp time.Time `protobuf:"bytes,3,opt,name=timestamp,proto3,stdtime" json:"timestamp"`
Release bool `protobuf:"varint,4,opt,name=release,proto3" json:"release,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *NodeVersion) Reset() { *m = NodeVersion{} }
@ -414,11 +416,11 @@ func (m *NodeVersion) GetCommitHash() string {
return ""
}
func (m *NodeVersion) GetTimestamp() *timestamp.Timestamp {
func (m *NodeVersion) GetTimestamp() time.Time {
if m != nil {
return m.Timestamp
}
return nil
return time.Time{}
}
func (m *NodeVersion) GetRelease() bool {
@ -443,42 +445,42 @@ func init() {
func init() { proto.RegisterFile("node.proto", fileDescriptor_0c843d59d2d938e7) }
var fileDescriptor_0c843d59d2d938e7 = []byte{
// 577 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x53, 0xcb, 0x6e, 0x13, 0x31,
0x14, 0xed, 0x24, 0xd3, 0x24, 0x73, 0xf3, 0xd0, 0x60, 0x2a, 0x88, 0x8a, 0x44, 0x42, 0x24, 0xa4,
0xa8, 0x48, 0xa9, 0x28, 0x1b, 0x16, 0x6c, 0x92, 0xb6, 0x2a, 0x81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 0x6c, 0xa2, 0xf9, 0x78, 0x72,
0x5f, 0x05, 0x44, 0x1d, 0xa8, 0xaf, 0xc4, 0x76, 0xcb, 0x4d, 0xb8, 0x21, 0x7a, 0x93, 0xdb, 0x83,
0x8c, 0xfa, 0x4c, 0xf4, 0x06, 0x7d, 0x04, 0xef, 0x7e, 0xc5, 0xdb, 0xe5, 0x74, 0x51, 0x0f, 0x07,
0xd9, 0x23, 0x18, 0x14, 0x8f, 0x60, 0x10, 0x14, 0x0a, 0xfc, 0x20, 0xb6, 0x97, 0x2a, 0x16, 0x31,
0xa2, 0x59, 0xdb, 0xed, 0x3a, 0xfd, 0x1a, 0x2e, 0xe0, 0xd1, 0x14, 0x6a, 0xe9, 0xf0, 0x77, 0x92,
0xa1, 0x3a, 0x54, 0xc7, 0xd3, 0xcb, 0xe1, 0x64, 0x7c, 0xe6, 0xef, 0xa1, 0x26, 0x78, 0x8b, 0x61,
0x70, 0x3e, 0x99, 0x8c, 0x83, 0x73, 0xdf, 0xb1, 0xb5, 0x45, 0x30, 0xc3, 0xc3, 0x8b, 0x73, 0xbf,
0x84, 0x00, 0x2a, 0xdf, 0xe7, 0x93, 0xf1, 0xf4, 0xab, 0x5f, 0xb6, 0xba, 0xd1, 0x6c, 0x16, 0x2c,
0x02, 0x3c, 0x9c, 0xfb, 0xee, 0xd1, 0x1b, 0x68, 0x3e, 0x59, 0x26, 0xe4, 0x43, 0x23, 0x38, 0x9d,
0x87, 0xc1, 0x64, 0x11, 0x5e, 0xe0, 0xf9, 0xa9, 0xbf, 0x37, 0x72, 0xaf, 0x4a, 0x72, 0xb9, 0xac,
0xa4, 0x8e, 0x3f, 0xfc, 0x0d, 0x00, 0x00, 0xff, 0xff, 0xf3, 0xa6, 0x6e, 0x66, 0xe4, 0x03, 0x00,
0x00,
// 587 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x53, 0xcd, 0x6e, 0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 0x5e, 0x95, 0xe4, 0x72, 0x59, 0x49, 0xbd, 0xbf, 0xfb, 0x13, 0x00,
0x00, 0xff, 0xff, 0x44, 0x0c, 0xb7, 0x9a, 0xee, 0x03, 0x00, 0x00,
}

View File

@ -68,6 +68,6 @@ message NodeRestrictions {
message NodeVersion {
string version = 1; // must be semver formatted
string commit_hash = 2;
google.protobuf.Timestamp timestamp = 3;
google.protobuf.Timestamp timestamp = 3 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
bool release = 4;
}

View File

@ -2435,7 +2435,17 @@
{
"id": 3,
"name": "timestamp",
"type": "google.protobuf.Timestamp"
"type": "google.protobuf.Timestamp",
"options": [
{
"name": "(gogoproto.stdtime)",
"value": "true"
},
{
"name": "(gogoproto.nullable)",
"value": "false"
}
]
},
{
"id": 4,

View File

@ -9,11 +9,10 @@ import (
"strings"
"time"
"github.com/golang/protobuf/ptypes"
"github.com/lib/pq"
sqlite3 "github.com/mattn/go-sqlite3"
"github.com/mattn/go-sqlite3"
"github.com/zeebo/errs"
monkit "gopkg.in/spacemonkeygo/monkit.v2"
"gopkg.in/spacemonkeygo/monkit.v2"
"storj.io/storj/internal/version"
"storj.io/storj/pkg/overlay"
@ -734,15 +733,11 @@ func (cache *overlaycache) UpdateNodeInfo(ctx context.Context, nodeID storj.Node
if err != nil {
return nil, errs.New("unable to convert version to semVer")
}
pbts, err := ptypes.Timestamp(nodeInfo.GetVersion().GetTimestamp())
if err != nil {
return nil, errs.New("unable to convert version timestamp")
}
updateFields.Major = dbx.Node_Major(semVer.Major)
updateFields.Minor = dbx.Node_Minor(semVer.Minor)
updateFields.Patch = dbx.Node_Patch(semVer.Patch)
updateFields.Hash = dbx.Node_Hash(nodeInfo.GetVersion().GetCommitHash())
updateFields.Timestamp = dbx.Node_Timestamp(pbts)
updateFields.Timestamp = dbx.Node_Timestamp(nodeInfo.GetVersion().Timestamp)
updateFields.Release = dbx.Node_Release(nodeInfo.GetVersion().GetRelease())
}
}
@ -853,11 +848,6 @@ func convertDBNode(ctx context.Context, info *dbx.Node) (_ *overlay.NodeDossier,
Patch: info.Patch,
}
pbts, err := ptypes.TimestampProto(info.Timestamp)
if err != nil {
return nil, err
}
node := &overlay.NodeDossier{
Node: pb.Node{
Id: id,
@ -880,7 +870,7 @@ func convertDBNode(ctx context.Context, info *dbx.Node) (_ *overlay.NodeDossier,
Version: pb.NodeVersion{
Version: ver.String(),
CommitHash: info.Hash,
Timestamp: pbts,
Timestamp: info.Timestamp,
Release: info.Release,
},
Contained: info.Contained,