Skip to content

Commit 0358b58

Browse files
committed
[yarn] whitelist authorized application_tags
Risk of context spam.
1 parent 325f1e6 commit 0358b58

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

checks.d/yarn.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ class YarnCheck(AgentCheck):
143143
'''
144144
Extract statistics from YARN's ResourceManger REST API
145145
'''
146+
_ALLOWED_APPLICATION_TAGS = [
147+
'applicationTags',
148+
'applicationType',
149+
'name',
150+
'queue',
151+
'user'
152+
]
146153

147154
def check(self, instance):
148155

@@ -154,9 +161,16 @@ def check(self, instance):
154161
self.log.error('application_tags is incorrect: %s is not a dictionary', app_tags)
155162
app_tags = {}
156163

164+
filtered_app_tags = {}
165+
for dd_prefix, yarn_key in app_tags.iteritems():
166+
if yarn_key in self._ALLOWED_APPLICATION_TAGS:
167+
filtered_app_tags[dd_prefix] = yarn_key
168+
app_tags = filtered_app_tags
169+
157170
# Collected by default
158171
app_tags['app_name'] = 'name'
159172

173+
160174
# Get additional tags from the conf file
161175
tags = instance.get('tags', [])
162176
if tags is None:
@@ -201,7 +215,7 @@ def _yarn_app_metrics(self, rm_address, app_tags, addl_tags):
201215
)
202216

203217
if (metrics_json and metrics_json['apps'] is not None and
204-
metrics_json['apps']['app'] is not None):
218+
metrics_json['apps']['app'] is not None):
205219

206220
for app_json in metrics_json['apps']['app']:
207221

@@ -225,7 +239,7 @@ def _yarn_node_metrics(self, rm_address, addl_tags):
225239
metrics_json = self._rest_request_to_json(rm_address, YARN_NODES_PATH)
226240

227241
if (metrics_json and metrics_json['nodes'] is not None and
228-
metrics_json['nodes']['node'] is not None):
242+
metrics_json['nodes']['node'] is not None):
229243

230244
for node_json in metrics_json['nodes']['node']:
231245
node_id = node_json['id']

conf.d/yarn.yaml.example

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,16 @@ instances:
1919

2020
# Optional tags to be applied to every emitted metric.
2121
# tags:
22-
# - key:value
23-
# - instance:production
22+
# - "key:value"
23+
# - "instance:production"
2424

2525
# Optional tags retrieved from the application data to be applied to the
2626
# application metrics.
2727
# application_tags:
28-
# # tag_prefix: yarn_key
29-
# - app_queue: queue
28+
# # tag_prefix: yarn_key
29+
# app_queue: queue
3030
# This will add a tag 'app_queue:name_of_the_queue' to the app metrics,
31-
# app_queue being the tag_prefix and queue the actual YARN key. Whole list
32-
# of keys on yarn api reference:
33-
# https://hadoop.apache.org/docs/current/hadoop-yarn/hadoop-yarn-site/ResourceManagerRest.html#Cluster_Applications_API
31+
# app_queue being the tag_prefix and queue the actual YARN key.
32+
# Allowed yarn keys: applicationType, applicationTags, name, queue, user
3433
# By default, the application name is collected with the prefix app_name.
3534

tests/checks/mock/test_yarn.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ class YARNCheck(AgentCheckTest):
5858
'opt_key:opt_value'
5959
],
6060
'application_tags': {
61-
'app_id': 'id'
61+
'app_id': 'id',
62+
'app_queue': 'queue'
6263
}
6364
}
6465

@@ -108,7 +109,7 @@ class YARNCheck(AgentCheckTest):
108109
YARN_APP_METRICS_TAGS = [
109110
'cluster_name:%s' % CLUSTER_NAME,
110111
'app_name:word count',
111-
'app_id:application_1326815542473_0001',
112+
'app_queue:default',
112113
'opt_key:opt_value'
113114
]
114115

0 commit comments

Comments
 (0)