Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Side by Side Diff: common/tsmon/target/target.go

Issue 1854583002: Migrate tsmon protos to proto3 (Closed) Base URL: git@github.com:luci/luci-go.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 target contains information about the thing that is sending metrics - 5 // Package target contains information about the thing that is sending metrics -
6 // either a NetworkDevice (a machine) or a Task (a service). 6 // either a NetworkDevice (a machine) or a Task (a service).
7 // There is a default target that is usually configured with commandline flags 7 // There is a default target that is usually configured with commandline flags
8 // (flags.go), but a target can also be passed through the Context (context.go) 8 // (flags.go), but a target can also be passed through the Context (context.go)
9 // if you need to set metric values for a different target. 9 // if you need to set metric values for a different target.
10 package target 10 package target
(...skipping 14 matching lines...) Expand all
25 25
26 // AsProto returns this object as a tsmon.proto.Task message. 26 // AsProto returns this object as a tsmon.proto.Task message.
27 func (t *Task) AsProto() *pb.Task { return (*pb.Task)(t) } 27 func (t *Task) AsProto() *pb.Task { return (*pb.Task)(t) }
28 28
29 // PopulateProto implements Target. 29 // PopulateProto implements Target.
30 func (t *Task) PopulateProto(d *pb.MetricsData) { d.Task = t.AsProto() } 30 func (t *Task) PopulateProto(d *pb.MetricsData) { d.Task = t.AsProto() }
31 31
32 // IsPopulatedIn returns true if the MetricsData message is for this target. 32 // IsPopulatedIn returns true if the MetricsData message is for this target.
33 func (t *Task) IsPopulatedIn(d *pb.MetricsData) bool { 33 func (t *Task) IsPopulatedIn(d *pb.MetricsData) bool {
34 return d.Task != nil && 34 return d.Task != nil &&
35 » » d.Task.GetServiceName() == t.AsProto().GetServiceName() && 35 » » d.Task.ServiceName == t.AsProto().ServiceName &&
36 » » d.Task.GetJobName() == t.AsProto().GetJobName() && 36 » » d.Task.JobName == t.AsProto().JobName &&
37 » » d.Task.GetDataCenter() == t.AsProto().GetDataCenter() && 37 » » d.Task.DataCenter == t.AsProto().DataCenter &&
38 » » d.Task.GetHostName() == t.AsProto().GetHostName() && 38 » » d.Task.HostName == t.AsProto().HostName &&
39 » » d.Task.GetTaskNum() == t.AsProto().GetTaskNum() 39 » » d.Task.TaskNum == t.AsProto().TaskNum
40 } 40 }
41 41
42 // Hash returns a uint64 hash of this target. 42 // Hash returns a uint64 hash of this target.
43 func (t *Task) Hash() uint64 { 43 func (t *Task) Hash() uint64 {
44 h := fnv.New64a() 44 h := fnv.New64a()
45 fmt.Fprintf(h, "%s\n%s\n%s\n%s\n%d", 45 fmt.Fprintf(h, "%s\n%s\n%s\n%s\n%d",
46 » » t.AsProto().GetServiceName(), 46 » » t.AsProto().ServiceName,
47 » » t.AsProto().GetJobName(), 47 » » t.AsProto().JobName,
48 » » t.AsProto().GetDataCenter(), 48 » » t.AsProto().DataCenter,
49 » » t.AsProto().GetHostName(), 49 » » t.AsProto().HostName,
50 » » t.AsProto().GetTaskNum()) 50 » » t.AsProto().TaskNum)
51 return h.Sum64() 51 return h.Sum64()
52 } 52 }
53 53
54 // Clone returns a copy of this object. 54 // Clone returns a copy of this object.
55 func (t *Task) Clone() types.Target { 55 func (t *Task) Clone() types.Target {
56 return (*Task)(proto.Clone(t.AsProto()).(*pb.Task)) 56 return (*Task)(proto.Clone(t.AsProto()).(*pb.Task))
57 } 57 }
58 58
59 // A NetworkDevice is a machine that has a hostname. 59 // A NetworkDevice is a machine that has a hostname.
60 type NetworkDevice pb.NetworkDevice 60 type NetworkDevice pb.NetworkDevice
61 61
62 // AsProto returns this object as a tsmon.proto.NetworkDevice message. 62 // AsProto returns this object as a tsmon.proto.NetworkDevice message.
63 func (t *NetworkDevice) AsProto() *pb.NetworkDevice { return (*pb.NetworkDevice) (t) } 63 func (t *NetworkDevice) AsProto() *pb.NetworkDevice { return (*pb.NetworkDevice) (t) }
64 64
65 // PopulateProto implements Target. 65 // PopulateProto implements Target.
66 func (t *NetworkDevice) PopulateProto(d *pb.MetricsData) { d.NetworkDevice = t.A sProto() } 66 func (t *NetworkDevice) PopulateProto(d *pb.MetricsData) { d.NetworkDevice = t.A sProto() }
67 67
68 // IsPopulatedIn returns true if the MetricsData message is for this target. 68 // IsPopulatedIn returns true if the MetricsData message is for this target.
69 func (t *NetworkDevice) IsPopulatedIn(d *pb.MetricsData) bool { 69 func (t *NetworkDevice) IsPopulatedIn(d *pb.MetricsData) bool {
70 return d.NetworkDevice != nil && 70 return d.NetworkDevice != nil &&
71 » » d.NetworkDevice.GetAlertable() == t.AsProto().GetAlertable() && 71 » » d.NetworkDevice.Alertable == t.AsProto().Alertable &&
72 » » d.NetworkDevice.GetRealm() == t.AsProto().GetRealm() && 72 » » d.NetworkDevice.Realm == t.AsProto().Realm &&
73 » » d.NetworkDevice.GetMetro() == t.AsProto().GetMetro() && 73 » » d.NetworkDevice.Metro == t.AsProto().Metro &&
74 » » d.NetworkDevice.GetRole() == t.AsProto().GetRole() && 74 » » d.NetworkDevice.Role == t.AsProto().Role &&
75 » » d.NetworkDevice.GetHostname() == t.AsProto().GetHostname() && 75 » » d.NetworkDevice.Hostname == t.AsProto().Hostname &&
76 » » d.NetworkDevice.GetHostgroup() == t.AsProto().GetHostgroup() 76 » » d.NetworkDevice.Hostgroup == t.AsProto().Hostgroup
77 } 77 }
78 78
79 // Hash returns a uint64 hash of this target. 79 // Hash returns a uint64 hash of this target.
80 func (t *NetworkDevice) Hash() uint64 { 80 func (t *NetworkDevice) Hash() uint64 {
81 h := fnv.New64a() 81 h := fnv.New64a()
82 fmt.Fprintf(h, "%t%s\n%s\n%s\n%s\n%s", 82 fmt.Fprintf(h, "%t%s\n%s\n%s\n%s\n%s",
83 » » t.AsProto().GetAlertable(), 83 » » t.AsProto().Alertable,
84 » » t.AsProto().GetRealm(), 84 » » t.AsProto().Realm,
85 » » t.AsProto().GetMetro(), 85 » » t.AsProto().Metro,
86 » » t.AsProto().GetRole(), 86 » » t.AsProto().Role,
87 » » t.AsProto().GetHostname(), 87 » » t.AsProto().Hostname,
88 » » t.AsProto().GetHostgroup()) 88 » » t.AsProto().Hostgroup)
89 return h.Sum64() 89 return h.Sum64()
90 } 90 }
91 91
92 // Clone returns a copy of this object. 92 // Clone returns a copy of this object.
93 func (t *NetworkDevice) Clone() types.Target { 93 func (t *NetworkDevice) Clone() types.Target {
94 return (*NetworkDevice)(proto.Clone(t.AsProto()).(*pb.NetworkDevice)) 94 return (*NetworkDevice)(proto.Clone(t.AsProto()).(*pb.NetworkDevice))
95 } 95 }
96 96
97 // NewFromFlags returns a Target configured from commandline flags. 97 // NewFromFlags returns a Target configured from commandline flags.
98 func NewFromFlags(fl *Flags) (types.Target, error) { 98 func NewFromFlags(fl *Flags) (types.Target, error) {
99 if fl.TargetType == "task" { 99 if fl.TargetType == "task" {
100 if fl.TaskServiceName == "" { 100 if fl.TaskServiceName == "" {
101 return nil, errors.New( 101 return nil, errors.New(
102 "--ts-mon-task-service-name must be provided whe n using --ts-mon-target-type=task") 102 "--ts-mon-task-service-name must be provided whe n using --ts-mon-target-type=task")
103 } 103 }
104 if fl.TaskJobName == "" { 104 if fl.TaskJobName == "" {
105 return nil, errors.New( 105 return nil, errors.New(
106 "--ts-mon-task-job-name must be provided when us ing --ts-mon-target-type=task") 106 "--ts-mon-task-job-name must be provided when us ing --ts-mon-target-type=task")
107 } 107 }
108 108
109 return (*Task)(&pb.Task{ 109 return (*Task)(&pb.Task{
110 » » » ServiceName: proto.String(fl.TaskServiceName), 110 » » » ServiceName: fl.TaskServiceName,
111 » » » JobName: proto.String(fl.TaskJobName), 111 » » » JobName: fl.TaskJobName,
112 » » » DataCenter: proto.String(fl.TaskRegion), 112 » » » DataCenter: fl.TaskRegion,
113 » » » HostName: proto.String(fl.TaskHostname), 113 » » » HostName: fl.TaskHostname,
114 » » » TaskNum: proto.Int32(int32(fl.TaskNumber)), 114 » » » TaskNum: int32(fl.TaskNumber),
115 }), nil 115 }), nil
116 } else if fl.TargetType == "device" { 116 } else if fl.TargetType == "device" {
117 return (*NetworkDevice)(&pb.NetworkDevice{ 117 return (*NetworkDevice)(&pb.NetworkDevice{
118 » » » Alertable: proto.Bool(true), 118 » » » Alertable: true,
119 » » » Realm: proto.String("ACQ_CHROME"), 119 » » » Realm: "ACQ_CHROME",
120 » » » Metro: proto.String(fl.DeviceRegion), 120 » » » Metro: fl.DeviceRegion,
121 » » » Role: proto.String(fl.DeviceRole), 121 » » » Role: fl.DeviceRole,
122 » » » Hostname: proto.String(fl.DeviceHostname), 122 » » » Hostname: fl.DeviceHostname,
123 » » » Hostgroup: proto.String(fl.DeviceNetwork), 123 » » » Hostgroup: fl.DeviceNetwork,
124 }), nil 124 }), nil
125 } else { 125 } else {
126 return nil, fmt.Errorf("unknown --ts-mon-target-type '%s'", fl.T argetType) 126 return nil, fmt.Errorf("unknown --ts-mon-target-type '%s'", fl.T argetType)
127 } 127 }
128 } 128 }
OLDNEW
« no previous file with comments | « common/tsmon/store/testing.go ('k') | common/tsmon/ts_mon_proto/acquisition_network_device.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698