Bug 1393277 - Record information about action tasks to support cot draft
authorBrian Stack <bstack@mozilla.com>
Fri, 22 Sep 2017 12:48:33 -0700
changeset 672297 21ba633fe218780d95e247a606cd3815b01852a2
parent 672296 e6c32278f32cd5f7d159627b2157396b62d0c4a9
child 733768 62df0d73675621272816e60efb883fa5093605fc
push id82210
push userbstack@mozilla.com
push dateFri, 29 Sep 2017 01:05:57 +0000
bugs1393277
milestone58.0a1
Bug 1393277 - Record information about action tasks to support cot MozReview-Commit-ID: Kyyh6G6yw2W
taskcluster/taskgraph/actions/registry.py
taskcluster/taskgraph/actions/util.py
taskcluster/taskgraph/transforms/task.py
--- a/taskcluster/taskgraph/actions/registry.py
+++ b/taskcluster/taskgraph/actions/registry.py
@@ -260,16 +260,26 @@ ln -s /builds/worker/artifacts artifacts
                     ],
                 },
                 'extra': {
                     'treeherder': {
                         'groupName': 'action-callback',
                         'groupSymbol': 'AC',
                         'symbol': symbol,
                     },
+                    'parent': task_group_id,
+                    'action': {
+                        'name': name,
+                        'context': {
+                            'taskGroupId': task_group_id,
+                            'taskId': {'$eval': 'taskId'},
+                            'input': {'$eval': 'input'},
+                            'parameters': {'$eval': 'parameters'},
+                        },
+                    },
                 },
             }
         mem['registered'] = True
         callbacks[cb.__name__] = cb
     return register_callback
 
 
 def render_actions_json(parameters):
--- a/taskcluster/taskgraph/actions/util.py
+++ b/taskcluster/taskgraph/actions/util.py
@@ -2,16 +2,17 @@
 
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from __future__ import absolute_import, print_function, unicode_literals
 
 import logging
+import os
 
 from requests.exceptions import HTTPError
 
 from taskgraph import create
 from taskgraph.decision import write_artifact
 from taskgraph.taskgraph import TaskGraph
 from taskgraph.optimize import optimize_task_graph
 from taskgraph.util.taskcluster import get_session, find_task_id, get_artifact, list_tasks
@@ -60,27 +61,35 @@ def create_task_from_def(task_id, task_d
     it to this function. No dependencies will be scheduled. You must handle
     this yourself. Seeing how create_tasks handles it might prove helpful."""
     task_def['schedulerId'] = 'gecko-level-{}'.format(level)
     label = task_def['metadata']['name']
     session = get_session()
     create.create_task(session, task_id, label, task_def)
 
 
-def create_tasks(to_run, full_task_graph, label_to_taskid, params, decision_task_id):
+def update_parent(task, graph):
+    task.task.setdefault('extra', {})['parent'] = os.environ.get('TASK_ID', '')
+    return task
+
+
+def create_tasks(to_run, full_task_graph, label_to_taskid, params, decision_task_id=None):
     """Create new tasks.  The task definition will have {relative-datestamp':
     '..'} rendered just like in a decision task.  Action callbacks should use
     this function to create new tasks,
     allowing easy debugging with `mach taskgraph action-callback --test`.
-    This builds up all required tasks to run in order to run the tasks requested."""
+    This builds up all required tasks to run in order to run the tasks requested.
+
+    If you wish to create the tasks in a new group, leave out decision_task_id."""
     to_run = set(to_run)
     target_graph = full_task_graph.graph.transitive_closure(to_run)
     target_task_graph = TaskGraph(
         {l: full_task_graph[l] for l in target_graph.nodes},
         target_graph)
+    target_task_graph.for_each_task(update_parent)
     optimized_task_graph, label_to_taskid = optimize_task_graph(target_task_graph,
                                                                 params,
                                                                 to_run,
                                                                 label_to_taskid)
     write_artifact('task-graph.json', optimized_task_graph.to_json())
     write_artifact('label-to-taskid.json', label_to_taskid)
     write_artifact('to-run.json', list(to_run))
     create.create_tasks(optimized_task_graph, label_to_taskid, params, decision_task_id)
--- a/taskcluster/taskgraph/transforms/task.py
+++ b/taskcluster/taskgraph/transforms/task.py
@@ -1137,16 +1137,17 @@ def build_task(config, tasks):
         worker_type = task['worker-type'].format(level=level)
         provisioner_id, worker_type = worker_type.split('/', 1)
 
         routes = task.get('routes', [])
         scopes = [s.format(level=level) for s in task.get('scopes', [])]
 
         # set up extra
         extra = task.get('extra', {})
+        extra['parent'] = os.environ.get('TASK_ID', '')
         task_th = task.get('treeherder')
         if task_th:
             extra['treeherderEnv'] = task_th['environments']
 
             treeherder = extra.setdefault('treeherder', {})
 
             machine_platform, collection = task_th['platform'].split('/', 1)
             treeherder['machine'] = {'platform': machine_platform}
@@ -1184,16 +1185,17 @@ def build_task(config, tasks):
             task['priority'] = BRANCH_PRIORITIES.get(
                 config.params['project'],
                 DEFAULT_BRANCH_PRIORITY)
 
         tags = task.get('tags', {})
         tags.update({
             'createdForUser': config.params['owner'],
             'kind': config.kind,
+            'label': task['label'],
         })
 
         task_def = {
             'provisionerId': provisioner_id,
             'workerType': worker_type,
             'routes': routes,
             'created': {'relative-datestamp': '0 seconds'},
             'deadline': {'relative-datestamp': task['deadline-after']},