| 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 | |
| 12 pb "github.com/luci/luci-go/common/tsmon/ts_mon_proto" | 10 pb "github.com/luci/luci-go/common/tsmon/ts_mon_proto" |
| 13 ) | 11 ) |
| 14 | 12 |
| 15 // Field is the definition of a metric field. It has a name and a type | 13 // Field is the definition of a metric field. It has a name and a type |
| 16 // (string, int or bool). | 14 // (string, int or bool). |
| 17 type Field struct { | 15 type Field struct { |
| 18 Name string | 16 Name string |
| 19 Type pb.MetricsField_FieldType | 17 Type pb.MetricsField_FieldType |
| 20 } | 18 } |
| 21 | 19 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 33 // stored as int64s. | 31 // stored as int64s. |
| 34 func Int(name string) Field { return Field{name, pb.MetricsField_INT} } | 32 func Int(name string) Field { return Field{name, pb.MetricsField_INT} } |
| 35 | 33 |
| 36 // Serialize returns a slice of ts_mon_proto.MetricsField messages representing | 34 // Serialize returns a slice of ts_mon_proto.MetricsField messages representing |
| 37 // the field names, types and values. | 35 // the field names, types and values. |
| 38 func Serialize(fields []Field, values []interface{}) []*pb.MetricsField { | 36 func Serialize(fields []Field, values []interface{}) []*pb.MetricsField { |
| 39 ret := make([]*pb.MetricsField, len(fields)) | 37 ret := make([]*pb.MetricsField, len(fields)) |
| 40 | 38 |
| 41 for i, f := range fields { | 39 for i, f := range fields { |
| 42 d := &pb.MetricsField{ | 40 d := &pb.MetricsField{ |
| 43 » » » Name: proto.String(f.Name), | 41 » » » Name: f.Name, |
| 44 » » » Type: f.Type.Enum(), | 42 » » » Type: f.Type, |
| 45 } | 43 } |
| 46 | 44 |
| 47 switch f.Type { | 45 switch f.Type { |
| 48 case pb.MetricsField_STRING: | 46 case pb.MetricsField_STRING: |
| 49 » » » d.StringValue = proto.String(values[i].(string)) | 47 » » » d.StringValue = values[i].(string) |
| 50 case pb.MetricsField_BOOL: | 48 case pb.MetricsField_BOOL: |
| 51 » » » d.BoolValue = proto.Bool(values[i].(bool)) | 49 » » » d.BoolValue = values[i].(bool) |
| 52 case pb.MetricsField_INT: | 50 case pb.MetricsField_INT: |
| 53 » » » d.IntValue = proto.Int64(values[i].(int64)) | 51 » » » d.IntValue = values[i].(int64) |
| 54 } | 52 } |
| 55 | 53 |
| 56 ret[i] = d | 54 ret[i] = d |
| 57 } | 55 } |
| 58 | 56 |
| 59 return ret | 57 return ret |
| 60 } | 58 } |
| OLD | NEW |