Пример #1
0
func verifyJsonValue(
	t *testing.T, m *metric, tp types.Type, bits int, value interface{}) {
	var ametric messages.Metric
	ametric.Unit = m.Unit()
	m.UpdateJsonMetric(nil, &ametric)
	assertValueEquals(t, tp, ametric.Kind)
	assertValueEquals(t, bits, ametric.Bits)
	assertValueEquals(t, value, ametric.Value)
}
Пример #2
0
func (v *value) updateJsonOrRpcMetric(
	s *session, metric *messages.Metric, encoding rpcEncoding) {
	t := v.Type()
	metric.Kind = t
	metric.Bits = v.Bits()
	switch t {
	case types.Dist:
		snapshot := v.AsDistribution().Snapshot()
		metric.Value = &messages.Distribution{
			Min:             snapshot.Min,
			Max:             snapshot.Max,
			Average:         snapshot.Average,
			Median:          snapshot.Median,
			Sum:             snapshot.Sum,
			Count:           snapshot.Count,
			Generation:      snapshot.Generation,
			IsNotCumulative: snapshot.IsNotCumulative,
			Ranges:          asRanges(snapshot.Breakdown)}
	default:
		metric.Value = v.AsInterface(s)
	}
	if encoding == jsonEncoding {
		metric.ConvertToJson()
	}
}
Пример #3
0
func (v *value) updateJsonOrRpcMetric(
	s *session, metric *messages.Metric, encoding rpcEncoding) {
	t := v.Type()
	metric.Kind = t
	metric.SubType = v.SubType()
	metric.Bits = v.Bits()
	metric.Unit = v.Unit()
	switch t {
	case types.Dist:
		dist := v.AsDistribution()
		snapshot := dist.Snapshot()
		metric.Value = &messages.Distribution{
			Min:             snapshot.Min,
			Max:             snapshot.Max,
			Average:         snapshot.Average,
			Median:          snapshot.Median,
			Sum:             snapshot.Sum,
			Count:           snapshot.Count,
			Generation:      snapshot.Generation,
			IsNotCumulative: snapshot.IsNotCumulative,
			Ranges:          asRanges(snapshot.Breakdown)}
		metric.GroupId = dist.GroupId()
		metric.TimeStamp = snapshot.TimeStamp
	case types.List:
		alist := v.AsList()
		metric.Value, metric.TimeStamp = alist.AsSlice()
		metric.GroupId = alist.GroupId()
	default:
		if s == nil {
			s = newSession()
			defer s.Close()
		}
		metric.Value = v.AsInterface(s)
		metric.GroupId = v.RegionId()
		metric.TimeStamp = v.TimeStamp(s)
	}
	if encoding == jsonEncoding {
		metric.ConvertToJson()
	}
}