ALBS-1099

- Test task started_at attribute now is set as oldest start_ts attribute among all test steps
Various
  - grafana-dashbords/Test task details.json: fixed 'max stack call' error (added LITMIT 1000 to id query)
  - fix typo in config_default.yml
This commit is contained in:
Kirill Zhukov 2023-04-21 09:31:58 +02:00
parent 4149925e8e
commit 7a1d84a076
4 changed files with 47 additions and 34 deletions

View File

@ -1,7 +1,7 @@
from datetime import datetime from datetime import datetime
import logging import logging
from urllib.parse import urljoin from urllib.parse import urljoin
from typing import Dict, List, Any from typing import Dict, List, Any, Optional
import requests import requests
@ -104,7 +104,8 @@ class APIclient():
if not task['performance_stats']: if not task['performance_stats']:
logging.warning( logging.warning(
"no perfomance_stats for build_id: %s, build_task_id: %s", build_id, task['id']) "no perfomance_stats for build_id: %s, build_task_id: %s", build_id, task['id'])
stats = {'build_node_stats': {}, 'build_done_stats': {}} stats: dict[str, Any] = {
'build_node_stats': {}, 'build_done_stats': {}}
else: else:
stats = task['performance_stats'][0]['statistics'] stats = task['performance_stats'][0]['statistics']
@ -161,17 +162,10 @@ class APIclient():
return result return result
def __parse_test_tasks(self, raw_tasks: List[Dict[str, Any]], def __parse_test_tasks(self, raw_tasks: List[Dict[str, Any]],
build_task_id: int, build_task_id: int) -> List[TestTask]:
started_at: str = None) -> List[TestTask]:
result: List[TestTask] = [] result: List[TestTask] = []
for task in raw_tasks: for task in raw_tasks:
if task['alts_response']: if task['alts_response']:
try:
started_raw = task['alts_response']['stats']['started_at']
except KeyError:
started_at = None
else:
started_at = datetime.fromisoformat(started_raw+TZ_OFFSET)
try: try:
stats_raw = task['alts_response']['stats'] stats_raw = task['alts_response']['stats']
except KeyError: except KeyError:
@ -179,7 +173,6 @@ class APIclient():
else: else:
steps_stats = self.__parse_test_steps_stats(stats_raw) steps_stats = self.__parse_test_steps_stats(stats_raw)
else: else:
started_at = None
steps_stats = None steps_stats = None
params = { params = {
'id': task['id'], 'id': task['id'],
@ -189,7 +182,8 @@ class APIclient():
'package_fullname': '_'.join([task['package_name'], 'package_fullname': '_'.join([task['package_name'],
task['package_version'], task['package_version'],
task['package_release']]), task['package_release']]),
'started_at': started_at, 'started_at': self.__get_test_task_started_at(
steps_stats) if steps_stats else None,
'steps_stats': steps_stats 'steps_stats': steps_stats
} }
@ -209,3 +203,21 @@ class APIclient():
p[k] = datetime.fromisoformat(p[k]+TZ_OFFSET) p[k] = datetime.fromisoformat(p[k]+TZ_OFFSET)
teast_steps_params[field_name] = TestStepStat(**p) teast_steps_params[field_name] = TestStepStat(**p)
return TestStepsStats(**teast_steps_params) return TestStepsStats(**teast_steps_params)
def __get_test_task_started_at(self, stats: TestStepsStats) -> Optional[datetime]:
"""
getting started_at attribute for test by using oldest start_ts timestamp
among all test tasks steps
"""
if not stats:
return None
start_ts = None
for field_name in stats.__fields__.keys():
stat: TestStepStat = getattr(stats, field_name)
if not stat:
continue
if not start_ts or start_ts > stat.start_ts:
start_ts = stat.start_ts
return start_ts

View File

@ -60,7 +60,7 @@ scrape_interval: 3600
# build_id to start populating empty db with # build_id to start populating empty db with
# required: false # required: false
# default: 5808 (first build with correct metrics) # default: 5808 (first build with correct metrics)
start_from: start_from: 5808
# oldest_to_update # oldest_to_update
# oldest (in days) unfinished object (build/task/step...) that we will try to update # oldest (in days) unfinished object (build/task/step...) that we will try to update

View File

@ -1,8 +1,8 @@
{ {
"__inputs": [ "__inputs": [
{ {
"name": "DS_POSTGRESQL", "name": "DS_ALBS_ANALYTICS",
"label": "PostgreSQL", "label": "albs_analytics",
"description": "", "description": "",
"type": "datasource", "type": "datasource",
"pluginId": "postgres", "pluginId": "postgres",
@ -21,7 +21,7 @@
"type": "grafana", "type": "grafana",
"id": "grafana", "id": "grafana",
"name": "Grafana", "name": "Grafana",
"version": "9.3.2" "version": "9.3.6"
}, },
{ {
"type": "datasource", "type": "datasource",
@ -58,7 +58,7 @@
} }
] ]
}, },
"editable": false, "editable": true,
"fiscalYearStartMonth": 0, "fiscalYearStartMonth": 0,
"graphTooltip": 0, "graphTooltip": 0,
"id": null, "id": null,
@ -68,7 +68,7 @@
{ {
"datasource": { "datasource": {
"type": "postgres", "type": "postgres",
"uid": "${DS_POSTGRESQL}" "uid": "${DS_ALBS_ANALYTICS}"
}, },
"fieldConfig": { "fieldConfig": {
"defaults": { "defaults": {
@ -152,13 +152,13 @@
"showHeader": true, "showHeader": true,
"sortBy": [] "sortBy": []
}, },
"pluginVersion": "9.3.2", "pluginVersion": "9.3.6",
"targets": [ "targets": [
{ {
"cacheDurationSeconds": 300, "cacheDurationSeconds": 300,
"datasource": { "datasource": {
"type": "postgres", "type": "postgres",
"uid": "${DS_POSTGRESQL}" "uid": "${DS_ALBS_ANALYTICS}"
}, },
"editorMode": "code", "editorMode": "code",
"fields": [ "fields": [
@ -216,7 +216,7 @@
{ {
"datasource": { "datasource": {
"type": "postgres", "type": "postgres",
"uid": "${DS_POSTGRESQL}" "uid": "${DS_ALBS_ANALYTICS}"
}, },
"fieldConfig": { "fieldConfig": {
"defaults": { "defaults": {
@ -263,13 +263,13 @@
}, },
"showUnfilled": false "showUnfilled": false
}, },
"pluginVersion": "9.3.2", "pluginVersion": "9.3.6",
"targets": [ "targets": [
{ {
"cacheDurationSeconds": 300, "cacheDurationSeconds": 300,
"datasource": { "datasource": {
"type": "postgres", "type": "postgres",
"uid": "${DS_POSTGRESQL}" "uid": "${DS_ALBS_ANALYTICS}"
}, },
"editorMode": "code", "editorMode": "code",
"fields": [ "fields": [
@ -315,7 +315,7 @@
{ {
"datasource": { "datasource": {
"type": "postgres", "type": "postgres",
"uid": "${DS_POSTGRESQL}" "uid": "${DS_ALBS_ANALYTICS}"
}, },
"fieldConfig": { "fieldConfig": {
"defaults": { "defaults": {
@ -409,18 +409,18 @@
"showHeader": true, "showHeader": true,
"sortBy": [ "sortBy": [
{ {
"desc": true, "desc": false,
"displayName": "finished" "displayName": "started"
} }
] ]
}, },
"pluginVersion": "9.3.2", "pluginVersion": "9.3.6",
"targets": [ "targets": [
{ {
"cacheDurationSeconds": 300, "cacheDurationSeconds": 300,
"datasource": { "datasource": {
"type": "postgres", "type": "postgres",
"uid": "${DS_POSTGRESQL}" "uid": "${DS_ALBS_ANALYTICS}"
}, },
"editorMode": "code", "editorMode": "code",
"fields": [ "fields": [
@ -485,16 +485,16 @@
"current": {}, "current": {},
"datasource": { "datasource": {
"type": "postgres", "type": "postgres",
"uid": "${DS_POSTGRESQL}" "uid": "${DS_ALBS_ANALYTICS}"
}, },
"definition": "SELECT id\nFROM test_tasks\nORDER BY id DESC", "definition": "SELECT id\nFROM test_tasks\nORDER BY id DESC\nLIMIT 1000;",
"hide": 0, "hide": 0,
"includeAll": false, "includeAll": false,
"label": "Test task id", "label": "Test task id",
"multi": false, "multi": false,
"name": "id", "name": "id",
"options": [], "options": [],
"query": "SELECT id\nFROM test_tasks\nORDER BY id DESC", "query": "SELECT id\nFROM test_tasks\nORDER BY id DESC\nLIMIT 1000;",
"refresh": 1, "refresh": 1,
"regex": "", "regex": "",
"skipUrlSync": false, "skipUrlSync": false,
@ -511,6 +511,6 @@
"timezone": "", "timezone": "",
"title": "Test task details", "title": "Test task details",
"uid": "8nFXlkB4z", "uid": "8nFXlkB4z",
"version": 8, "version": 3,
"weekStart": "" "weekStart": ""
} }

View File

@ -22,5 +22,6 @@ First version
- Bugfix ALBS-1060 - Bugfix ALBS-1060
0.3.3 (IN PROGRESS) 0.3.3 (IN PROGRESS)
- [ALBS-1099] build-analytics: change source of Test task started_at timestamp build-analytics:
- [ALBS-1077] build_analytics: start deleting builds that were removed from ALBS - [ALBS-1099] change source of Test task started_at timestamp
- [ALBS-1077] start deleting builds that were removed from ALBS