func verifyList(list List) error { length := list.Len() pathSet := make(map[string]bool, length) groupIdToTimeStamp := make(map[int]time.Time) for i := 0; i < length; i++ { var value Value list.Index(i, &value) if pathSet[value.Path] { return errors.New( fmt.Sprintf("Duplicate path: %s", value.Path)) } pathSet[value.Path] = true if types.FromGoValue(value.Value) == types.Unknown { return errors.New( fmt.Sprintf("Bad value: %v", value.Value)) } if !value.TimeStamp.IsZero() { lastTs, ok := groupIdToTimeStamp[value.GroupId] if !ok { groupIdToTimeStamp[value.GroupId] = value.TimeStamp } else if value.TimeStamp != lastTs { return errGroupId } } } return nil }
func (l *loggerType) reportNewNamesForSuggest( list metrics.List) { length := list.Len() for i := 0; i < length; i++ { var value metrics.Value list.Index(i, &value) if types.FromGoValue(value.Value).CanToFromFloat() { if !l.NamesSentToSuggest[value.Path] { l.MetricNameAdder.Add(value.Path) l.NamesSentToSuggest[value.Path] = true } } } }
func TestFromGoValue(t *testing.T) { assertValueEquals(t, types.Bool, types.FromGoValue(true)) assertValueEquals(t, types.Int8, types.FromGoValue(int8(0))) assertValueEquals(t, types.Int16, types.FromGoValue(int16(32))) assertValueEquals(t, types.Int32, types.FromGoValue(int32(47))) assertValueEquals(t, types.Int64, types.FromGoValue(int64(50))) assertValueEquals(t, types.Uint8, types.FromGoValue(uint8(0))) assertValueEquals(t, types.Uint16, types.FromGoValue(uint16(32))) assertValueEquals(t, types.Uint32, types.FromGoValue(uint32(47))) assertValueEquals(t, types.Uint64, types.FromGoValue(uint64(50))) assertValueEquals(t, types.Float32, types.FromGoValue(float32(9.24))) assertValueEquals(t, types.Float64, types.FromGoValue(9.24)) assertValueEquals(t, types.String, types.FromGoValue("boo")) assertValueEquals(t, types.GoDuration, types.FromGoValue(time.Minute)) assertValueEquals(t, types.GoTime, types.FromGoValue(time.Now())) var dist *messages.Distribution assertValueEquals(t, types.Dist, types.FromGoValue(dist)) }