Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mesos] extract chronos_job and chronos_job_owner if not empty #3417

Merged
merged 1 commit into from
Jul 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 21 additions & 4 deletions tests/core/test_mesosutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,35 @@ def test_extract_tags(self, mock_init):
mock_init.return_value = None
mesos = MesosUtil()

env = ["CHRONOS_JOB_NAME=test-job",
env = ["CHRONOS_JOB_NAME=app1_process-orders",
"CHRONOS_JOB_OWNER=qa",
"MARATHON_APP_ID=/system/dd-agent",
"MESOS_TASK_ID=system_dd-agent.dcc75b42-4b87-11e7-9a62-70b3d5800001"]

tags = ['marathon_app:/system/dd-agent']
## Removed 'chronos_job:test-job', 'mesos_task:system_dd-agent.dcc75b42-4b87-11e7-9a62-70b3d5800001'
## because of high cardinality
tags = ['marathon_app:/system/dd-agent',
'chronos_job_owner:qa',
'chronos_job:app1_process-orders']
# Removed 'mesos_task:' because of high cardinality

container = {'Config': {'Env': env}}

self.assertEqual(sorted(tags), sorted(mesos._get_cacheable_tags(CO_ID, co=container)))

@mock.patch('docker.Client.__init__')
def test_dont_extract_empty_owner(self, mock_init):
mock_init.return_value = None
mesos = MesosUtil()

env = ["CHRONOS_JOB_NAME=app1_process-orders",
"CHRONOS_JOB_OWNER=",
"MARATHON_APP_ID=/system/dd-agent"]

tags = ['marathon_app:/system/dd-agent',
'chronos_job:app1_process-orders']
container = {'Config': {'Env': env}}

self.assertEqual(sorted(tags), sorted(mesos._get_cacheable_tags(CO_ID, co=container)))

@mock.patch.dict(os.environ, {"MESOS_TASK_ID": "test"})
def test_detect(self):
self.assertTrue(MesosUtil.is_detected())
Expand Down
7 changes: 5 additions & 2 deletions utils/orchestrator/mesosutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .baseutil import BaseUtil

CHRONOS_JOB_NAME = "CHRONOS_JOB_NAME"
CHRONOS_JOB_OWNER = "CHRONOS_JOB_OWNER"
MARATHON_APP_ID = "MARATHON_APP_ID"
MESOS_TASK_ID = "MESOS_TASK_ID"

Expand All @@ -33,9 +34,11 @@ def _get_cacheable_tags(self, cid, co=None):
for var in envvars:
if var.startswith(MARATHON_APP_ID):
tags.append('marathon_app:%s' % var[len(MARATHON_APP_ID) + 1:])
elif var.startswith(CHRONOS_JOB_NAME) and len(var) > len(CHRONOS_JOB_NAME) + 1:
tags.append('chronos_job:%s' % var[len(CHRONOS_JOB_NAME) + 1:])
elif var.startswith(CHRONOS_JOB_OWNER) and len(var) > len(CHRONOS_JOB_OWNER) + 1:
tags.append('chronos_job_owner:%s' % var[len(CHRONOS_JOB_OWNER) + 1:])
## Disabled for now because of high cardinality (~container card.)
#elif var.startswith(CHRONOS_JOB_NAME):
# tags.append('chronos_job:%s' % var[len(CHRONOS_JOB_NAME) + 1:])
#elif var.startswith(MESOS_TASK_ID):
# tags.append('mesos_task:%s' % var[len(MESOS_TASK_ID) + 1:])

Expand Down