diff --git a/metric/aggregated/types.go b/metric/aggregated/types.go index 62f67a6..e70507e 100644 --- a/metric/aggregated/types.go +++ b/metric/aggregated/types.go @@ -31,8 +31,8 @@ import ( // Metric is a metric, which is essentially a named value at certain time. type Metric struct { metric.ID - TimeNs int64 - Value float64 + TimeNanos int64 + Value float64 } // String is the string representation of a metric. @@ -40,7 +40,7 @@ func (m Metric) String() string { return fmt.Sprintf( "{id:%s,timestamp:%s,value:%f}", m.ID.String(), - time.Unix(0, m.TimeNs).String(), + time.Unix(0, m.TimeNanos).String(), m.Value, ) } @@ -48,8 +48,8 @@ func (m Metric) String() string { // ChunkedMetric is a metric with a chunked ID. type ChunkedMetric struct { metric.ChunkedID - TimeNs int64 - Value float64 + TimeNanos int64 + Value float64 } // RawMetric is a metric in its raw form (e.g., encoded bytes associated with @@ -58,8 +58,8 @@ type RawMetric interface { // ID is the metric identifier. ID() (metric.ID, error) - // TimeNs is the metric timestamp in nanoseconds. - TimeNs() (int64, error) + // TimeNanos is the metric timestamp in nanoseconds. + TimeNanos() (int64, error) // Value is the metric value. Value() (float64, error) diff --git a/policy/policy.go b/policy/policy.go index d7a4c47..31e2216 100644 --- a/policy/policy.go +++ b/policy/policy.go @@ -42,19 +42,18 @@ var ( // EmptyPolicy represents an empty policy. EmptyPolicy Policy - // EmptyStagedPolicies represents an empty staged policies. - EmptyStagedPolicies StagedPolicies - - // DefaultPoliciesList represents a default policies list. - DefaultPoliciesList = PoliciesList{EmptyStagedPolicies} - - // defaultPolicies are the default policies. - // TODO(xichen): possibly make this dynamically configurable in the future. - defaultPolicies = []Policy{ + // DefaultPolicies are the default policies. + DefaultPolicies = []Policy{ NewPolicy(10*time.Second, xtime.Second, 2*24*time.Hour), NewPolicy(time.Minute, xtime.Minute, 30*24*time.Hour), } + // DefaultStagedPolicies represents a default staged policies. + DefaultStagedPolicies StagedPolicies + + // DefaultPoliciesList represents a default policies list. + DefaultPoliciesList = PoliciesList{DefaultStagedPolicies} + errNilPolicySchema = errors.New("nil policy schema") ) @@ -154,7 +153,7 @@ func (pr ByResolutionAsc) Less(i, j int) bool { // StagedPolicies represent a list of policies at a specified version. type StagedPolicies struct { // Cutover is when the policies take effect. - CutoverNs int64 + CutoverNanos int64 // Tombstoned determines whether the associated (rollup) metric has been tombstoned. Tombstoned bool @@ -164,29 +163,34 @@ type StagedPolicies struct { } // NewStagedPolicies create a new staged policies. -func NewStagedPolicies(cutoverNs int64, tombstoned bool, policies []Policy) StagedPolicies { - return StagedPolicies{CutoverNs: cutoverNs, Tombstoned: tombstoned, policies: policies} +func NewStagedPolicies(cutoverNanos int64, tombstoned bool, policies []Policy) StagedPolicies { + return StagedPolicies{CutoverNanos: cutoverNanos, Tombstoned: tombstoned, policies: policies} } // Reset resets the staged policies. -func (p *StagedPolicies) Reset() { *p = EmptyStagedPolicies } +func (p *StagedPolicies) Reset() { *p = DefaultStagedPolicies } -// Policies returns the policies. -func (p StagedPolicies) Policies() []Policy { - if p.hasDefaultPolicies() { - return defaultPolicies - } - return p.policies +// IsDefault returns whether this is a default staged policies. +func (p StagedPolicies) IsDefault() bool { + return p.CutoverNanos == 0 && !p.Tombstoned && p.hasDefaultPolicies() +} + +// Policies returns the policies and whether the policies are the default policies. +func (p StagedPolicies) Policies() ([]Policy, bool) { + return p.policies, p.hasDefaultPolicies() } // SamePolicies returns whether two staged policies have the same policy list, // assuming the policies are sorted in the same order. func (p StagedPolicies) SamePolicies(other StagedPolicies) bool { - if p.hasDefaultPolicies() && other.hasDefaultPolicies() { + currPolicies, currIsDefault := p.Policies() + otherPolicies, otherIsDefault := other.Policies() + if currIsDefault && otherIsDefault { return true } - currPolicies := p.Policies() - otherPolicies := other.Policies() + if currIsDefault || otherIsDefault { + return false + } if len(currPolicies) != len(otherPolicies) { return false } @@ -201,7 +205,7 @@ func (p StagedPolicies) SamePolicies(other StagedPolicies) bool { // String is the representation of staged policies. func (p StagedPolicies) String() string { var buf bytes.Buffer - buf.WriteString(fmt.Sprintf("{cutover:%s,tombstoned:%v,policies:[", time.Unix(0, p.CutoverNs).String(), p.Tombstoned)) + buf.WriteString(fmt.Sprintf("{cutover:%s,tombstoned:%v,policies:[", time.Unix(0, p.CutoverNanos).String(), p.Tombstoned)) for i := range p.policies { buf.WriteString(p.policies[i].String()) if i < len(p.policies)-1 { @@ -212,10 +216,6 @@ func (p StagedPolicies) String() string { return buf.String() } -func (p StagedPolicies) isEmpty() bool { - return p.CutoverNs == 0 && !p.Tombstoned && p.hasDefaultPolicies() -} - func (p StagedPolicies) hasDefaultPolicies() bool { return len(p.policies) == 0 } @@ -225,5 +225,5 @@ type PoliciesList []StagedPolicies // IsDefault determines whether this is a default policies list. func (l PoliciesList) IsDefault() bool { - return len(l) == 1 && l[0].isEmpty() + return len(l) == 1 && l[0].IsDefault() } diff --git a/policy/policy_benchmark_test.go b/policy/policy_benchmark_test.go index 1f6bf02..cf6eec4 100644 --- a/policy/policy_benchmark_test.go +++ b/policy/policy_benchmark_test.go @@ -26,76 +26,76 @@ import ( ) var ( - testNowNs = time.Now().UnixNano() + testNowNanos = time.Now().UnixNano() ) func BenchmarkStagedPoliciesAsStruct(b *testing.B) { - sp := NewStagedPolicies(testNowNs, false, defaultPolicies) + sp := NewStagedPolicies(testNowNanos, false, DefaultPolicies) for n := 0; n < b.N; n++ { validatePolicyByValue(b, sp) } } func BenchmarkStagedPoliciesAsPointer(b *testing.B) { - sp := NewStagedPolicies(testNowNs, false, defaultPolicies) + sp := NewStagedPolicies(testNowNanos, false, DefaultPolicies) for n := 0; n < b.N; n++ { validatePolicyByPointer(b, &sp) } } func BenchmarkStagedPoliciesAsInterface(b *testing.B) { - sp := &testStagedPolicies{cutoverNs: testNowNs, policies: defaultPolicies} + sp := &testStagedPolicies{cutoverNanos: testNowNanos, policies: DefaultPolicies} for n := 0; n < b.N; n++ { validatePolicyByInterface(b, sp) } } func BenchmarkStagedPoliciesAsStructExported(b *testing.B) { - sp := testStagedPolicies{cutoverNs: testNowNs, policies: defaultPolicies} + sp := testStagedPolicies{cutoverNanos: testNowNanos, policies: DefaultPolicies} for n := 0; n < b.N; n++ { validatePolicyByStructExported(b, sp) } } type testStagedPoliciesInt64 interface { - CutoverNs() int64 + CutoverNanos() int64 } // StagedPolicies represent a list of policies at a specified version. type testStagedPolicies struct { - cutoverNs int64 - tombstoned bool - policies []Policy + cutoverNanos int64 + tombstoned bool + policies []Policy } -func (v testStagedPolicies) ValCutoverNs() int64 { - return v.cutoverNs +func (v testStagedPolicies) ValCutoverNanos() int64 { + return v.cutoverNanos } -func (v *testStagedPolicies) CutoverNs() int64 { - return v.cutoverNs +func (v *testStagedPolicies) CutoverNanos() int64 { + return v.cutoverNanos } func validatePolicyByValue(b *testing.B, sp StagedPolicies) { - if sp.CutoverNs != testNowNs { + if sp.CutoverNanos != testNowNanos { b.FailNow() } } func validatePolicyByPointer(b *testing.B, sp *StagedPolicies) { - if sp.CutoverNs != testNowNs { + if sp.CutoverNanos != testNowNanos { b.FailNow() } } func validatePolicyByInterface(b *testing.B, sp testStagedPoliciesInt64) { - if sp.CutoverNs() != testNowNs { + if sp.CutoverNanos() != testNowNanos { b.FailNow() } } func validatePolicyByStructExported(b *testing.B, sp testStagedPolicies) { - if sp.ValCutoverNs() != testNowNs { + if sp.ValCutoverNanos() != testNowNanos { b.FailNow() } } diff --git a/policy/policy_test.go b/policy/policy_test.go index 750c8ac..2ae7405 100644 --- a/policy/policy_test.go +++ b/policy/policy_test.go @@ -46,10 +46,10 @@ func TestPoliciesByResolutionAsc(t *testing.T) { } func TestStagedPoliciesHasDefaultPolicies(t *testing.T) { - sp := NewStagedPolicies(testNowNs, true, nil) - require.Equal(t, testNowNs, sp.CutoverNs) - require.True(t, sp.hasDefaultPolicies()) - require.Equal(t, defaultPolicies, sp.Policies()) + sp := NewStagedPolicies(testNowNanos, true, nil) + require.Equal(t, testNowNanos, sp.CutoverNanos) + _, isDefault := sp.Policies() + require.True(t, isDefault) } func TestStagedPoliciesHasCustomPolicies(t *testing.T) { @@ -57,10 +57,11 @@ func TestStagedPoliciesHasCustomPolicies(t *testing.T) { NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), NewPolicy(10*time.Second, xtime.Second, 2*time.Hour), } - sp := NewStagedPolicies(testNowNs, false, policies) - require.Equal(t, testNowNs, sp.CutoverNs) - require.False(t, sp.hasDefaultPolicies()) - require.Equal(t, policies, sp.Policies()) + sp := NewStagedPolicies(testNowNanos, false, policies) + require.Equal(t, testNowNanos, sp.CutoverNanos) + actual, isDefault := sp.Policies() + require.False(t, isDefault) + require.Equal(t, policies, actual) } func TestStagedPoliciesSamePoliciesDefaultPolicies(t *testing.T) { @@ -162,7 +163,7 @@ func TestStagedPoliciesIsEmpty(t *testing.T) { }, } for _, input := range inputs { - require.Equal(t, input.expected, input.sp.isEmpty()) + require.Equal(t, input.expected, input.sp.IsDefault()) } } @@ -187,7 +188,7 @@ func TestPoliciesListIsDefault(t *testing.T) { expected: false, }, { - pl: []StagedPolicies{EmptyStagedPolicies, EmptyStagedPolicies}, + pl: []StagedPolicies{DefaultStagedPolicies, DefaultStagedPolicies}, expected: false, }, } diff --git a/protocol/msgpack/aggregated_encoder.go b/protocol/msgpack/aggregated_encoder.go index d6500e3..1f6413f 100644 --- a/protocol/msgpack/aggregated_encoder.go +++ b/protocol/msgpack/aggregated_encoder.go @@ -103,7 +103,7 @@ func (enc *aggregatedEncoder) encodeMetricAsRaw(m aggregated.Metric) []byte { enc.buf.resetData() enc.encodeMetricProlog() enc.buf.encodeID(m.ID) - enc.buf.encodeVarint(m.TimeNs) + enc.buf.encodeVarint(m.TimeNanos) enc.buf.encodeFloat64(m.Value) return enc.buf.encoder().Bytes() } @@ -112,7 +112,7 @@ func (enc *aggregatedEncoder) encodeChunkedMetricAsRaw(m aggregated.ChunkedMetri enc.buf.resetData() enc.encodeMetricProlog() enc.buf.encodeChunkedID(m.ChunkedID) - enc.buf.encodeVarint(m.TimeNs) + enc.buf.encodeVarint(m.TimeNanos) enc.buf.encodeFloat64(m.Value) return enc.buf.encoder().Bytes() } diff --git a/protocol/msgpack/aggregated_encoder_test.go b/protocol/msgpack/aggregated_encoder_test.go index 96b4af1..36a7437 100644 --- a/protocol/msgpack/aggregated_encoder_test.go +++ b/protocol/msgpack/aggregated_encoder_test.go @@ -73,7 +73,7 @@ func TestAggregatedEncodeMetric(t *testing.T) { int64(metricVersion), int(numFieldsForType(metricType)), []byte(testMetric.ID), - testMetric.TimeNs, + testMetric.TimeNanos, testMetric.Value, } require.Equal(t, expected, *result) diff --git a/protocol/msgpack/aggregated_roundtrip_test.go b/protocol/msgpack/aggregated_roundtrip_test.go index b3bef59..ed79c3a 100644 --- a/protocol/msgpack/aggregated_roundtrip_test.go +++ b/protocol/msgpack/aggregated_roundtrip_test.go @@ -37,9 +37,9 @@ import ( var ( testMetric = aggregated.Metric{ - ID: metric.ID("foo"), - TimeNs: time.Now().UnixNano(), - Value: 123.45, + ID: metric.ID("foo"), + TimeNanos: time.Now().UnixNano(), + Value: 123.45, } testChunkedMetric = aggregated.ChunkedMetric{ ChunkedID: metric.ChunkedID{ @@ -47,13 +47,13 @@ var ( Data: []byte("bar"), Suffix: []byte(".baz"), }, - TimeNs: time.Now().UnixNano(), - Value: 123.45, + TimeNanos: time.Now().UnixNano(), + Value: 123.45, } testMetric2 = aggregated.Metric{ - ID: metric.ID("bar"), - TimeNs: time.Now().UnixNano(), - Value: 678.90, + ID: metric.ID("bar"), + TimeNanos: time.Now().UnixNano(), + Value: 678.90, } testPolicy = policy.NewPolicy(time.Second, xtime.Second, time.Hour) ) @@ -142,9 +142,9 @@ func validateAggregatedRoundtripWithEncoderAndIterator( id = append(id, inputMetric.ChunkedID.Suffix...) expected = append(expected, metricWithPolicy{ metric: aggregated.Metric{ - ID: id, - TimeNs: inputMetric.TimeNs, - Value: inputMetric.Value, + ID: id, + TimeNanos: inputMetric.TimeNanos, + Value: inputMetric.Value, }, policy: input.policy, }) diff --git a/protocol/msgpack/raw_metric.go b/protocol/msgpack/raw_metric.go index 1456f9f..c72cb4d 100644 --- a/protocol/msgpack/raw_metric.go +++ b/protocol/msgpack/raw_metric.go @@ -65,13 +65,13 @@ func (m *rawMetric) ID() (metric.ID, error) { return m.metric.ID, nil } -func (m *rawMetric) TimeNs() (int64, error) { +func (m *rawMetric) TimeNanos() (int64, error) { m.decodeID() m.decodeTime() if err := m.it.err(); err != nil { return 0, err } - return m.metric.TimeNs, nil + return m.metric.TimeNanos, nil } func (m *rawMetric) Value() (float64, error) { @@ -151,11 +151,11 @@ func (m *rawMetric) decodeTime() { if m.it.err() != nil || m.timeDecoded { return } - timeNs := m.it.decodeVarint() + timeNanos := m.it.decodeVarint() if m.it.err() != nil { return } - m.metric.TimeNs = timeNs + m.metric.TimeNanos = timeNanos m.timeDecoded = true } diff --git a/protocol/msgpack/raw_metric_test.go b/protocol/msgpack/raw_metric_test.go index 587859a..0208dd7 100644 --- a/protocol/msgpack/raw_metric_test.go +++ b/protocol/msgpack/raw_metric_test.go @@ -94,7 +94,7 @@ func TestRawMetricDecodeIDSuccess(t *testing.T) { func TestRawMetricDecodeTimestampExistingError(t *testing.T) { m := testRawMetric() m.it.setErr(errTestDecodeRawMetric) - _, err := m.TimeNs() + _, err := m.TimeNanos() require.Equal(t, errTestDecodeRawMetric, err) } @@ -104,20 +104,20 @@ func TestRawMetricDecodeTimestampDecodeError(t *testing.T) { m.it.setErr(errTestDecodeRawMetric) return 0 } - _, err := m.TimeNs() + _, err := m.TimeNanos() require.Equal(t, errTestDecodeRawMetric, err) } func TestRawMetricDecodeTimestampSuccess(t *testing.T) { m := testRawMetric() - timeNs, err := m.TimeNs() + timeNanos, err := m.TimeNanos() require.NoError(t, err) - require.Equal(t, testMetric.TimeNs, timeNs) + require.Equal(t, testMetric.TimeNanos, timeNanos) require.True(t, m.timeDecoded) // Get timestamp again to make sure we don't re-decode the timestamp. require.NoError(t, err) - require.Equal(t, testMetric.TimeNs, timeNs) + require.Equal(t, testMetric.TimeNanos, timeNanos) } func TestRawMetricDecodeValueExistingError(t *testing.T) { @@ -186,9 +186,9 @@ func TestRawMetricNilID(t *testing.T) { func TestRawMetricReset(t *testing.T) { metrics := []aggregated.Metric{ - {ID: metric.ID("foo"), TimeNs: testMetric.TimeNs, Value: 1.0}, - {ID: metric.ID("bar"), TimeNs: testMetric.TimeNs, Value: 2.3}, - {ID: metric.ID("baz"), TimeNs: testMetric.TimeNs, Value: 4234.234}, + {ID: metric.ID("foo"), TimeNanos: testMetric.TimeNanos, Value: 1.0}, + {ID: metric.ID("bar"), TimeNanos: testMetric.TimeNanos, Value: 2.3}, + {ID: metric.ID("baz"), TimeNanos: testMetric.TimeNanos, Value: 4234.234}, } rawMetric := NewRawMetric(nil, 16) for i := 0; i < len(metrics); i++ { @@ -201,9 +201,9 @@ func TestRawMetricReset(t *testing.T) { func TestRawMetricRoundtripStress(t *testing.T) { metrics := []aggregated.Metric{ - {ID: metric.ID("foo"), TimeNs: testMetric.TimeNs, Value: 1.0}, - {ID: metric.ID("bar"), TimeNs: testMetric.TimeNs, Value: 2.3}, - {ID: metric.ID("baz"), TimeNs: testMetric.TimeNs, Value: 4234.234}, + {ID: metric.ID("foo"), TimeNanos: testMetric.TimeNanos, Value: 1.0}, + {ID: metric.ID("bar"), TimeNanos: testMetric.TimeNanos, Value: 2.3}, + {ID: metric.ID("baz"), TimeNanos: testMetric.TimeNanos, Value: 4234.234}, } var ( inputs []aggregated.Metric @@ -267,7 +267,7 @@ func testRawMetric() *rawMetric { mockIt := &mockBaseIterator{} mockIt.decodeVersionFn = func() int { return metricVersion } mockIt.decodeBytesLenFn = func() int { return len(testMetric.ID) } - mockIt.decodeVarintFn = func() int64 { return testMetric.TimeNs } + mockIt.decodeVarintFn = func() int64 { return testMetric.TimeNanos } mockIt.decodeFloat64Fn = func() float64 { return testMetric.Value } mockIt.bufReader = bytes.NewReader(testRawMetricData) diff --git a/protocol/msgpack/unaggregated_encoder.go b/protocol/msgpack/unaggregated_encoder.go index 3b3ae49..cf6717c 100644 --- a/protocol/msgpack/unaggregated_encoder.go +++ b/protocol/msgpack/unaggregated_encoder.go @@ -158,9 +158,9 @@ func (enc *unaggregatedEncoder) encodePoliciesList(pl policy.PoliciesList) { func (enc *unaggregatedEncoder) encodeStagedPolicies(sp policy.StagedPolicies) { enc.encodeNumObjectFields(numFieldsForType(stagedPoliciesType)) - enc.encodeVarint(sp.CutoverNs) + enc.encodeVarint(sp.CutoverNanos) enc.encodeBool(sp.Tombstoned) - policies := sp.Policies() + policies, _ := sp.Policies() enc.encodeArrayLen(len(policies)) for _, policy := range policies { enc.encodePolicy(policy) diff --git a/protocol/msgpack/unaggregated_encoder_test.go b/protocol/msgpack/unaggregated_encoder_test.go index d19306f..6a213e1 100644 --- a/protocol/msgpack/unaggregated_encoder_test.go +++ b/protocol/msgpack/unaggregated_encoder_test.go @@ -234,10 +234,10 @@ func expectedResultsForPolicy(t *testing.T, p policy.Policy) []interface{} { } func expectedResultsForStagedPolicies(t *testing.T, sp policy.StagedPolicies) []interface{} { - policies := sp.Policies() + policies, _ := sp.Policies() results := []interface{}{ numFieldsForType(stagedPoliciesType), - sp.CutoverNs, + sp.CutoverNanos, sp.Tombstoned, len(policies), } diff --git a/protocol/msgpack/unaggregated_iterator.go b/protocol/msgpack/unaggregated_iterator.go index a88c9f9..7b58306 100644 --- a/protocol/msgpack/unaggregated_iterator.go +++ b/protocol/msgpack/unaggregated_iterator.go @@ -264,9 +264,9 @@ func (it *unaggregatedIterator) decodePoliciesList() { func (it *unaggregatedIterator) decodeStagedPolicies(policyIdx int) policy.StagedPolicies { numExpectedFields, numActualFields, ok := it.checkNumFieldsForType(stagedPoliciesType) if !ok { - return policy.EmptyStagedPolicies + return policy.DefaultStagedPolicies } - cutoverNs := it.decodeVarint() + cutoverNanos := it.decodeVarint() tombstoned := it.decodeBool() numPolicies := it.decodeArrayLen() if cap(it.cachedPolicies[policyIdx]) < numPolicies { @@ -277,7 +277,7 @@ func (it *unaggregatedIterator) decodeStagedPolicies(policyIdx int) policy.Stage for i := 0; i < numPolicies; i++ { it.cachedPolicies[policyIdx] = append(it.cachedPolicies[policyIdx], it.decodePolicy()) } - stagedPolicies := policy.NewStagedPolicies(cutoverNs, tombstoned, it.cachedPolicies[policyIdx]) + stagedPolicies := policy.NewStagedPolicies(cutoverNanos, tombstoned, it.cachedPolicies[policyIdx]) it.skip(numActualFields - numExpectedFields) return stagedPolicies } diff --git a/protocol/msgpack/unaggregated_iterator_test.go b/protocol/msgpack/unaggregated_iterator_test.go index 76349e8..378052c 100644 --- a/protocol/msgpack/unaggregated_iterator_test.go +++ b/protocol/msgpack/unaggregated_iterator_test.go @@ -57,7 +57,8 @@ func TestUnaggregatedIteratorDecodeSingleCustomPoliciesListWithAlloc(t *testing. _, pl := it.Value() require.Equal(t, testSingleCustomStagedPoliciesList, pl) require.Equal(t, len(it.cachedPolicies), len(testSingleCustomStagedPoliciesList)) - require.Equal(t, it.cachedPolicies[0], testSingleCustomStagedPoliciesList[0].Policies()) + policies, _ := testSingleCustomStagedPoliciesList[0].Policies() + require.Equal(t, it.cachedPolicies[0], policies) } func TestUnaggregatedIteratorDecodeSingleCustomPoliciesListNoPoliciesListAlloc(t *testing.T) { @@ -71,7 +72,8 @@ func TestUnaggregatedIteratorDecodeSingleCustomPoliciesListNoPoliciesListAlloc(t _, pl := it.Value() require.Equal(t, testSingleCustomStagedPoliciesList, pl) require.Equal(t, len(it.cachedPolicies), len(testSingleCustomStagedPoliciesList)) - require.Equal(t, it.cachedPolicies[0], testSingleCustomStagedPoliciesList[0].Policies()) + policies, _ := testSingleCustomStagedPoliciesList[0].Policies() + require.Equal(t, it.cachedPolicies[0], policies) } func TestUnaggregatedIteratorDecodeSingleCustomPoliciesListNoAlloc(t *testing.T) { @@ -87,7 +89,8 @@ func TestUnaggregatedIteratorDecodeSingleCustomPoliciesListNoAlloc(t *testing.T) _, pl := it.Value() require.Equal(t, testSingleCustomStagedPoliciesList, pl) require.Equal(t, len(it.cachedPolicies), len(testSingleCustomStagedPoliciesList)) - require.Equal(t, it.cachedPolicies[0], testSingleCustomStagedPoliciesList[0].Policies()) + policies, _ := testSingleCustomStagedPoliciesList[0].Policies() + require.Equal(t, it.cachedPolicies[0], policies) } func TestUnaggregatedIteratorDecodeMultiCustomPoliciesListWithAlloc(t *testing.T) { @@ -102,7 +105,8 @@ func TestUnaggregatedIteratorDecodeMultiCustomPoliciesListWithAlloc(t *testing.T require.Equal(t, input, pl) require.Equal(t, len(it.cachedPolicies), len(input)) for i := 0; i < len(input); i++ { - require.Equal(t, it.cachedPolicies[i], input[i].Policies()) + policies, _ := input[i].Policies() + require.Equal(t, it.cachedPolicies[i], policies) } } diff --git a/protocol/msgpack/unaggregated_roundtrip_test.go b/protocol/msgpack/unaggregated_roundtrip_test.go index 796ff7e..4bd503f 100644 --- a/protocol/msgpack/unaggregated_roundtrip_test.go +++ b/protocol/msgpack/unaggregated_roundtrip_test.go @@ -386,9 +386,12 @@ func compareUnaggregatedMetric(t *testing.T, expected unaggregated.MetricUnion, func comparedPoliciesList(t *testing.T, expected policy.PoliciesList, actual policy.PoliciesList) { require.Equal(t, len(expected), len(actual)) for i := 0; i < len(expected); i++ { - require.Equal(t, expected[i].CutoverNs, actual[i].CutoverNs) + require.Equal(t, expected[i].CutoverNanos, actual[i].CutoverNanos) require.Equal(t, expected[i].Tombstoned, actual[i].Tombstoned) - require.Equal(t, expected[i].Policies(), actual[i].Policies()) + expectedPolicies, expectedIsDefault := expected[i].Policies() + actualPolicies, actualIsDefault := actual[i].Policies() + require.Equal(t, expectedIsDefault, actualIsDefault) + require.Equal(t, expectedPolicies, actualPolicies) } } @@ -442,11 +445,12 @@ func validateMetricsWithPoliciesList(t *testing.T, inputs, results []metricWithP } func toStagedPolicies(t *testing.T, p policy.StagedPolicies) policy.StagedPolicies { - policies := make([]policy.Policy, len(p.Policies())) - for i, policy := range p.Policies() { - policies[i] = policy + srcPolicies, _ := p.Policies() + destPolicies := make([]policy.Policy, len(srcPolicies)) + for i, policy := range srcPolicies { + destPolicies[i] = policy } - return policy.NewStagedPolicies(p.CutoverNs, p.Tombstoned, policies) + return policy.NewStagedPolicies(p.CutoverNanos, p.Tombstoned, destPolicies) } func toPoliciesList(t *testing.T, pl policy.PoliciesList) policy.PoliciesList { diff --git a/rules/mapping.go b/rules/mapping.go index c083af8..ea70195 100644 --- a/rules/mapping.go +++ b/rules/mapping.go @@ -36,11 +36,11 @@ var ( // mappingRuleSnapshot defines a rule snapshot such that if a metric matches the // provided filters, it is aggregated and retained under the provided set of policies. type mappingRuleSnapshot struct { - name string - tombstoned bool - cutoverNs int64 - filter filters.Filter - policies []policy.Policy + name string + tombstoned bool + cutoverNanos int64 + filter filters.Filter + policies []policy.Policy } func newMappingRuleSnapshot( @@ -59,11 +59,11 @@ func newMappingRuleSnapshot( return nil, err } return &mappingRuleSnapshot{ - name: r.Name, - tombstoned: r.Tombstoned, - cutoverNs: r.CutoverTime, - filter: filter, - policies: policies, + name: r.Name, + tombstoned: r.Tombstoned, + cutoverNanos: r.CutoverTime, + filter: filter, + policies: policies, }, nil } @@ -95,19 +95,19 @@ func newMappingRule( } // ActiveSnapshot returns the latest snapshot whose cutover time is earlier than or -// equal to timeNs, or nil if not found. -func (mc *mappingRule) ActiveSnapshot(timeNs int64) *mappingRuleSnapshot { - idx := mc.activeIndex(timeNs) +// equal to timeNanos, or nil if not found. +func (mc *mappingRule) ActiveSnapshot(timeNanos int64) *mappingRuleSnapshot { + idx := mc.activeIndex(timeNanos) if idx < 0 { return nil } return mc.snapshots[idx] } -// ActiveRule returns the rule containing snapshots that's in effect at time timeNs -// and all future snapshots after time timeNs. -func (mc *mappingRule) ActiveRule(timeNs int64) *mappingRule { - idx := mc.activeIndex(timeNs) +// ActiveRule returns the rule containing snapshots that's in effect at time timeNanos +// and all future snapshots after time timeNanos. +func (mc *mappingRule) ActiveRule(timeNanos int64) *mappingRule { + idx := mc.activeIndex(timeNanos) // If there are no snapshots that are currently in effect, it means either all // snapshots are in the future, or there are no snapshots. if idx < 0 { @@ -116,9 +116,9 @@ func (mc *mappingRule) ActiveRule(timeNs int64) *mappingRule { return &mappingRule{uuid: mc.uuid, snapshots: mc.snapshots[idx:]} } -func (mc *mappingRule) activeIndex(timeNs int64) int { +func (mc *mappingRule) activeIndex(timeNanos int64) int { idx := len(mc.snapshots) - 1 - for idx >= 0 && mc.snapshots[idx].cutoverNs > timeNs { + for idx >= 0 && mc.snapshots[idx].cutoverNanos > timeNanos { idx-- } return idx diff --git a/rules/mapping_test.go b/rules/mapping_test.go index d3111dc..165cfcd 100644 --- a/rules/mapping_test.go +++ b/rules/mapping_test.go @@ -103,23 +103,23 @@ func TestNewMappingRule(t *testing.T) { require.NoError(t, err) require.Equal(t, "12669817-13ae-40e6-ba2f-33087b262c68", mr.uuid) expectedSnapshots := []struct { - name string - tombstoned bool - cutoverNs int64 - policies []policy.Policy + name string + tombstoned bool + cutoverNanos int64 + policies []policy.Policy }{ { - name: "foo", - tombstoned: false, - cutoverNs: 12345, + name: "foo", + tombstoned: false, + cutoverNanos: 12345, policies: []policy.Policy{ policy.NewPolicy(10*time.Second, xtime.Second, 24*time.Hour), }, }, { - name: "bar", - tombstoned: true, - cutoverNs: 67890, + name: "bar", + tombstoned: true, + cutoverNanos: 67890, policies: []policy.Policy{ policy.NewPolicy(time.Minute, xtime.Minute, 24*time.Hour), policy.NewPolicy(5*time.Minute, xtime.Minute, 48*time.Hour), @@ -129,7 +129,7 @@ func TestNewMappingRule(t *testing.T) { for i, snapshot := range expectedSnapshots { require.Equal(t, snapshot.name, mr.snapshots[i].name) require.Equal(t, snapshot.tombstoned, mr.snapshots[i].tombstoned) - require.Equal(t, snapshot.cutoverNs, mr.snapshots[i].cutoverNs) + require.Equal(t, snapshot.cutoverNanos, mr.snapshots[i].cutoverNanos) require.Equal(t, snapshot.policies, mr.snapshots[i].policies) } } diff --git a/rules/result.go b/rules/result.go index d9bbb77..8ec34a2 100644 --- a/rules/result.go +++ b/rules/result.go @@ -29,7 +29,7 @@ import ( var ( // EmptyMatchResult is the result when no matches were found. - EmptyMatchResult = NewMatchResult(timeNsMax, policy.DefaultPoliciesList, nil) + EmptyMatchResult = NewMatchResult(timeNanosMax, policy.DefaultPoliciesList, nil) ) // RollupResult contains the rollup metric id and the associated policies list. @@ -47,26 +47,26 @@ func (a RollupResultsByIDAsc) Less(i, j int) bool { return bytes.Compare(a[i].ID // MatchResult represents a match result. type MatchResult struct { - expireAtNs int64 - mappings policy.PoliciesList - rollups []RollupResult + expireAtNanos int64 + mappings policy.PoliciesList + rollups []RollupResult } // NewMatchResult creates a new match result. func NewMatchResult( - expireAtNs int64, + expireAtNanos int64, mappings policy.PoliciesList, rollups []RollupResult, ) MatchResult { return MatchResult{ - expireAtNs: expireAtNs, - mappings: mappings, - rollups: rollups, + expireAtNanos: expireAtNanos, + mappings: mappings, + rollups: rollups, } } // HasExpired returns whether the match result has expired for a given time. -func (r *MatchResult) HasExpired(t time.Time) bool { return r.expireAtNs <= t.UnixNano() } +func (r *MatchResult) HasExpired(t time.Time) bool { return r.expireAtNanos <= t.UnixNano() } // NumRollups returns the number of rollup metrics. func (r *MatchResult) NumRollups() int { return len(r.rollups) } @@ -88,9 +88,9 @@ func (r *MatchResult) RollupsAt(idx int, t time.Time) RollupResult { // activePolicies returns the active policies at a given time, assuming // the input policies are sorted by cutover time in ascending order. func activePoliciesAt(policies policy.PoliciesList, t time.Time) policy.PoliciesList { - timeNs := t.UnixNano() + timeNanos := t.UnixNano() for idx := len(policies) - 1; idx >= 0; idx-- { - if policies[idx].CutoverNs <= timeNs { + if policies[idx].CutoverNanos <= timeNanos { return policies[idx:] } } diff --git a/rules/result_test.go b/rules/result_test.go index f395b12..3600063 100644 --- a/rules/result_test.go +++ b/rules/result_test.go @@ -38,7 +38,7 @@ func TestMatchResultHasExpired(t *testing.T) { func TestMatchResult(t *testing.T) { var ( - testExpireAtNs = int64(67890) + testExpireAtNanos = int64(67890) testResultMappings = policy.PoliciesList{ policy.NewStagedPolicies( 12345, @@ -137,7 +137,7 @@ func TestMatchResult(t *testing.T) { }, } - res := NewMatchResult(testExpireAtNs, testResultMappings, testResultRollups) + res := NewMatchResult(testExpireAtNanos, testResultMappings, testResultRollups) for _, input := range inputs { require.Equal(t, input.expectedMappings, res.MappingsAt(input.matchAt)) require.Equal(t, len(input.expectedRollups), res.NumRollups()) diff --git a/rules/rollup.go b/rules/rollup.go index 2072790..d213ef9 100644 --- a/rules/rollup.go +++ b/rules/rollup.go @@ -97,11 +97,11 @@ func (t *rollupTarget) clone() rollupTarget { // rollupRuleSnapshot defines a rule snapshot such that if a metric matches the // provided filters, it is rolled up using the provided list of rollup targets. type rollupRuleSnapshot struct { - name string - tombstoned bool - cutoverNs int64 - filter filters.Filter - targets []rollupTarget + name string + tombstoned bool + cutoverNanos int64 + filter filters.Filter + targets []rollupTarget } func newRollupRuleSnapshot( @@ -124,11 +124,11 @@ func newRollupRuleSnapshot( return nil, err } return &rollupRuleSnapshot{ - name: r.Name, - tombstoned: r.Tombstoned, - cutoverNs: r.CutoverTime, - filter: filter, - targets: targets, + name: r.Name, + tombstoned: r.Tombstoned, + cutoverNanos: r.CutoverTime, + filter: filter, + targets: targets, }, nil } @@ -160,28 +160,28 @@ func newRollupRule( } // ActiveSnapshot returns the latest rule snapshot whose cutover time is earlier -// than or equal to timeNs, or nil if not found. -func (rc *rollupRule) ActiveSnapshot(timeNs int64) *rollupRuleSnapshot { - idx := rc.activeIndex(timeNs) +// than or equal to timeNanos, or nil if not found. +func (rc *rollupRule) ActiveSnapshot(timeNanos int64) *rollupRuleSnapshot { + idx := rc.activeIndex(timeNanos) if idx < 0 { return nil } return rc.snapshots[idx] } -// ActiveRule returns the rule containing snapshots that's in effect at time timeNs -// and all future rules after time timeNs. -func (rc *rollupRule) ActiveRule(timeNs int64) *rollupRule { - idx := rc.activeIndex(timeNs) +// ActiveRule returns the rule containing snapshots that's in effect at time timeNanos +// and all future rules after time timeNanos. +func (rc *rollupRule) ActiveRule(timeNanos int64) *rollupRule { + idx := rc.activeIndex(timeNanos) if idx < 0 { return rc } return &rollupRule{uuid: rc.uuid, snapshots: rc.snapshots[idx:]} } -func (rc *rollupRule) activeIndex(timeNs int64) int { +func (rc *rollupRule) activeIndex(timeNanos int64) int { idx := len(rc.snapshots) - 1 - for idx >= 0 && rc.snapshots[idx].cutoverNs > timeNs { + for idx >= 0 && rc.snapshots[idx].cutoverNanos > timeNanos { idx-- } return idx diff --git a/rules/rollup_test.go b/rules/rollup_test.go index 93686dc..8cd626b 100644 --- a/rules/rollup_test.go +++ b/rules/rollup_test.go @@ -169,15 +169,15 @@ func TestRollupRuleValidSchema(t *testing.T) { require.Equal(t, "12669817-13ae-40e6-ba2f-33087b262c68", rr.uuid) expectedSnapshots := []struct { - name string - tombstoned bool - cutoverNs int64 - targets []rollupTarget + name string + tombstoned bool + cutoverNanos int64 + targets []rollupTarget }{ { - name: "foo", - tombstoned: false, - cutoverNs: 12345, + name: "foo", + tombstoned: false, + cutoverNanos: 12345, targets: []rollupTarget{ { Name: b("rName1"), @@ -189,9 +189,9 @@ func TestRollupRuleValidSchema(t *testing.T) { }, }, { - name: "bar", - tombstoned: true, - cutoverNs: 67890, + name: "bar", + tombstoned: true, + cutoverNanos: 67890, targets: []rollupTarget{ { Name: b("rName1"), @@ -207,7 +207,7 @@ func TestRollupRuleValidSchema(t *testing.T) { for i, snapshot := range expectedSnapshots { require.Equal(t, snapshot.name, rr.snapshots[i].name) require.Equal(t, snapshot.tombstoned, rr.snapshots[i].tombstoned) - require.Equal(t, snapshot.cutoverNs, rr.snapshots[i].cutoverNs) + require.Equal(t, snapshot.cutoverNanos, rr.snapshots[i].cutoverNanos) require.Equal(t, snapshot.targets, rr.snapshots[i].targets) } } diff --git a/rules/ruleset.go b/rules/ruleset.go index c9b06c8..66514b4 100644 --- a/rules/ruleset.go +++ b/rules/ruleset.go @@ -33,7 +33,7 @@ import ( ) const ( - timeNsMax = int64(math.MaxInt64) + timeNanosMax = int64(math.MaxInt64) ) var ( @@ -69,12 +69,12 @@ func newActiveRuleSet( uniqueCutoverTimes := make(map[int64]struct{}) for _, mappingRule := range mappingRules { for _, snapshot := range mappingRule.snapshots { - uniqueCutoverTimes[snapshot.cutoverNs] = struct{}{} + uniqueCutoverTimes[snapshot.cutoverNanos] = struct{}{} } } for _, rollupRule := range rollupRules { for _, snapshot := range rollupRule.snapshots { - uniqueCutoverTimes[snapshot.cutoverNs] = struct{}{} + uniqueCutoverTimes[snapshot.cutoverNanos] = struct{}{} } } @@ -97,36 +97,36 @@ func newActiveRuleSet( // at previous iteration and incrementally update match results. func (as *activeRuleSet) MatchAll(id []byte, from time.Time, to time.Time) MatchResult { var ( - fromNs = from.UnixNano() - toNs = to.UnixNano() - currMappingResults = policy.PoliciesList{as.matchMappings(id, fromNs)} - currRollupResults = as.matchRollups(id, fromNs) - nextIdx = as.nextCutoverIdx(fromNs) - nextCutoverNs = as.cutoverNsAt(nextIdx) + fromNanos = from.UnixNano() + toNanos = to.UnixNano() + currMappingResults = policy.PoliciesList{as.matchMappings(id, fromNanos)} + currRollupResults = as.matchRollups(id, fromNanos) + nextIdx = as.nextCutoverIdx(fromNanos) + nextCutoverNanos = as.cutoverNanosAt(nextIdx) ) - for nextIdx < len(as.cutoverTimesAsc) && nextCutoverNs < toNs { - nextMappingPolicies := as.matchMappings(id, nextCutoverNs) - nextRollupResults := as.matchRollups(id, nextCutoverNs) + for nextIdx < len(as.cutoverTimesAsc) && nextCutoverNanos < toNanos { + nextMappingPolicies := as.matchMappings(id, nextCutoverNanos) + nextRollupResults := as.matchRollups(id, nextCutoverNanos) currMappingResults = mergeMappingResults(currMappingResults, nextMappingPolicies) - currRollupResults = mergeRollupResults(currRollupResults, nextRollupResults, nextCutoverNs) + currRollupResults = mergeRollupResults(currRollupResults, nextRollupResults, nextCutoverNanos) nextIdx++ - nextCutoverNs = as.cutoverNsAt(nextIdx) + nextCutoverNanos = as.cutoverNanosAt(nextIdx) } // The result expires when it reaches the first cutover time after t among all // active rules because the metric may then be matched against a different set of rules. - return NewMatchResult(nextCutoverNs, currMappingResults, currRollupResults) + return NewMatchResult(nextCutoverNanos, currMappingResults, currRollupResults) } -func (as *activeRuleSet) matchMappings(id []byte, timeNs int64) policy.StagedPolicies { +func (as *activeRuleSet) matchMappings(id []byte, timeNanos int64) policy.StagedPolicies { // TODO(xichen): pool the policies. var ( - cutoverNs int64 - policies []policy.Policy + cutoverNanos int64 + policies []policy.Policy ) for _, mappingRule := range as.mappingRules { - snapshot := mappingRule.ActiveSnapshot(timeNs) + snapshot := mappingRule.ActiveSnapshot(timeNanos) if snapshot == nil { continue } @@ -136,48 +136,48 @@ func (as *activeRuleSet) matchMappings(id []byte, timeNs int64) policy.StagedPol // match the id because the cutover time of the result policies only needs to be best effort // as long as it is before the time passed in. if snapshot.tombstoned { - if cutoverNs < snapshot.cutoverNs { - cutoverNs = snapshot.cutoverNs + if cutoverNanos < snapshot.cutoverNanos { + cutoverNanos = snapshot.cutoverNanos } continue } if !snapshot.filter.Matches(id) { continue } - if cutoverNs < snapshot.cutoverNs { - cutoverNs = snapshot.cutoverNs + if cutoverNanos < snapshot.cutoverNanos { + cutoverNanos = snapshot.cutoverNanos } policies = append(policies, snapshot.policies...) } if len(policies) == 0 { - return policy.EmptyStagedPolicies + return policy.DefaultStagedPolicies } resolved := resolvePolicies(policies) - return policy.NewStagedPolicies(cutoverNs, false, resolved) + return policy.NewStagedPolicies(cutoverNanos, false, resolved) } -func (as *activeRuleSet) matchRollups(id []byte, timeNs int64) []RollupResult { +func (as *activeRuleSet) matchRollups(id []byte, timeNanos int64) []RollupResult { // TODO(xichen): pool the rollup targets. var ( - cutoverNs int64 - rollups []rollupTarget + cutoverNanos int64 + rollups []rollupTarget ) for _, rollupRule := range as.rollupRules { - snapshot := rollupRule.ActiveSnapshot(timeNs) + snapshot := rollupRule.ActiveSnapshot(timeNanos) if snapshot == nil { continue } if snapshot.tombstoned { - if cutoverNs < snapshot.cutoverNs { - cutoverNs = snapshot.cutoverNs + if cutoverNanos < snapshot.cutoverNanos { + cutoverNanos = snapshot.cutoverNanos } continue } if !snapshot.filter.Matches(id) { continue } - if cutoverNs < snapshot.cutoverNs { - cutoverNs = snapshot.cutoverNs + if cutoverNanos < snapshot.cutoverNanos { + cutoverNanos = snapshot.cutoverNanos } for _, target := range snapshot.targets { found := false @@ -205,11 +205,11 @@ func (as *activeRuleSet) matchRollups(id []byte, timeNs int64) []RollupResult { rollups[i].Policies = resolvePolicies(rollups[i].Policies) } - return as.toRollupResults(id, cutoverNs, rollups) + return as.toRollupResults(id, cutoverNanos, rollups) } // toRollupResults encodes rollup target name and values into ids for each rollup target. -func (as *activeRuleSet) toRollupResults(id []byte, cutoverNs int64, targets []rollupTarget) []RollupResult { +func (as *activeRuleSet) toRollupResults(id []byte, cutoverNanos int64, targets []rollupTarget) []RollupResult { // NB(r): This is n^2 however this should be quite fast still as // long as there is not an absurdly high number of rollup // targets for any given ID and that iterfn is alloc free. @@ -238,7 +238,7 @@ func (as *activeRuleSet) toRollupResults(id []byte, cutoverNs int64, targets []r } result := RollupResult{ ID: as.newIDFn(target.Name, tagPairs), - PoliciesList: policy.PoliciesList{policy.NewStagedPolicies(cutoverNs, false, target.Policies)}, + PoliciesList: policy.PoliciesList{policy.NewStagedPolicies(cutoverNanos, false, target.Policies)}, } rollups = append(rollups, result) } @@ -262,12 +262,12 @@ func (as *activeRuleSet) nextCutoverIdx(t int64) int { return i } -// cutoverNsAt returns the cutover time at given index. -func (as *activeRuleSet) cutoverNsAt(idx int) int64 { +// cutoverNanosAt returns the cutover time at given index. +func (as *activeRuleSet) cutoverNanosAt(idx int) int64 { if idx < len(as.cutoverTimesAsc) { return as.cutoverTimesAsc[idx] } - return timeNsMax + return timeNanosMax } // RuleSet is a set of rules associated with a namespace. @@ -278,8 +278,8 @@ type RuleSet interface { // Version returns the ruleset version. Version() int - // CutoverNs returns when the ruleset takes effect. - CutoverNs() int64 + // CutoverNanos returns when the ruleset takes effect. + CutoverNanos() int64 // TombStoned returns whether the ruleset is tombstoned. TombStoned() bool @@ -289,17 +289,17 @@ type RuleSet interface { } type ruleSet struct { - uuid string - version int - namespace []byte - createdAtNs int64 - lastUpdatedAtNs int64 - tombstoned bool - cutoverNs int64 - iterFn filters.NewSortedTagIteratorFn - newIDFn NewIDFn - mappingRules []*mappingRule - rollupRules []*rollupRule + uuid string + version int + namespace []byte + createdAtNanos int64 + lastUpdatedAtNanos int64 + tombstoned bool + cutoverNanos int64 + iterFn filters.NewSortedTagIteratorFn + newIDFn NewIDFn + mappingRules []*mappingRule + rollupRules []*rollupRule } // NewRuleSet creates a new ruleset. @@ -325,35 +325,35 @@ func NewRuleSet(version int, rs *schema.RuleSet, opts Options) (RuleSet, error) rollupRules = append(rollupRules, rc) } return &ruleSet{ - uuid: rs.Uuid, - version: version, - namespace: []byte(rs.Namespace), - createdAtNs: rs.CreatedAt, - lastUpdatedAtNs: rs.LastUpdatedAt, - tombstoned: rs.Tombstoned, - cutoverNs: rs.CutoverTime, - iterFn: iterFn, - newIDFn: opts.NewIDFn(), - mappingRules: mappingRules, - rollupRules: rollupRules, + uuid: rs.Uuid, + version: version, + namespace: []byte(rs.Namespace), + createdAtNanos: rs.CreatedAt, + lastUpdatedAtNanos: rs.LastUpdatedAt, + tombstoned: rs.Tombstoned, + cutoverNanos: rs.CutoverTime, + iterFn: iterFn, + newIDFn: opts.NewIDFn(), + mappingRules: mappingRules, + rollupRules: rollupRules, }, nil } -func (rs *ruleSet) Namespace() []byte { return rs.namespace } -func (rs *ruleSet) Version() int { return rs.version } -func (rs *ruleSet) CutoverNs() int64 { return rs.cutoverNs } -func (rs *ruleSet) TombStoned() bool { return rs.tombstoned } +func (rs *ruleSet) Namespace() []byte { return rs.namespace } +func (rs *ruleSet) Version() int { return rs.version } +func (rs *ruleSet) CutoverNanos() int64 { return rs.cutoverNanos } +func (rs *ruleSet) TombStoned() bool { return rs.tombstoned } func (rs *ruleSet) ActiveSet(t time.Time) Matcher { - timeNs := t.UnixNano() + timeNanos := t.UnixNano() mappingRules := make([]*mappingRule, 0, len(rs.mappingRules)) for _, mappingRule := range rs.mappingRules { - activeRule := mappingRule.ActiveRule(timeNs) + activeRule := mappingRule.ActiveRule(timeNanos) mappingRules = append(mappingRules, activeRule) } rollupRules := make([]*rollupRule, 0, len(rs.rollupRules)) for _, rollupRule := range rs.rollupRules { - activeRule := rollupRule.ActiveRule(timeNs) + activeRule := rollupRule.ActiveRule(timeNanos) rollupRules = append(rollupRules, activeRule) } return newActiveRuleSet(rs.iterFn, rs.newIDFn, mappingRules, rollupRules) @@ -409,7 +409,7 @@ func mergeMappingResults( func mergeRollupResults( currRollupResults []RollupResult, nextRollupResults []RollupResult, - nextCutoverNs int64, + nextCutoverNanos int64, ) []RollupResult { var ( numCurrRollupResults = len(currRollupResults) @@ -439,7 +439,7 @@ func mergeRollupResults( if compareResult < 0 { currRollupPolicies := currRollupResult.PoliciesList[len(currRollupResult.PoliciesList)-1] if !currRollupPolicies.Tombstoned { - tombstonedPolicies := policy.NewStagedPolicies(nextCutoverNs, true, nil) + tombstonedPolicies := policy.NewStagedPolicies(nextCutoverNanos, true, nil) currRollupResults[currRollupIdx].PoliciesList = append(currRollupResults[currRollupIdx].PoliciesList, tombstonedPolicies) } currRollupIdx++ @@ -457,7 +457,7 @@ func mergeRollupResults( currRollupResult := currRollupResults[currRollupIdx] currRollupPolicies := currRollupResult.PoliciesList[len(currRollupResult.PoliciesList)-1] if !currRollupPolicies.Tombstoned { - tombstonedPolicies := policy.NewStagedPolicies(nextCutoverNs, true, nil) + tombstonedPolicies := policy.NewStagedPolicies(nextCutoverNanos, true, nil) currRollupResults[currRollupIdx].PoliciesList = append(currRollupResults[currRollupIdx].PoliciesList, tombstonedPolicies) } currRollupIdx++ diff --git a/rules/ruleset_test.go b/rules/ruleset_test.go index d68dd64..dc3f051 100644 --- a/rules/ruleset_test.go +++ b/rules/ruleset_test.go @@ -36,10 +36,10 @@ import ( func TestActiveRuleSetMatchMappingRules(t *testing.T) { inputs := []testMappingsData{ { - id: "mtagName1=mtagValue1", - matchFrom: time.Unix(0, 25000), - matchTo: time.Unix(0, 25001), - expireAtNs: 30000, + id: "mtagName1=mtagValue1", + matchFrom: time.Unix(0, 25000), + matchTo: time.Unix(0, 25001), + expireAtNanos: 30000, result: policy.PoliciesList{ policy.NewStagedPolicies( 22000, @@ -53,10 +53,10 @@ func TestActiveRuleSetMatchMappingRules(t *testing.T) { }, }, { - id: "mtagName1=mtagValue1", - matchFrom: time.Unix(0, 35000), - matchTo: time.Unix(0, 35001), - expireAtNs: 100000, + id: "mtagName1=mtagValue1", + matchFrom: time.Unix(0, 35000), + matchTo: time.Unix(0, 35001), + expireAtNanos: 100000, result: policy.PoliciesList{ policy.NewStagedPolicies( 35000, @@ -69,10 +69,10 @@ func TestActiveRuleSetMatchMappingRules(t *testing.T) { }, }, { - id: "mtagName1=mtagValue2", - matchFrom: time.Unix(0, 25000), - matchTo: time.Unix(0, 25001), - expireAtNs: 30000, + id: "mtagName1=mtagValue2", + matchFrom: time.Unix(0, 25000), + matchTo: time.Unix(0, 25001), + expireAtNanos: 30000, result: policy.PoliciesList{ policy.NewStagedPolicies( 24000, @@ -84,17 +84,17 @@ func TestActiveRuleSetMatchMappingRules(t *testing.T) { }, }, { - id: "mtagName1=mtagValue3", - matchFrom: time.Unix(0, 25000), - matchTo: time.Unix(0, 25001), - expireAtNs: 30000, - result: policy.DefaultPoliciesList, + id: "mtagName1=mtagValue3", + matchFrom: time.Unix(0, 25000), + matchTo: time.Unix(0, 25001), + expireAtNanos: 30000, + result: policy.DefaultPoliciesList, }, { - id: "mtagName1=mtagValue1", - matchFrom: time.Unix(0, 10000), - matchTo: time.Unix(0, 40000), - expireAtNs: 100000, + id: "mtagName1=mtagValue1", + matchFrom: time.Unix(0, 10000), + matchTo: time.Unix(0, 40000), + expireAtNanos: 100000, result: policy.PoliciesList{ policy.NewStagedPolicies( 10000, @@ -131,12 +131,12 @@ func TestActiveRuleSetMatchMappingRules(t *testing.T) { }, }, { - id: "mtagName1=mtagValue2", - matchFrom: time.Unix(0, 10000), - matchTo: time.Unix(0, 40000), - expireAtNs: 100000, + id: "mtagName1=mtagValue2", + matchFrom: time.Unix(0, 10000), + matchTo: time.Unix(0, 40000), + expireAtNanos: 100000, result: policy.PoliciesList{ - policy.EmptyStagedPolicies, + policy.DefaultStagedPolicies, policy.NewStagedPolicies( 24000, false, @@ -159,7 +159,7 @@ func TestActiveRuleSetMatchMappingRules(t *testing.T) { require.Equal(t, expectedCutovers, as.cutoverTimesAsc) for _, input := range inputs { res := as.MatchAll(b(input.id), input.matchFrom, input.matchTo) - require.Equal(t, input.expireAtNs, res.expireAtNs) + require.Equal(t, input.expireAtNanos, res.expireAtNanos) require.Equal(t, input.result, res.MappingsAt(time.Unix(0, 0))) } } @@ -167,10 +167,10 @@ func TestActiveRuleSetMatchMappingRules(t *testing.T) { func TestActiveRuleSetMatchRollupRules(t *testing.T) { inputs := []testRollupResultsData{ { - id: "rtagName1=rtagValue1,rtagName2=rtagValue2,rtagName3=rtagValue3", - matchFrom: time.Unix(0, 25000), - matchTo: time.Unix(0, 25001), - expireAtNs: 30000, + id: "rtagName1=rtagValue1,rtagName2=rtagValue2,rtagName3=rtagValue3", + matchFrom: time.Unix(0, 25000), + matchTo: time.Unix(0, 25001), + expireAtNanos: 30000, result: []RollupResult{ { ID: b("rName1|rtagName1=rtagValue1,rtagName2=rtagValue2"), @@ -201,10 +201,10 @@ func TestActiveRuleSetMatchRollupRules(t *testing.T) { }, }, { - id: "rtagName1=rtagValue2", - matchFrom: time.Unix(0, 25000), - matchTo: time.Unix(0, 25001), - expireAtNs: 30000, + id: "rtagName1=rtagValue2", + matchFrom: time.Unix(0, 25000), + matchTo: time.Unix(0, 25001), + expireAtNanos: 30000, result: []RollupResult{ { ID: b("rName3|rtagName1=rtagValue2"), @@ -221,17 +221,17 @@ func TestActiveRuleSetMatchRollupRules(t *testing.T) { }, }, { - id: "rtagName5=rtagValue5", - matchFrom: time.Unix(0, 25000), - matchTo: time.Unix(0, 25001), - expireAtNs: 30000, - result: []RollupResult{}, + id: "rtagName5=rtagValue5", + matchFrom: time.Unix(0, 25000), + matchTo: time.Unix(0, 25001), + expireAtNanos: 30000, + result: []RollupResult{}, }, { - id: "rtagName1=rtagValue1,rtagName2=rtagValue2,rtagName3=rtagValue3", - matchFrom: time.Unix(0, 10000), - matchTo: time.Unix(0, 40000), - expireAtNs: 100000, + id: "rtagName1=rtagValue1,rtagName2=rtagValue2,rtagName3=rtagValue3", + matchFrom: time.Unix(0, 10000), + matchTo: time.Unix(0, 40000), + expireAtNanos: 100000, result: []RollupResult{ { ID: b("rName1|rtagName1=rtagValue1,rtagName2=rtagValue2"), @@ -319,7 +319,7 @@ func TestActiveRuleSetMatchRollupRules(t *testing.T) { require.Equal(t, expectedCutovers, as.cutoverTimesAsc) for _, input := range inputs { res := as.MatchAll(b(input.id), input.matchFrom, input.matchTo) - require.Equal(t, input.expireAtNs, res.expireAtNs) + require.Equal(t, input.expireAtNanos, res.expireAtNanos) require.Equal(t, len(input.result), res.NumRollups()) for i := 0; i < len(input.result); i++ { rollup := res.RollupsAt(i, time.Unix(0, 0)) @@ -348,7 +348,7 @@ func TestRuleSetProperties(t *testing.T) { require.Equal(t, "ruleset", ruleSet.uuid) require.Equal(t, []byte("namespace"), ruleSet.Namespace()) require.Equal(t, 1, ruleSet.Version()) - require.Equal(t, int64(34923), ruleSet.CutoverNs()) + require.Equal(t, int64(34923), ruleSet.CutoverNanos()) require.Equal(t, false, ruleSet.TombStoned()) } @@ -371,10 +371,10 @@ func TestRuleSetActiveSet(t *testing.T) { activeSetTime: time.Unix(0, 0), mappingInputs: []testMappingsData{ { - id: "mtagName1=mtagValue1", - matchFrom: time.Unix(0, 25000), - matchTo: time.Unix(0, 25001), - expireAtNs: 30000, + id: "mtagName1=mtagValue1", + matchFrom: time.Unix(0, 25000), + matchTo: time.Unix(0, 25001), + expireAtNanos: 30000, result: policy.PoliciesList{ policy.NewStagedPolicies( 22000, @@ -388,10 +388,10 @@ func TestRuleSetActiveSet(t *testing.T) { }, }, { - id: "mtagName1=mtagValue1", - matchFrom: time.Unix(0, 35000), - matchTo: time.Unix(0, 35001), - expireAtNs: 100000, + id: "mtagName1=mtagValue1", + matchFrom: time.Unix(0, 35000), + matchTo: time.Unix(0, 35001), + expireAtNanos: 100000, result: policy.PoliciesList{ policy.NewStagedPolicies( 35000, @@ -404,10 +404,10 @@ func TestRuleSetActiveSet(t *testing.T) { }, }, { - id: "mtagName1=mtagValue2", - matchFrom: time.Unix(0, 25000), - matchTo: time.Unix(0, 25001), - expireAtNs: 30000, + id: "mtagName1=mtagValue2", + matchFrom: time.Unix(0, 25000), + matchTo: time.Unix(0, 25001), + expireAtNanos: 30000, result: policy.PoliciesList{ policy.NewStagedPolicies( 24000, @@ -419,19 +419,19 @@ func TestRuleSetActiveSet(t *testing.T) { }, }, { - id: "mtagName1=mtagValue3", - matchFrom: time.Unix(0, 25000), - matchTo: time.Unix(0, 25001), - expireAtNs: 30000, - result: policy.DefaultPoliciesList, + id: "mtagName1=mtagValue3", + matchFrom: time.Unix(0, 25000), + matchTo: time.Unix(0, 25001), + expireAtNanos: 30000, + result: policy.DefaultPoliciesList, }, }, rollupInputs: []testRollupResultsData{ { - id: "rtagName1=rtagValue1,rtagName2=rtagValue2,rtagName3=rtagValue3", - matchFrom: time.Unix(0, 25000), - matchTo: time.Unix(0, 25001), - expireAtNs: 30000, + id: "rtagName1=rtagValue1,rtagName2=rtagValue2,rtagName3=rtagValue3", + matchFrom: time.Unix(0, 25000), + matchTo: time.Unix(0, 25001), + expireAtNanos: 30000, result: []RollupResult{ { ID: b("rName1|rtagName1=rtagValue1,rtagName2=rtagValue2"), @@ -462,10 +462,10 @@ func TestRuleSetActiveSet(t *testing.T) { }, }, { - id: "rtagName1=rtagValue2", - matchFrom: time.Unix(0, 25000), - matchTo: time.Unix(0, 25001), - expireAtNs: 30000, + id: "rtagName1=rtagValue2", + matchFrom: time.Unix(0, 25000), + matchTo: time.Unix(0, 25001), + expireAtNanos: 30000, result: []RollupResult{ { ID: b("rName3|rtagName1=rtagValue2"), @@ -482,11 +482,11 @@ func TestRuleSetActiveSet(t *testing.T) { }, }, { - id: "rtagName5=rtagValue5", - matchFrom: time.Unix(0, 25000), - matchTo: time.Unix(0, 25001), - expireAtNs: 30000, - result: []RollupResult{}, + id: "rtagName5=rtagValue5", + matchFrom: time.Unix(0, 25000), + matchTo: time.Unix(0, 25001), + expireAtNanos: 30000, + result: []RollupResult{}, }, }, }, @@ -494,10 +494,10 @@ func TestRuleSetActiveSet(t *testing.T) { activeSetTime: time.Unix(0, 30000), mappingInputs: []testMappingsData{ { - id: "mtagName1=mtagValue1", - matchFrom: time.Unix(0, 35000), - matchTo: time.Unix(0, 35001), - expireAtNs: 100000, + id: "mtagName1=mtagValue1", + matchFrom: time.Unix(0, 35000), + matchTo: time.Unix(0, 35001), + expireAtNanos: 100000, result: policy.PoliciesList{ policy.NewStagedPolicies( 35000, @@ -510,10 +510,10 @@ func TestRuleSetActiveSet(t *testing.T) { }, }, { - id: "mtagName1=mtagValue2", - matchFrom: time.Unix(0, 35000), - matchTo: time.Unix(0, 35001), - expireAtNs: 100000, + id: "mtagName1=mtagValue2", + matchFrom: time.Unix(0, 35000), + matchTo: time.Unix(0, 35001), + expireAtNanos: 100000, result: policy.PoliciesList{ policy.NewStagedPolicies( 35000, @@ -525,19 +525,19 @@ func TestRuleSetActiveSet(t *testing.T) { }, }, { - id: "mtagName1=mtagValue3", - matchFrom: time.Unix(0, 35000), - matchTo: time.Unix(0, 35001), - expireAtNs: 100000, - result: policy.DefaultPoliciesList, + id: "mtagName1=mtagValue3", + matchFrom: time.Unix(0, 35000), + matchTo: time.Unix(0, 35001), + expireAtNanos: 100000, + result: policy.DefaultPoliciesList, }, }, rollupInputs: []testRollupResultsData{ { - id: "rtagName1=rtagValue1,rtagName2=rtagValue2,rtagName3=rtagValue3", - matchFrom: time.Unix(0, 35000), - matchTo: time.Unix(0, 35001), - expireAtNs: 100000, + id: "rtagName1=rtagValue1,rtagName2=rtagValue2,rtagName3=rtagValue3", + matchFrom: time.Unix(0, 35000), + matchTo: time.Unix(0, 35001), + expireAtNanos: 100000, result: []RollupResult{ { ID: b("rName1|rtagName1=rtagValue1,rtagName2=rtagValue2"), @@ -555,10 +555,10 @@ func TestRuleSetActiveSet(t *testing.T) { }, }, { - id: "rtagName1=rtagValue2", - matchFrom: time.Unix(0, 35000), - matchTo: time.Unix(0, 35001), - expireAtNs: 100000, + id: "rtagName1=rtagValue2", + matchFrom: time.Unix(0, 35000), + matchTo: time.Unix(0, 35001), + expireAtNanos: 100000, result: []RollupResult{ { ID: b("rName3|rtagName1=rtagValue2"), @@ -575,11 +575,11 @@ func TestRuleSetActiveSet(t *testing.T) { }, }, { - id: "rtagName5=rtagValue5", - matchFrom: time.Unix(0, 35000), - matchTo: time.Unix(0, 35001), - expireAtNs: 100000, - result: []RollupResult{}, + id: "rtagName5=rtagValue5", + matchFrom: time.Unix(0, 35000), + matchTo: time.Unix(0, 35001), + expireAtNanos: 100000, + result: []RollupResult{}, }, }, }, @@ -587,10 +587,10 @@ func TestRuleSetActiveSet(t *testing.T) { activeSetTime: time.Unix(0, 200000), mappingInputs: []testMappingsData{ { - id: "mtagName1=mtagValue1", - matchFrom: time.Unix(0, 250000), - matchTo: time.Unix(0, 250001), - expireAtNs: timeNsMax, + id: "mtagName1=mtagValue1", + matchFrom: time.Unix(0, 250000), + matchTo: time.Unix(0, 250001), + expireAtNanos: timeNanosMax, result: policy.PoliciesList{ policy.NewStagedPolicies( 100000, @@ -602,10 +602,10 @@ func TestRuleSetActiveSet(t *testing.T) { }, }, { - id: "mtagName1=mtagValue2", - matchFrom: time.Unix(0, 250000), - matchTo: time.Unix(0, 250001), - expireAtNs: timeNsMax, + id: "mtagName1=mtagValue2", + matchFrom: time.Unix(0, 250000), + matchTo: time.Unix(0, 250001), + expireAtNanos: timeNanosMax, result: policy.PoliciesList{ policy.NewStagedPolicies( 35000, @@ -617,19 +617,19 @@ func TestRuleSetActiveSet(t *testing.T) { }, }, { - id: "mtagName1=mtagValue3", - matchFrom: time.Unix(0, 250000), - matchTo: time.Unix(0, 250001), - expireAtNs: timeNsMax, - result: policy.DefaultPoliciesList, + id: "mtagName1=mtagValue3", + matchFrom: time.Unix(0, 250000), + matchTo: time.Unix(0, 250001), + expireAtNanos: timeNanosMax, + result: policy.DefaultPoliciesList, }, }, rollupInputs: []testRollupResultsData{ { - id: "rtagName1=rtagValue1,rtagName2=rtagValue2,rtagName3=rtagValue3", - matchFrom: time.Unix(0, 250000), - matchTo: time.Unix(0, 250001), - expireAtNs: timeNsMax, + id: "rtagName1=rtagValue1,rtagName2=rtagValue2,rtagName3=rtagValue3", + matchFrom: time.Unix(0, 250000), + matchTo: time.Unix(0, 250001), + expireAtNanos: timeNanosMax, result: []RollupResult{ { ID: b("rName1|rtagName1=rtagValue1,rtagName2=rtagValue2"), @@ -659,10 +659,10 @@ func TestRuleSetActiveSet(t *testing.T) { }, }, { - id: "rtagName1=rtagValue2", - matchFrom: time.Unix(0, 250000), - matchTo: time.Unix(0, 250001), - expireAtNs: timeNsMax, + id: "rtagName1=rtagValue2", + matchFrom: time.Unix(0, 250000), + matchTo: time.Unix(0, 250001), + expireAtNanos: timeNanosMax, result: []RollupResult{ { ID: b("rName3|rtagName1=rtagValue2"), @@ -679,11 +679,11 @@ func TestRuleSetActiveSet(t *testing.T) { }, }, { - id: "rtagName5=rtagValue5", - matchFrom: time.Unix(0, 250000), - matchTo: time.Unix(0, 250001), - expireAtNs: timeNsMax, - result: []RollupResult{}, + id: "rtagName5=rtagValue5", + matchFrom: time.Unix(0, 250000), + matchTo: time.Unix(0, 250001), + expireAtNanos: timeNanosMax, + result: []RollupResult{}, }, }, }, @@ -693,12 +693,12 @@ func TestRuleSetActiveSet(t *testing.T) { as := newRuleSet.ActiveSet(inputs.activeSetTime) for _, input := range inputs.mappingInputs { res := as.MatchAll(b(input.id), input.matchFrom, input.matchTo) - require.Equal(t, input.expireAtNs, res.expireAtNs) + require.Equal(t, input.expireAtNanos, res.expireAtNanos) require.Equal(t, input.result, res.MappingsAt(time.Unix(0, 0))) } for _, input := range inputs.rollupInputs { res := as.MatchAll(b(input.id), input.matchFrom, input.matchTo) - require.Equal(t, input.expireAtNs, res.expireAtNs) + require.Equal(t, input.expireAtNanos, res.expireAtNanos) require.Equal(t, len(input.result), res.NumRollups()) for i := 0; i < len(input.result); i++ { rollup := res.RollupsAt(i, time.Unix(0, 0)) @@ -728,19 +728,19 @@ func testMappingRules(t *testing.T) []*mappingRule { uuid: "mappingRule1", snapshots: []*mappingRuleSnapshot{ &mappingRuleSnapshot{ - name: "mappingRule1.snapshot1", - tombstoned: false, - cutoverNs: 10000, - filter: filter1, + name: "mappingRule1.snapshot1", + tombstoned: false, + cutoverNanos: 10000, + filter: filter1, policies: []policy.Policy{ policy.NewPolicy(10*time.Second, xtime.Second, 24*time.Hour), }, }, &mappingRuleSnapshot{ - name: "mappingRule1.snapshot2", - tombstoned: false, - cutoverNs: 20000, - filter: filter1, + name: "mappingRule1.snapshot2", + tombstoned: false, + cutoverNanos: 20000, + filter: filter1, policies: []policy.Policy{ policy.NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), policy.NewPolicy(5*time.Minute, xtime.Minute, 48*time.Hour), @@ -748,10 +748,10 @@ func testMappingRules(t *testing.T) []*mappingRule { }, }, &mappingRuleSnapshot{ - name: "mappingRule1.snapshot3", - tombstoned: false, - cutoverNs: 30000, - filter: filter1, + name: "mappingRule1.snapshot3", + tombstoned: false, + cutoverNanos: 30000, + filter: filter1, policies: []policy.Policy{ policy.NewPolicy(30*time.Second, xtime.Second, 6*time.Hour), }, @@ -763,30 +763,30 @@ func testMappingRules(t *testing.T) []*mappingRule { uuid: "mappingRule2", snapshots: []*mappingRuleSnapshot{ &mappingRuleSnapshot{ - name: "mappingRule2.snapshot1", - tombstoned: false, - cutoverNs: 15000, - filter: filter1, + name: "mappingRule2.snapshot1", + tombstoned: false, + cutoverNanos: 15000, + filter: filter1, policies: []policy.Policy{ policy.NewPolicy(10*time.Second, xtime.Second, 12*time.Hour), }, }, &mappingRuleSnapshot{ - name: "mappingRule2.snapshot2", - tombstoned: false, - cutoverNs: 22000, - filter: filter1, + name: "mappingRule2.snapshot2", + tombstoned: false, + cutoverNanos: 22000, + filter: filter1, policies: []policy.Policy{ policy.NewPolicy(10*time.Second, xtime.Second, 2*time.Hour), policy.NewPolicy(time.Minute, xtime.Minute, time.Hour), }, }, &mappingRuleSnapshot{ - name: "mappingRule2.snapshot3", - tombstoned: true, - cutoverNs: 35000, - filter: filter1, - policies: []policy.Policy{}, + name: "mappingRule2.snapshot3", + tombstoned: true, + cutoverNanos: 35000, + filter: filter1, + policies: []policy.Policy{}, }, }, } @@ -795,10 +795,10 @@ func testMappingRules(t *testing.T) []*mappingRule { uuid: "mappingRule3", snapshots: []*mappingRuleSnapshot{ &mappingRuleSnapshot{ - name: "mappingRule3.snapshot1", - tombstoned: false, - cutoverNs: 22000, - filter: filter1, + name: "mappingRule3.snapshot1", + tombstoned: false, + cutoverNanos: 22000, + filter: filter1, policies: []policy.Policy{ policy.NewPolicy(10*time.Second, xtime.Second, 12*time.Hour), policy.NewPolicy(time.Minute, xtime.Minute, 24*time.Hour), @@ -806,10 +806,10 @@ func testMappingRules(t *testing.T) []*mappingRule { }, }, &mappingRuleSnapshot{ - name: "mappingRule3.snapshot2", - tombstoned: false, - cutoverNs: 34000, - filter: filter1, + name: "mappingRule3.snapshot2", + tombstoned: false, + cutoverNanos: 34000, + filter: filter1, policies: []policy.Policy{ policy.NewPolicy(10*time.Second, xtime.Second, 2*time.Hour), policy.NewPolicy(time.Minute, xtime.Minute, time.Hour), @@ -822,10 +822,10 @@ func testMappingRules(t *testing.T) []*mappingRule { uuid: "mappingRule4", snapshots: []*mappingRuleSnapshot{ &mappingRuleSnapshot{ - name: "mappingRule4.snapshot1", - tombstoned: false, - cutoverNs: 24000, - filter: filter2, + name: "mappingRule4.snapshot1", + tombstoned: false, + cutoverNanos: 24000, + filter: filter2, policies: []policy.Policy{ policy.NewPolicy(10*time.Second, xtime.Second, 24*time.Hour), }, @@ -837,10 +837,10 @@ func testMappingRules(t *testing.T) []*mappingRule { uuid: "mappingRule5", snapshots: []*mappingRuleSnapshot{ &mappingRuleSnapshot{ - name: "mappingRule5.snapshot1", - tombstoned: false, - cutoverNs: 100000, - filter: filter1, + name: "mappingRule5.snapshot1", + tombstoned: false, + cutoverNanos: 100000, + filter: filter1, policies: []policy.Policy{ policy.NewPolicy(10*time.Second, xtime.Second, 24*time.Hour), }, @@ -874,10 +874,10 @@ func testRollupRules(t *testing.T) []*rollupRule { uuid: "rollupRule1", snapshots: []*rollupRuleSnapshot{ &rollupRuleSnapshot{ - name: "rollupRule1.snapshot1", - tombstoned: false, - cutoverNs: 10000, - filter: filter1, + name: "rollupRule1.snapshot1", + tombstoned: false, + cutoverNanos: 10000, + filter: filter1, targets: []rollupTarget{ { Name: b("rName1"), @@ -889,10 +889,10 @@ func testRollupRules(t *testing.T) []*rollupRule { }, }, &rollupRuleSnapshot{ - name: "rollupRule1.snapshot2", - tombstoned: false, - cutoverNs: 20000, - filter: filter1, + name: "rollupRule1.snapshot2", + tombstoned: false, + cutoverNanos: 20000, + filter: filter1, targets: []rollupTarget{ { Name: b("rName1"), @@ -906,10 +906,10 @@ func testRollupRules(t *testing.T) []*rollupRule { }, }, &rollupRuleSnapshot{ - name: "rollupRule1.snapshot3", - tombstoned: false, - cutoverNs: 30000, - filter: filter1, + name: "rollupRule1.snapshot3", + tombstoned: false, + cutoverNanos: 30000, + filter: filter1, targets: []rollupTarget{ { Name: b("rName1"), @@ -927,10 +927,10 @@ func testRollupRules(t *testing.T) []*rollupRule { uuid: "rollupRule2", snapshots: []*rollupRuleSnapshot{ &rollupRuleSnapshot{ - name: "rollupRule2.snapshot1", - tombstoned: false, - cutoverNs: 15000, - filter: filter1, + name: "rollupRule2.snapshot1", + tombstoned: false, + cutoverNanos: 15000, + filter: filter1, targets: []rollupTarget{ { Name: b("rName1"), @@ -942,10 +942,10 @@ func testRollupRules(t *testing.T) []*rollupRule { }, }, &rollupRuleSnapshot{ - name: "rollupRule2.snapshot2", - tombstoned: false, - cutoverNs: 22000, - filter: filter1, + name: "rollupRule2.snapshot2", + tombstoned: false, + cutoverNanos: 22000, + filter: filter1, targets: []rollupTarget{ { Name: b("rName1"), @@ -958,10 +958,10 @@ func testRollupRules(t *testing.T) []*rollupRule { }, }, &rollupRuleSnapshot{ - name: "rollupRule2.snapshot3", - tombstoned: false, - cutoverNs: 35000, - filter: filter1, + name: "rollupRule2.snapshot3", + tombstoned: false, + cutoverNanos: 35000, + filter: filter1, targets: []rollupTarget{ { Name: b("rName1"), @@ -979,10 +979,10 @@ func testRollupRules(t *testing.T) []*rollupRule { uuid: "rollupRule3", snapshots: []*rollupRuleSnapshot{ &rollupRuleSnapshot{ - name: "rollupRule3.snapshot1", - tombstoned: false, - cutoverNs: 22000, - filter: filter1, + name: "rollupRule3.snapshot1", + tombstoned: false, + cutoverNanos: 22000, + filter: filter1, targets: []rollupTarget{ { Name: b("rName1"), @@ -1003,10 +1003,10 @@ func testRollupRules(t *testing.T) []*rollupRule { }, }, &rollupRuleSnapshot{ - name: "rollupRule3.snapshot2", - tombstoned: false, - cutoverNs: 34000, - filter: filter1, + name: "rollupRule3.snapshot2", + tombstoned: false, + cutoverNanos: 34000, + filter: filter1, targets: []rollupTarget{ { Name: b("rName1"), @@ -1019,11 +1019,11 @@ func testRollupRules(t *testing.T) []*rollupRule { }, }, &rollupRuleSnapshot{ - name: "rollupRule3.snapshot3", - tombstoned: true, - cutoverNs: 38000, - filter: filter1, - targets: []rollupTarget{}, + name: "rollupRule3.snapshot3", + tombstoned: true, + cutoverNanos: 38000, + filter: filter1, + targets: []rollupTarget{}, }, }, } @@ -1032,10 +1032,10 @@ func testRollupRules(t *testing.T) []*rollupRule { uuid: "rollupRule4", snapshots: []*rollupRuleSnapshot{ &rollupRuleSnapshot{ - name: "rollupRule4.snapshot1", - tombstoned: false, - cutoverNs: 24000, - filter: filter2, + name: "rollupRule4.snapshot1", + tombstoned: false, + cutoverNanos: 24000, + filter: filter2, targets: []rollupTarget{ { Name: b("rName3"), @@ -1053,10 +1053,10 @@ func testRollupRules(t *testing.T) []*rollupRule { uuid: "rollupRule5", snapshots: []*rollupRuleSnapshot{ &rollupRuleSnapshot{ - name: "rollupRule5.snapshot1", - tombstoned: false, - cutoverNs: 100000, - filter: filter1, + name: "rollupRule5.snapshot1", + tombstoned: false, + cutoverNanos: 100000, + filter: filter1, targets: []rollupTarget{ { Name: b("rName3"), @@ -1712,19 +1712,19 @@ func testRollupRulesConfig() []*schema.RollupRule { } type testMappingsData struct { - id string - matchFrom time.Time - matchTo time.Time - expireAtNs int64 - result policy.PoliciesList + id string + matchFrom time.Time + matchTo time.Time + expireAtNanos int64 + result policy.PoliciesList } type testRollupResultsData struct { - id string - matchFrom time.Time - matchTo time.Time - expireAtNs int64 - result []RollupResult + id string + matchFrom time.Time + matchTo time.Time + expireAtNanos int64 + result []RollupResult } func b(v string) []byte {