diff --git a/output/cloud/expv2/hdr.go b/output/cloud/expv2/hdr.go index b0afa29c4e7..8e2cc6fef92 100644 --- a/output/cloud/expv2/hdr.go +++ b/output/cloud/expv2/hdr.go @@ -143,13 +143,14 @@ func histogramAsProto(h *histogram, time int64) *pbcloud.TrendHdrValue { } hval := &pbcloud.TrendHdrValue{ - Time: timestampAsProto(time), - MinValue: h.Min, - MaxValue: h.Max, - Sum: h.Sum, - Count: h.Count, - Counters: counters, - Spans: spans, + Time: timestampAsProto(time), + MinValue: h.Min, + MaxValue: h.Max, + Sum: h.Sum, + Count: h.Count, + Counters: counters, + Spans: spans, + MinResolution: h.MinimumResolution, } if h.ExtraLowBucket > 0 { hval.ExtraLowValuesCounter = &h.ExtraLowBucket @@ -157,9 +158,6 @@ func histogramAsProto(h *histogram, time int64) *pbcloud.TrendHdrValue { if h.ExtraHighBucket > 0 { hval.ExtraHighValuesCounter = &h.ExtraHighBucket } - // We don't expect to change the minimum resolution at runtime - // so it is safe use directly a pointer without creating a copy - hval.MinResolution = &h.MinimumResolution return hval } diff --git a/output/cloud/expv2/hdr_test.go b/output/cloud/expv2/hdr_test.go index 3950416e4ad..a7dacbaf7ea 100644 --- a/output/cloud/expv2/hdr_test.go +++ b/output/cloud/expv2/hdr_test.go @@ -130,6 +130,8 @@ func TestHistogramAddWithSimpleValues(t *testing.T) { t.Run(strconv.Itoa(i), func(t *testing.T) { t.Parallel() h := newHistogram() + // We use a lower resolution instead of the default + // so we can keep smaller numbers in this test h.MinimumResolution = 1.0 for _, v := range tc.vals { h.Add(v) @@ -188,7 +190,6 @@ func TestHistogramAddWithNegativeNum(t *testing.T) { t.Parallel() h := newHistogram() - h.MinimumResolution = 1.0 h.Add(-2.42314) exp := &histogram{ @@ -199,7 +200,7 @@ func TestHistogramAddWithNegativeNum(t *testing.T) { ExtraHighBucket: 0, Sum: -2.42314, Count: 1, - MinimumResolution: 1.0, + MinimumResolution: .001, } assert.Equal(t, exp, h) } @@ -207,7 +208,6 @@ func TestHistogramAddWithNegativeNum(t *testing.T) { func TestHistogramAddWithMultipleNegativeNums(t *testing.T) { t.Parallel() h := newHistogram() - h.MinimumResolution = 1.0 for _, v := range []float64{-0.001, -0.001, -0.001} { h.Add(v) } @@ -220,9 +220,8 @@ func TestHistogramAddWithMultipleNegativeNums(t *testing.T) { Min: -0.001, Sum: -0.003, Count: 3, - MinimumResolution: 1.0, + MinimumResolution: .001, } - h.MinimumResolution = 1.0 assert.Equal(t, exp, h) } @@ -257,7 +256,7 @@ func TestNewHistoram(t *testing.T) { Max: -math.MaxFloat64, Min: math.MaxFloat64, Sum: 0, - MinimumResolution: 0.001, + MinimumResolution: .001, } assert.Equal(t, exp, h) } @@ -283,8 +282,9 @@ func TestHistogramAsProto(t *testing.T) { }, }, { - name: "UntrackableValues", - vals: []float64{-0.23, 1<<64 - 1}, + name: "UntrackableValues", + vals: []float64{-0.23, 1<<64 - 1}, + minResolution: 1.0, exp: &pbcloud.TrendHdrValue{ ExtraLowValuesCounter: uint32ptr(1), ExtraHighValuesCounter: uint32ptr(1), @@ -294,11 +294,13 @@ func TestHistogramAsProto(t *testing.T) { MinValue: -0.23, MaxValue: 1<<64 - 1, Sum: (1 << 64) - 1 - 0.23, + MinResolution: 1.0, }, }, { - name: "SimpleValues", - vals: []float64{7, 8, 9, 11, 12, 11.5, 10.5}, + name: "SimpleValuesWithLowerResolution", + vals: []float64{7, 8, 9, 11, 12, 11.5, 10.5}, + minResolution: 1.0, exp: &pbcloud.TrendHdrValue{ Count: 7, ExtraLowValuesCounter: nil, @@ -306,16 +308,42 @@ func TestHistogramAsProto(t *testing.T) { Counters: []uint32{1, 1, 1, 2, 2}, Spans: []*pbcloud.BucketSpan{ {Offset: 7, Length: 3}, - {Offset: 1, Length: 2}, + {Offset: 1, Length: 2}, // 11 + }, + MinValue: 7, + MaxValue: 12, + Sum: 69, + MinResolution: 1.0, + }, + }, + { + name: "SimpleValues", + vals: []float64{7, 8, 9, 11, 12, 11.5, 10.5}, + minResolution: .001, + exp: &pbcloud.TrendHdrValue{ + Count: 7, + ExtraLowValuesCounter: nil, + ExtraHighValuesCounter: nil, + Counters: []uint32{1, 1, 1, 1, 1, 1, 1}, + Spans: []*pbcloud.BucketSpan{ + {Offset: 858, Length: 1}, + {Offset: 31, Length: 1}, // 890 + {Offset: 17, Length: 1}, // 908 + {Offset: 23, Length: 1}, // 932 + {Offset: 6, Length: 1}, // 939 + {Offset: 7, Length: 1}, // 947 + {Offset: 7, Length: 1}, // 955 }, - MinValue: 7, - MaxValue: 12, - Sum: 69, + MinValue: 7, + MaxValue: 12, + Sum: 69, + MinResolution: .001, }, }, { - name: "WithZeroPointValues", - vals: []float64{2, 0.01, 3}, + name: "WithZeroPointValues", + vals: []float64{2, 0.01, 3}, + minResolution: .001, exp: &pbcloud.TrendHdrValue{ Count: 3, ExtraLowValuesCounter: nil, @@ -323,18 +351,28 @@ func TestHistogramAsProto(t *testing.T) { Counters: []uint32{1, 1, 1}, Spans: []*pbcloud.BucketSpan{ { - Offset: 1, - Length: 3, + Offset: 10, + Length: 1, + }, + { + Offset: 623, + Length: 1, + }, + { + Offset: 64, + Length: 1, }, }, - MinValue: 0.01, - MaxValue: 3, - Sum: 5.01, + MinValue: 0.01, + MaxValue: 3, + Sum: 5.01, + MinResolution: .001, }, }, { - name: "VeryBasic", - vals: []float64{2, 1.1, 3}, + name: "VeryBasic", + vals: []float64{2, 1.1, 3}, + minResolution: 1.0, exp: &pbcloud.TrendHdrValue{ Count: 3, ExtraLowValuesCounter: nil, @@ -346,9 +384,10 @@ func TestHistogramAsProto(t *testing.T) { Length: 2, }, }, - MinValue: 1.1, - MaxValue: 3, - Sum: 6.1, + MinValue: 1.1, + MaxValue: 3, + Sum: 6.1, + MinResolution: 1.0, }, }, { @@ -358,6 +397,9 @@ func TestHistogramAsProto(t *testing.T) { 163.85, 4105, 835.27, 52, 18.28, 238.44, 39751, 18.86, 967.05, 967.01, 967, 4123.5, 270.69, 677.27, }, + // It uses 1.0 as resolution for keeping numbers smaller + // and the test more controllable. + minResolution: 1.0, // Sorted: // 18.28,18.49,18.86,52,52.25,163.85, // 238.44,268.85,270.69,383.47,677.27,835.27,967,967.01,967.05 @@ -388,11 +430,13 @@ func TestHistogramAsProto(t *testing.T) { MinValue: 18.28, MaxValue: 39751, Sum: 56153.280000000006, + MinResolution: 1.0, }, }, { - name: "Unrealistic", - vals: []float64{math.MaxUint32}, + name: "Unrealistic", + vals: []float64{math.MaxUint32}, + minResolution: .001, exp: &pbcloud.TrendHdrValue{ Count: 1, ExtraLowValuesCounter: nil, @@ -400,13 +444,14 @@ func TestHistogramAsProto(t *testing.T) { Counters: []uint32{1}, Spans: []*pbcloud.BucketSpan{ { - Offset: 3327, + Offset: 4601, Length: 1, }, }, - MinValue: math.MaxUint32, - MaxValue: math.MaxUint32, - Sum: math.MaxUint32, + MinValue: math.MaxUint32, + MaxValue: math.MaxUint32, + Sum: math.MaxUint32, + MinResolution: .001, }, }, { @@ -417,7 +462,7 @@ func TestHistogramAsProto(t *testing.T) { Count: 3, ExtraLowValuesCounter: nil, ExtraHighValuesCounter: nil, - MinResolution: float64ptr(defaultMinimumResolution), + MinResolution: defaultMinimumResolution, Counters: []uint32{1, 2}, Spans: []*pbcloud.BucketSpan{ { @@ -442,12 +487,6 @@ func TestHistogramAsProto(t *testing.T) { t.Parallel() h := newHistogram() - // TODO: refactor - // An hack for preserving as the default for the tests the old value 1.0 - if tc.minResolution == 0 { - tc.minResolution = 1.0 - tc.exp.MinResolution = float64ptr(1.0) - } h.MinimumResolution = tc.minResolution for _, v := range tc.vals { @@ -462,7 +501,3 @@ func TestHistogramAsProto(t *testing.T) { }) } } - -func float64ptr(n float64) *float64 { - return &n -} diff --git a/output/cloud/expv2/pbcloud/metric.pb.go b/output/cloud/expv2/pbcloud/metric.pb.go index 6b472355419..189b1bb603c 100644 --- a/output/cloud/expv2/pbcloud/metric.pb.go +++ b/output/cloud/expv2/pbcloud/metric.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.28.1 +// protoc-gen-go v1.31.0 // protoc v3.21.12 // source: metric.proto @@ -876,9 +876,10 @@ type TrendHdrValue struct { // counters for zero- and infinity-buckets ExtraLowValuesCounter *uint32 `protobuf:"varint,9,opt,name=extra_low_values_counter,json=extraLowValuesCounter,proto3,oneof" json:"extra_low_values_counter,omitempty"` ExtraHighValuesCounter *uint32 `protobuf:"varint,10,opt,name=extra_high_values_counter,json=extraHighValuesCounter,proto3,oneof" json:"extra_high_values_counter,omitempty"` - // histogram parameter - value multiplier aka smallest value + // min_resolution is a multiplier factor applied to the tracked values of the histogram. + // It is helpful for up and down scaling values and representing different orders of magnitude. // default = 1.0 - MinResolution *float64 `protobuf:"fixed64,11,opt,name=min_resolution,json=minResolution,proto3,oneof" json:"min_resolution,omitempty"` + MinResolution float64 `protobuf:"fixed64,11,opt,name=min_resolution,json=minResolution,proto3" json:"min_resolution,omitempty"` // histogram parameter - number of significant digits used to calculate buckets formula // default = 2 SignificantDigits *uint32 `protobuf:"varint,12,opt,name=significant_digits,json=significantDigits,proto3,oneof" json:"significant_digits,omitempty"` @@ -980,8 +981,8 @@ func (x *TrendHdrValue) GetExtraHighValuesCounter() uint32 { } func (x *TrendHdrValue) GetMinResolution() float64 { - if x != nil && x.MinResolution != nil { - return *x.MinResolution + if x != nil { + return x.MinResolution } return 0 } @@ -1082,7 +1083,7 @@ var file_metric_proto_rawDesc = []byte{ 0x42, 0x75, 0x63, 0x6b, 0x65, 0x74, 0x53, 0x70, 0x61, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x0d, 0x52, 0x06, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x22, 0xab, 0x04, 0x0a, 0x0d, 0x54, + 0x28, 0x0d, 0x52, 0x06, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x22, 0x93, 0x04, 0x0a, 0x0d, 0x54, 0x72, 0x65, 0x6e, 0x64, 0x48, 0x64, 0x72, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x2e, 0x0a, 0x04, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, @@ -1105,31 +1106,29 @@ var file_metric_proto_rawDesc = []byte{ 0x68, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x0d, 0x48, 0x01, 0x52, 0x16, 0x65, 0x78, 0x74, 0x72, 0x61, 0x48, 0x69, 0x67, 0x68, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72, - 0x88, 0x01, 0x01, 0x12, 0x2a, 0x0a, 0x0e, 0x6d, 0x69, 0x6e, 0x5f, 0x72, 0x65, 0x73, 0x6f, 0x6c, - 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x01, 0x48, 0x02, 0x52, 0x0d, 0x6d, - 0x69, 0x6e, 0x52, 0x65, 0x73, 0x6f, 0x6c, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x88, 0x01, 0x01, 0x12, - 0x32, 0x0a, 0x12, 0x73, 0x69, 0x67, 0x6e, 0x69, 0x66, 0x69, 0x63, 0x61, 0x6e, 0x74, 0x5f, 0x64, - 0x69, 0x67, 0x69, 0x74, 0x73, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x0d, 0x48, 0x03, 0x52, 0x11, 0x73, - 0x69, 0x67, 0x6e, 0x69, 0x66, 0x69, 0x63, 0x61, 0x6e, 0x74, 0x44, 0x69, 0x67, 0x69, 0x74, 0x73, - 0x88, 0x01, 0x01, 0x42, 0x1b, 0x0a, 0x19, 0x5f, 0x65, 0x78, 0x74, 0x72, 0x61, 0x5f, 0x6c, 0x6f, - 0x77, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72, - 0x42, 0x1c, 0x0a, 0x1a, 0x5f, 0x65, 0x78, 0x74, 0x72, 0x61, 0x5f, 0x68, 0x69, 0x67, 0x68, 0x5f, - 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72, 0x42, 0x11, - 0x0a, 0x0f, 0x5f, 0x6d, 0x69, 0x6e, 0x5f, 0x72, 0x65, 0x73, 0x6f, 0x6c, 0x75, 0x74, 0x69, 0x6f, - 0x6e, 0x42, 0x15, 0x0a, 0x13, 0x5f, 0x73, 0x69, 0x67, 0x6e, 0x69, 0x66, 0x69, 0x63, 0x61, 0x6e, - 0x74, 0x5f, 0x64, 0x69, 0x67, 0x69, 0x74, 0x73, 0x2a, 0x86, 0x01, 0x0a, 0x0a, 0x4d, 0x65, 0x74, - 0x72, 0x69, 0x63, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1b, 0x0a, 0x17, 0x4d, 0x45, 0x54, 0x52, 0x49, - 0x43, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, - 0x45, 0x44, 0x10, 0x00, 0x12, 0x17, 0x0a, 0x13, 0x4d, 0x45, 0x54, 0x52, 0x49, 0x43, 0x5f, 0x54, - 0x59, 0x50, 0x45, 0x5f, 0x43, 0x4f, 0x55, 0x4e, 0x54, 0x45, 0x52, 0x10, 0x01, 0x12, 0x15, 0x0a, - 0x11, 0x4d, 0x45, 0x54, 0x52, 0x49, 0x43, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x47, 0x41, 0x55, - 0x47, 0x45, 0x10, 0x02, 0x12, 0x14, 0x0a, 0x10, 0x4d, 0x45, 0x54, 0x52, 0x49, 0x43, 0x5f, 0x54, - 0x59, 0x50, 0x45, 0x5f, 0x52, 0x41, 0x54, 0x45, 0x10, 0x03, 0x12, 0x15, 0x0a, 0x11, 0x4d, 0x45, - 0x54, 0x52, 0x49, 0x43, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x54, 0x52, 0x45, 0x4e, 0x44, 0x10, - 0x04, 0x42, 0x28, 0x5a, 0x26, 0x67, 0x6f, 0x2e, 0x6b, 0x36, 0x2e, 0x69, 0x6f, 0x2f, 0x6b, 0x36, - 0x2f, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x2f, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x2f, 0x65, 0x78, - 0x70, 0x76, 0x32, 0x2f, 0x70, 0x62, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, + 0x88, 0x01, 0x01, 0x12, 0x25, 0x0a, 0x0e, 0x6d, 0x69, 0x6e, 0x5f, 0x72, 0x65, 0x73, 0x6f, 0x6c, + 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x01, 0x52, 0x0d, 0x6d, 0x69, 0x6e, + 0x52, 0x65, 0x73, 0x6f, 0x6c, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x32, 0x0a, 0x12, 0x73, 0x69, + 0x67, 0x6e, 0x69, 0x66, 0x69, 0x63, 0x61, 0x6e, 0x74, 0x5f, 0x64, 0x69, 0x67, 0x69, 0x74, 0x73, + 0x18, 0x0c, 0x20, 0x01, 0x28, 0x0d, 0x48, 0x02, 0x52, 0x11, 0x73, 0x69, 0x67, 0x6e, 0x69, 0x66, + 0x69, 0x63, 0x61, 0x6e, 0x74, 0x44, 0x69, 0x67, 0x69, 0x74, 0x73, 0x88, 0x01, 0x01, 0x42, 0x1b, + 0x0a, 0x19, 0x5f, 0x65, 0x78, 0x74, 0x72, 0x61, 0x5f, 0x6c, 0x6f, 0x77, 0x5f, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x73, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72, 0x42, 0x1c, 0x0a, 0x1a, 0x5f, + 0x65, 0x78, 0x74, 0x72, 0x61, 0x5f, 0x68, 0x69, 0x67, 0x68, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x73, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72, 0x42, 0x15, 0x0a, 0x13, 0x5f, 0x73, 0x69, + 0x67, 0x6e, 0x69, 0x66, 0x69, 0x63, 0x61, 0x6e, 0x74, 0x5f, 0x64, 0x69, 0x67, 0x69, 0x74, 0x73, + 0x2a, 0x86, 0x01, 0x0a, 0x0a, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x54, 0x79, 0x70, 0x65, 0x12, + 0x1b, 0x0a, 0x17, 0x4d, 0x45, 0x54, 0x52, 0x49, 0x43, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x55, + 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x17, 0x0a, 0x13, + 0x4d, 0x45, 0x54, 0x52, 0x49, 0x43, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x43, 0x4f, 0x55, 0x4e, + 0x54, 0x45, 0x52, 0x10, 0x01, 0x12, 0x15, 0x0a, 0x11, 0x4d, 0x45, 0x54, 0x52, 0x49, 0x43, 0x5f, + 0x54, 0x59, 0x50, 0x45, 0x5f, 0x47, 0x41, 0x55, 0x47, 0x45, 0x10, 0x02, 0x12, 0x14, 0x0a, 0x10, + 0x4d, 0x45, 0x54, 0x52, 0x49, 0x43, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x52, 0x41, 0x54, 0x45, + 0x10, 0x03, 0x12, 0x15, 0x0a, 0x11, 0x4d, 0x45, 0x54, 0x52, 0x49, 0x43, 0x5f, 0x54, 0x59, 0x50, + 0x45, 0x5f, 0x54, 0x52, 0x45, 0x4e, 0x44, 0x10, 0x04, 0x42, 0x28, 0x5a, 0x26, 0x67, 0x6f, 0x2e, + 0x6b, 0x36, 0x2e, 0x69, 0x6f, 0x2f, 0x6b, 0x36, 0x2f, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x2f, + 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x2f, 0x65, 0x78, 0x70, 0x76, 0x32, 0x2f, 0x70, 0x62, 0x63, 0x6c, + 0x6f, 0x75, 0x64, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/output/cloud/expv2/pbcloud/metric.proto b/output/cloud/expv2/pbcloud/metric.proto index 4e66cae57e3..de89e58eec1 100644 --- a/output/cloud/expv2/pbcloud/metric.proto +++ b/output/cloud/expv2/pbcloud/metric.proto @@ -144,9 +144,10 @@ message TrendHdrValue { optional uint32 extra_low_values_counter = 9; optional uint32 extra_high_values_counter = 10; - // histogram parameter - value multiplier aka smallest value + // min_resolution is a multiplier factor applied to the tracked values of the histogram. + // It is helpful for up and down scaling values and representing different orders of magnitude. // default = 1.0 - optional double min_resolution = 11; + double min_resolution = 11; // histogram parameter - number of significant digits used to calculate buckets formula // default = 2