Skip to content

Commit

Permalink
Update the display strings for model
Browse files Browse the repository at this point in the history
Signed-off-by: Jeanette Tan <[email protected]>
  • Loading branch information
zenador committed Dec 8, 2022
1 parent 6f7d46a commit 63beb45
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
29 changes: 22 additions & 7 deletions model/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,17 @@ func (s *Sample) Equal(o *Sample) bool {
}

func (s Sample) String() string {
return fmt.Sprintf("%s => %s", s.Metric, SamplePair{
Timestamp: s.Timestamp,
Value: s.Value,
})
if s.Histogram.Count != 0 {
return fmt.Sprintf("%s => %s", s.Metric, SampleHistogramPair{
Timestamp: s.Timestamp,
Histogram: s.Histogram,
})
} else {
return fmt.Sprintf("%s => %s", s.Metric, SamplePair{
Timestamp: s.Timestamp,
Value: s.Value,
})
}
}

// MarshalJSON implements json.Marshaler.
Expand Down Expand Up @@ -175,9 +182,17 @@ type SampleStream struct {
}

func (ss SampleStream) String() string {
vals := make([]string, len(ss.Values))
for i, v := range ss.Values {
vals[i] = v.String()
var vals []string
if len(ss.Histograms) > 0 {
vals = make([]string, len(ss.Histograms))
for i, v := range ss.Histograms {
vals[i] = v.String()
}
} else {
vals = make([]string, len(ss.Values))
for i, v := range ss.Values {
vals[i] = v.String()
}
}
return fmt.Sprintf("%s =>\n%s", ss.Metric, strings.Join(vals, "\n"))
}
Expand Down
8 changes: 8 additions & 0 deletions model/value_histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ type SampleHistogram struct {
Buckets HistogramBuckets `json:"buckets"`
}

func (s SampleHistogram) String() string {
return fmt.Sprintf("Count: %d, Sum: %f, Buckets: [redacted]", s.Count, s.Sum)
}

func (s *SampleHistogram) Equal(o *SampleHistogram) bool {
return s == o || (s.Count.Equal(o.Count) && s.Sum.Equal(o.Sum) && s.Buckets.Equal(o.Buckets))
}
Expand Down Expand Up @@ -168,6 +172,10 @@ func (s *SampleHistogramPair) UnmarshalJSON(buf []byte) error {
return nil
}

func (s SampleHistogramPair) String() string {
return fmt.Sprintf("%s @[%s]", s.Histogram, s.Timestamp)
}

func (s *SampleHistogramPair) Equal(o *SampleHistogramPair) bool {
return s == o || (s.Histogram.Equal(&o.Histogram) && s.Timestamp.Equal(o.Timestamp))
}

0 comments on commit 63beb45

Please sign in to comment.