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

Side by Side Diff: client/third_party/infra_libs/ts_mon/common/targets.py

Issue 2991803002: Update infra_libs to 1.1.15 / 0b44aba87c1c6538439df6d24a409870810747ab (Closed)
Patch Set: fix Created 3 years, 4 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 """Classes representing the monitoring interface for tasks or devices.""" 5 """Classes representing the monitoring interface for tasks or devices."""
6 6
7 7
8 class Target(object): 8 class Target(object):
9 """Abstract base class for a monitoring target. 9 """Abstract base class for a monitoring target.
10 10
11 A Target is a "thing" that should be monitored, for example, a device or a 11 A Target is a "thing" that should be monitored, for example, a device or a
12 process. The majority of the time, a single process will have only a single 12 process. The majority of the time, a single process will have only a single
13 Target. 13 Target.
14 14
15 Do not directly instantiate an object of this class. 15 Do not directly instantiate an object of this class.
16 Use the concrete child classes instead: 16 Use the concrete child classes instead:
17 * TaskTarget to monitor a job or tasks running in (potentially) many places; 17 * TaskTarget to monitor a job or tasks running in (potentially) many places;
18 * DeviceTarget to monitor a host machine that may be running a task. 18 * DeviceTarget to monitor a host machine that may be running a task.
19 """ 19 """
20 20
21 def __init__(self): 21 def __init__(self):
22 # Subclasses should list the updatable target fields here. 22 # Subclasses should list the updatable target fields here.
23 self._fields = tuple() 23 self._fields = tuple()
24 24
25 def _populate_target_pb(self, metric): 25 def populate_target_pb(self, collection_pb):
26 """Populate the 'target' embedded message field of a metric protobuf."""
27 raise NotImplementedError()
28
29 def _populate_target_pb_new(self, collection_pb):
30 """Populate the 'target' into a MetricsCollection.""" 26 """Populate the 'target' into a MetricsCollection."""
31 raise NotImplementedError() 27 raise NotImplementedError()
32 28
33 def to_dict(self): 29 def to_dict(self):
34 """Return target field values as a dictionary.""" 30 """Return target field values as a dictionary."""
35 return {field: getattr(self, field) for field in self._fields} 31 return {field: getattr(self, field) for field in self._fields}
36 32
37 def update(self, target_fields): 33 def update(self, target_fields):
38 """Update values of some target fields given as a dict.""" 34 """Update values of some target fields given as a dict."""
39 for field, value in target_fields.iteritems(): 35 for field, value in target_fields.iteritems():
(...skipping 30 matching lines...) Expand all
70 """ 66 """
71 super(DeviceTarget, self).__init__() 67 super(DeviceTarget, self).__init__()
72 self.region = region 68 self.region = region
73 self.role = role 69 self.role = role
74 self.network = network 70 self.network = network
75 self.hostname = hostname 71 self.hostname = hostname
76 self.realm = 'ACQ_CHROME' 72 self.realm = 'ACQ_CHROME'
77 self.alertable = True 73 self.alertable = True
78 self._fields = ('region', 'role', 'network', 'hostname') 74 self._fields = ('region', 'role', 'network', 'hostname')
79 75
80 def _populate_target_pb(self, metric): 76 def populate_target_pb(self, collection):
81 """Populate the 'network_device' embedded message of a metric protobuf. 77 """Populate the 'network_device' target into metrics_pb2.MetricsCollection.
82 78
83 Args: 79 Args:
84 metric (metrics_pb2.MetricsData): the metric proto to be populated.
85 """
86 metric.network_device.metro = self.region
87 metric.network_device.role = self.role
88 metric.network_device.hostgroup = self.network
89 metric.network_device.hostname = self.hostname
90 metric.network_device.realm = self.realm
91 metric.network_device.alertable = self.alertable
92
93 def _populate_target_pb_new(self, collection):
94 """Populate the 'network_device' target into
95 new_metrics_pb2.MetricsCollection.
96 Args:
97 collection (metrics_pb2.MetricsCollection): the collection proto to be 80 collection (metrics_pb2.MetricsCollection): the collection proto to be
98 populated. 81 populated.
99 """ 82 """
100 collection.network_device.metro = self.region 83 collection.network_device.metro = self.region
101 collection.network_device.role = self.role 84 collection.network_device.role = self.role
102 collection.network_device.hostgroup = self.network 85 collection.network_device.hostgroup = self.network
103 collection.network_device.hostname = self.hostname 86 collection.network_device.hostname = self.hostname
104 collection.network_device.realm = self.realm 87 collection.network_device.realm = self.realm
105 collection.network_device.alertable = self.alertable 88 collection.network_device.alertable = self.alertable
106 89
(...skipping 13 matching lines...) Expand all
120 """ 103 """
121 super(TaskTarget, self).__init__() 104 super(TaskTarget, self).__init__()
122 self.service_name = service_name 105 self.service_name = service_name
123 self.job_name = job_name 106 self.job_name = job_name
124 self.region = region 107 self.region = region
125 self.hostname = hostname 108 self.hostname = hostname
126 self.task_num = task_num 109 self.task_num = task_num
127 self._fields = ('service_name', 'job_name', 'region', 110 self._fields = ('service_name', 'job_name', 'region',
128 'hostname', 'task_num') 111 'hostname', 'task_num')
129 112
130 def _populate_target_pb(self, metric): 113 def populate_target_pb(self, collection):
131 """Populate the 'task' embedded message field of a metric protobuf. 114 """Populate the 'task' target into metrics_pb2.MetricsCollection.
132
133 Args:
134 metric (metrics_pb2.MetricsData): the metric proto to be populated.
135 """
136 metric.task.service_name = self.service_name
137 metric.task.job_name = self.job_name
138 metric.task.data_center = self.region
139 metric.task.host_name = self.hostname
140 metric.task.task_num = self.task_num
141
142 def _populate_target_pb_new(self, collection):
143 """Populate the 'task' target into new_metrics_pb2.MetricsCollection.
144 115
145 Args: 116 Args:
146 collection (metrics_pb2.MetricsCollection): the collection proto to be 117 collection (metrics_pb2.MetricsCollection): the collection proto to be
147 populated. 118 populated.
148 """ 119 """
149 collection.task.service_name = self.service_name 120 collection.task.service_name = self.service_name
150 collection.task.job_name = self.job_name 121 collection.task.job_name = self.job_name
151 collection.task.data_center = self.region 122 collection.task.data_center = self.region
152 collection.task.host_name = self.hostname 123 collection.task.host_name = self.hostname
153 collection.task.task_num = self.task_num 124 collection.task.task_num = self.task_num
154 125
OLDNEW
« no previous file with comments | « client/third_party/infra_libs/ts_mon/common/monitors.py ('k') | client/third_party/infra_libs/ts_mon/config.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698