From 0b5cd71c90de58e2d7c831d791bc55c31d19f94d Mon Sep 17 00:00:00 2001 From: Vytenis Darulis Date: Thu, 29 Oct 2020 18:23:37 -0400 Subject: [PATCH 1/4] Allow zero-alloc reuse of AggregateMetrics protobuf payloads --- src/collector/integration/defaults.go | 8 +- .../encoding/protobuf/aggregated_decoder.go | 17 ++- .../aggregated_decoder_benchmark_test.go | 52 +++++++ .../encoding/protobuf/aggregated_encoder.go | 2 +- src/metrics/encoding/protobuf/reset.go | 18 +-- src/metrics/encoding/protobuf/reset_test.go | 8 +- .../protobuf/unaggregated_encoder_test.go | 44 +++--- .../generated/proto/metricpb/composite.pb.go | 20 +-- .../generated/proto/policypb/policy.pb.go | 117 +++++++-------- .../generated/proto/policypb/policy.proto | 5 +- .../match_rule_update_stress_test.go | 8 +- src/metrics/metadata/metadata_test.go | 40 +++--- src/metrics/metric/aggregated/types_test.go | 8 +- src/metrics/metric/unaggregated/types_test.go | 12 +- src/metrics/policy/policy_test.go | 28 ++-- src/metrics/policy/resolution.go | 7 +- src/metrics/policy/retention.go | 7 +- src/metrics/policy/storage_policy.go | 10 +- src/metrics/policy/storage_policy_test.go | 20 +-- src/metrics/rules/convert_test.go | 40 +++--- src/metrics/rules/mapping_test.go | 32 ++--- src/metrics/rules/rollup_target_test.go | 56 ++++---- src/metrics/rules/rollup_test.go | 36 ++--- src/metrics/rules/ruleset_test.go | 136 +++++++++--------- src/metrics/rules/store/kv/store_test.go | 44 +++--- src/query/remote/codecs_test.go | 20 +-- 26 files changed, 423 insertions(+), 372 deletions(-) create mode 100644 src/metrics/encoding/protobuf/aggregated_decoder_benchmark_test.go diff --git a/src/collector/integration/defaults.go b/src/collector/integration/defaults.go index 284c045cce..5a2d7c712a 100644 --- a/src/collector/integration/defaults.go +++ b/src/collector/integration/defaults.go @@ -101,11 +101,11 @@ func defaultMappingRulesConfig() []*rulepb.MappingRule { Filter: "mtagName1:mtagValue1", StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(10 * time.Second), Precision: int64(time.Second), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(24 * time.Hour), }, }, @@ -142,11 +142,11 @@ func defaultRollupRulesConfig() []*rulepb.RollupRule { }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(time.Minute), Precision: int64(time.Minute), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(48 * time.Hour), }, }, diff --git a/src/metrics/encoding/protobuf/aggregated_decoder.go b/src/metrics/encoding/protobuf/aggregated_decoder.go index c90fdc0a85..3f1cc5b890 100644 --- a/src/metrics/encoding/protobuf/aggregated_decoder.go +++ b/src/metrics/encoding/protobuf/aggregated_decoder.go @@ -27,8 +27,10 @@ import ( // AggregatedDecoder is a decoder for decoding aggregated metrics. type AggregatedDecoder struct { - pool AggregatedDecoderPool - pb metricpb.AggregatedMetric + pool AggregatedDecoderPool + pb metricpb.AggregatedMetric + sp policy.StoragePolicy + spErr error } // NewAggregatedDecoder creates an aggregated decoder. @@ -40,7 +42,11 @@ func NewAggregatedDecoder(p AggregatedDecoderPool) *AggregatedDecoder { // Decode decodes the aggregated metric from the given bytes. func (d *AggregatedDecoder) Decode(b []byte) error { - return d.pb.Unmarshal(b) + if err := d.pb.Unmarshal(b); err != nil { + return err + } + d.spErr = d.sp.FromProto(d.pb.Metric.StoragePolicy) + return nil } // ID returns the decoded id. @@ -60,7 +66,7 @@ func (d AggregatedDecoder) Value() float64 { // StoragePolicy returns the decoded storage policy. func (d AggregatedDecoder) StoragePolicy() (policy.StoragePolicy, error) { - return policy.NewStoragePolicyFromProto(&d.pb.Metric.StoragePolicy) + return d.sp, d.spErr } // EncodeNanos returns the decoded encodeNanos. @@ -70,7 +76,8 @@ func (d AggregatedDecoder) EncodeNanos() int64 { // Close closes the decoder. func (d *AggregatedDecoder) Close() { - resetAggregatedMetricProto(&d.pb) + d.sp, d.spErr = policy.StoragePolicy{}, nil + ReuseAggregatedMetricProto(&d.pb) if d.pool != nil { d.pool.Put(d) } diff --git a/src/metrics/encoding/protobuf/aggregated_decoder_benchmark_test.go b/src/metrics/encoding/protobuf/aggregated_decoder_benchmark_test.go new file mode 100644 index 0000000000..530e63d4a3 --- /dev/null +++ b/src/metrics/encoding/protobuf/aggregated_decoder_benchmark_test.go @@ -0,0 +1,52 @@ +// Copyright (c) 2018 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package protobuf + +import ( + "runtime" + "testing" + + "github.com/m3db/m3/src/metrics/policy" +) + +func BenchmarkDecodeStoragePolicy(b *testing.B) { + var ( + enc = NewAggregatedEncoder(nil) + dec = NewAggregatedDecoder(nil) + sp policy.StoragePolicy + err error + ) + if err := enc.Encode(testAggregatedMetric1, 2000); err != nil { + b.Fatal(err) + } + + buf := enc.Buffer().Bytes() + b.ResetTimer() + + for i := 0; i < b.N; i++ { + _ = dec.Decode(buf) + if sp, err = dec.StoragePolicy(); err != nil { + b.FailNow() + } + dec.Close() + } + runtime.KeepAlive(sp) +} diff --git a/src/metrics/encoding/protobuf/aggregated_encoder.go b/src/metrics/encoding/protobuf/aggregated_encoder.go index bdd3e1930f..c27c60226b 100644 --- a/src/metrics/encoding/protobuf/aggregated_encoder.go +++ b/src/metrics/encoding/protobuf/aggregated_encoder.go @@ -55,7 +55,7 @@ func (enc *aggregatedEncoder) Encode( m aggregated.MetricWithStoragePolicy, encodedAtNanos int64, ) error { - resetAggregatedMetricProto(&enc.pb) + ReuseAggregatedMetricProto(&enc.pb) if err := m.ToProto(&enc.pb.Metric); err != nil { return err } diff --git a/src/metrics/encoding/protobuf/reset.go b/src/metrics/encoding/protobuf/reset.go index 6a97fdff5e..077e17c48f 100644 --- a/src/metrics/encoding/protobuf/reset.go +++ b/src/metrics/encoding/protobuf/reset.go @@ -24,14 +24,6 @@ import ( "github.com/m3db/m3/src/metrics/generated/proto/metricpb" ) -func resetAggregatedMetricProto(pb *metricpb.AggregatedMetric) { - if pb == nil { - return - } - resetTimedMetricWithStoragePolicyProto(&pb.Metric) - pb.EncodeNanos = 0 -} - // ReuseMetricWithMetadatasProto allows for zero-alloc reuse of // *metricpb.MetricWithMetadatas by deep resetting the internal slices // and when using gogoprotobuf's unmarshal function will reuse the slices @@ -60,6 +52,16 @@ func ReuseMetricWithMetadatasProto(pb *metricpb.MetricWithMetadatas) { resetTimedMetricWithStoragePolicyProto(pb.TimedMetricWithStoragePolicy) } +// ReuseAggregatedMetricProto allows for zero-alloc reuse of +// *metricpb.AggregatedMetric +func ReuseAggregatedMetricProto(pb *metricpb.AggregatedMetric) { + if pb == nil { + return + } + resetTimedMetricWithStoragePolicyProto(&pb.Metric) + pb.EncodeNanos = 0 +} + func resetCounterWithMetadatasProto(pb *metricpb.CounterWithMetadatas) { if pb == nil { return diff --git a/src/metrics/encoding/protobuf/reset_test.go b/src/metrics/encoding/protobuf/reset_test.go index a3a8b3eb94..e489862669 100644 --- a/src/metrics/encoding/protobuf/reset_test.go +++ b/src/metrics/encoding/protobuf/reset_test.go @@ -118,23 +118,23 @@ func TestReuseMetricWithMetadatasProtoNilProto(t *testing.T) { require.NotPanics(t, func() { ReuseMetricWithMetadatasProto(nil) }) } -func TestResetAggregatedMetricProto(t *testing.T) { +func TestReuseAggregatedMetricProto(t *testing.T) { input := &metricpb.AggregatedMetric{ Metric: metricpb.TimedMetricWithStoragePolicy{ TimedMetric: testTimedMetricBeforeResetProto, StoragePolicy: policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: 10 * time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: (6 * time.Hour).Nanoseconds(), }, }, }, EncodeNanos: 1234, } - resetAggregatedMetricProto(input) + ReuseAggregatedMetricProto(input) require.Equal(t, metricpb.AggregatedMetric{ Metric: metricpb.TimedMetricWithStoragePolicy{ TimedMetric: metricpb.TimedMetric{Id: []byte{}}, diff --git a/src/metrics/encoding/protobuf/unaggregated_encoder_test.go b/src/metrics/encoding/protobuf/unaggregated_encoder_test.go index 57364bd604..7c3ad0026d 100644 --- a/src/metrics/encoding/protobuf/unaggregated_encoder_test.go +++ b/src/metrics/encoding/protobuf/unaggregated_encoder_test.go @@ -324,11 +324,11 @@ var ( AggregationId: aggregationpb.AggregationID{Id: aggregation.MustCompressTypes(aggregation.Sum)[0]}, StoragePolicies: []policypb.StoragePolicy{ { - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: time.Hour.Nanoseconds(), }, }, @@ -338,11 +338,11 @@ var ( AggregationId: aggregationpb.AggregationID{Id: 0}, StoragePolicies: []policypb.StoragePolicy{ { - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: 10 * time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: time.Hour.Nanoseconds(), }, }, @@ -379,11 +379,11 @@ var ( AggregationId: aggregationpb.AggregationID{Id: aggregation.MustCompressTypes(aggregation.Count)[0]}, StoragePolicies: []policypb.StoragePolicy{ { - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: time.Hour.Nanoseconds(), }, }, @@ -393,20 +393,20 @@ var ( AggregationId: aggregationpb.AggregationID{Id: 0}, StoragePolicies: []policypb.StoragePolicy{ { - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Minute.Nanoseconds(), Precision: time.Minute.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: (6 * time.Hour).Nanoseconds(), }, }, { - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Hour.Nanoseconds(), Precision: time.Hour.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: (30 * 24 * time.Hour).Nanoseconds(), }, }, @@ -465,11 +465,11 @@ var ( testForwardMetadata1Proto = metricpb.ForwardMetadata{ AggregationId: aggregationpb.AggregationID{Id: 0}, StoragePolicy: policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Minute.Nanoseconds(), Precision: time.Minute.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: (12 * time.Hour).Nanoseconds(), }, }, @@ -490,11 +490,11 @@ var ( testForwardMetadata2Proto = metricpb.ForwardMetadata{ AggregationId: aggregationpb.AggregationID{Id: aggregation.MustCompressTypes(aggregation.Sum)[0]}, StoragePolicy: policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: 10 * time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: (6 * time.Hour).Nanoseconds(), }, }, @@ -521,11 +521,11 @@ var ( testTimedMetadata1Proto = metricpb.TimedMetadata{ AggregationId: aggregationpb.AggregationID{Id: 0}, StoragePolicy: policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Minute.Nanoseconds(), Precision: time.Minute.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: (12 * time.Hour).Nanoseconds(), }, }, @@ -533,30 +533,30 @@ var ( testTimedMetadata2Proto = metricpb.TimedMetadata{ AggregationId: aggregationpb.AggregationID{Id: aggregation.MustCompressTypes(aggregation.Sum)[0]}, StoragePolicy: policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: 10 * time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: (6 * time.Hour).Nanoseconds(), }, }, } testPassthroughMetadata1Proto = policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Minute.Nanoseconds(), Precision: time.Minute.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: (12 * time.Hour).Nanoseconds(), }, } testPassthroughMetadata2Proto = policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: 10 * time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: (6 * time.Hour).Nanoseconds(), }, } diff --git a/src/metrics/generated/proto/metricpb/composite.pb.go b/src/metrics/generated/proto/metricpb/composite.pb.go index ad2c896bd2..c1181345b5 100644 --- a/src/metrics/generated/proto/metricpb/composite.pb.go +++ b/src/metrics/generated/proto/metricpb/composite.pb.go @@ -143,10 +143,12 @@ type BatchTimerWithMetadatas struct { Metadatas StagedMetadatas `protobuf:"bytes,2,opt,name=metadatas" json:"metadatas"` } -func (m *BatchTimerWithMetadatas) Reset() { *m = BatchTimerWithMetadatas{} } -func (m *BatchTimerWithMetadatas) String() string { return proto.CompactTextString(m) } -func (*BatchTimerWithMetadatas) ProtoMessage() {} -func (*BatchTimerWithMetadatas) Descriptor() ([]byte, []int) { return fileDescriptorComposite, []int{1} } +func (m *BatchTimerWithMetadatas) Reset() { *m = BatchTimerWithMetadatas{} } +func (m *BatchTimerWithMetadatas) String() string { return proto.CompactTextString(m) } +func (*BatchTimerWithMetadatas) ProtoMessage() {} +func (*BatchTimerWithMetadatas) Descriptor() ([]byte, []int) { + return fileDescriptorComposite, []int{1} +} func (m *BatchTimerWithMetadatas) GetBatchTimer() BatchTimer { if m != nil { @@ -217,10 +219,12 @@ type TimedMetricWithMetadata struct { Metadata TimedMetadata `protobuf:"bytes,2,opt,name=metadata" json:"metadata"` } -func (m *TimedMetricWithMetadata) Reset() { *m = TimedMetricWithMetadata{} } -func (m *TimedMetricWithMetadata) String() string { return proto.CompactTextString(m) } -func (*TimedMetricWithMetadata) ProtoMessage() {} -func (*TimedMetricWithMetadata) Descriptor() ([]byte, []int) { return fileDescriptorComposite, []int{4} } +func (m *TimedMetricWithMetadata) Reset() { *m = TimedMetricWithMetadata{} } +func (m *TimedMetricWithMetadata) String() string { return proto.CompactTextString(m) } +func (*TimedMetricWithMetadata) ProtoMessage() {} +func (*TimedMetricWithMetadata) Descriptor() ([]byte, []int) { + return fileDescriptorComposite, []int{4} +} func (m *TimedMetricWithMetadata) GetMetric() TimedMetric { if m != nil { diff --git a/src/metrics/generated/proto/policypb/policy.pb.go b/src/metrics/generated/proto/policypb/policy.pb.go index eca5808305..f890d31ca6 100644 --- a/src/metrics/generated/proto/policypb/policy.pb.go +++ b/src/metrics/generated/proto/policypb/policy.pb.go @@ -38,6 +38,7 @@ package policypb import proto "github.com/gogo/protobuf/proto" import fmt "fmt" import math "math" +import _ "github.com/gogo/protobuf/gogoproto" import aggregationpb "github.com/m3db/m3/src/metrics/generated/proto/aggregationpb" import io "io" @@ -118,8 +119,8 @@ func (m *Retention) GetPeriod() int64 { } type StoragePolicy struct { - Resolution *Resolution `protobuf:"bytes,1,opt,name=resolution" json:"resolution,omitempty"` - Retention *Retention `protobuf:"bytes,2,opt,name=retention" json:"retention,omitempty"` + Resolution Resolution `protobuf:"bytes,1,opt,name=resolution" json:"resolution"` + Retention Retention `protobuf:"bytes,2,opt,name=retention" json:"retention"` } func (m *StoragePolicy) Reset() { *m = StoragePolicy{} } @@ -127,18 +128,18 @@ func (m *StoragePolicy) String() string { return proto.CompactTextStr func (*StoragePolicy) ProtoMessage() {} func (*StoragePolicy) Descriptor() ([]byte, []int) { return fileDescriptorPolicy, []int{2} } -func (m *StoragePolicy) GetResolution() *Resolution { +func (m *StoragePolicy) GetResolution() Resolution { if m != nil { return m.Resolution } - return nil + return Resolution{} } -func (m *StoragePolicy) GetRetention() *Retention { +func (m *StoragePolicy) GetRetention() Retention { if m != nil { return m.Retention } - return nil + return Retention{} } type Policy struct { @@ -238,26 +239,22 @@ func (m *StoragePolicy) MarshalTo(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.Resolution != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintPolicy(dAtA, i, uint64(m.Resolution.Size())) - n1, err := m.Resolution.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n1 + dAtA[i] = 0xa + i++ + i = encodeVarintPolicy(dAtA, i, uint64(m.Resolution.Size())) + n1, err := m.Resolution.MarshalTo(dAtA[i:]) + if err != nil { + return 0, err } - if m.Retention != nil { - dAtA[i] = 0x12 - i++ - i = encodeVarintPolicy(dAtA, i, uint64(m.Retention.Size())) - n2, err := m.Retention.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n2 + i += n1 + dAtA[i] = 0x12 + i++ + i = encodeVarintPolicy(dAtA, i, uint64(m.Retention.Size())) + n2, err := m.Retention.MarshalTo(dAtA[i:]) + if err != nil { + return 0, err } + i += n2 return i, nil } @@ -339,14 +336,10 @@ func (m *Retention) Size() (n int) { func (m *StoragePolicy) Size() (n int) { var l int _ = l - if m.Resolution != nil { - l = m.Resolution.Size() - n += 1 + l + sovPolicy(uint64(l)) - } - if m.Retention != nil { - l = m.Retention.Size() - n += 1 + l + sovPolicy(uint64(l)) - } + l = m.Resolution.Size() + n += 1 + l + sovPolicy(uint64(l)) + l = m.Retention.Size() + n += 1 + l + sovPolicy(uint64(l)) return n } @@ -592,9 +585,6 @@ func (m *StoragePolicy) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.Resolution == nil { - m.Resolution = &Resolution{} - } if err := m.Resolution.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -625,9 +615,6 @@ func (m *StoragePolicy) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.Retention == nil { - m.Retention = &Retention{} - } if err := m.Retention.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -908,30 +895,32 @@ func init() { } var fileDescriptorPolicy = []byte{ - // 390 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x52, 0xcd, 0xce, 0xd2, 0x40, - 0x14, 0xfd, 0xca, 0x67, 0xc8, 0xd7, 0x4b, 0x20, 0x75, 0x34, 0x48, 0x8c, 0xa9, 0xa4, 0x6e, 0x88, - 0x8b, 0x36, 0x82, 0x89, 0x2b, 0x4d, 0x50, 0x34, 0x12, 0xa4, 0x90, 0x01, 0x17, 0xba, 0x69, 0xfa, - 0x33, 0xa9, 0x93, 0xd0, 0xce, 0x64, 0x66, 0x08, 0xc2, 0x53, 0xb8, 0xf1, 0x9d, 0x5c, 0xfa, 0x08, - 0x06, 0x5f, 0xc4, 0x38, 0x2d, 0xb6, 0x5d, 0xfa, 0xed, 0xe6, 0x9c, 0x7b, 0xef, 0x39, 0xe7, 0xde, - 0x0c, 0xcc, 0x52, 0xaa, 0xbe, 0xec, 0x23, 0x37, 0x66, 0x99, 0x97, 0x4d, 0x92, 0xc8, 0xcb, 0x26, - 0x9e, 0x14, 0xb1, 0x97, 0x11, 0x25, 0x68, 0x2c, 0xbd, 0x94, 0xe4, 0x44, 0x84, 0x8a, 0x24, 0x1e, - 0x17, 0x4c, 0x31, 0x8f, 0xb3, 0x1d, 0x8d, 0x8f, 0x3c, 0x2a, 0x1f, 0xae, 0x66, 0xd1, 0xcd, 0x85, - 0x7e, 0xe8, 0xff, 0xa7, 0x5e, 0x98, 0xa6, 0x82, 0xa4, 0xa1, 0xa2, 0x2c, 0xe7, 0x51, 0x1d, 0x15, - 0xca, 0xce, 0x02, 0x00, 0x13, 0xc9, 0x76, 0xfb, 0xbf, 0x1c, 0x7a, 0x0c, 0x9d, 0x03, 0xcd, 0x13, - 0x76, 0x08, 0x24, 0x3d, 0x91, 0x81, 0x31, 0x34, 0x46, 0xd7, 0x18, 0x0a, 0x6a, 0x43, 0x4f, 0x04, - 0x3d, 0x02, 0x93, 0x0b, 0x12, 0x53, 0x49, 0x59, 0x3e, 0x68, 0xe9, 0x72, 0x45, 0x38, 0x4f, 0xc0, - 0xc4, 0x44, 0x91, 0x5c, 0x6b, 0xf5, 0xa1, 0xcd, 0x89, 0xa0, 0x2c, 0x29, 0x65, 0x4a, 0xe4, 0x7c, - 0x85, 0xee, 0x46, 0x31, 0x11, 0xa6, 0x64, 0xad, 0x97, 0x42, 0xcf, 0x01, 0xc4, 0xbf, 0x08, 0xba, - 0xb9, 0x33, 0xbe, 0xef, 0x5e, 0x36, 0x76, 0xab, 0x78, 0xb8, 0xd6, 0x87, 0x9e, 0x81, 0x29, 0x2e, - 0x5e, 0x3a, 0x49, 0x67, 0x7c, 0xaf, 0x3e, 0x54, 0x96, 0x70, 0xd5, 0xe5, 0x7c, 0x37, 0xa0, 0x5d, - 0x7a, 0xbe, 0x82, 0x9e, 0x2c, 0x42, 0x04, 0xc5, 0x4c, 0xe9, 0xfb, 0xa0, 0x92, 0x68, 0x84, 0xc4, - 0x5d, 0xd9, 0xc8, 0xbc, 0x80, 0xbb, 0xb5, 0x5b, 0x06, 0xea, 0xc8, 0x89, 0x1c, 0xb4, 0x86, 0xd7, - 0xa3, 0xde, 0xd8, 0x76, 0x1b, 0x37, 0x77, 0xa7, 0x15, 0xda, 0x1e, 0x39, 0xc1, 0x56, 0xd8, 0x24, - 0xe4, 0xd3, 0x97, 0x00, 0x33, 0xc1, 0x78, 0x29, 0x7d, 0x03, 0x77, 0xfc, 0x95, 0xff, 0xd6, 0xba, - 0x42, 0x5d, 0x30, 0x67, 0x78, 0xb5, 0x0e, 0x96, 0x1f, 0x37, 0x5b, 0xcb, 0x40, 0x7d, 0x40, 0x1a, - 0xce, 0xdf, 0x05, 0x2b, 0xff, 0xc3, 0xa7, 0x60, 0x39, 0xdd, 0xbe, 0x79, 0x6f, 0xb5, 0x5e, 0xcf, - 0x7f, 0x9c, 0x6d, 0xe3, 0xe7, 0xd9, 0x36, 0x7e, 0x9d, 0x6d, 0xe3, 0xdb, 0x6f, 0xfb, 0xea, 0xf3, - 0x8b, 0x5b, 0x7e, 0xba, 0xa8, 0xad, 0xf1, 0xe4, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x4d, 0x58, - 0xd9, 0xc4, 0xb6, 0x02, 0x00, 0x00, + // 420 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x52, 0x5d, 0x6b, 0x13, 0x41, + 0x14, 0xcd, 0xa4, 0x25, 0x34, 0x37, 0xa4, 0xac, 0xa3, 0xd4, 0x50, 0x64, 0x5b, 0xd6, 0x97, 0x22, + 0xb8, 0x0b, 0xc9, 0x43, 0x41, 0x50, 0x68, 0x8d, 0x62, 0xa9, 0xdd, 0x94, 0x4d, 0x7c, 0xd0, 0x97, + 0x65, 0x3f, 0xc6, 0x71, 0xa0, 0xbb, 0x33, 0xcc, 0x4c, 0x28, 0xe9, 0xb3, 0x3f, 0xc0, 0x17, 0xff, + 0x53, 0x1f, 0xfd, 0x05, 0x22, 0xf1, 0x8f, 0x48, 0x66, 0x27, 0xee, 0xee, 0xa3, 0xbe, 0xdd, 0x73, + 0xee, 0x3d, 0xe7, 0x1e, 0xee, 0x0c, 0x4c, 0x29, 0xd3, 0x5f, 0x96, 0xa9, 0x9f, 0xf1, 0x22, 0x28, + 0x26, 0x79, 0x1a, 0x14, 0x93, 0x40, 0xc9, 0x2c, 0x28, 0x88, 0x96, 0x2c, 0x53, 0x01, 0x25, 0x25, + 0x91, 0x89, 0x26, 0x79, 0x20, 0x24, 0xd7, 0x3c, 0x10, 0xfc, 0x86, 0x65, 0x2b, 0x91, 0xda, 0xc2, + 0x37, 0x2c, 0xde, 0xdb, 0xd2, 0x87, 0xcf, 0x1b, 0x7e, 0x94, 0x53, 0x5e, 0xc9, 0xd2, 0xe5, 0x67, + 0x83, 0x2a, 0x8f, 0x4d, 0x55, 0x09, 0x0f, 0xc3, 0x7f, 0x5c, 0x9f, 0x50, 0x2a, 0x09, 0x4d, 0x34, + 0xe3, 0xa5, 0x48, 0x9b, 0xa8, 0xf2, 0xf3, 0x2e, 0x01, 0x22, 0xa2, 0xf8, 0xcd, 0x72, 0xc3, 0xe1, + 0x23, 0x18, 0xdc, 0xb2, 0x32, 0xe7, 0xb7, 0xb1, 0x62, 0x77, 0x64, 0x84, 0x8e, 0xd1, 0xc9, 0x4e, + 0x04, 0x15, 0x35, 0x67, 0x77, 0x04, 0x3f, 0x81, 0xbe, 0x90, 0x24, 0x63, 0x8a, 0xf1, 0x72, 0xd4, + 0x35, 0xed, 0x9a, 0xf0, 0x9e, 0x42, 0x3f, 0x22, 0x9a, 0x94, 0xc6, 0xeb, 0x00, 0x7a, 0x82, 0x48, + 0xc6, 0x73, 0x6b, 0x63, 0x91, 0xf7, 0x15, 0xc1, 0x70, 0xae, 0xb9, 0x4c, 0x28, 0xb9, 0x36, 0x47, + 0xc0, 0x2f, 0x00, 0xe4, 0xdf, 0x0c, 0x66, 0x7a, 0x30, 0x7e, 0xe4, 0x6f, 0x2f, 0xe4, 0xd7, 0xf9, + 0xce, 0x77, 0xef, 0x7f, 0x1e, 0x75, 0xa2, 0xc6, 0x34, 0x3e, 0x85, 0xbe, 0xdc, 0xae, 0x34, 0x81, + 0x06, 0xe3, 0x87, 0x4d, 0xa9, 0x6d, 0x59, 0x65, 0x3d, 0xeb, 0x7d, 0x47, 0xd0, 0xb3, 0xfb, 0x5f, + 0xc1, 0xbe, 0xaa, 0x02, 0xc5, 0x95, 0xd2, 0x66, 0x78, 0x5c, 0x1b, 0xb5, 0x02, 0x47, 0x43, 0xd5, + 0xca, 0x7f, 0x09, 0x0f, 0x1a, 0x87, 0x8d, 0xf5, 0x4a, 0x10, 0x35, 0xea, 0x1e, 0xef, 0x9c, 0xec, + 0x8f, 0x5d, 0xbf, 0xf5, 0x00, 0xfe, 0x59, 0x8d, 0x16, 0x2b, 0x41, 0x22, 0x27, 0x69, 0x13, 0xea, + 0xd9, 0x4b, 0x80, 0xa9, 0xe4, 0xc2, 0x5a, 0xef, 0xc1, 0x6e, 0x38, 0x0b, 0xdf, 0x38, 0x1d, 0x3c, + 0x84, 0xfe, 0x34, 0x9a, 0x5d, 0xc7, 0x57, 0x1f, 0xe6, 0x0b, 0x07, 0xe1, 0x03, 0xc0, 0x06, 0x5e, + 0xbc, 0x8d, 0x67, 0xe1, 0xfb, 0x8f, 0xf1, 0xd5, 0xd9, 0xe2, 0xf5, 0x3b, 0xa7, 0x7b, 0x7e, 0x71, + 0xbf, 0x76, 0xd1, 0x8f, 0xb5, 0x8b, 0x7e, 0xad, 0x5d, 0xf4, 0xed, 0xb7, 0xdb, 0xf9, 0x74, 0xfa, + 0x9f, 0x1f, 0x36, 0xed, 0x19, 0x3c, 0xf9, 0x13, 0x00, 0x00, 0xff, 0xff, 0x16, 0x63, 0x9d, 0x5c, + 0xf2, 0x02, 0x00, 0x00, } diff --git a/src/metrics/generated/proto/policypb/policy.proto b/src/metrics/generated/proto/policypb/policy.proto index a3e183a001..0d6ca47fdc 100644 --- a/src/metrics/generated/proto/policypb/policy.proto +++ b/src/metrics/generated/proto/policypb/policy.proto @@ -24,6 +24,7 @@ option go_package = "github.com/m3db/m3/src/metrics/generated/proto/policypb"; package policypb; +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; import "github.com/m3db/m3/src/metrics/generated/proto/aggregationpb/aggregation.proto"; message Resolution { @@ -36,8 +37,8 @@ message Retention { } message StoragePolicy { - Resolution resolution = 1; - Retention retention = 2; + Resolution resolution = 1 [(gogoproto.nullable) = false]; + Retention retention = 2 [(gogoproto.nullable) = false]; } message Policy { diff --git a/src/metrics/integration/match_rule_update_stress_test.go b/src/metrics/integration/match_rule_update_stress_test.go index fb4603bd7e..7fda3c0938 100644 --- a/src/metrics/integration/match_rule_update_stress_test.go +++ b/src/metrics/integration/match_rule_update_stress_test.go @@ -327,11 +327,11 @@ func stressTestMappingRulesConfig() []*rulepb.MappingRule { Filter: "mtagName1:mtagValue1", StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(10 * time.Second), Precision: int64(time.Second), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(24 * time.Hour), }, }, @@ -368,11 +368,11 @@ func stressTestRollupRulesConfig() []*rulepb.RollupRule { }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(time.Minute), Precision: int64(time.Minute), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(48 * time.Hour), }, }, diff --git a/src/metrics/metadata/metadata_test.go b/src/metrics/metadata/metadata_test.go index abd8087061..d1d834b8d0 100644 --- a/src/metrics/metadata/metadata_test.go +++ b/src/metrics/metadata/metadata_test.go @@ -239,11 +239,11 @@ var ( testSmallForwardMetadataProto = metricpb.ForwardMetadata{ AggregationId: aggregationpb.AggregationID{Id: 0}, StoragePolicy: policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Minute.Nanoseconds(), Precision: time.Minute.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: (12 * time.Hour).Nanoseconds(), }, }, @@ -264,11 +264,11 @@ var ( testLargeForwardMetadataProto = metricpb.ForwardMetadata{ AggregationId: aggregationpb.AggregationID{Id: aggregation.MustCompressTypes(aggregation.Sum)[0]}, StoragePolicy: policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: 10 * time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: (6 * time.Hour).Nanoseconds(), }, }, @@ -297,11 +297,11 @@ var ( AggregationId: aggregationpb.AggregationID{Id: 0}, StoragePolicies: []policypb.StoragePolicy{ { - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Minute.Nanoseconds(), Precision: time.Minute.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: (6 * time.Hour).Nanoseconds(), }, }, @@ -321,20 +321,20 @@ var ( AggregationId: aggregationpb.AggregationID{Id: 0}, StoragePolicies: []policypb.StoragePolicy{ { - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Minute.Nanoseconds(), Precision: time.Minute.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: (12 * time.Hour).Nanoseconds(), }, }, { - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Hour.Nanoseconds(), Precision: time.Hour.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: (30 * 24 * time.Hour).Nanoseconds(), }, }, @@ -373,11 +373,11 @@ var ( AggregationId: aggregationpb.AggregationID{Id: aggregation.MustCompressTypes(aggregation.Sum)[0]}, StoragePolicies: []policypb.StoragePolicy{ { - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: time.Hour.Nanoseconds(), }, }, @@ -387,11 +387,11 @@ var ( AggregationId: aggregationpb.AggregationID{Id: 0}, StoragePolicies: []policypb.StoragePolicy{ { - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: 10 * time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: time.Hour.Nanoseconds(), }, }, @@ -428,11 +428,11 @@ var ( AggregationId: aggregationpb.AggregationID{Id: aggregation.MustCompressTypes(aggregation.Count)[0]}, StoragePolicies: []policypb.StoragePolicy{ { - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: time.Hour.Nanoseconds(), }, }, @@ -442,20 +442,20 @@ var ( AggregationId: aggregationpb.AggregationID{Id: 0}, StoragePolicies: []policypb.StoragePolicy{ { - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Minute.Nanoseconds(), Precision: time.Minute.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: (6 * time.Hour).Nanoseconds(), }, }, { - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Hour.Nanoseconds(), Precision: time.Hour.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: (30 * 24 * time.Hour).Nanoseconds(), }, }, diff --git a/src/metrics/metric/aggregated/types_test.go b/src/metrics/metric/aggregated/types_test.go index 5448d730f9..9d27d8de02 100644 --- a/src/metrics/metric/aggregated/types_test.go +++ b/src/metrics/metric/aggregated/types_test.go @@ -142,11 +142,11 @@ var ( testForwardMetadata1Proto = metricpb.ForwardMetadata{ AggregationId: aggregationpb.AggregationID{Id: 0}, StoragePolicy: policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Minute.Nanoseconds(), Precision: time.Minute.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: (12 * time.Hour).Nanoseconds(), }, }, @@ -167,11 +167,11 @@ var ( testForwardMetadata2Proto = metricpb.ForwardMetadata{ AggregationId: aggregationpb.AggregationID{Id: aggregation.MustCompressTypes(aggregation.Sum)[0]}, StoragePolicy: policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: 10 * time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: (6 * time.Hour).Nanoseconds(), }, }, diff --git a/src/metrics/metric/unaggregated/types_test.go b/src/metrics/metric/unaggregated/types_test.go index 228f22a662..bc770be87f 100644 --- a/src/metrics/metric/unaggregated/types_test.go +++ b/src/metrics/metric/unaggregated/types_test.go @@ -190,11 +190,11 @@ var ( AggregationId: aggregationpb.AggregationID{Id: aggregation.MustCompressTypes(aggregation.Count)[0]}, StoragePolicies: []policypb.StoragePolicy{ { - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: time.Hour.Nanoseconds(), }, }, @@ -204,20 +204,20 @@ var ( AggregationId: aggregationpb.AggregationID{Id: 0}, StoragePolicies: []policypb.StoragePolicy{ { - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Minute.Nanoseconds(), Precision: time.Minute.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: (6 * time.Hour).Nanoseconds(), }, }, { - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Hour.Nanoseconds(), Precision: time.Hour.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: (30 * 24 * time.Hour).Nanoseconds(), }, }, diff --git a/src/metrics/policy/policy_test.go b/src/metrics/policy/policy_test.go index 2ddd3d77ea..11709ba9b7 100644 --- a/src/metrics/policy/policy_test.go +++ b/src/metrics/policy/policy_test.go @@ -135,11 +135,11 @@ func TestNewPoliciesFromProto(t *testing.T) { input := []*policypb.Policy{ &policypb.Policy{ StoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(10 * time.Second), Precision: int64(time.Second), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(24 * time.Hour), }, }, @@ -150,11 +150,11 @@ func TestNewPoliciesFromProto(t *testing.T) { }, &policypb.Policy{ StoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(time.Minute), Precision: int64(time.Minute), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(240 * time.Hour), }, }, @@ -182,11 +182,11 @@ func TestParsePolicyIntoProto(t *testing.T) { str: "1s:1h", expected: &policypb.Policy{ StoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: time.Hour.Nanoseconds(), }, }, @@ -196,11 +196,11 @@ func TestParsePolicyIntoProto(t *testing.T) { str: "1s:1h|Mean", expected: &policypb.Policy{ StoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: time.Hour.Nanoseconds(), }, }, @@ -211,11 +211,11 @@ func TestParsePolicyIntoProto(t *testing.T) { str: "60s:24h|Mean,Count", expected: &policypb.Policy{ StoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Minute.Nanoseconds(), Precision: time.Minute.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 24 * time.Hour.Nanoseconds(), }, }, @@ -226,11 +226,11 @@ func TestParsePolicyIntoProto(t *testing.T) { str: "1m:1d|Count,Mean", expected: &policypb.Policy{ StoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Minute.Nanoseconds(), Precision: time.Minute.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 24 * time.Hour.Nanoseconds(), }, }, @@ -241,11 +241,11 @@ func TestParsePolicyIntoProto(t *testing.T) { str: "1m@1s:1h|P999,P9999", expected: &policypb.Policy{ StoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Minute.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: time.Hour.Nanoseconds(), }, }, diff --git a/src/metrics/policy/resolution.go b/src/metrics/policy/resolution.go index c2cf1cb829..290ff8e36c 100644 --- a/src/metrics/policy/resolution.go +++ b/src/metrics/policy/resolution.go @@ -36,7 +36,8 @@ const ( var ( emptyResolution Resolution - errNilResolutionProto = errors.New("nil resolution proto message") + emptyResolutionProto = policypb.Resolution{} + errNilResolutionProto = errors.New("empty resolution proto message") ) // Resolution is the sampling resolution for datapoints. @@ -60,8 +61,8 @@ func (r Resolution) ToProto(pb *policypb.Resolution) error { } // FromProto converts the protobuf message to a resolution in place. -func (r *Resolution) FromProto(pb *policypb.Resolution) error { - if pb == nil { +func (r *Resolution) FromProto(pb policypb.Resolution) error { + if pb == emptyResolutionProto { return errNilResolutionProto } precision, err := xtime.UnitFromDuration(time.Duration(pb.Precision)) diff --git a/src/metrics/policy/retention.go b/src/metrics/policy/retention.go index 064b3abd22..cde4b23ae9 100644 --- a/src/metrics/policy/retention.go +++ b/src/metrics/policy/retention.go @@ -30,7 +30,8 @@ import ( ) var ( - errNilRetentionProto = errors.New("nil retention proto message") + errNilRetentionProto = errors.New("empty retention proto message") + emptyRetentionProto = policypb.Retention{} ) // Retention is the retention period for datapoints. @@ -52,8 +53,8 @@ func (r Retention) ToProto(pb *policypb.Retention) { } // FromProto converts the protobuf message to a retention in place. -func (r *Retention) FromProto(pb *policypb.Retention) error { - if pb == nil { +func (r *Retention) FromProto(pb policypb.Retention) error { + if pb == emptyRetentionProto { return errNilRetentionProto } *r = Retention(pb.Period) diff --git a/src/metrics/policy/storage_policy.go b/src/metrics/policy/storage_policy.go index 1c4221a22e..3d8e2905c0 100644 --- a/src/metrics/policy/storage_policy.go +++ b/src/metrics/policy/storage_policy.go @@ -107,16 +107,10 @@ func (p StoragePolicy) Proto() (*policypb.StoragePolicy, error) { // ToProto converts the storage policy to a protobuf message in place. func (p StoragePolicy) ToProto(pb *policypb.StoragePolicy) error { - if pb.Resolution == nil { - pb.Resolution = &policypb.Resolution{} - } - if err := p.resolution.ToProto(pb.Resolution); err != nil { + if err := p.resolution.ToProto(&pb.Resolution); err != nil { return err } - if pb.Retention == nil { - pb.Retention = &policypb.Retention{} - } - p.retention.ToProto(pb.Retention) + p.retention.ToProto(&pb.Retention) return nil } diff --git a/src/metrics/policy/storage_policy_test.go b/src/metrics/policy/storage_policy_test.go index 3390d8a604..f00f67928d 100644 --- a/src/metrics/policy/storage_policy_test.go +++ b/src/metrics/policy/storage_policy_test.go @@ -38,31 +38,31 @@ var ( testStoragePolicy = NewStoragePolicy(10*time.Second, xtime.Second, time.Hour) testBadStoragePolicy = NewStoragePolicy(10*time.Second, xtime.Unit(100), time.Hour) testStoragePolicyProto = policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: (10 * time.Second).Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: time.Hour.Nanoseconds(), }, } testStoragePolicyProtoNoResolution = policypb.StoragePolicy{ - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: time.Hour.Nanoseconds(), }, } testStoragePolicyProtoNoRetention = policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: (10 * time.Second).Nanoseconds(), Precision: time.Second.Nanoseconds(), }, } testStoragePolicyProtoBadPrecision = policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: (10 * time.Second).Nanoseconds(), Precision: 2, }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: time.Hour.Nanoseconds(), }, } @@ -407,11 +407,11 @@ func TestNewStoragePolicyFromProto(t *testing.T) { }{ { s: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(10 * time.Second), Precision: int64(time.Second), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(24 * time.Hour), }, }, @@ -419,11 +419,11 @@ func TestNewStoragePolicyFromProto(t *testing.T) { }, { s: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(time.Minute), Precision: int64(time.Minute), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(240 * time.Hour), }, }, diff --git a/src/metrics/rules/convert_test.go b/src/metrics/rules/convert_test.go index d5c595a273..3f6512e426 100644 --- a/src/metrics/rules/convert_test.go +++ b/src/metrics/rules/convert_test.go @@ -52,8 +52,8 @@ func TestToAggregationIDAndStoragePoliciesInvalidStoragePolicyProto(t *testing.T policiesProto := []*policypb.Policy{ &policypb.Policy{ StoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{Precision: 1234}, - Retention: &policypb.Retention{Period: 5678}, + Resolution: policypb.Resolution{Precision: 1234}, + Retention: policypb.Retention{Period: 5678}, }, }, } @@ -65,11 +65,11 @@ func TestToAggregationIDAndStoragePoliciesInvalidAggregationTypes(t *testing.T) policiesProto := []*policypb.Policy{ &policypb.Policy{ StoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: 10 * time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 24 * time.Hour.Nanoseconds(), }, }, @@ -84,11 +84,11 @@ func TestToAggregationIDAndStoragePoliciesInconsistentAggregationIDs(t *testing. policiesProto := []*policypb.Policy{ &policypb.Policy{ StoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: 10 * time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 24 * time.Hour.Nanoseconds(), }, }, @@ -96,11 +96,11 @@ func TestToAggregationIDAndStoragePoliciesInconsistentAggregationIDs(t *testing. }, &policypb.Policy{ StoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Minute.Nanoseconds(), Precision: time.Minute.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 720 * time.Hour.Nanoseconds(), }, }, @@ -116,33 +116,33 @@ func TestToAggregationIDAndStoragePoliciesDefaultAggregationID(t *testing.T) { policiesProto := []*policypb.Policy{ &policypb.Policy{ StoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: 10 * time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 24 * time.Hour.Nanoseconds(), }, }, }, &policypb.Policy{ StoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Minute.Nanoseconds(), Precision: time.Minute.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 720 * time.Hour.Nanoseconds(), }, }, }, &policypb.Policy{ StoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Hour.Nanoseconds(), Precision: time.Hour.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 365 * 24 * time.Hour.Nanoseconds(), }, }, @@ -163,11 +163,11 @@ func TestToAggregationIDAndStoragePoliciesCustomAggregationID(t *testing.T) { policiesProto := []*policypb.Policy{ &policypb.Policy{ StoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: 10 * time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 24 * time.Hour.Nanoseconds(), }, }, @@ -175,11 +175,11 @@ func TestToAggregationIDAndStoragePoliciesCustomAggregationID(t *testing.T) { }, &policypb.Policy{ StoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Minute.Nanoseconds(), Precision: time.Minute.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 720 * time.Hour.Nanoseconds(), }, }, @@ -187,11 +187,11 @@ func TestToAggregationIDAndStoragePoliciesCustomAggregationID(t *testing.T) { }, &policypb.Policy{ StoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Hour.Nanoseconds(), Precision: time.Hour.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 365 * 24 * time.Hour.Nanoseconds(), }, }, diff --git a/src/metrics/rules/mapping_test.go b/src/metrics/rules/mapping_test.go index a714bcd3be..fb4e6620c2 100644 --- a/src/metrics/rules/mapping_test.go +++ b/src/metrics/rules/mapping_test.go @@ -51,11 +51,11 @@ var ( Policies: []*policypb.Policy{ &policypb.Policy{ StoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(10 * time.Second), Precision: int64(time.Second), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(24 * time.Hour), }, }, @@ -73,11 +73,11 @@ var ( Policies: []*policypb.Policy{ &policypb.Policy{ StoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(time.Minute), Precision: int64(time.Minute), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(24 * time.Hour), }, }, @@ -87,11 +87,11 @@ var ( }, &policypb.Policy{ StoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(5 * time.Minute), Precision: int64(time.Minute), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(48 * time.Hour), }, }, @@ -113,29 +113,29 @@ var ( LastUpdatedBy: "someone", StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: 10 * time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 24 * time.Hour.Nanoseconds(), }, }, &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Minute.Nanoseconds(), Precision: time.Minute.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 720 * time.Hour.Nanoseconds(), }, }, &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Hour.Nanoseconds(), Precision: time.Hour.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 365 * 24 * time.Hour.Nanoseconds(), }, }, @@ -156,11 +156,11 @@ var ( }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: 10 * time.Minute.Nanoseconds(), Precision: time.Minute.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 1800 * time.Hour.Nanoseconds(), }, }, @@ -430,11 +430,11 @@ func TestNewMappingRuleSnapshotStoragePoliciesAndDropPolicy(t *testing.T) { proto := &rulepb.MappingRuleSnapshot{ StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: 10 * time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 24 * time.Hour.Nanoseconds(), }, }, diff --git a/src/metrics/rules/rollup_target_test.go b/src/metrics/rules/rollup_target_test.go index 9cab2fab16..fab69e4dfc 100644 --- a/src/metrics/rules/rollup_target_test.go +++ b/src/metrics/rules/rollup_target_test.go @@ -48,11 +48,11 @@ func TestNewRollupTargetV1ProtoInvalidProto(t *testing.T) { Policies: []*policypb.Policy{ &policypb.Policy{ StoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: 10 * time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 24 * time.Hour.Nanoseconds(), }, }, @@ -71,33 +71,33 @@ func TestNewRollupTargetV1ProtoWithDefaultAggregationID(t *testing.T) { Policies: []*policypb.Policy{ &policypb.Policy{ StoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: 10 * time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 24 * time.Hour.Nanoseconds(), }, }, }, &policypb.Policy{ StoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Minute.Nanoseconds(), Precision: time.Minute.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 720 * time.Hour.Nanoseconds(), }, }, }, &policypb.Policy{ StoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Hour.Nanoseconds(), Precision: time.Hour.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 365 * 24 * time.Hour.Nanoseconds(), }, }, @@ -134,11 +134,11 @@ func TestNewRollupTargetV1ProtoWithCustomAggregationID(t *testing.T) { Policies: []*policypb.Policy{ &policypb.Policy{ StoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: 10 * time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 24 * time.Hour.Nanoseconds(), }, }, @@ -146,11 +146,11 @@ func TestNewRollupTargetV1ProtoWithCustomAggregationID(t *testing.T) { }, &policypb.Policy{ StoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Minute.Nanoseconds(), Precision: time.Minute.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 720 * time.Hour.Nanoseconds(), }, }, @@ -158,11 +158,11 @@ func TestNewRollupTargetV1ProtoWithCustomAggregationID(t *testing.T) { }, &policypb.Policy{ StoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Hour.Nanoseconds(), Precision: time.Hour.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 365 * 24 * time.Hour.Nanoseconds(), }, }, @@ -229,8 +229,8 @@ func TestNewRollupTargetV2ProtoInvalidStoragePoliciesProto(t *testing.T) { }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{Precision: 1234}, - Retention: &policypb.Retention{Period: 5678}, + Resolution: policypb.Resolution{Precision: 1234}, + Retention: policypb.Retention{Period: 5678}, }, }, } @@ -269,29 +269,29 @@ func TestNewRollupTargetV2Proto(t *testing.T) { }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: 10 * time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 24 * time.Hour.Nanoseconds(), }, }, &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Minute.Nanoseconds(), Precision: time.Minute.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 720 * time.Hour.Nanoseconds(), }, }, &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Hour.Nanoseconds(), Precision: time.Hour.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 365 * 24 * time.Hour.Nanoseconds(), }, }, @@ -472,29 +472,29 @@ func TestRollupTargetProto(t *testing.T) { }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: 10 * time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 24 * time.Hour.Nanoseconds(), }, }, &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Minute.Nanoseconds(), Precision: time.Minute.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 720 * time.Hour.Nanoseconds(), }, }, &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Hour.Nanoseconds(), Precision: time.Hour.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 365 * 24 * time.Hour.Nanoseconds(), }, }, diff --git a/src/metrics/rules/rollup_test.go b/src/metrics/rules/rollup_test.go index 3bbf8add9c..0a2655290a 100644 --- a/src/metrics/rules/rollup_test.go +++ b/src/metrics/rules/rollup_test.go @@ -60,11 +60,11 @@ var ( Policies: []*policypb.Policy{ &policypb.Policy{ StoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(10 * time.Second), Precision: int64(time.Second), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(24 * time.Hour), }, }, @@ -88,11 +88,11 @@ var ( Policies: []*policypb.Policy{ &policypb.Policy{ StoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(time.Minute), Precision: int64(time.Minute), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(24 * time.Hour), }, }, @@ -102,11 +102,11 @@ var ( }, &policypb.Policy{ StoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(5 * time.Minute), Precision: int64(time.Minute), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(48 * time.Hour), }, }, @@ -157,29 +157,29 @@ var ( }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: 10 * time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 24 * time.Hour.Nanoseconds(), }, }, &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Minute.Nanoseconds(), Precision: time.Minute.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 720 * time.Hour.Nanoseconds(), }, }, &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Hour.Nanoseconds(), Precision: time.Hour.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 365 * 24 * time.Hour.Nanoseconds(), }, }, @@ -205,11 +205,11 @@ var ( }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: time.Minute.Nanoseconds(), Precision: time.Minute.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 720 * time.Hour.Nanoseconds(), }, }, @@ -243,11 +243,11 @@ var ( }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: 10 * time.Minute.Nanoseconds(), Precision: time.Minute.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 1800 * time.Hour.Nanoseconds(), }, }, @@ -490,11 +490,11 @@ func TestNewRollupRuleSnapshotFromV2ProtoInvalidProto(t *testing.T) { }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: 10 * time.Minute.Nanoseconds(), Precision: time.Minute.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 1800 * time.Hour.Nanoseconds(), }, }, diff --git a/src/metrics/rules/ruleset_test.go b/src/metrics/rules/ruleset_test.go index 1b4a4d5bc1..a1f55f1a92 100644 --- a/src/metrics/rules/ruleset_test.go +++ b/src/metrics/rules/ruleset_test.go @@ -1430,11 +1430,11 @@ func testMappingRulesConfig() []*rulepb.MappingRule { Filter: "mtagName1:mtagValue1", StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: 10 * time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 24 * time.Hour.Nanoseconds(), }, }, @@ -1448,29 +1448,29 @@ func testMappingRulesConfig() []*rulepb.MappingRule { Filter: "mtagName1:mtagValue1", StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: 10 * time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 6 * time.Hour.Nanoseconds(), }, }, &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: 5 * time.Minute.Nanoseconds(), Precision: time.Minute.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 48 * time.Hour.Nanoseconds(), }, }, &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: 10 * time.Minute.Nanoseconds(), Precision: time.Minute.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 48 * time.Hour.Nanoseconds(), }, }, @@ -1484,11 +1484,11 @@ func testMappingRulesConfig() []*rulepb.MappingRule { Filter: "mtagName1:mtagValue1", StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: 30 * time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 6 * time.Hour.Nanoseconds(), }, }, @@ -1507,11 +1507,11 @@ func testMappingRulesConfig() []*rulepb.MappingRule { Filter: "mtagName1:mtagValue1", StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: 10 * time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 12 * time.Hour.Nanoseconds(), }, }, @@ -1528,20 +1528,20 @@ func testMappingRulesConfig() []*rulepb.MappingRule { }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: 10 * time.Second.Nanoseconds(), Precision: time.Second.Nanoseconds(), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: 2 * time.Hour.Nanoseconds(), }, }, &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(time.Minute), Precision: int64(time.Minute), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(time.Hour), }, }, @@ -1558,20 +1558,20 @@ func testMappingRulesConfig() []*rulepb.MappingRule { }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(10 * time.Second), Precision: int64(time.Second), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(2 * time.Hour), }, }, &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(time.Minute), Precision: int64(time.Minute), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(time.Hour), }, }, @@ -1593,20 +1593,20 @@ func testMappingRulesConfig() []*rulepb.MappingRule { }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(10 * time.Second), Precision: int64(time.Second), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(12 * time.Hour), }, }, &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(5 * time.Minute), Precision: int64(time.Minute), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(48 * time.Hour), }, }, @@ -1620,20 +1620,20 @@ func testMappingRulesConfig() []*rulepb.MappingRule { Filter: "mtagName1:mtagValue1", StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(10 * time.Second), Precision: int64(time.Second), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(2 * time.Hour), }, }, &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(time.Minute), Precision: int64(time.Minute), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(time.Hour), }, }, @@ -1655,11 +1655,11 @@ func testMappingRulesConfig() []*rulepb.MappingRule { }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(10 * time.Second), Precision: int64(time.Second), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(24 * time.Hour), }, }, @@ -1680,11 +1680,11 @@ func testMappingRulesConfig() []*rulepb.MappingRule { Filter: "mtagName1:mtagValue1", StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(10 * time.Second), Precision: int64(time.Second), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(24 * time.Hour), }, }, @@ -1721,11 +1721,11 @@ func testRollupRulesConfig() []*rulepb.RollupRule { }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(10 * time.Second), Precision: int64(time.Second), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(24 * time.Hour), }, }, @@ -1753,29 +1753,29 @@ func testRollupRulesConfig() []*rulepb.RollupRule { }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(10 * time.Second), Precision: int64(time.Second), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(6 * time.Hour), }, }, &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(5 * time.Minute), Precision: int64(time.Minute), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(48 * time.Hour), }, }, &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(10 * time.Minute), Precision: int64(time.Minute), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(48 * time.Hour), }, }, @@ -1803,11 +1803,11 @@ func testRollupRulesConfig() []*rulepb.RollupRule { }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(30 * time.Second), Precision: int64(time.Second), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(6 * time.Hour), }, }, @@ -1840,11 +1840,11 @@ func testRollupRulesConfig() []*rulepb.RollupRule { }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(10 * time.Second), Precision: int64(time.Second), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(12 * time.Hour), }, }, @@ -1872,20 +1872,20 @@ func testRollupRulesConfig() []*rulepb.RollupRule { }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(10 * time.Second), Precision: int64(time.Second), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(2 * time.Hour), }, }, &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(time.Minute), Precision: int64(time.Minute), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(time.Hour), }, }, @@ -1913,11 +1913,11 @@ func testRollupRulesConfig() []*rulepb.RollupRule { }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(time.Minute), Precision: int64(time.Minute), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(time.Hour), }, }, @@ -1950,29 +1950,29 @@ func testRollupRulesConfig() []*rulepb.RollupRule { }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(10 * time.Second), Precision: int64(time.Second), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(12 * time.Hour), }, }, &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(time.Minute), Precision: int64(time.Minute), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(24 * time.Hour), }, }, &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(5 * time.Minute), Precision: int64(time.Minute), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(48 * time.Hour), }, }, @@ -1992,11 +1992,11 @@ func testRollupRulesConfig() []*rulepb.RollupRule { }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(10 * time.Second), Precision: int64(time.Second), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(24 * time.Hour), }, }, @@ -2024,20 +2024,20 @@ func testRollupRulesConfig() []*rulepb.RollupRule { }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(10 * time.Second), Precision: int64(time.Second), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(2 * time.Hour), }, }, &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(time.Minute), Precision: int64(time.Minute), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(time.Hour), }, }, @@ -2070,11 +2070,11 @@ func testRollupRulesConfig() []*rulepb.RollupRule { }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(time.Minute), Precision: int64(time.Minute), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(time.Hour), }, }, @@ -2107,11 +2107,11 @@ func testRollupRulesConfig() []*rulepb.RollupRule { }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(time.Second), Precision: int64(time.Second), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(time.Minute), }, }, @@ -2144,11 +2144,11 @@ func testRollupRulesConfig() []*rulepb.RollupRule { }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(time.Minute), Precision: int64(time.Minute), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(time.Hour), }, }, diff --git a/src/metrics/rules/store/kv/store_test.go b/src/metrics/rules/store/kv/store_test.go index fa1551131e..0286840125 100644 --- a/src/metrics/rules/store/kv/store_test.go +++ b/src/metrics/rules/store/kv/store_test.go @@ -96,11 +96,11 @@ var ( Filter: "tag1:value1 tag2:value2", StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(10 * time.Second), Precision: int64(time.Second), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(24 * time.Hour), }, }, @@ -119,20 +119,20 @@ var ( Filter: "tag3:value3 tag4:value4", StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(time.Minute), Precision: int64(time.Minute), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(24 * time.Hour), }, }, &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(5 * time.Minute), Precision: int64(time.Minute), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(48 * time.Hour), }, }, @@ -159,11 +159,11 @@ var ( }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(10 * time.Second), Precision: int64(time.Second), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(24 * time.Hour), }, }, @@ -202,11 +202,11 @@ var ( }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(10 * time.Second), Precision: int64(time.Second), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(24 * time.Hour), }, }, @@ -237,20 +237,20 @@ var ( }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(10 * time.Second), Precision: int64(time.Second), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(24 * time.Hour), }, }, &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(5 * time.Minute), Precision: int64(time.Minute), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(48 * time.Hour), }, }, @@ -283,11 +283,11 @@ var ( }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(10 * time.Second), Precision: int64(time.Second), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(24 * time.Hour), }, }, @@ -318,20 +318,20 @@ var ( }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(time.Minute), Precision: int64(time.Minute), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(24 * time.Hour), }, }, &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(5 * time.Minute), Precision: int64(time.Minute), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(48 * time.Hour), }, }, @@ -365,11 +365,11 @@ var ( }, StoragePolicies: []*policypb.StoragePolicy{ &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(10 * time.Second), Precision: int64(time.Second), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(24 * time.Hour), }, }, diff --git a/src/query/remote/codecs_test.go b/src/query/remote/codecs_test.go index 03dcc49006..fc3ea85932 100644 --- a/src/query/remote/codecs_test.go +++ b/src/query/remote/codecs_test.go @@ -261,11 +261,11 @@ func TestNewRestrictQueryOptionsFromProto(t *testing.T) { RestrictQueryType: &rpcpb.RestrictQueryType{ MetricsType: rpcpb.MetricsType_AGGREGATED_METRICS_TYPE, MetricsStoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(time.Minute), Precision: int64(time.Second), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(24 * time.Hour), }, }, @@ -312,11 +312,11 @@ func TestNewRestrictQueryOptionsFromProto(t *testing.T) { RestrictQueryType: &rpcpb.RestrictQueryType{ MetricsType: rpcpb.MetricsType_UNAGGREGATED_METRICS_TYPE, MetricsStoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(time.Minute), Precision: int64(time.Second), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(24 * time.Hour), }, }, @@ -329,7 +329,7 @@ func TestNewRestrictQueryOptionsFromProto(t *testing.T) { RestrictQueryType: &rpcpb.RestrictQueryType{ MetricsType: rpcpb.MetricsType_AGGREGATED_METRICS_TYPE, MetricsStoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: -1, }, }, @@ -342,7 +342,7 @@ func TestNewRestrictQueryOptionsFromProto(t *testing.T) { RestrictQueryType: &rpcpb.RestrictQueryType{ MetricsType: rpcpb.MetricsType_AGGREGATED_METRICS_TYPE, MetricsStoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(time.Minute), Precision: int64(-1), }, @@ -356,11 +356,11 @@ func TestNewRestrictQueryOptionsFromProto(t *testing.T) { RestrictQueryType: &rpcpb.RestrictQueryType{ MetricsType: rpcpb.MetricsType_AGGREGATED_METRICS_TYPE, MetricsStoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(time.Minute), Precision: int64(time.Second), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(-1), }, }, @@ -450,11 +450,11 @@ func TestRestrictQueryOptionsProto(t *testing.T) { RestrictQueryType: &rpcpb.RestrictQueryType{ MetricsType: rpcpb.MetricsType_AGGREGATED_METRICS_TYPE, MetricsStoragePolicy: &policypb.StoragePolicy{ - Resolution: &policypb.Resolution{ + Resolution: policypb.Resolution{ WindowSize: int64(time.Minute), Precision: int64(time.Second), }, - Retention: &policypb.Retention{ + Retention: policypb.Retention{ Period: int64(24 * time.Hour), }, }, From 7163b265b5836013125a3cfc184c6c932df29e14 Mon Sep 17 00:00:00 2001 From: Vytenis Darulis Date: Thu, 29 Oct 2020 20:28:30 -0400 Subject: [PATCH 2/4] fix date --- .../encoding/protobuf/aggregated_decoder_benchmark_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/metrics/encoding/protobuf/aggregated_decoder_benchmark_test.go b/src/metrics/encoding/protobuf/aggregated_decoder_benchmark_test.go index 530e63d4a3..1481f9b1ea 100644 --- a/src/metrics/encoding/protobuf/aggregated_decoder_benchmark_test.go +++ b/src/metrics/encoding/protobuf/aggregated_decoder_benchmark_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2018 Uber Technologies, Inc. +// Copyright (c) 2020 Uber Technologies, Inc. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal From d27e602ecb0c0e577b577ae3821d300708d508ac Mon Sep 17 00:00:00 2001 From: Vytenis Darulis Date: Thu, 29 Oct 2020 20:54:59 -0400 Subject: [PATCH 3/4] feedback --- .../aggregator/handler/writer/protobuf_test.go | 5 ++--- .../server/m3msg/protobuf_handler.go | 13 +------------ .../encoding/protobuf/aggregated_decoder.go | 16 +++++++--------- .../aggregated_decoder_benchmark_test.go | 5 +---- .../protobuf/aggregated_roundtrip_test.go | 12 ++++-------- 5 files changed, 15 insertions(+), 36 deletions(-) diff --git a/src/aggregator/aggregator/handler/writer/protobuf_test.go b/src/aggregator/aggregator/handler/writer/protobuf_test.go index 727be98b27..8fe686d8d2 100644 --- a/src/aggregator/aggregator/handler/writer/protobuf_test.go +++ b/src/aggregator/aggregator/handler/writer/protobuf_test.go @@ -121,10 +121,9 @@ func TestProtobufWriterWrite(t *testing.T) { actualData := make(map[uint32][]decodeData) writer.p.(*producer.MockProducer).EXPECT().Produce(gomock.Any()).Do(func(m producer.Message) error { d := protobuf.NewAggregatedDecoder(nil) - d.Decode(m.Bytes()) + require.NoError(t, d.Decode(m.Bytes())) s := m.Shard() - sp, err := d.StoragePolicy() - require.NoError(t, err) + sp := d.StoragePolicy() actualData[s] = append(actualData[s], decodeData{ MetricWithStoragePolicy: aggregated.MetricWithStoragePolicy{ Metric: aggregated.Metric{ diff --git a/src/cmd/services/m3coordinator/server/m3msg/protobuf_handler.go b/src/cmd/services/m3coordinator/server/m3msg/protobuf_handler.go index 7589b95595..ffca0e0c1d 100644 --- a/src/cmd/services/m3coordinator/server/m3msg/protobuf_handler.go +++ b/src/cmd/services/m3coordinator/server/m3msg/protobuf_handler.go @@ -47,7 +47,6 @@ type handlerMetrics struct { metricAccepted tally.Counter droppedMetricBlackholePolicy tally.Counter droppedMetricDecodeError tally.Counter - droppedMetricDecodeMalformed tally.Counter } func newHandlerMetrics(scope tally.Scope) handlerMetrics { @@ -61,9 +60,6 @@ func newHandlerMetrics(scope tally.Scope) handlerMetrics { droppedMetricBlackholePolicy: messageScope.Tagged(map[string]string{ "reason": "blackhole-policy", }).Counter("dropped"), - droppedMetricDecodeMalformed: messageScope.Tagged(map[string]string{ - "reason": "decode-malformed", - }).Counter("dropped"), } } @@ -111,18 +107,11 @@ func (h *pbHandler) Process(msg consumer.Message) { h.m.droppedMetricDecodeError.Inc(1) return } - sp, err := dec.StoragePolicy() - if err != nil { - h.logger.Error("invalid storage policy", zap.Error(err)) - h.m.droppedMetricDecodeMalformed.Inc(1) - return - } - h.m.metricAccepted.Inc(1) h.wg.Add(1) r := NewProtobufCallback(msg, dec, h.wg) - + sp := dec.StoragePolicy() // If storage policy is blackholed, ack the message immediately and don't // bother passing down the write path. for _, blackholeSp := range h.blackholePolicies { diff --git a/src/metrics/encoding/protobuf/aggregated_decoder.go b/src/metrics/encoding/protobuf/aggregated_decoder.go index 3f1cc5b890..ca9052c44c 100644 --- a/src/metrics/encoding/protobuf/aggregated_decoder.go +++ b/src/metrics/encoding/protobuf/aggregated_decoder.go @@ -27,10 +27,9 @@ import ( // AggregatedDecoder is a decoder for decoding aggregated metrics. type AggregatedDecoder struct { - pool AggregatedDecoderPool - pb metricpb.AggregatedMetric - sp policy.StoragePolicy - spErr error + pool AggregatedDecoderPool + pb metricpb.AggregatedMetric + sp policy.StoragePolicy } // NewAggregatedDecoder creates an aggregated decoder. @@ -45,8 +44,7 @@ func (d *AggregatedDecoder) Decode(b []byte) error { if err := d.pb.Unmarshal(b); err != nil { return err } - d.spErr = d.sp.FromProto(d.pb.Metric.StoragePolicy) - return nil + return d.sp.FromProto(d.pb.Metric.StoragePolicy) } // ID returns the decoded id. @@ -65,8 +63,8 @@ func (d AggregatedDecoder) Value() float64 { } // StoragePolicy returns the decoded storage policy. -func (d AggregatedDecoder) StoragePolicy() (policy.StoragePolicy, error) { - return d.sp, d.spErr +func (d AggregatedDecoder) StoragePolicy() policy.StoragePolicy { + return d.sp } // EncodeNanos returns the decoded encodeNanos. @@ -76,7 +74,7 @@ func (d AggregatedDecoder) EncodeNanos() int64 { // Close closes the decoder. func (d *AggregatedDecoder) Close() { - d.sp, d.spErr = policy.StoragePolicy{}, nil + d.sp = policy.StoragePolicy{} ReuseAggregatedMetricProto(&d.pb) if d.pool != nil { d.pool.Put(d) diff --git a/src/metrics/encoding/protobuf/aggregated_decoder_benchmark_test.go b/src/metrics/encoding/protobuf/aggregated_decoder_benchmark_test.go index 1481f9b1ea..56e83b4891 100644 --- a/src/metrics/encoding/protobuf/aggregated_decoder_benchmark_test.go +++ b/src/metrics/encoding/protobuf/aggregated_decoder_benchmark_test.go @@ -32,7 +32,6 @@ func BenchmarkDecodeStoragePolicy(b *testing.B) { enc = NewAggregatedEncoder(nil) dec = NewAggregatedDecoder(nil) sp policy.StoragePolicy - err error ) if err := enc.Encode(testAggregatedMetric1, 2000); err != nil { b.Fatal(err) @@ -43,9 +42,7 @@ func BenchmarkDecodeStoragePolicy(b *testing.B) { for i := 0; i < b.N; i++ { _ = dec.Decode(buf) - if sp, err = dec.StoragePolicy(); err != nil { - b.FailNow() - } + sp = dec.StoragePolicy() dec.Close() } runtime.KeepAlive(sp) diff --git a/src/metrics/encoding/protobuf/aggregated_roundtrip_test.go b/src/metrics/encoding/protobuf/aggregated_roundtrip_test.go index f30544e32a..516d41f6e6 100644 --- a/src/metrics/encoding/protobuf/aggregated_roundtrip_test.go +++ b/src/metrics/encoding/protobuf/aggregated_roundtrip_test.go @@ -57,8 +57,7 @@ func TestAggregatedEncoderDecoder_RoundTrip(t *testing.T) { require.NoError(t, enc.Encode(testAggregatedMetric1, 2000)) require.NoError(t, dec.Decode(enc.Buffer().Bytes())) require.Equal(t, int64(2000), dec.EncodeNanos()) - sp, err := dec.StoragePolicy() - require.NoError(t, err) + sp := dec.StoragePolicy() require.Equal(t, testAggregatedMetric1.StoragePolicy, sp) require.Equal(t, string(testAggregatedMetric1.ID), string(dec.ID())) require.Equal(t, testAggregatedMetric1.TimeNanos, dec.TimeNanos()) @@ -77,8 +76,7 @@ func TestAggregatedEncoderDecoder_WithBytesPool(t *testing.T) { require.NoError(t, enc.Encode(testAggregatedMetric1, 2000)) require.NoError(t, dec.Decode(enc.Buffer().Bytes())) require.Equal(t, int64(2000), dec.EncodeNanos()) - sp, err := dec.StoragePolicy() - require.NoError(t, err) + sp := dec.StoragePolicy() require.Equal(t, testAggregatedMetric1.StoragePolicy, sp) require.Equal(t, string(testAggregatedMetric1.ID), string(dec.ID())) require.Equal(t, testAggregatedMetric1.TimeNanos, dec.TimeNanos()) @@ -91,8 +89,7 @@ func TestAggregatedEncoderDecoder_ResetProtobuf(t *testing.T) { require.NoError(t, enc.Encode(testAggregatedMetric1, 2000)) require.NoError(t, dec.Decode(enc.Buffer().Bytes())) require.Equal(t, int64(2000), dec.EncodeNanos()) - sp, err := dec.StoragePolicy() - require.NoError(t, err) + sp := dec.StoragePolicy() require.Equal(t, testAggregatedMetric1.StoragePolicy, sp) require.Equal(t, string(testAggregatedMetric1.ID), string(dec.ID())) require.Equal(t, testAggregatedMetric1.TimeNanos, dec.TimeNanos()) @@ -105,8 +102,7 @@ func TestAggregatedEncoderDecoder_ResetProtobuf(t *testing.T) { require.NoError(t, enc.Encode(testAggregatedMetric2, 3000)) require.NoError(t, dec.Decode(enc.Buffer().Bytes())) require.Equal(t, int64(3000), dec.EncodeNanos()) - sp, err = dec.StoragePolicy() - require.NoError(t, err) + sp = dec.StoragePolicy() require.Equal(t, testAggregatedMetric2.StoragePolicy, sp) require.Equal(t, string(testAggregatedMetric2.ID), string(dec.ID())) require.Equal(t, testAggregatedMetric2.TimeNanos, dec.TimeNanos()) From e7933c34d73a4a82d1edeccfe27f70218cd7269d Mon Sep 17 00:00:00 2001 From: Vytenis Darulis Date: Thu, 29 Oct 2020 21:24:29 -0400 Subject: [PATCH 4/4] regen proto --- .../generated/proto/metricpb/composite.pb.go | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/metrics/generated/proto/metricpb/composite.pb.go b/src/metrics/generated/proto/metricpb/composite.pb.go index c1181345b5..ad2c896bd2 100644 --- a/src/metrics/generated/proto/metricpb/composite.pb.go +++ b/src/metrics/generated/proto/metricpb/composite.pb.go @@ -143,12 +143,10 @@ type BatchTimerWithMetadatas struct { Metadatas StagedMetadatas `protobuf:"bytes,2,opt,name=metadatas" json:"metadatas"` } -func (m *BatchTimerWithMetadatas) Reset() { *m = BatchTimerWithMetadatas{} } -func (m *BatchTimerWithMetadatas) String() string { return proto.CompactTextString(m) } -func (*BatchTimerWithMetadatas) ProtoMessage() {} -func (*BatchTimerWithMetadatas) Descriptor() ([]byte, []int) { - return fileDescriptorComposite, []int{1} -} +func (m *BatchTimerWithMetadatas) Reset() { *m = BatchTimerWithMetadatas{} } +func (m *BatchTimerWithMetadatas) String() string { return proto.CompactTextString(m) } +func (*BatchTimerWithMetadatas) ProtoMessage() {} +func (*BatchTimerWithMetadatas) Descriptor() ([]byte, []int) { return fileDescriptorComposite, []int{1} } func (m *BatchTimerWithMetadatas) GetBatchTimer() BatchTimer { if m != nil { @@ -219,12 +217,10 @@ type TimedMetricWithMetadata struct { Metadata TimedMetadata `protobuf:"bytes,2,opt,name=metadata" json:"metadata"` } -func (m *TimedMetricWithMetadata) Reset() { *m = TimedMetricWithMetadata{} } -func (m *TimedMetricWithMetadata) String() string { return proto.CompactTextString(m) } -func (*TimedMetricWithMetadata) ProtoMessage() {} -func (*TimedMetricWithMetadata) Descriptor() ([]byte, []int) { - return fileDescriptorComposite, []int{4} -} +func (m *TimedMetricWithMetadata) Reset() { *m = TimedMetricWithMetadata{} } +func (m *TimedMetricWithMetadata) String() string { return proto.CompactTextString(m) } +func (*TimedMetricWithMetadata) ProtoMessage() {} +func (*TimedMetricWithMetadata) Descriptor() ([]byte, []int) { return fileDescriptorComposite, []int{4} } func (m *TimedMetricWithMetadata) GetMetric() TimedMetric { if m != nil {