Revert "[chromite] Capture job_name and git timing for ts_mon in cbuildbot runs."

This reverts commit 7657336de212e6dba55511f3f07457f9add6e3e3.

Reason for revert: Suspected to have blown out our metric memory quota
See https://bugs.chromium.org/p/chromium/issues/detail?id=842423

Original change's description:
> [chromite] Capture job_name and git timing for ts_mon in cbuildbot runs.
>
> Simple overload of existing configuration to provide a means to capture
> the builder config as part of the metric schema.  It is easy to overload
> the schema but using the Task schema limits options for capturing more
> fields.  Will need to examine options for passing metric fields to the
> lower level calls.
>
> Wraps RunGit command in SecondsTimer metric to collect overall durations
> of git calls in metric distributions.
>
> BUG=chromium:829289
> TEST=`./cbuildbot/run_tests` PASS
>
> Change-Id: I23f0fd6e8f4870dffdb87a06b4384f351d93e6c4
> Reviewed-on: https://chromium-review.googlesource.com/1050954
> Commit-Ready: Mike Nichols <mikenichols@chromium.org>
> Tested-by: Mike Nichols <mikenichols@chromium.org>
> Reviewed-by: Jason Clinton <jclinton@chromium.org>

Bug: chromium:829289
Change-Id: I23497c75a6803b7274d9a40e5584c43aa3bf0616
Reviewed-on: https://chromium-review.googlesource.com/1058207
Commit-Ready: Ben Pastene <bpastene@chromium.org>
Tested-by: Ben Pastene <bpastene@chromium.org>
Reviewed-by: Jason Clinton <jclinton@chromium.org>
Reviewed-by: Mike Nichols <mikenichols@chromium.org>
diff --git a/lib/git.py b/lib/git.py
index 8432b42..2807ae3 100644
--- a/lib/git.py
+++ b/lib/git.py
@@ -20,7 +20,6 @@
 from chromite.lib import constants
 from chromite.lib import cros_build_lib
 from chromite.lib import cros_logging as logging
-from chromite.lib import metrics
 from chromite.lib import osutils
 
 
@@ -806,12 +805,7 @@
   kwargs.setdefault('print_cmd', False)
   kwargs.setdefault('cwd', git_repo)
   kwargs.setdefault('capture_output', True)
-  fields = {'git_repo': git_repo, 'cmd': 'git ' + ' '.join(cmd)}
-  m_timer = 'chromeos/cbuildbot/git/command_durations'
-  with metrics.SecondsTimer(m_timer, fields=fields):
-    result = cros_build_lib.RunCommand(['git'] + cmd, **kwargs)
-
-  return result
+  return cros_build_lib.RunCommand(['git'] + cmd, **kwargs)
 
 
 def Init(git_repo):
diff --git a/lib/ts_mon_config.py b/lib/ts_mon_config.py
index 0033728..4f551e9 100644
--- a/lib/ts_mon_config.py
+++ b/lib/ts_mon_config.py
@@ -45,8 +45,7 @@
                           short_lived=False,
                           auto_flush=True,
                           debug_file=None,
-                          task_num=0,
-                          job_name=None):
+                          task_num=0):
   """Uses a dummy argument parser to get the default behavior from ts-mon.
 
   Args:
@@ -62,8 +61,6 @@
                 minute.
     debug_file: If non-none, send metrics to this path instead of to PubSub.
     task_num: (Default 0) The task_num target field of the metrics to emit.
-    job_name: (Default service_name) The job_name target field of the
-              metrics to emit.
   """
   if not config:
     return TrivialContextManager()
@@ -74,8 +71,7 @@
 
   # google-api-client has too much noisey logging.
   options = _GenerateTsMonArgparseOptions(
-      service_name, short_lived, auto_flush, debug_file,
-      task_num, job_name=job_name)
+      service_name, short_lived, auto_flush, debug_file, task_num)
 
   if indirect:
     return _CreateTsMonFlushingProcess(options)
@@ -106,8 +102,7 @@
 
 
 def _GenerateTsMonArgparseOptions(service_name, short_lived,
-                                  auto_flush, debug_file, task_num,
-                                  job_name=None):
+                                  auto_flush, debug_file, task_num):
   """Generates an arg list for ts-mon to consume.
 
   Args:
@@ -118,19 +113,14 @@
                 minute.
     debug_file: If non-none, send metrics to this path instead of to PubSub.
     task_num: Override the default task num of 0.
-    job_name: (Default service_name) The job_name target field of the
-              metrics to emit.
   """
   parser = argparse.ArgumentParser()
   config.add_argparse_options(parser)
 
-  if not job_name:
-    job_name = service_name
-
   args = [
       '--ts-mon-target-type', 'task',
       '--ts-mon-task-service-name', service_name,
-      '--ts-mon-task-job-name', job_name,
+      '--ts-mon-task-job-name', service_name,
   ]
 
   if debug_file:
diff --git a/scripts/cbuildbot.py b/scripts/cbuildbot.py
index 24d13f9..b7a416a 100644
--- a/scripts/cbuildbot.py
+++ b/scripts/cbuildbot.py
@@ -796,9 +796,7 @@
   if run_type == _ENVIRONMENT_PROD:
     cidb.CIDBConnectionFactory.SetupProdCidb()
     context = ts_mon_config.SetupTsMonGlobalState(
-        'cbuildbot', indirect=True,
-        task_num=options.ts_mon_task_num,
-        job_name=options.build_config_name)
+        'cbuildbot', indirect=True, task_num=options.ts_mon_task_num)
   elif run_type == _ENVIRONMENT_DEBUG:
     cidb.CIDBConnectionFactory.SetupDebugCidb()
     context = ts_mon_config.TrivialContextManager()
diff --git a/scripts/cbuildbot_launch.py b/scripts/cbuildbot_launch.py
index c7dca52..449bc71 100644
--- a/scripts/cbuildbot_launch.py
+++ b/scripts/cbuildbot_launch.py
@@ -424,61 +424,58 @@
       'tryjob': options.remote_trybot,
   }
 
-  with ts_mon_config.SetupTsMonGlobalState(
-      'cbuildbot_launch', indirect=True,
-      job_name=metrics_fields['build_config']):
-    # Does the entire build pass or fail.
-    with metrics.Presence(METRIC_ACTIVE, metrics_fields), \
-         metrics.SuccessCounter(METRIC_COMPLETED, metrics_fields) as s_fields:
+  # Does the entire build pass or fail.
+  with metrics.Presence(METRIC_ACTIVE, metrics_fields), \
+       metrics.SuccessCounter(METRIC_COMPLETED, metrics_fields) as s_fields:
 
-      # Preliminary set, mostly command line parsing.
-      with metrics.SuccessCounter(METRIC_INVOKED, metrics_fields):
-        if options.enable_buildbot_tags:
-          logging.EnableBuildbotMarkers()
-        ConfigureGlobalEnvironment()
+    # Preliminary set, mostly command line parsing.
+    with metrics.SuccessCounter(METRIC_INVOKED, metrics_fields):
+      if options.enable_buildbot_tags:
+        logging.EnableBuildbotMarkers()
+      ConfigureGlobalEnvironment()
 
-      # Prepare the buildroot with source for the build.
-      with metrics.SuccessCounter(METRIC_PREP, metrics_fields):
-        site_config = config_lib.GetConfig()
-        manifest_url = site_config.params['MANIFEST_INT_URL']
-        repo = repository.RepoRepository(manifest_url, buildroot,
-                                         branch=branchname,
-                                         git_cache_dir=options.git_cache_dir)
-        previous_build_state = GetLastBuildState(root)
+    # Prepare the buildroot with source for the build.
+    with metrics.SuccessCounter(METRIC_PREP, metrics_fields):
+      site_config = config_lib.GetConfig()
+      manifest_url = site_config.params['MANIFEST_INT_URL']
+      repo = repository.RepoRepository(manifest_url, buildroot,
+                                       branch=branchname,
+                                       git_cache_dir=options.git_cache_dir)
+      previous_build_state = GetLastBuildState(root)
 
-        # Clean up the buildroot to a safe state.
-        with metrics.SecondsTimer(METRIC_CLEAN, fields=metrics_fields):
-          build_state = GetCurrentBuildState(options, branchname)
-          CleanBuildRoot(root, repo, metrics_fields, build_state)
+      # Clean up the buildroot to a safe state.
+      with metrics.SecondsTimer(METRIC_CLEAN, fields=metrics_fields):
+        build_state = GetCurrentBuildState(options, branchname)
+        CleanBuildRoot(root, repo, metrics_fields, build_state)
 
-        # Get a checkout close enough to the branch that cbuildbot can
-        # handle it.
-        if options.sync:
-          with metrics.SecondsTimer(METRIC_INITIAL, fields=metrics_fields):
-            InitialCheckout(repo)
+      # Get a checkout close enough to the branch that cbuildbot can handle it.
+      if options.sync:
+        with metrics.SecondsTimer(METRIC_INITIAL, fields=metrics_fields):
+          InitialCheckout(repo)
 
-        # Get a checkout close enough to the branch that cbuildbot can
-        # handle it.
-        with metrics.SecondsTimer(METRIC_DEPOT_TOOLS, fields=metrics_fields):
-          DepotToolsEnsureBootstrap(depot_tools_path)
+      # Get a checkout close enough to the branch that cbuildbot can handle it.
+      with metrics.SecondsTimer(METRIC_DEPOT_TOOLS, fields=metrics_fields):
+        DepotToolsEnsureBootstrap(depot_tools_path)
 
-      # Run cbuildbot inside the full ChromeOS checkout, on the
-      # specified branch.
-      with metrics.SecondsTimer(METRIC_CBUILDBOT, fields=metrics_fields):
-        if previous_build_state.is_valid():
-          argv.append('--previous-build-state')
-          argv.append(base64.b64encode(previous_build_state.to_json()))
+    # Run cbuildbot inside the full ChromeOS checkout, on the specified branch.
+    with metrics.SecondsTimer(METRIC_CBUILDBOT, fields=metrics_fields):
+      if previous_build_state.is_valid():
+        argv.append('--previous-build-state')
+        argv.append(base64.b64encode(previous_build_state.to_json()))
 
-        result = Cbuildbot(buildroot, depot_tools_path, argv)
-        s_fields['success'] = (result == 0)
+      result = Cbuildbot(buildroot, depot_tools_path, argv)
+      s_fields['success'] = (result == 0)
 
-        build_state.status = (
-            constants.BUILDER_STATUS_PASSED
-            if result == 0 else constants.BUILDER_STATUS_FAILED)
-        SetLastBuildState(root, build_state)
+      build_state.status = (
+          constants.BUILDER_STATUS_PASSED
+          if result == 0 else constants.BUILDER_STATUS_FAILED)
+      SetLastBuildState(root, build_state)
 
-        CleanupChroot(buildroot)
-        return result
+      CleanupChroot(buildroot)
+      return result
+
 
 def main(argv):
-  return _main(argv)
+  # Enable Monarch metrics gathering.
+  with ts_mon_config.SetupTsMonGlobalState('cbuildbot_launch', indirect=True):
+    return _main(argv)