diff --git a/internal/server/mock/metrics/server.go b/internal/server/mock/metrics/server.go index 4f8dd0e..49981d2 100644 --- a/internal/server/mock/metrics/server.go +++ b/internal/server/mock/metrics/server.go @@ -19,19 +19,20 @@ type Server struct { pb.UnimplementedMetricsServer } -func deterministicRange(t time.Time, minVal, maxVal, seconds int64, key string) int64 { +// deterministicRange returns a specific value consistently for a point in a time series. +func deterministicRange(t time.Time, minVal, maxVal float64, seconds int64, key string) float64 { h := fnv.New32a() bucketKey := fmt.Sprintf("%d-%s", t.Unix()/seconds, key) _, _ = h.Write([]byte(bucketKey)) - hashVal := int64(h.Sum32()) + hashVal := float64(h.Sum32()) / float64(^uint32(0)) - rangeSize := maxVal - minVal + 1 - return minVal + (hashVal % rangeSize) + rangeSize := maxVal - minVal + return minVal + (hashVal * rangeSize) } -func metricMappings(metricType pb.MetricType) map[string][]int64 { - data := map[pb.MetricType]map[string][]int64{ +func metricMappings(metricType pb.MetricType) map[string][]float64 { + data := map[pb.MetricType]map[string][]float64{ pb.MetricType_CLUSTER: { "requests": {250_000, 4_000_000}, "httpcode_target_200": {500, 1_000}, @@ -42,7 +43,7 @@ func metricMappings(metricType pb.MetricType) map[string][]int64 { pb.MetricType_ENVIRONMENT: { "requests": {25_000, 200_000}, "cpu": {25, 100}, - "memory": {512, 4096}, + "memory": {512_000, 4_294_967_296}, // 512KB to 4GB "replicas": {2, 8}, "php_active": {4, 48}, "php_idle": {2, 12}, @@ -55,9 +56,9 @@ func metricMappings(metricType pb.MetricType) map[string][]int64 { "httpcode_target_300": {25, 50}, "httpcode_target_400": {10, 25}, "httpcode_target_500": {0, 10}, - "response_times_avg": {100, 250}, - "response_times_p95": {2_000, 5_000}, - "response_times_p99": {10_000, 20_000}, + "response_times_avg": {0.1, 0.25}, + "response_times_p95": {2.0, 5.0}, + "response_times_p99": {10.0, 20.0}, }, } return data[metricType] diff --git a/metrics.proto b/metrics.proto index 1176026..aa674ba 100644 --- a/metrics.proto +++ b/metrics.proto @@ -68,5 +68,5 @@ message AbsoluteRangeResponse { */ message MetricValue { google.protobuf.Timestamp timestamp = 1; // The timestamp of the metric.. - int64 value = 2; // The value of the metric at the given timestamp. + double value = 2; // The value of the metric at the given timestamp. } diff --git a/pb/metrics.pb.go b/pb/metrics.pb.go index 71c3cd3..648524e 100644 --- a/pb/metrics.pb.go +++ b/pb/metrics.pb.go @@ -377,7 +377,7 @@ type MetricValue struct { unknownFields protoimpl.UnknownFields Timestamp *timestamppb.Timestamp `protobuf:"bytes,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"` // The timestamp of the metric.. - Value int64 `protobuf:"varint,2,opt,name=value,proto3" json:"value,omitempty"` // The value of the metric at the given timestamp. + Value float64 `protobuf:"fixed64,2,opt,name=value,proto3" json:"value,omitempty"` // The value of the metric at the given timestamp. } func (x *MetricValue) Reset() { @@ -419,7 +419,7 @@ func (x *MetricValue) GetTimestamp() *timestamppb.Timestamp { return nil } -func (x *MetricValue) GetValue() int64 { +func (x *MetricValue) GetValue() float64 { if x != nil { return x.Value } @@ -476,7 +476,7 @@ var file_metrics_proto_rawDesc = []byte{ 0x74, 0x61, 0x6d, 0x70, 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, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, - 0x70, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, + 0x70, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x01, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x2a, 0x54, 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,