mirror of https://github.com/hashicorp/consul
Add support for implementing new requests with protobufs instea… (#6502)
* Add build system support for protobuf generation This is done generically so that we don’t have to keep updating the makefile to add another proto generation. Note: anything not in the vendor directory and with a .proto extension will be run through protoc if the corresponding namespace.pb.go file is not up to date. If you want to rebuild just a single proto file you can do so with: make proto-rebuild PROTOFILES=<list of proto files to rebuild> Providing the PROTOFILES var will override the default behavior of finding all the .proto files. * Start adding types to the agent/proto package These will be needed for some other work and are by no means comprehensive. * Add ability to resolve/fixup the agentpb.ACLLinks structure in the state store. * Use protobuf marshalling of raft requests instead of msgpack for protoc generated types. This does not change any encoding of existing types. * Removed structs package automatically encoding with protobuf marshalling Instead the caller of raftApply that wants to opt-in to protobuf encoding will have to call `raftApplyProtobuf` * Run update-vendor to fixup modules.txt Nothing changed as far as dependencies go but the ordering of modules in that file depends on the time they are first seen and its not alphabetical. * Rename some things and implement the structs.RPCInfo interface bits agentpb.QueryOptions and agentpb.WriteRequest implement 3 of the 4 RPCInfo funcs and the new TargetDatacenter message type implements the fourth. * Use the right encoding function. * Renamed agent/proto package to agent/agentpb to prevent package name conflicts * Update modules.txt to fix ordering * Change blockingQuery to take in interfaces for the query options and meta * Add %T to error output. * Add/Update some commentspull/6516/head
parent
9f4ecdbf3e
commit
51dcd126b7
@ -0,0 +1,378 @@
|
||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// source: acl.proto
|
||||
|
||||
package agentpb
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
_ "github.com/gogo/protobuf/gogoproto"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
io "io"
|
||||
math "math"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the proto package it is being compiled against.
|
||||
// A compilation error at this line likely means your copy of the
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||
|
||||
type ACLLink struct {
|
||||
ID string `protobuf:"bytes,1,opt,name=ID,proto3" json:"ID,omitempty"`
|
||||
Name string `protobuf:"bytes,2,opt,name=Name,proto3" json:"Name,omitempty" hash:"ignore"`
|
||||
}
|
||||
|
||||
func (m *ACLLink) Reset() { *m = ACLLink{} }
|
||||
func (m *ACLLink) String() string { return proto.CompactTextString(m) }
|
||||
func (*ACLLink) ProtoMessage() {}
|
||||
func (*ACLLink) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_a452f070aeef01eb, []int{0}
|
||||
}
|
||||
func (m *ACLLink) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
}
|
||||
func (m *ACLLink) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
if deterministic {
|
||||
return xxx_messageInfo_ACLLink.Marshal(b, m, deterministic)
|
||||
} else {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalTo(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return b[:n], nil
|
||||
}
|
||||
}
|
||||
func (m *ACLLink) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_ACLLink.Merge(m, src)
|
||||
}
|
||||
func (m *ACLLink) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *ACLLink) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_ACLLink.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_ACLLink proto.InternalMessageInfo
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*ACLLink)(nil), "agentpb.ACLLink")
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("acl.proto", fileDescriptor_a452f070aeef01eb) }
|
||||
|
||||
var fileDescriptor_a452f070aeef01eb = []byte{
|
||||
// 159 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4c, 0x4c, 0xce, 0xd1,
|
||||
0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x4f, 0x4c, 0x4f, 0xcd, 0x2b, 0x29, 0x48, 0x92, 0x12,
|
||||
0x49, 0xcf, 0x4f, 0xcf, 0x07, 0x8b, 0xe9, 0x83, 0x58, 0x10, 0x69, 0x25, 0x07, 0x2e, 0x76, 0x47,
|
||||
0x67, 0x1f, 0x9f, 0xcc, 0xbc, 0x6c, 0x21, 0x3e, 0x2e, 0x26, 0x4f, 0x17, 0x09, 0x46, 0x05, 0x46,
|
||||
0x0d, 0xce, 0x20, 0x26, 0x4f, 0x17, 0x21, 0x55, 0x2e, 0x16, 0xbf, 0xc4, 0xdc, 0x54, 0x09, 0x26,
|
||||
0x90, 0x88, 0x93, 0xe0, 0xa7, 0x7b, 0xf2, 0xbc, 0x19, 0x89, 0xc5, 0x19, 0x56, 0x4a, 0x99, 0xe9,
|
||||
0x79, 0xf9, 0x45, 0xa9, 0x4a, 0x41, 0x60, 0x69, 0x27, 0x85, 0x13, 0x0f, 0xe5, 0x18, 0x4e, 0x3c,
|
||||
0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x66,
|
||||
0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x24, 0x36, 0xb0, 0x55,
|
||||
0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x0e, 0xc8, 0xbd, 0xdf, 0x96, 0x00, 0x00, 0x00,
|
||||
}
|
||||
|
||||
func (m *ACLLink) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalTo(dAtA)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dAtA[:n], nil
|
||||
}
|
||||
|
||||
func (m *ACLLink) MarshalTo(dAtA []byte) (int, error) {
|
||||
var i int
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.ID) > 0 {
|
||||
dAtA[i] = 0xa
|
||||
i++
|
||||
i = encodeVarintAcl(dAtA, i, uint64(len(m.ID)))
|
||||
i += copy(dAtA[i:], m.ID)
|
||||
}
|
||||
if len(m.Name) > 0 {
|
||||
dAtA[i] = 0x12
|
||||
i++
|
||||
i = encodeVarintAcl(dAtA, i, uint64(len(m.Name)))
|
||||
i += copy(dAtA[i:], m.Name)
|
||||
}
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func encodeVarintAcl(dAtA []byte, offset int, v uint64) int {
|
||||
for v >= 1<<7 {
|
||||
dAtA[offset] = uint8(v&0x7f | 0x80)
|
||||
v >>= 7
|
||||
offset++
|
||||
}
|
||||
dAtA[offset] = uint8(v)
|
||||
return offset + 1
|
||||
}
|
||||
func (m *ACLLink) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
l = len(m.ID)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovAcl(uint64(l))
|
||||
}
|
||||
l = len(m.Name)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovAcl(uint64(l))
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func sovAcl(x uint64) (n int) {
|
||||
for {
|
||||
n++
|
||||
x >>= 7
|
||||
if x == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
func sozAcl(x uint64) (n int) {
|
||||
return sovAcl(uint64((x << 1) ^ uint64((int64(x) >> 63))))
|
||||
}
|
||||
func (m *ACLLink) Unmarshal(dAtA []byte) error {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
preIndex := iNdEx
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowAcl
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
fieldNum := int32(wire >> 3)
|
||||
wireType := int(wire & 0x7)
|
||||
if wireType == 4 {
|
||||
return fmt.Errorf("proto: ACLLink: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return fmt.Errorf("proto: ACLLink: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType)
|
||||
}
|
||||
var stringLen uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowAcl
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
stringLen |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
intStringLen := int(stringLen)
|
||||
if intStringLen < 0 {
|
||||
return ErrInvalidLengthAcl
|
||||
}
|
||||
postIndex := iNdEx + intStringLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthAcl
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.ID = string(dAtA[iNdEx:postIndex])
|
||||
iNdEx = postIndex
|
||||
case 2:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType)
|
||||
}
|
||||
var stringLen uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowAcl
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
stringLen |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
intStringLen := int(stringLen)
|
||||
if intStringLen < 0 {
|
||||
return ErrInvalidLengthAcl
|
||||
}
|
||||
postIndex := iNdEx + intStringLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthAcl
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Name = string(dAtA[iNdEx:postIndex])
|
||||
iNdEx = postIndex
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := skipAcl(dAtA[iNdEx:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if skippy < 0 {
|
||||
return ErrInvalidLengthAcl
|
||||
}
|
||||
if (iNdEx + skippy) < 0 {
|
||||
return ErrInvalidLengthAcl
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func skipAcl(dAtA []byte) (n int, err error) {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowAcl
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= (uint64(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
wireType := int(wire & 0x7)
|
||||
switch wireType {
|
||||
case 0:
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowAcl
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx++
|
||||
if dAtA[iNdEx-1] < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
return iNdEx, nil
|
||||
case 1:
|
||||
iNdEx += 8
|
||||
return iNdEx, nil
|
||||
case 2:
|
||||
var length int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowAcl
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
length |= (int(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if length < 0 {
|
||||
return 0, ErrInvalidLengthAcl
|
||||
}
|
||||
iNdEx += length
|
||||
if iNdEx < 0 {
|
||||
return 0, ErrInvalidLengthAcl
|
||||
}
|
||||
return iNdEx, nil
|
||||
case 3:
|
||||
for {
|
||||
var innerWire uint64
|
||||
var start int = iNdEx
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowAcl
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
innerWire |= (uint64(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
innerWireType := int(innerWire & 0x7)
|
||||
if innerWireType == 4 {
|
||||
break
|
||||
}
|
||||
next, err := skipAcl(dAtA[start:])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
iNdEx = start + next
|
||||
if iNdEx < 0 {
|
||||
return 0, ErrInvalidLengthAcl
|
||||
}
|
||||
}
|
||||
return iNdEx, nil
|
||||
case 4:
|
||||
return iNdEx, nil
|
||||
case 5:
|
||||
iNdEx += 4
|
||||
return iNdEx, nil
|
||||
default:
|
||||
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
var (
|
||||
ErrInvalidLengthAcl = fmt.Errorf("proto: negative length found during unmarshaling")
|
||||
ErrIntOverflowAcl = fmt.Errorf("proto: integer overflow")
|
||||
)
|
@ -0,0 +1,21 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package agentpb;
|
||||
|
||||
// Go Modules now includes the version in the filepath for packages within GOPATH/pkg/mode
|
||||
// Therefore unless we want to hardcode a version here like
|
||||
// github.com/gogo/protobuf@v1.3.0/gogoproto/gogo.proto then the only other choice is to
|
||||
// have a more relative import and pass the right import path to protoc. I don't like it
|
||||
// but its necessary.
|
||||
import "gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.goproto_unkeyed_all) = false;
|
||||
option (gogoproto.goproto_unrecognized_all) = false;
|
||||
option (gogoproto.goproto_getters_all) = false;
|
||||
option (gogoproto.goproto_sizecache_all) = false;
|
||||
|
||||
message ACLLink {
|
||||
string ID = 1;
|
||||
string Name = 2
|
||||
[(gogoproto.moretags) = "hash:\"ignore\""];
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package agentpb
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// IsRead is always true for QueryOption
|
||||
func (q *QueryOptions) IsRead() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// AllowStaleRead returns whether a stale read should be allowed
|
||||
func (q *QueryOptions) AllowStaleRead() bool {
|
||||
return q.AllowStale
|
||||
}
|
||||
|
||||
// TokenSecret returns the token to be used to authorize the request
|
||||
func (q *QueryOptions) TokenSecret() string {
|
||||
return q.Token
|
||||
}
|
||||
|
||||
// GetMinQueryIndex implements the interface necessary to be used
|
||||
// in a blocking query
|
||||
func (q *QueryOptions) GetMinQueryIndex() uint64 {
|
||||
return q.MinQueryIndex
|
||||
}
|
||||
|
||||
// GetMaxQueryTime implements the interface necessary to be used
|
||||
// in a blocking query
|
||||
func (q *QueryOptions) GetMaxQueryTime() time.Duration {
|
||||
return q.MaxQueryTime
|
||||
}
|
||||
|
||||
// GetRequireConsistent implements the interface necessary to be used
|
||||
// in a blocking query
|
||||
func (q *QueryOptions) GetRequireConsistent() bool {
|
||||
return q.RequireConsistent
|
||||
}
|
||||
|
||||
// SetLastContact implements the interface necessary to be used
|
||||
// in a blocking query
|
||||
func (q *QueryMeta) SetLastContact(lastContact time.Duration) {
|
||||
q.LastContact = lastContact
|
||||
}
|
||||
|
||||
// SetKnownLeader implements the interface necessary to be used
|
||||
// in a blocking query
|
||||
func (q *QueryMeta) SetKnownLeader(knownLeader bool) {
|
||||
q.KnownLeader = knownLeader
|
||||
}
|
||||
|
||||
// GetIndex implements the interface necessary to be used
|
||||
// in a blocking query
|
||||
func (q *QueryMeta) GetIndex() uint64 {
|
||||
return q.Index
|
||||
}
|
||||
|
||||
// SetIndex implements the interface necessary to be used
|
||||
// in a blocking query
|
||||
func (q *QueryMeta) SetIndex(index uint64) {
|
||||
q.Index = index
|
||||
}
|
||||
|
||||
// WriteRequest only applies to writes, always false
|
||||
func (w WriteRequest) IsRead() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// AllowStaleRead returns whether a stale read should be allowed
|
||||
func (w WriteRequest) AllowStaleRead() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// TokenSecret returns the token to be used to authorize the request
|
||||
func (w WriteRequest) TokenSecret() string {
|
||||
return w.Token
|
||||
}
|
||||
|
||||
func (td TargetDatacenter) RequestDatacenter() string {
|
||||
return td.Datacenter
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,123 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package agentpb;
|
||||
|
||||
import "google/protobuf/duration.proto";
|
||||
// Go Modules now includes the version in the filepath for packages within GOPATH/pkg/mode
|
||||
// Therefore unless we want to hardcode a version here like
|
||||
// github.com/gogo/protobuf@v1.3.0/gogoproto/gogo.proto then the only other choice is to
|
||||
// have a more relative import and pass the right import path to protoc. I don't like it
|
||||
// but its necessary.
|
||||
import "gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.goproto_unkeyed_all) = false;
|
||||
option (gogoproto.goproto_unrecognized_all) = false;
|
||||
option (gogoproto.goproto_getters_all) = false;
|
||||
option (gogoproto.goproto_sizecache_all) = false;
|
||||
|
||||
// RaftIndex is used to track the index used while creating
|
||||
// or modifying a given struct type.
|
||||
message RaftIndex {
|
||||
uint64 CreateIndex = 1 [(gogoproto.moretags) = "bexpr:\"-\""];
|
||||
uint64 ModifyIndex = 2 [(gogoproto.moretags) = "bexpr:\"-\""];
|
||||
}
|
||||
|
||||
// TargetDatacenter is intended to be used within other messages used for RPC routing
|
||||
// amongst the various Consul datacenters
|
||||
message TargetDatacenter {
|
||||
string Datacenter = 1;
|
||||
}
|
||||
|
||||
message WriteRequest {
|
||||
// Token is the ACL token ID. If not provided, the 'anonymous'
|
||||
// token is assumed for backwards compatibility.
|
||||
string Token = 1;
|
||||
}
|
||||
|
||||
// QueryOptions is used to specify various flags for read queries
|
||||
message QueryOptions {
|
||||
// Token is the ACL token ID. If not provided, the 'anonymous'
|
||||
// token is assumed for backwards compatibility.
|
||||
string Token = 1;
|
||||
|
||||
// If set, wait until query exceeds given index. Must be provided
|
||||
// with MaxQueryTime.
|
||||
uint64 MinQueryIndex = 2;
|
||||
|
||||
// Provided with MinQueryIndex to wait for change.
|
||||
google.protobuf.Duration MaxQueryTime = 3
|
||||
[(gogoproto.stdduration) = true, (gogoproto.nullable) = false];
|
||||
|
||||
// If set, any follower can service the request. Results
|
||||
// may be arbitrarily stale.
|
||||
bool AllowStale = 4;
|
||||
|
||||
// If set, the leader must verify leadership prior to
|
||||
// servicing the request. Prevents a stale read.
|
||||
bool RequireConsistent = 5;
|
||||
|
||||
// If set, the local agent may respond with an arbitrarily stale locally
|
||||
// cached response. The semantics differ from AllowStale since the agent may
|
||||
// be entirely partitioned from the servers and still considered "healthy" by
|
||||
// operators. Stale responses from Servers are also arbitrarily stale, but can
|
||||
// provide additional bounds on the last contact time from the leader. It's
|
||||
// expected that servers that are partitioned are noticed and replaced in a
|
||||
// timely way by operators while the same may not be true for client agents.
|
||||
bool UseCache = 6;
|
||||
|
||||
// If set and AllowStale is true, will try first a stale
|
||||
// read, and then will perform a consistent read if stale
|
||||
// read is older than value.
|
||||
google.protobuf.Duration MaxStaleDuration = 7
|
||||
[(gogoproto.stdduration) = true, (gogoproto.nullable) = false];
|
||||
|
||||
// MaxAge limits how old a cached value will be returned if UseCache is true.
|
||||
// If there is a cached response that is older than the MaxAge, it is treated
|
||||
// as a cache miss and a new fetch invoked. If the fetch fails, the error is
|
||||
// returned. Clients that wish to allow for stale results on error can set
|
||||
// StaleIfError to a longer duration to change this behavior. It is ignored
|
||||
// if the endpoint supports background refresh caching. See
|
||||
// https://www.consul.io/api/index.html#agent-caching for more details.
|
||||
google.protobuf.Duration MaxAge = 8
|
||||
[(gogoproto.stdduration) = true, (gogoproto.nullable) = false];
|
||||
|
||||
// MustRevalidate forces the agent to fetch a fresh version of a cached
|
||||
// resource or at least validate that the cached version is still fresh. It is
|
||||
// implied by either max-age=0 or must-revalidate Cache-Control headers. It
|
||||
// only makes sense when UseCache is true. We store it since MaxAge = 0 is the
|
||||
// default unset value.
|
||||
bool MustRevalidate = 9;
|
||||
|
||||
// StaleIfError specifies how stale the client will accept a cached response
|
||||
// if the servers are unavailable to fetch a fresh one. Only makes sense when
|
||||
// UseCache is true and MaxAge is set to a lower, non-zero value. It is
|
||||
// ignored if the endpoint supports background refresh caching. See
|
||||
// https://www.consul.io/api/index.html#agent-caching for more details.
|
||||
google.protobuf.Duration StaleIfError = 10
|
||||
[(gogoproto.stdduration) = true, (gogoproto.nullable) = false];
|
||||
|
||||
// Filter specifies the go-bexpr filter expression to be used for
|
||||
// filtering the data prior to returning a response
|
||||
string Filter = 11;
|
||||
}
|
||||
|
||||
// QueryMeta allows a query response to include potentially
|
||||
// useful metadata about a query
|
||||
message QueryMeta {
|
||||
// This is the index associated with the read
|
||||
uint64 Index = 1;
|
||||
|
||||
// If AllowStale is used, this is time elapsed since
|
||||
// last contact between the follower and leader. This
|
||||
// can be used to gauge staleness.
|
||||
google.protobuf.Duration LastContact = 2
|
||||
[(gogoproto.stdduration) = true, (gogoproto.nullable) = false];
|
||||
|
||||
// Used to indicate if there is a known leader node
|
||||
bool KnownLeader = 3;
|
||||
|
||||
// Consistencylevel returns the consistency used to serve the query
|
||||
// Having `discovery_max_stale` on the agent can affect whether
|
||||
// the request was served by a leader.
|
||||
string ConsistencyLevel = 4;
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package agentpb
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/consul/agent/structs"
|
||||
)
|
||||
|
||||
type ProtoMarshaller interface {
|
||||
Size() int
|
||||
MarshalTo([]byte) (int, error)
|
||||
Unmarshal([]byte) error
|
||||
ProtoMessage()
|
||||
}
|
||||
|
||||
func EncodeInterface(t structs.MessageType, message interface{}) ([]byte, error) {
|
||||
if marshaller, ok := message.(ProtoMarshaller); ok {
|
||||
return Encode(t, marshaller)
|
||||
}
|
||||
return nil, fmt.Errorf("message does not implement the ProtoMarshaller interface: %T", message)
|
||||
}
|
||||
|
||||
func Encode(t structs.MessageType, message ProtoMarshaller) ([]byte, error) {
|
||||
data := make([]byte, message.Size()+1)
|
||||
data[0] = uint8(t)
|
||||
if _, err := message.MarshalTo(data[1:]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func Decode(buf []byte, out ProtoMarshaller) error {
|
||||
// Note that this assumes the leading byte indicating the type has already been stripped off
|
||||
return out.Unmarshal(buf)
|
||||
}
|
@ -0,0 +1,141 @@
|
||||
#!/bin/bash
|
||||
SCRIPT_NAME="$(basename ${BASH_SOURCE[0]})"
|
||||
pushd $(dirname ${BASH_SOURCE[0]}) > /dev/null
|
||||
SCRIPT_DIR=$(pwd)
|
||||
pushd ../.. > /dev/null
|
||||
SOURCE_DIR=$(pwd)
|
||||
popd > /dev/null
|
||||
pushd ../functions > /dev/null
|
||||
FN_DIR=$(pwd)
|
||||
popd > /dev/null
|
||||
popd > /dev/null
|
||||
|
||||
source "${SCRIPT_DIR}/functions.sh"
|
||||
|
||||
function usage {
|
||||
cat <<-EOF
|
||||
Usage: ${SCRIPT_NAME} [<options ...>] <proto filepath>
|
||||
|
||||
Description:
|
||||
This script will build generate the Go files from protobuf files. In addition to
|
||||
just running the correct protoc generator it will also fixup build tags in the
|
||||
generated code.
|
||||
|
||||
Options:
|
||||
--import-replace Replace imports of google types with those from the gogo/protobuf repo.
|
||||
|
||||
--generator Which generator to use: gogo, gofast etc. Defaults to gofast.
|
||||
|
||||
--grpc Enable the gRPC plugin
|
||||
|
||||
-h | --help Print this help text.
|
||||
EOF
|
||||
}
|
||||
|
||||
function err_usage {
|
||||
err "$1"
|
||||
err ""
|
||||
err "$(usage)"
|
||||
}
|
||||
|
||||
function main {
|
||||
local generator=gofast
|
||||
local -i grpc=0
|
||||
local -i imp_replace=0
|
||||
local proto_path=
|
||||
|
||||
while test $# -gt 0
|
||||
do
|
||||
case "$1" in
|
||||
-h | --help )
|
||||
usage
|
||||
return 0
|
||||
;;
|
||||
generator )
|
||||
if test -z "$2"
|
||||
then
|
||||
err_usage "ERROR: option -g/--generator requires an argument"
|
||||
return 1
|
||||
fi
|
||||
|
||||
generator="$2"
|
||||
shift 2
|
||||
;;
|
||||
--grpc )
|
||||
grpc=1
|
||||
shift
|
||||
;;
|
||||
--import-replace )
|
||||
imp_replace=1
|
||||
shift
|
||||
;;
|
||||
* )
|
||||
proto_path="$1"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if test -z "${proto_path}"
|
||||
then
|
||||
err_usage "ERROR: No proto file specified"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local gogo_proto_path=$(go list -f '{{ .Dir }}' -m github.com/gogo/protobuf)
|
||||
local gogo_proto_mod_path=$(sed -e 's,\(.*\)github.com.*,\1,' <<< "${gogo_proto_path}")
|
||||
|
||||
local gogo_proto_imp_replace="Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types"
|
||||
gogo_proto_imp_replace="${gogo_proto_imp_replace},Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types"
|
||||
gogo_proto_imp_replace="${gogo_proto_imp_replace},Mgoogle/protobuf/empty.proto=github.com/gogo/protobuf/types"
|
||||
gogo_proto_imp_replace="${gogo_proto_imp_replace},Mgoogle/api/annotations.proto=github.com/gogo/googleapis/google/api"
|
||||
gogo_proto_imp_replace="${gogo_proto_imp_replace},Mgoogle/protobuf/field_mask.proto=github.com/gogo/protobuf/types"
|
||||
|
||||
local proto_go_path=${proto_path%%.proto}.pb.go
|
||||
|
||||
local go_proto_out=""
|
||||
local sep=""
|
||||
if is_set "${grpc}"
|
||||
then
|
||||
go_proto_out="plugins=grpc"
|
||||
sep=","
|
||||
fi
|
||||
|
||||
if is_set "${imp_replace}"
|
||||
then
|
||||
go_proto_out="${go_proto_out}${sep}${gogo_proto_imp_replace}"
|
||||
fi
|
||||
|
||||
if test -n "${go_proto_out}"
|
||||
then
|
||||
go_proto_out="${go_proto_out}:"
|
||||
fi
|
||||
|
||||
local -i ret=0
|
||||
status_stage "Generating ${proto_go_path} from ${proto_path}"
|
||||
debug_run protoc \
|
||||
-I="$(dirname ${proto_path})" \
|
||||
-I="${gogo_proto_path}/protobuf" \
|
||||
-I="${gogo_proto_path}" \
|
||||
-I="${gogo_proto_mod_path}" \
|
||||
--${generator}_out="${go_proto_out}$(dirname ${proto_path})" \
|
||||
"${proto_path}"
|
||||
if test $? -ne 0
|
||||
then
|
||||
err "Failed to generate ${proto_go_path} from ${proto_path}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
BUILD_TAGS=$(sed -e '/^[:space:]*$/,$d' < "${proto_path}" | grep '// +build')
|
||||
if test -n "${BUILD_TAGS}"
|
||||
then
|
||||
echo -e "${BUILD_TAGS}\n" >> "${proto_go_path}.new"
|
||||
cat "${proto_go_path}" >> "${proto_go_path}.new"
|
||||
mv "${proto_go_path}.new" "${proto_go_path}"
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
main "$@"
|
||||
exit $?
|
Loading…
Reference in new issue