From 14ed1f8cd23062d57f0d1db85d3f0a11fbcab813 Mon Sep 17 00:00:00 2001 From: Jeanette Tan Date: Fri, 23 Dec 2022 19:53:04 +0800 Subject: [PATCH] Add generic interface for float/histogram sample pair (bumping go version - experimental) Signed-off-by: Jeanette Tan --- go.mod | 2 +- model/value.go | 5 +++++ model/value_float.go | 4 ++++ model/value_histogram.go | 4 ++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index f3914717..04c820ec 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/prometheus/common -go 1.17 +go 1.18 require ( github.com/go-kit/log v0.2.1 diff --git a/model/value.go b/model/value.go index 15a87570..387ce9e9 100644 --- a/model/value.go +++ b/model/value.go @@ -379,3 +379,8 @@ func (mat Matrix) String() string { return strings.Join(strs, "\n") } + +type GenericSamplePair interface { + SamplePair | SampleHistogramPair + GetTimestamp() Time +} diff --git a/model/value_float.go b/model/value_float.go index 9266fb98..679af22b 100644 --- a/model/value_float.go +++ b/model/value_float.go @@ -99,3 +99,7 @@ func (s *SamplePair) Equal(o *SamplePair) bool { func (s SamplePair) String() string { return fmt.Sprintf("%s @[%s]", s.Value, s.Timestamp) } + +func (s SamplePair) GetTimestamp() Time { + return s.Timestamp +} diff --git a/model/value_histogram.go b/model/value_histogram.go index a4be0bca..9498ded9 100644 --- a/model/value_histogram.go +++ b/model/value_histogram.go @@ -169,3 +169,7 @@ func (s SampleHistogramPair) String() string { func (s *SampleHistogramPair) Equal(o *SampleHistogramPair) bool { return s == o || (s.Histogram.Equal(&o.Histogram) && s.Timestamp.Equal(o.Timestamp)) } + +func (s SampleHistogramPair) GetTimestamp() Time { + return s.Timestamp +}