aboutsummaryrefslogtreecommitdiff
path: root/cros_utils/bugs.py
diff options
context:
space:
mode:
authorStephen Hines <srhines@google.com>2022-01-05 21:47:21 -0800
committerStephen Hines <srhines@google.com>2022-01-05 21:47:21 -0800
commit7bc245bad95c6f4c15bc3f819f61312705b59a5a (patch)
treecf4cdad04e1c146844e2a790910cf9cd1b97082a /cros_utils/bugs.py
parentf103b9f78baa21b4edf25d5dd5a1226b6c0ff159 (diff)
parentdbc8cb672a14f4a8bb136074817c71a22f743eaf (diff)
downloadtoolchain-utils-e48fee30760995c0a1ffc94f20d72d58c8079f07.tar.gz
Merged commit digest: dbc8cb67 compiler_wrapper: Use ld.bfd to detect binutils path 0274702f patch_sync: Add show subcommand 7fd98520 patch_sync: Add patch_parsing module 72bb9a35 patch_sync: Base code, version control managing 457d96b5 pgo_tools: make monitor_pgo_profiles fail rather than emailing ed486b7b afdo_metadata: Publish the new kernel profiles a170d3e2 crosperf: remove dead bob DUT d60f468c afdo_metadata: Publish the new kernel profiles 26b91865 llvm_tools: Update get_upstream_patch schema 811429e3 llvm_tools: Catch dup SHAs in get_upstream_patch ed2aa295 compiler_wrapper: Drop "-fno-experimental-pass-manager" e8d03f7e rust_watch: report bugs for new minor or major versions of rustc 443e0b36 cros_utils: Add a bug reporting module 86fe58c1 compiler_wrapper: adds ${sysroot}/usr/lib to linker path d02a62da compiler_wrapper: add missing unused-but-set-var 50d42705 afdo_metadata: Publish the new kernel profiles 7afc3522 llvm_tools: Make skip_dependencies optional 9de6ecbf crosperf: Increase timeout for a crosfleet call 58a779e7 llvm_tools: adds a way to skip dependencies when pulling from Phab 28d6cbe1 crosperf: Replace non-inclusive language c965dab6 afdo_metadata: Publish the new kernel profiles 58bc0488 crosperf: Update default_remotes to new DUTs 70c83ac3 Replace non-inclusive language d080198a llvm_tools: fix yapf warnings 5200728b llvm_tools: Add lldb_server to updated_packages afd2d4b0 compiler_wrapper: ignore unused_but_set_variable 217c68a1 Add crosperf_autolock.py wrapper dcb168bf afdo_metadata: Publish the new kernel profiles a7a19342 Auto-format the crosperf files c5e12fba Add 'no_lock' crosperf setting ec4d2aec afdo_metadata: Publish the new kernel profiles 2c5d6278 compiler_wrapper: move llvmnext flag to post flags Change-Id: Id8af179e775f6fe23c22ce05b8be9b5b02ccbaf4
Diffstat (limited to 'cros_utils/bugs.py')
-rwxr-xr-xcros_utils/bugs.py104
1 files changed, 104 insertions, 0 deletions
diff --git a/cros_utils/bugs.py b/cros_utils/bugs.py
new file mode 100755
index 00000000..88fb7675
--- /dev/null
+++ b/cros_utils/bugs.py
@@ -0,0 +1,104 @@
+#!/usr/bin/env python3
+# Copyright 2021 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Utilities to file bugs."""
+
+import base64
+import datetime
+import enum
+import json
+import os
+from typing import Any, Dict, List, Optional
+
+X20_PATH = '/google/data/rw/teams/c-compiler-chrome/prod_bugs'
+
+
+class WellKnownComponents(enum.IntEnum):
+ """A listing of "well-known" components recognized by our infra."""
+ CrOSToolchainPublic = -1
+ CrOSToolchainPrivate = -2
+
+
+def _WriteBugJSONFile(object_type: str, json_object: Dict[str, Any]):
+ """Writes a JSON file to X20_PATH with the given bug-ish object."""
+ final_object = {
+ 'type': object_type,
+ 'value': json_object,
+ }
+
+ # The name of this has two parts:
+ # - An easily sortable time, to provide uniqueness and let our service send
+ # things in the order they were put into the outbox.
+ # - 64 bits of entropy, so two racing bug writes don't clobber the same file.
+ now = datetime.datetime.utcnow().isoformat('T', 'seconds') + 'Z'
+ entropy = base64.urlsafe_b64encode(os.getrandom(8))
+ entropy_str = entropy.rstrip(b'=').decode('utf-8')
+ file_path = os.path.join(X20_PATH, f'{now}_{entropy_str}.json')
+
+ temp_path = file_path + '.in_progress'
+ try:
+ with open(temp_path, 'w') as f:
+ json.dump(final_object, f)
+ os.rename(temp_path, file_path)
+ except:
+ os.remove(temp_path)
+ raise
+ return file_path
+
+
+def AppendToExistingBug(bug_id: int, body: str):
+ """Sends a reply to an existing bug."""
+ _WriteBugJSONFile('AppendToExistingBugRequest', {
+ 'body': body,
+ 'bug_id': bug_id,
+ })
+
+
+def CreateNewBug(component_id: int,
+ title: str,
+ body: str,
+ assignee: Optional[str] = None,
+ cc: Optional[List[str]] = None):
+ """Sends a request to create a new bug.
+
+ Args:
+ component_id: The component ID to add. Anything from WellKnownComponents
+ also works.
+ title: Title of the bug. Must be nonempty.
+ body: Body of the bug. Must be nonempty.
+ assignee: Assignee of the bug. Must be either an email address, or a
+ "well-known" assignee (detective, mage).
+ cc: A list of emails to add to the CC list. Must either be an email
+ address, or a "well-known" individual (detective, mage).
+ """
+ obj = {
+ 'component_id': component_id,
+ 'subject': title,
+ 'body': body,
+ }
+
+ if assignee:
+ obj['assignee'] = assignee
+
+ if cc:
+ obj['cc'] = cc
+
+ _WriteBugJSONFile('FileNewBugRequest', obj)
+
+
+def SendCronjobLog(cronjob_name: str, failed: bool, message: str):
+ """Sends the record of a cronjob to our bug infra.
+
+ cronjob_name: The name of the cronjob. Expected to remain consistent over
+ time.
+ failed: Whether the job failed or not.
+ message: Any seemingly relevant context. This is pasted verbatim in a bug, if
+ the cronjob infra deems it worthy.
+ """
+ _WriteBugJSONFile('ChrotomationCronjobUpdate', {
+ 'name': cronjob_name,
+ 'message': message,
+ 'failed': failed,
+ })