| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package field | 5 package field |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 | 9 |
| 10 "github.com/golang/protobuf/proto" |
| 11 |
| 10 pb "github.com/luci/luci-go/common/tsmon/ts_mon_proto" | 12 pb "github.com/luci/luci-go/common/tsmon/ts_mon_proto" |
| 11 ) | 13 ) |
| 12 | 14 |
| 13 // Field is the definition of a metric field. It has a name and a type | 15 // Field is the definition of a metric field. It has a name and a type |
| 14 // (string, int or bool). | 16 // (string, int or bool). |
| 15 type Field struct { | 17 type Field struct { |
| 16 Name string | 18 Name string |
| 17 Type pb.MetricsField_FieldType | 19 Type pb.MetricsField_FieldType |
| 18 } | 20 } |
| 19 | 21 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 31 // stored as int64s. | 33 // stored as int64s. |
| 32 func Int(name string) Field { return Field{name, pb.MetricsField_INT} } | 34 func Int(name string) Field { return Field{name, pb.MetricsField_INT} } |
| 33 | 35 |
| 34 // Serialize returns a slice of ts_mon_proto.MetricsField messages representing | 36 // Serialize returns a slice of ts_mon_proto.MetricsField messages representing |
| 35 // the field names, types and values. | 37 // the field names, types and values. |
| 36 func Serialize(fields []Field, values []interface{}) []*pb.MetricsField { | 38 func Serialize(fields []Field, values []interface{}) []*pb.MetricsField { |
| 37 ret := make([]*pb.MetricsField, len(fields)) | 39 ret := make([]*pb.MetricsField, len(fields)) |
| 38 | 40 |
| 39 for i, f := range fields { | 41 for i, f := range fields { |
| 40 d := &pb.MetricsField{ | 42 d := &pb.MetricsField{ |
| 41 » » » Name: f.Name, | 43 » » » Name: proto.String(f.Name), |
| 42 » » » Type: f.Type, | 44 » » » Type: f.Type.Enum(), |
| 43 } | 45 } |
| 44 | 46 |
| 45 switch f.Type { | 47 switch f.Type { |
| 46 case pb.MetricsField_STRING: | 48 case pb.MetricsField_STRING: |
| 47 » » » d.StringValue = values[i].(string) | 49 » » » d.StringValue = proto.String(values[i].(string)) |
| 48 case pb.MetricsField_BOOL: | 50 case pb.MetricsField_BOOL: |
| 49 » » » d.BoolValue = values[i].(bool) | 51 » » » d.BoolValue = proto.Bool(values[i].(bool)) |
| 50 case pb.MetricsField_INT: | 52 case pb.MetricsField_INT: |
| 51 » » » d.IntValue = values[i].(int64) | 53 » » » d.IntValue = proto.Int64(values[i].(int64)) |
| 52 } | 54 } |
| 53 | 55 |
| 54 ret[i] = d | 56 ret[i] = d |
| 55 } | 57 } |
| 56 | 58 |
| 57 return ret | 59 return ret |
| 58 } | 60 } |
| OLD | NEW |