From 4258b028d665afc563a2b48be9b5dcc414ffa3e3 Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Tue, 18 Apr 2017 10:03:57 +0200 Subject: [PATCH] nflog: switch to gogoproto This switches the nflog to generate Go code via gogoproto and thereby use standard library timestamp types. --- nflog/nflog.go | 53 +- nflog/nflog_test.go | 46 +- nflog/nflogpb/nflog.pb.go | 1125 ++++++++++++++++++++++++++++++++----- nflog/nflogpb/nflog.proto | 10 +- notify/notify.go | 7 +- notify/notify_test.go | 12 +- scripts/genproto.gogo.sh | 37 ++ scripts/genproto.sh | 1 - 8 files changed, 1067 insertions(+), 224 deletions(-) create mode 100755 scripts/genproto.gogo.sh diff --git a/nflog/nflog.go b/nflog/nflog.go index b7301320..f7e6a1c3 100644 --- a/nflog/nflog.go +++ b/nflog/nflog.go @@ -27,7 +27,6 @@ import ( "sync" "time" - "github.com/golang/protobuf/ptypes" "github.com/matttproud/golang_protobuf_extensions/pbutil" pb "github.com/prometheus/alertmanager/nflog/nflogpb" "github.com/prometheus/client_golang/prometheus" @@ -340,34 +339,21 @@ func (l *nlog) Log(r *pb.Receiver, gkey []byte, firingAlerts, resolvedAlerts []u if prevle, ok := l.st[key]; ok { // Entry already exists, only overwrite if timestamp is newer. - // This may with raciness or clock-drift across AM nodes. - prevts, err := ptypes.Timestamp(prevle.Entry.Timestamp) - if err != nil { - return err - } - if prevts.After(now) { + // This may happen with raciness or clock-drift across AM nodes. + if prevle.Entry.Timestamp.After(now) { return nil } } - ts, err := ptypes.TimestampProto(now) - if err != nil { - return err - } - expts, err := ptypes.TimestampProto(now.Add(l.retention)) - if err != nil { - return err - } - e := &pb.MeshEntry{ Entry: &pb.Entry{ Receiver: r, GroupKey: gkey, - Timestamp: ts, + Timestamp: now, FiringAlerts: firingAlerts, ResolvedAlerts: resolvedAlerts, }, - ExpiresAt: expts, + ExpiresAt: now.Add(l.retention), } l.gossip.GossipBroadcast(gossipData{ key: e, @@ -389,9 +375,10 @@ func (l *nlog) GC() (int, error) { defer l.mtx.Unlock() for k, le := range l.st { - if ets, err := ptypes.Timestamp(le.ExpiresAt); err != nil { - return n, err - } else if !ets.After(now) { + if le.ExpiresAt.IsZero() { + return n, errors.New("unexpected zero expiration timestamp") + } + if !le.ExpiresAt.After(now) { delete(l.st, k) n++ } @@ -589,17 +576,7 @@ func (gd gossipData) Merge(other mesh.GossipData) mesh.GossipData { gd[k] = e continue } - pts, err := ptypes.Timestamp(prev.Entry.Timestamp) - if err != nil { - // TODO(fabxc): log error and skip entry. What can actually error here? - panic(err) - } - ets, err := ptypes.Timestamp(e.Entry.Timestamp) - if err != nil { - // TODO(fabxc): see above. - panic(err) - } - if pts.Before(ets) { + if prev.Entry.Timestamp.Before(e.Entry.Timestamp) { gd[k] = e } } @@ -617,17 +594,7 @@ func (gd gossipData) mergeDelta(od gossipData) gossipData { delta[k] = e continue } - pts, err := ptypes.Timestamp(prev.Entry.Timestamp) - if err != nil { - // TODO(fabxc): log error and skip entry. What can actually error here? - panic(err) - } - ets, err := ptypes.Timestamp(e.Entry.Timestamp) - if err != nil { - // TODO(fabxc): see above. - panic(err) - } - if pts.Before(ets) { + if prev.Entry.Timestamp.Before(e.Entry.Timestamp) { gd[k] = e delta[k] = e } diff --git a/nflog/nflog_test.go b/nflog/nflog_test.go index 2addd05c..1afd7fba 100644 --- a/nflog/nflog_test.go +++ b/nflog/nflog_test.go @@ -20,8 +20,6 @@ import ( "testing" "time" - "github.com/golang/protobuf/ptypes" - "github.com/golang/protobuf/ptypes/timestamp" pb "github.com/prometheus/alertmanager/nflog/nflogpb" "github.com/stretchr/testify/require" ) @@ -31,7 +29,7 @@ func TestNlogGC(t *testing.T) { // We only care about key names and expiration timestamps. newEntry := func(ts time.Time) *pb.MeshEntry { return &pb.MeshEntry{ - ExpiresAt: mustTimestampProto(ts), + ExpiresAt: ts, } } @@ -69,27 +67,27 @@ func TestNlogSnapshot(t *testing.T) { Receiver: &pb.Receiver{GroupName: "abc", Integration: "test1", Idx: 1}, GroupHash: []byte("126a8a51b9d1bbd07fddc65819a542c3"), Resolved: false, - Timestamp: mustTimestampProto(now), + Timestamp: now, }, - ExpiresAt: mustTimestampProto(now), + ExpiresAt: now, }, { Entry: &pb.Entry{ GroupKey: []byte("d8e8fca2dc0f8abce7cb4cb0031ba249"), Receiver: &pb.Receiver{GroupName: "def", Integration: "test2", Idx: 29}, GroupHash: []byte("122c2331b9d1bbd07fddc65819a542c3"), Resolved: true, - Timestamp: mustTimestampProto(now), + Timestamp: now, }, - ExpiresAt: mustTimestampProto(now), + ExpiresAt: now, }, { Entry: &pb.Entry{ GroupKey: []byte("aaaaaca2dc0f896fd7cb4cb0031ba249"), Receiver: &pb.Receiver{GroupName: "ghi", Integration: "test3", Idx: 0}, GroupHash: []byte("126a8a51b9d1bbd07fddc6e3e3e542c3"), Resolved: false, - Timestamp: mustTimestampProto(now), + Timestamp: now, }, - ExpiresAt: mustTimestampProto(now), + ExpiresAt: now, }, }, }, @@ -160,7 +158,7 @@ func TestGossipDataMerge(t *testing.T) { // merging logic. newEntry := func(ts time.Time) *pb.MeshEntry { return &pb.MeshEntry{ - Entry: &pb.Entry{Timestamp: mustTimestampProto(ts)}, + Entry: &pb.Entry{Timestamp: ts}, } } cases := []struct { @@ -225,27 +223,27 @@ func TestGossipDataCoding(t *testing.T) { Receiver: &pb.Receiver{GroupName: "abc", Integration: "test1", Idx: 1}, GroupHash: []byte("126a8a51b9d1bbd07fddc65819a542c3"), Resolved: false, - Timestamp: mustTimestampProto(now), + Timestamp: now, }, - ExpiresAt: mustTimestampProto(now), + ExpiresAt: now, }, { Entry: &pb.Entry{ GroupKey: []byte("d8e8fca2dc0f8abce7cb4cb0031ba249"), Receiver: &pb.Receiver{GroupName: "def", Integration: "test2", Idx: 29}, GroupHash: []byte("122c2331b9d1bbd07fddc65819a542c3"), Resolved: true, - Timestamp: mustTimestampProto(now), + Timestamp: now, }, - ExpiresAt: mustTimestampProto(now), + ExpiresAt: now, }, { Entry: &pb.Entry{ GroupKey: []byte("aaaaaca2dc0f896fd7cb4cb0031ba249"), Receiver: &pb.Receiver{GroupName: "ghi", Integration: "test3", Idx: 0}, GroupHash: []byte("126a8a51b9d1bbd07fddc6e3e3e542c3"), Resolved: false, - Timestamp: mustTimestampProto(now), + Timestamp: now, }, - ExpiresAt: mustTimestampProto(now), + ExpiresAt: now, }, }, }, @@ -266,19 +264,3 @@ func TestGossipDataCoding(t *testing.T) { require.Equal(t, in, out, "decoded data doesn't match encoded data") } } - -func mustTimestamp(ts *timestamp.Timestamp) time.Time { - res, err := ptypes.Timestamp(ts) - if err != nil { - panic(err) - } - return res -} - -func mustTimestampProto(ts time.Time) *timestamp.Timestamp { - res, err := ptypes.TimestampProto(ts) - if err != nil { - panic(err) - } - return res -} diff --git a/nflog/nflogpb/nflog.pb.go b/nflog/nflogpb/nflog.pb.go index 744c727f..5b33d322 100644 --- a/nflog/nflogpb/nflog.pb.go +++ b/nflog/nflogpb/nflog.pb.go @@ -1,71 +1,56 @@ -// Code generated by protoc-gen-go. -// source: nflog/nflogpb/nflog.proto +// Code generated by protoc-gen-gogo. +// source: nflog.proto // DO NOT EDIT! /* -Package nflogpb is a generated protocol buffer package. + Package nflogpb is a generated protocol buffer package. -It is generated from these files: - nflog/nflogpb/nflog.proto + It is generated from these files: + nflog.proto -It has these top-level messages: - Receiver - Entry - MeshEntry + It has these top-level messages: + Receiver + Entry + MeshEntry */ package nflogpb -import proto "github.com/golang/protobuf/proto" +import proto "github.com/gogo/protobuf/proto" import fmt "fmt" import math "math" -import google_protobuf "github.com/golang/protobuf/ptypes/timestamp" + +import time "time" + +import github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + +import io "io" // 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. // 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 +const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package type Receiver struct { // Configured name of the receiver group. - GroupName string `protobuf:"bytes,1,opt,name=group_name,json=groupName" json:"group_name,omitempty"` + GroupName string `protobuf:"bytes,1,opt,name=group_name,json=groupName,proto3" json:"group_name,omitempty"` // Name of the integration of the receiver. - Integration string `protobuf:"bytes,2,opt,name=integration" json:"integration,omitempty"` + Integration string `protobuf:"bytes,2,opt,name=integration,proto3" json:"integration,omitempty"` // Index of the receiver with respect to the integration. // Every integration in a group may have 0..N configurations. - Idx uint32 `protobuf:"varint,3,opt,name=idx" json:"idx,omitempty"` + Idx uint32 `protobuf:"varint,3,opt,name=idx,proto3" json:"idx,omitempty"` } func (m *Receiver) Reset() { *m = Receiver{} } func (m *Receiver) String() string { return proto.CompactTextString(m) } func (*Receiver) ProtoMessage() {} -func (*Receiver) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } - -func (m *Receiver) GetGroupName() string { - if m != nil { - return m.GroupName - } - return "" -} - -func (m *Receiver) GetIntegration() string { - if m != nil { - return m.Integration - } - return "" -} - -func (m *Receiver) GetIdx() uint32 { - if m != nil { - return m.Idx - } - return 0 -} +func (*Receiver) Descriptor() ([]byte, []int) { return fileDescriptorNflog, []int{0} } // Entry holds information about a successful notification // sent to a receiver. @@ -79,68 +64,19 @@ type Entry struct { GroupHash []byte `protobuf:"bytes,3,opt,name=group_hash,json=groupHash,proto3" json:"group_hash,omitempty"` // Whether the notification was about a resolved alert. // Deprecated in favor of ResolvedAlerts field, but kept for compatibility. - Resolved bool `protobuf:"varint,4,opt,name=resolved" json:"resolved,omitempty"` + Resolved bool `protobuf:"varint,4,opt,name=resolved,proto3" json:"resolved,omitempty"` // Timestamp of the succeeding notification. - Timestamp *google_protobuf.Timestamp `protobuf:"bytes,5,opt,name=timestamp" json:"timestamp,omitempty"` - // FiringAlerts list of hashes of firing alerts at last notification. + Timestamp time.Time `protobuf:"bytes,5,opt,name=timestamp,stdtime" json:"timestamp"` + // FiringAlerts list of hashes of firing alerts at the last notification time. FiringAlerts []uint64 `protobuf:"varint,6,rep,packed,name=firing_alerts,json=firingAlerts" json:"firing_alerts,omitempty"` - // ResolvedAlerts list hashes of resolved alerts at last notification. + // ResolvedAlerts list of hashes of resolved alerts at the last notification time. ResolvedAlerts []uint64 `protobuf:"varint,7,rep,packed,name=resolved_alerts,json=resolvedAlerts" json:"resolved_alerts,omitempty"` } func (m *Entry) Reset() { *m = Entry{} } func (m *Entry) String() string { return proto.CompactTextString(m) } func (*Entry) ProtoMessage() {} -func (*Entry) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } - -func (m *Entry) GetGroupKey() []byte { - if m != nil { - return m.GroupKey - } - return nil -} - -func (m *Entry) GetReceiver() *Receiver { - if m != nil { - return m.Receiver - } - return nil -} - -func (m *Entry) GetGroupHash() []byte { - if m != nil { - return m.GroupHash - } - return nil -} - -func (m *Entry) GetResolved() bool { - if m != nil { - return m.Resolved - } - return false -} - -func (m *Entry) GetTimestamp() *google_protobuf.Timestamp { - if m != nil { - return m.Timestamp - } - return nil -} - -func (m *Entry) GetFiringAlerts() []uint64 { - if m != nil { - return m.FiringAlerts - } - return nil -} - -func (m *Entry) GetResolvedAlerts() []uint64 { - if m != nil { - return m.ResolvedAlerts - } - return nil -} +func (*Entry) Descriptor() ([]byte, []int) { return fileDescriptorNflog, []int{1} } // MeshEntry is a wrapper message to communicate a notify log // entry through a mesh network. @@ -149,58 +85,979 @@ type MeshEntry struct { Entry *Entry `protobuf:"bytes,1,opt,name=entry" json:"entry,omitempty"` // A timestamp indicating when the mesh peer should evict // the log entry from its state. - ExpiresAt *google_protobuf.Timestamp `protobuf:"bytes,2,opt,name=expires_at,json=expiresAt" json:"expires_at,omitempty"` + ExpiresAt time.Time `protobuf:"bytes,2,opt,name=expires_at,json=expiresAt,stdtime" json:"expires_at"` } func (m *MeshEntry) Reset() { *m = MeshEntry{} } func (m *MeshEntry) String() string { return proto.CompactTextString(m) } func (*MeshEntry) ProtoMessage() {} -func (*MeshEntry) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} } - -func (m *MeshEntry) GetEntry() *Entry { - if m != nil { - return m.Entry - } - return nil -} - -func (m *MeshEntry) GetExpiresAt() *google_protobuf.Timestamp { - if m != nil { - return m.ExpiresAt - } - return nil -} +func (*MeshEntry) Descriptor() ([]byte, []int) { return fileDescriptorNflog, []int{2} } func init() { proto.RegisterType((*Receiver)(nil), "nflogpb.Receiver") proto.RegisterType((*Entry)(nil), "nflogpb.Entry") proto.RegisterType((*MeshEntry)(nil), "nflogpb.MeshEntry") } - -func init() { proto.RegisterFile("nflog/nflogpb/nflog.proto", fileDescriptor0) } - -var fileDescriptor0 = []byte{ - // 341 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x90, 0x4f, 0x4f, 0xe3, 0x30, - 0x10, 0xc5, 0x95, 0xfe, 0x4d, 0xa6, 0x7f, 0x76, 0xd7, 0xa7, 0x6c, 0x57, 0x2b, 0xa2, 0x82, 0x44, - 0x2e, 0xa4, 0x52, 0xb9, 0xc0, 0xb1, 0x07, 0x24, 0x24, 0x04, 0x07, 0x8b, 0x2b, 0x8a, 0x5c, 0x3a, - 0x4d, 0x2c, 0x92, 0x38, 0x72, 0xdc, 0xaa, 0xfd, 0x22, 0x7c, 0x5e, 0xd4, 0x71, 0x92, 0x72, 0xe2, - 0x92, 0xd8, 0x6f, 0x7e, 0x7a, 0xf3, 0xfc, 0xe0, 0x6f, 0xb1, 0xcd, 0x54, 0xb2, 0xa0, 0x6f, 0xb9, - 0xb6, 0xff, 0xa8, 0xd4, 0xca, 0x28, 0x36, 0xac, 0xc5, 0xd9, 0x45, 0xa2, 0x54, 0x92, 0xe1, 0x82, - 0xe4, 0xf5, 0x6e, 0xbb, 0x30, 0x32, 0xc7, 0xca, 0x88, 0xbc, 0xb4, 0xe4, 0xfc, 0x0d, 0x5c, 0x8e, - 0xef, 0x28, 0xf7, 0xa8, 0xd9, 0x7f, 0x80, 0x44, 0xab, 0x5d, 0x19, 0x17, 0x22, 0x47, 0xdf, 0x09, - 0x9c, 0xd0, 0xe3, 0x1e, 0x29, 0x2f, 0x22, 0x47, 0x16, 0xc0, 0x48, 0x16, 0x06, 0x13, 0x2d, 0x8c, - 0x54, 0x85, 0xdf, 0xa1, 0xf9, 0x77, 0x89, 0xfd, 0x86, 0xae, 0xdc, 0x1c, 0xfc, 0x6e, 0xe0, 0x84, - 0x13, 0x7e, 0x3a, 0xce, 0x3f, 0x3b, 0xd0, 0x7f, 0x28, 0x8c, 0x3e, 0xb2, 0x7f, 0x60, 0xad, 0xe2, - 0x0f, 0x3c, 0x92, 0xf7, 0x98, 0xbb, 0x24, 0x3c, 0xe1, 0x91, 0xdd, 0x80, 0xab, 0xeb, 0x14, 0xe4, - 0x3b, 0x5a, 0xfe, 0x89, 0xea, 0x27, 0x44, 0x4d, 0x3c, 0xde, 0x22, 0xe7, 0xa0, 0xa9, 0xa8, 0x52, - 0x5a, 0x37, 0xae, 0x83, 0x3e, 0x8a, 0x2a, 0x65, 0xb3, 0x93, 0x5b, 0xa5, 0xb2, 0x3d, 0x6e, 0xfc, - 0x5e, 0xe0, 0x84, 0x2e, 0x6f, 0xef, 0xec, 0x0e, 0xbc, 0xb6, 0x02, 0xbf, 0x4f, 0xab, 0x66, 0x91, - 0x2d, 0x29, 0x6a, 0x4a, 0x8a, 0x5e, 0x1b, 0x82, 0x9f, 0x61, 0x76, 0x09, 0x93, 0xad, 0xd4, 0xb2, - 0x48, 0x62, 0x91, 0xa1, 0x36, 0x95, 0x3f, 0x08, 0xba, 0x61, 0x8f, 0x8f, 0xad, 0xb8, 0x22, 0x8d, - 0x5d, 0xc3, 0xaf, 0x66, 0x55, 0x83, 0x0d, 0x09, 0x9b, 0x36, 0xb2, 0x05, 0xe7, 0x19, 0x78, 0xcf, - 0x58, 0xa5, 0xb6, 0x9b, 0x2b, 0xe8, 0xe3, 0xe9, 0x40, 0xbd, 0x8c, 0x96, 0xd3, 0xf6, 0xed, 0x34, - 0xe6, 0x76, 0xc8, 0xee, 0x01, 0xf0, 0x50, 0x4a, 0x8d, 0x55, 0x2c, 0x4c, 0x5d, 0xd3, 0x8f, 0xd9, - 0x6b, 0x7a, 0x65, 0xd6, 0x03, 0x1a, 0xdf, 0x7e, 0x05, 0x00, 0x00, 0xff, 0xff, 0xe7, 0x4a, 0xda, - 0xe6, 0x33, 0x02, 0x00, 0x00, +func (m *Receiver) 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 *Receiver) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.GroupName) > 0 { + dAtA[i] = 0xa + i++ + i = encodeVarintNflog(dAtA, i, uint64(len(m.GroupName))) + i += copy(dAtA[i:], m.GroupName) + } + if len(m.Integration) > 0 { + dAtA[i] = 0x12 + i++ + i = encodeVarintNflog(dAtA, i, uint64(len(m.Integration))) + i += copy(dAtA[i:], m.Integration) + } + if m.Idx != 0 { + dAtA[i] = 0x18 + i++ + i = encodeVarintNflog(dAtA, i, uint64(m.Idx)) + } + return i, nil +} + +func (m *Entry) 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 *Entry) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.GroupKey) > 0 { + dAtA[i] = 0xa + i++ + i = encodeVarintNflog(dAtA, i, uint64(len(m.GroupKey))) + i += copy(dAtA[i:], m.GroupKey) + } + if m.Receiver != nil { + dAtA[i] = 0x12 + i++ + i = encodeVarintNflog(dAtA, i, uint64(m.Receiver.Size())) + n1, err := m.Receiver.MarshalTo(dAtA[i:]) + if err != nil { + return 0, err + } + i += n1 + } + if len(m.GroupHash) > 0 { + dAtA[i] = 0x1a + i++ + i = encodeVarintNflog(dAtA, i, uint64(len(m.GroupHash))) + i += copy(dAtA[i:], m.GroupHash) + } + if m.Resolved { + dAtA[i] = 0x20 + i++ + if m.Resolved { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i++ + } + dAtA[i] = 0x2a + i++ + i = encodeVarintNflog(dAtA, i, uint64(github_com_gogo_protobuf_types.SizeOfStdTime(m.Timestamp))) + n2, err := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.Timestamp, dAtA[i:]) + if err != nil { + return 0, err + } + i += n2 + if len(m.FiringAlerts) > 0 { + dAtA4 := make([]byte, len(m.FiringAlerts)*10) + var j3 int + for _, num := range m.FiringAlerts { + for num >= 1<<7 { + dAtA4[j3] = uint8(uint64(num)&0x7f | 0x80) + num >>= 7 + j3++ + } + dAtA4[j3] = uint8(num) + j3++ + } + dAtA[i] = 0x32 + i++ + i = encodeVarintNflog(dAtA, i, uint64(j3)) + i += copy(dAtA[i:], dAtA4[:j3]) + } + if len(m.ResolvedAlerts) > 0 { + dAtA6 := make([]byte, len(m.ResolvedAlerts)*10) + var j5 int + for _, num := range m.ResolvedAlerts { + for num >= 1<<7 { + dAtA6[j5] = uint8(uint64(num)&0x7f | 0x80) + num >>= 7 + j5++ + } + dAtA6[j5] = uint8(num) + j5++ + } + dAtA[i] = 0x3a + i++ + i = encodeVarintNflog(dAtA, i, uint64(j5)) + i += copy(dAtA[i:], dAtA6[:j5]) + } + return i, nil +} + +func (m *MeshEntry) 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 *MeshEntry) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if m.Entry != nil { + dAtA[i] = 0xa + i++ + i = encodeVarintNflog(dAtA, i, uint64(m.Entry.Size())) + n7, err := m.Entry.MarshalTo(dAtA[i:]) + if err != nil { + return 0, err + } + i += n7 + } + dAtA[i] = 0x12 + i++ + i = encodeVarintNflog(dAtA, i, uint64(github_com_gogo_protobuf_types.SizeOfStdTime(m.ExpiresAt))) + n8, err := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.ExpiresAt, dAtA[i:]) + if err != nil { + return 0, err + } + i += n8 + return i, nil +} + +func encodeFixed64Nflog(dAtA []byte, offset int, v uint64) int { + dAtA[offset] = uint8(v) + dAtA[offset+1] = uint8(v >> 8) + dAtA[offset+2] = uint8(v >> 16) + dAtA[offset+3] = uint8(v >> 24) + dAtA[offset+4] = uint8(v >> 32) + dAtA[offset+5] = uint8(v >> 40) + dAtA[offset+6] = uint8(v >> 48) + dAtA[offset+7] = uint8(v >> 56) + return offset + 8 +} +func encodeFixed32Nflog(dAtA []byte, offset int, v uint32) int { + dAtA[offset] = uint8(v) + dAtA[offset+1] = uint8(v >> 8) + dAtA[offset+2] = uint8(v >> 16) + dAtA[offset+3] = uint8(v >> 24) + return offset + 4 +} +func encodeVarintNflog(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 *Receiver) Size() (n int) { + var l int + _ = l + l = len(m.GroupName) + if l > 0 { + n += 1 + l + sovNflog(uint64(l)) + } + l = len(m.Integration) + if l > 0 { + n += 1 + l + sovNflog(uint64(l)) + } + if m.Idx != 0 { + n += 1 + sovNflog(uint64(m.Idx)) + } + return n +} + +func (m *Entry) Size() (n int) { + var l int + _ = l + l = len(m.GroupKey) + if l > 0 { + n += 1 + l + sovNflog(uint64(l)) + } + if m.Receiver != nil { + l = m.Receiver.Size() + n += 1 + l + sovNflog(uint64(l)) + } + l = len(m.GroupHash) + if l > 0 { + n += 1 + l + sovNflog(uint64(l)) + } + if m.Resolved { + n += 2 + } + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.Timestamp) + n += 1 + l + sovNflog(uint64(l)) + if len(m.FiringAlerts) > 0 { + l = 0 + for _, e := range m.FiringAlerts { + l += sovNflog(uint64(e)) + } + n += 1 + sovNflog(uint64(l)) + l + } + if len(m.ResolvedAlerts) > 0 { + l = 0 + for _, e := range m.ResolvedAlerts { + l += sovNflog(uint64(e)) + } + n += 1 + sovNflog(uint64(l)) + l + } + return n +} + +func (m *MeshEntry) Size() (n int) { + var l int + _ = l + if m.Entry != nil { + l = m.Entry.Size() + n += 1 + l + sovNflog(uint64(l)) + } + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.ExpiresAt) + n += 1 + l + sovNflog(uint64(l)) + return n +} + +func sovNflog(x uint64) (n int) { + for { + n++ + x >>= 7 + if x == 0 { + break + } + } + return n +} +func sozNflog(x uint64) (n int) { + return sovNflog(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Receiver) 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 ErrIntOverflowNflog + } + 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: Receiver: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Receiver: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field GroupName", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowNflog + } + 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 ErrInvalidLengthNflog + } + postIndex := iNdEx + intStringLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.GroupName = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Integration", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowNflog + } + 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 ErrInvalidLengthNflog + } + postIndex := iNdEx + intStringLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Integration = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Idx", wireType) + } + m.Idx = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowNflog + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Idx |= (uint32(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipNflog(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthNflog + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Entry) 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 ErrIntOverflowNflog + } + 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: Entry: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Entry: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field GroupKey", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowNflog + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthNflog + } + postIndex := iNdEx + byteLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.GroupKey = append(m.GroupKey[:0], dAtA[iNdEx:postIndex]...) + if m.GroupKey == nil { + m.GroupKey = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Receiver", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowNflog + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthNflog + } + postIndex := iNdEx + msglen + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Receiver == nil { + m.Receiver = &Receiver{} + } + if err := m.Receiver.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field GroupHash", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowNflog + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthNflog + } + postIndex := iNdEx + byteLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.GroupHash = append(m.GroupHash[:0], dAtA[iNdEx:postIndex]...) + if m.GroupHash == nil { + m.GroupHash = []byte{} + } + iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Resolved", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowNflog + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + m.Resolved = bool(v != 0) + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Timestamp", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowNflog + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthNflog + } + postIndex := iNdEx + msglen + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.Timestamp, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType == 0 { + var v uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowNflog + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + m.FiringAlerts = append(m.FiringAlerts, v) + } else if wireType == 2 { + var packedLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowNflog + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + packedLen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if packedLen < 0 { + return ErrInvalidLengthNflog + } + postIndex := iNdEx + packedLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + for iNdEx < postIndex { + var v uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowNflog + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + m.FiringAlerts = append(m.FiringAlerts, v) + } + } else { + return fmt.Errorf("proto: wrong wireType = %d for field FiringAlerts", wireType) + } + case 7: + if wireType == 0 { + var v uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowNflog + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + m.ResolvedAlerts = append(m.ResolvedAlerts, v) + } else if wireType == 2 { + var packedLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowNflog + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + packedLen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if packedLen < 0 { + return ErrInvalidLengthNflog + } + postIndex := iNdEx + packedLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + for iNdEx < postIndex { + var v uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowNflog + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + m.ResolvedAlerts = append(m.ResolvedAlerts, v) + } + } else { + return fmt.Errorf("proto: wrong wireType = %d for field ResolvedAlerts", wireType) + } + default: + iNdEx = preIndex + skippy, err := skipNflog(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthNflog + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MeshEntry) 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 ErrIntOverflowNflog + } + 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: MeshEntry: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MeshEntry: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Entry", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowNflog + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthNflog + } + postIndex := iNdEx + msglen + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Entry == nil { + m.Entry = &Entry{} + } + if err := m.Entry.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ExpiresAt", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowNflog + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthNflog + } + postIndex := iNdEx + msglen + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.ExpiresAt, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipNflog(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthNflog + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipNflog(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, ErrIntOverflowNflog + } + 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, ErrIntOverflowNflog + } + 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, ErrIntOverflowNflog + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + iNdEx += length + if length < 0 { + return 0, ErrInvalidLengthNflog + } + return iNdEx, nil + case 3: + for { + var innerWire uint64 + var start int = iNdEx + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowNflog + } + 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 := skipNflog(dAtA[start:]) + if err != nil { + return 0, err + } + iNdEx = start + next + } + 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 ( + ErrInvalidLengthNflog = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowNflog = fmt.Errorf("proto: integer overflow") +) + +func init() { proto.RegisterFile("nflog.proto", fileDescriptorNflog) } + +var fileDescriptorNflog = []byte{ + // 385 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x90, 0xcf, 0x6e, 0xd3, 0x40, + 0x10, 0xc6, 0xbb, 0x4d, 0xd3, 0xda, 0xe3, 0xb4, 0x94, 0x15, 0x07, 0xcb, 0x08, 0xc7, 0x0a, 0x48, + 0xf8, 0x82, 0x23, 0x95, 0x27, 0x68, 0x10, 0x12, 0x12, 0x82, 0xc3, 0x8a, 0x2b, 0xb2, 0x36, 0x74, + 0xb2, 0x5e, 0x61, 0x7b, 0xad, 0xf5, 0x36, 0x6a, 0xde, 0x82, 0x47, 0xe0, 0x71, 0x72, 0xe4, 0x09, + 0xf8, 0x93, 0x27, 0x41, 0xde, 0xb5, 0x1d, 0x8e, 0xdc, 0x66, 0x7f, 0xf3, 0xcd, 0xcc, 0xb7, 0x1f, + 0x04, 0xf5, 0xa6, 0x54, 0x22, 0x6b, 0xb4, 0x32, 0x8a, 0x5e, 0xd8, 0x47, 0xb3, 0x8e, 0xe6, 0x42, + 0x29, 0x51, 0xe2, 0xd2, 0xe2, 0xf5, 0xfd, 0x66, 0x69, 0x64, 0x85, 0xad, 0xe1, 0x55, 0xe3, 0x94, + 0xd1, 0x13, 0xa1, 0x84, 0xb2, 0xe5, 0xb2, 0xab, 0x1c, 0x5d, 0x7c, 0x06, 0x8f, 0xe1, 0x17, 0x94, + 0x5b, 0xd4, 0xf4, 0x19, 0x80, 0xd0, 0xea, 0xbe, 0xc9, 0x6b, 0x5e, 0x61, 0x48, 0x12, 0x92, 0xfa, + 0xcc, 0xb7, 0xe4, 0x23, 0xaf, 0x90, 0x26, 0x10, 0xc8, 0xda, 0xa0, 0xd0, 0xdc, 0x48, 0x55, 0x87, + 0xa7, 0xb6, 0xff, 0x2f, 0xa2, 0xd7, 0x30, 0x91, 0x77, 0x0f, 0xe1, 0x24, 0x21, 0xe9, 0x25, 0xeb, + 0xca, 0xc5, 0xf7, 0x53, 0x98, 0xbe, 0xad, 0x8d, 0xde, 0xd1, 0xa7, 0xe0, 0x56, 0xe5, 0x5f, 0x71, + 0x67, 0x77, 0xcf, 0x98, 0x67, 0xc1, 0x7b, 0xdc, 0xd1, 0x57, 0xe0, 0xe9, 0xde, 0x85, 0xdd, 0x1b, + 0xdc, 0x3c, 0xce, 0xfa, 0x8f, 0x65, 0x83, 0x3d, 0x36, 0x4a, 0x8e, 0x46, 0x0b, 0xde, 0x16, 0xf6, + 0xdc, 0xac, 0x37, 0xfa, 0x8e, 0xb7, 0x05, 0x8d, 0xba, 0x6d, 0xad, 0x2a, 0xb7, 0x78, 0x17, 0x9e, + 0x25, 0x24, 0xf5, 0xd8, 0xf8, 0xa6, 0x2b, 0xf0, 0xc7, 0x60, 0xc2, 0xa9, 0x3d, 0x15, 0x65, 0x2e, + 0xba, 0x6c, 0x88, 0x2e, 0xfb, 0x34, 0x28, 0x56, 0xde, 0xfe, 0xe7, 0xfc, 0xe4, 0xdb, 0xaf, 0x39, + 0x61, 0xc7, 0x31, 0xfa, 0x1c, 0x2e, 0x37, 0x52, 0xcb, 0x5a, 0xe4, 0xbc, 0x44, 0x6d, 0xda, 0xf0, + 0x3c, 0x99, 0xa4, 0x67, 0x6c, 0xe6, 0xe0, 0xad, 0x65, 0xf4, 0x25, 0x3c, 0x1a, 0x8e, 0x0e, 0xb2, + 0x0b, 0x2b, 0xbb, 0x1a, 0xb0, 0x13, 0x2e, 0xb6, 0xe0, 0x7f, 0xc0, 0xb6, 0x70, 0x29, 0xbd, 0x80, + 0x29, 0x76, 0x85, 0x4d, 0x28, 0xb8, 0xb9, 0x1a, 0x53, 0xb0, 0x6d, 0xe6, 0x9a, 0xf4, 0x0d, 0x00, + 0x3e, 0x34, 0x52, 0x63, 0x9b, 0x73, 0xd3, 0x07, 0xf6, 0x9f, 0xbf, 0xe8, 0xe7, 0x6e, 0xcd, 0xea, + 0x7a, 0xff, 0x27, 0x3e, 0xd9, 0x1f, 0x62, 0xf2, 0xe3, 0x10, 0x93, 0xdf, 0x87, 0x98, 0xac, 0xcf, + 0xed, 0xe8, 0xeb, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x49, 0xcd, 0xa7, 0x1e, 0x61, 0x02, 0x00, + 0x00, } diff --git a/nflog/nflogpb/nflog.proto b/nflog/nflogpb/nflog.proto index aefaaa44..c147d6f0 100644 --- a/nflog/nflogpb/nflog.proto +++ b/nflog/nflogpb/nflog.proto @@ -3,6 +3,12 @@ syntax = "proto3"; package nflogpb; import "google/protobuf/timestamp.proto"; +import "gogoproto/gogo.proto"; + +option (gogoproto.marshaler_all) = true; +option (gogoproto.sizer_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.goproto_getters_all) = false; message Receiver { // Configured name of the receiver group. @@ -28,7 +34,7 @@ message Entry { // Deprecated in favor of ResolvedAlerts field, but kept for compatibility. bool resolved = 4; // Timestamp of the succeeding notification. - google.protobuf.Timestamp timestamp = 5; + google.protobuf.Timestamp timestamp = 5 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; // FiringAlerts list of hashes of firing alerts at the last notification time. repeated uint64 firing_alerts = 6; // ResolvedAlerts list of hashes of resolved alerts at the last notification time. @@ -42,5 +48,5 @@ message MeshEntry { Entry entry = 1; // A timestamp indicating when the mesh peer should evict // the log entry from its state. - google.protobuf.Timestamp expires_at = 2; + google.protobuf.Timestamp expires_at = 2 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; } diff --git a/notify/notify.go b/notify/notify.go index 1a69a573..9af40761 100644 --- a/notify/notify.go +++ b/notify/notify.go @@ -22,7 +22,6 @@ import ( "github.com/cenkalti/backoff" "github.com/cespare/xxhash" - "github.com/golang/protobuf/ptypes" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/log" "github.com/prometheus/common/model" @@ -481,11 +480,7 @@ func (n *DedupStage) needsUpdate(entry *nflogpb.Entry, firing, resolved map[uint } // Nothing changed, only notify if the repeat interval has passed. - ts, err := ptypes.Timestamp(entry.Timestamp) - if err != nil { - return false, err - } - return ts.Before(n.now().Add(-repeat)), nil + return entry.Timestamp.Before(n.now().Add(-repeat)), nil } // Exec implements the Stage interface. diff --git a/notify/notify_test.go b/notify/notify_test.go index 30924772..d4d90cba 100644 --- a/notify/notify_test.go +++ b/notify/notify_test.go @@ -114,14 +114,14 @@ func TestDedupStageNeedsUpdate(t *testing.T) { }, { entry: &nflogpb.Entry{ FiringAlerts: []uint64{1, 2, 3}, - Timestamp: nil, // parsing will error + Timestamp: time.Time{}, // zero timestamp should always update }, firingAlerts: alertHashSet(1, 2, 3), - resErr: true, + res: true, }, { entry: &nflogpb.Entry{ FiringAlerts: []uint64{1, 2, 3}, - Timestamp: mustTimestampProto(now.Add(-9 * time.Minute)), + Timestamp: now.Add(-9 * time.Minute), }, repeat: 10 * time.Minute, firingAlerts: alertHashSet(1, 2, 3), @@ -129,7 +129,7 @@ func TestDedupStageNeedsUpdate(t *testing.T) { }, { entry: &nflogpb.Entry{ FiringAlerts: []uint64{1, 2, 3}, - Timestamp: mustTimestampProto(now.Add(-11 * time.Minute)), + Timestamp: now.Add(-11 * time.Minute), }, repeat: 10 * time.Minute, firingAlerts: alertHashSet(1, 2, 3), @@ -212,7 +212,7 @@ func TestDedupStage(t *testing.T) { qres: []*nflogpb.Entry{ { FiringAlerts: []uint64{0, 1, 2}, - Timestamp: mustTimestampProto(now), + Timestamp: now, }, }, } @@ -227,7 +227,7 @@ func TestDedupStage(t *testing.T) { qres: []*nflogpb.Entry{ { FiringAlerts: []uint64{1, 2, 3, 4}, - Timestamp: mustTimestampProto(now), + Timestamp: now, }, }, } diff --git a/scripts/genproto.gogo.sh b/scripts/genproto.gogo.sh new file mode 100755 index 00000000..be103d23 --- /dev/null +++ b/scripts/genproto.gogo.sh @@ -0,0 +1,37 @@ + +#!/usr/bin/env bash +# +# Generate all etcd protobuf bindings. +# Run from repository root. +set -e +set -u + +if ! [[ "$0" =~ "scripts/genproto.gogo.sh" ]]; then + echo "must be run from repository root" + exit 255 +fi + +if ! [[ $(protoc --version) =~ "3.2.0" ]]; then + echo "could not find protoc 3.2.0, is it installed + in PATH?" + exit 255 +fi + +GOGOPROTO_ROOT="${GOPATH}/src/github.com/gogo/protobuf" +GOGOPROTO_PATH="${GOGOPROTO_ROOT}:${GOGOPROTO_ROOT}/protobuf" +GRPC_GATEWAY_ROOT="${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway" + +DIRS="nflog/nflogpb" + +for dir in ${DIRS}; do + pushd ${dir} + protoc --gogofast_out=plugins=grpc:. -I=. \ + -I="${GOGOPROTO_PATH}" \ + -I="${GRPC_GATEWAY_ROOT}/third_party/googleapis" \ + *.proto + + sed -i.bak -E 's/import _ \"gogoproto\"//g' *.pb.go + sed -i.bak -E 's/import _ \"google\/protobuf\"//g' *.pb.go + rm -f *.bak + goimports -w *.pb.go + popd +done diff --git a/scripts/genproto.sh b/scripts/genproto.sh index 7c2c90dd..f0e2c534 100755 --- a/scripts/genproto.sh +++ b/scripts/genproto.sh @@ -1,2 +1 @@ -protoc --go_out=. nflog/nflogpb/nflog.proto protoc --go_out=. silence/silencepb/silence.proto