Skip to content

Commit

Permalink
feat(abr-testing): added search words for error logs
Browse files Browse the repository at this point in the history
  • Loading branch information
rclarke0 committed Jul 8, 2024
1 parent 4c5e3f9 commit 3f0295b
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 22 deletions.
28 changes: 20 additions & 8 deletions abr-testing/abr_testing/automation/jira_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def create_ticket(
robot: str,
) -> Tuple[str, str]:
"""Create ticket."""
# Check if software version is a field on JIRA, if not replaces with existing version
data = {
"fields": {
"project": {"id": "10273", "key": project_key},
Expand All @@ -73,7 +74,6 @@ def create_ticket(
"parent": {"key": robot},
"priority": {"name": priority},
"components": [{"name": component} for component in components],
"versions": [{"name": affects_versions}],
"description": {
"content": [
{
Expand All @@ -87,6 +87,12 @@ def create_ticket(
# Include other required fields as needed
}
}
available_versions = self.get_project_versions(project_key)
if affects_versions in available_versions:
data["fields"]["versions"] = [{"name": affects_versions}]
print(f"Software version {affects_versions} added.")
else:
print("Software version of robot not in jira releases.")
try:
response = requests.post(
f"{self.url}/rest/api/3/issue",
Expand Down Expand Up @@ -139,6 +145,17 @@ def get_project_issues(self, project_key: str) -> Dict[str, Any]:
response.raise_for_status()
return response.json()

def get_project_versions(self, project_key: str) -> List[str]:
"""Get all project software versions."""
url = f"{self.url}/rest/api/3/project/{project_key}/versions"
headers = {"Accept": "application/json"}
version_list = []
response = requests.request("GET", url, headers=headers, auth=self.auth)
versions = response.json()
for version in versions:
version_list.append(version["name"])
return version_list

def extract_users_from_issues(self, issues: dict) -> Dict[str, Any]:
"""Extract users from issues."""
users = dict()
Expand Down Expand Up @@ -185,20 +202,15 @@ def get_project_components(self, project_id: str) -> List[Dict[str, str]]:
components_list = response.json()
return components_list

def comment(self, comment_str: str, issue_url: str, comment_type: str) -> None:
def comment(self, content_list: List[Dict[str, Any]], issue_url: str) -> None:
"""Leave comment on JIRA Ticket."""
comment_url = issue_url + "/comment"
payload = json.dumps(
{
"body": {
"type": "doc",
"version": 1,
"content": [
{
"type": comment_type,
"content": [{"type": "text", "text": comment_str}],
}
],
"content": content_list,
}
}
)
Expand Down
60 changes: 47 additions & 13 deletions abr-testing/abr_testing/data_collection/abr_robot_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,57 @@ def read_each_log(folder_path: str, issue_url: str) -> None:
"""Read log and comment error portion on JIRA ticket."""
for file_name in os.listdir(folder_path):
file_path = os.path.join(folder_path, file_name)
not_found_words = []
print(file_path)
if file_path.endswith(".log"):
with open(file_path) as file:
lines = file.readlines()
word = "error"
words = [
"error",
"traceback",
"error frame encountered",
"did not receive",
"collision_detected",
"fail",
"warning",
"failure",
"homingfail",
"timed out",
"exception",
]
error_lines = ""
for line_index, line in enumerate(lines):
if word in line:
lines_before = max(0, line_index - 20)
lines_after = min(len(lines), line_index + 20)
print("Line Number:", line_index + 1)
error_lines = "".join(lines[lines_before:lines_after])
message = f"Error found in {file_path}"
ticket.comment(error_lines, issue_url, "codeBlock")
break
if len(error_lines) < 1:
message = f"No error found in {file_name}"
ticket.comment(message, issue_url, "paragraph")
for word in words:
content_list = []
for line_index, line in enumerate(lines):
if word in line.lower():
lines_before = max(0, line_index - 10)
lines_after = min(len(lines), line_index + 10)
error_lines = "".join(lines[lines_before:lines_after])
code_lines = {
"type": "codeBlock",
"content": [{"type": "text", "text": error_lines}],
}
content_list.append(code_lines)
num_times = len(content_list)
if num_times == 0:
not_found_words.append(word)
else:
message = f"Key word '{word.upper()}' found in {file_name} {num_times} TIMES."
line_1 = {
"type": "paragraph",
"content": [{"type": "text", "text": message}],
}
content_list.insert(0, line_1)
ticket.comment(content_list, issue_url)
no_word_found_message = (
f"Key words '{not_found_words} were not found in {file_name}."
)
no_word_found_dict = {
"type": "paragraph",
"content": [{"type": "text", "text": no_word_found_message}],
}
content_list.append(no_word_found_dict)
ticket.comment(content_list, issue_url)


def match_error_to_component(
Expand Down Expand Up @@ -282,6 +315,7 @@ def get_run_error_info_from_robot(
project_key = "RABR"
print(robot)
parent_key = project_key + "-" + robot.split("ABR")[1]

# TODO: read board to see if ticket for run id already exists.
# CREATE TICKET
issue_key, raw_issue_url = ticket.create_ticket(
Expand Down
4 changes: 3 additions & 1 deletion abr-testing/abr_testing/tools/abr_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ def get_most_recent_run_and_record(
google_sheet_abr_data.batch_update_cells(runs_and_robots, "A", start_row, "0")
print("Wrote run to ABR-run-data")
# Add LPC to google sheet
google_sheet_lpc = google_sheets_tool.google_sheet(credentials_path, "ABR-LPC", 0)
google_sheet_lpc = google_sheets_tool.google_sheet(
credentials_path, "ABR-LPC", tab_number=0
)
start_row_lpc = google_sheet_lpc.get_index_row() + 1
google_sheet_lpc.batch_update_cells(runs_and_lpc, "A", start_row_lpc, "0")

Expand Down

0 comments on commit 3f0295b

Please sign in to comment.