Skip to content

Commit

Permalink
[yarn] whitelist authorized application_tags
Browse files Browse the repository at this point in the history
Risk of context spam.
  • Loading branch information
degemer committed Dec 12, 2016
1 parent 325f1e6 commit 0358b58
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
18 changes: 16 additions & 2 deletions checks.d/yarn.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ class YarnCheck(AgentCheck):
'''
Extract statistics from YARN's ResourceManger REST API
'''
_ALLOWED_APPLICATION_TAGS = [
'applicationTags',
'applicationType',
'name',
'queue',
'user'
]

def check(self, instance):

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

filtered_app_tags = {}
for dd_prefix, yarn_key in app_tags.iteritems():
if yarn_key in self._ALLOWED_APPLICATION_TAGS:
filtered_app_tags[dd_prefix] = yarn_key
app_tags = filtered_app_tags

# Collected by default
app_tags['app_name'] = 'name'


# Get additional tags from the conf file
tags = instance.get('tags', [])
if tags is None:
Expand Down Expand Up @@ -201,7 +215,7 @@ def _yarn_app_metrics(self, rm_address, app_tags, addl_tags):
)

if (metrics_json and metrics_json['apps'] is not None and
metrics_json['apps']['app'] is not None):
metrics_json['apps']['app'] is not None):

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

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

if (metrics_json and metrics_json['nodes'] is not None and
metrics_json['nodes']['node'] is not None):
metrics_json['nodes']['node'] is not None):

for node_json in metrics_json['nodes']['node']:
node_id = node_json['id']
Expand Down
13 changes: 6 additions & 7 deletions conf.d/yarn.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@ instances:

# Optional tags to be applied to every emitted metric.
# tags:
# - key:value
# - instance:production
# - "key:value"
# - "instance:production"

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

5 changes: 3 additions & 2 deletions tests/checks/mock/test_yarn.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class YARNCheck(AgentCheckTest):
'opt_key:opt_value'
],
'application_tags': {
'app_id': 'id'
'app_id': 'id',
'app_queue': 'queue'
}
}

Expand Down Expand Up @@ -108,7 +109,7 @@ class YARNCheck(AgentCheckTest):
YARN_APP_METRICS_TAGS = [
'cluster_name:%s' % CLUSTER_NAME,
'app_name:word count',
'app_id:application_1326815542473_0001',
'app_queue:default',
'opt_key:opt_value'
]

Expand Down

0 comments on commit 0358b58

Please sign in to comment.