Skip to content

Commit 51b927a

Browse files
authored
#4 - Fix severe bug that cause the API to crash when querying contexts or sessions (#5)
1 parent 257384e commit 51b927a

14 files changed

Lines changed: 336 additions & 293 deletions

docs/source/api_cookbook.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ Objective
106106
metrics = Metrics()
107107
for build in last_3_builds:
108108
sessions = mon.list_build_sessions(PIPELINE, build)
109-
m = mon.list_session_metrics(sessions).filter_with(keep_only_test_that)
110-
metrics = metrics.merge(m)
109+
for session_id in sessions:
110+
m = mon.list_session_metrics(session_id).filter_with(keep_only_test_that)
111+
metrics = metrics.merge(m)
111112
print(len(metrics))
112113

docs/source/changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
Changelog
33
=========
44

5+
* :release:`1.0.2 <2021-22-10>`
6+
* :bug:`#4` Fix a bug which prevents the api to query sessions from the REST Api.
7+
58
* :release:`1.0.1 <2021-15-10>`
69
* :bug:`#2` Fix a bug which prevents the api to query sessions from the REST Api.
710

monitor_api/dialects/remote.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def translate(context: Optional[Dict[str, Any]] = None,
1515
session: Optional[Dict[str, Any]] = None,
1616
metric: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
1717
if context is not None:
18-
d = dict(h=context['h'],
18+
d = dict(h=context['context_h'],
1919
cpu_count=context['cpu_count'],
2020
cpu_freq=context['cpu_frequency'],
2121
cpu_type=context['cpu_type'],
@@ -125,7 +125,7 @@ def get_session_details(self, session_h) -> Optional[Session]:
125125
j = self.__session.get(self._make_url(f'/sessions/{session_h}'))
126126
if j.status_code == HTTPStatus.NO_CONTENT:
127127
return None
128-
return Session(**translate(session=j.json()['sessions']))
128+
return Session(**translate(session=j.json()['sessions'][0]))
129129
except requests.RequestException:
130130
return None
131131

@@ -153,7 +153,7 @@ def get_sessions(self, with_tags: Union[str, List[str]] = None,
153153
try:
154154
for page in self._collect(self._make_url(url, **params)):
155155
for session in page['sessions']:
156-
s = Session(**session)
156+
s = Session(**translate(session=session))
157157
sessions[s.h] = s
158158
return sessions
159159
except requests.RequestException:
@@ -310,7 +310,7 @@ def get_context_details(self, context_h: str) -> Optional[Context]:
310310
try:
311311
data = self.__session.get(self._make_url(f'/contexts/{context_h}'))
312312
if data.status_code == HTTPStatus.OK:
313-
return Context(**translate(context=data.json()))
313+
return Context(**translate(context=data.json()['contexts'][0]))
314314
return None
315315
except requests.RequestException:
316316
return None

monitor_server/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import os
1010
import pathlib
1111

12-
__version__ = '1.0.1'
12+
__version__ = '1.0.2'
1313

1414

1515
def _create_monitor_server():

tests/data/test_context_details.service.json

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,21 @@
55
},
66
"/api/v1/contexts/28dae49c83587322a3b535612add39e3": {
77
"data": {
8-
"h": "28dae49c83587322a3b535612add39e3",
9-
"cpu_count": 8,
10-
"cpu_frequency": 2500,
11-
"cpu_type": "i386",
12-
"cpu_vendor": "Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz",
13-
"ram_total": 16384,
14-
"machine_node": "Rotondu.local",
15-
"machine_type": "x86_64",
16-
"machine_arch": "64bit",
17-
"system_info": "Darwin - 18.7.0",
18-
"python_info": "3.8.6 | packaged by conda-forge | (default, Jan 25 2021, 23:22:12) [Clang 11.0.1 ]"
8+
"contexts": [
9+
{
10+
"context_h": "28dae49c83587322a3b535612add39e3",
11+
"cpu_count": 8,
12+
"cpu_frequency": 2500,
13+
"cpu_type": "i386",
14+
"cpu_vendor": "Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz",
15+
"ram_total": 16384,
16+
"machine_node": "Rotondu.local",
17+
"machine_type": "x86_64",
18+
"machine_arch": "64bit",
19+
"system_info": "Darwin - 18.7.0",
20+
"python_info": "3.8.6 | packaged by conda-forge | (default, Jan 25 2021, 23:22:12) [Clang 11.0.1 ]"
21+
}
22+
]
1923
},
2024
"status_code": 200
2125
}

tests/data/test_contexts.service.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"data": {
44
"contexts": [
55
{
6-
"h": "28dae49c83587322a3b535612add39e3",
6+
"context_h": "28dae49c83587322a3b535612add39e3",
77
"cpu_count": 8,
88
"cpu_frequency": 2500,
99
"cpu_type": "i386",
@@ -16,7 +16,7 @@
1616
"python_info": "3.8.6 | packaged by conda-forge | (default, Jan 25 2021, 23:22:12) [Clang 11.0.1 ]"
1717
},
1818
{
19-
"h": "9ae6c23d7c6b4562393385edf6da8500",
19+
"context_h": "9ae6c23d7c6b4562393385edf6da8500",
2020
"cpu_count": 8,
2121
"cpu_frequency": 2500,
2222
"cpu_type": "i386",

tests/data/test_get_contexts_from_metrics.service.json

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,33 +57,42 @@
5757
},
5858
"/api/v1/contexts/7768124332f353446557878a89ef6f4c": {
5959
"data": {
60-
"h": "7768124332f353446557878a89ef6f4c",
61-
"cpu_count": 8,
62-
"cpu_frequency": 2500,
63-
"cpu_type": "i386",
64-
"cpu_vendor": "Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz",
65-
"ram_total": 16384,
66-
"machine_node": "Rotondu.local",
67-
"machine_type": "x86_64",
68-
"machine_arch": "64bit",
69-
"system_info": "Darwin - 18.7.0",
70-
"python_info": "3.8.6 | packaged by conda-forge | (default, Jan 25 2021, 23:22:12) [Clang 11.0.1 ]"
60+
"contexts": [
61+
{
62+
"context_h": "7768124332f353446557878a89ef6f4c",
63+
"cpu_count": 8,
64+
"cpu_frequency": 2500,
65+
"cpu_type": "i386",
66+
"cpu_vendor": "Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz",
67+
"ram_total": 16384,
68+
"machine_node": "Rotondu.local",
69+
"machine_type": "x86_64",
70+
"machine_arch": "64bit",
71+
"system_info": "Darwin - 18.7.0",
72+
"python_info": "3.8.6 | packaged by conda-forge | (default, Jan 25 2021, 23:22:12) [Clang 11.0.1 ]"
73+
}
74+
]
7175
},
7276
"status_code": 200
7377
},
7478
"/api/v1/contexts/c4f6fe98a878755644353f2334218677": {
7579
"data": {
76-
"h": "c4f6fe98a878755644353f2334218677",
77-
"cpu_count": 8,
78-
"cpu_frequency": 2500,
79-
"cpu_type": "i386",
80-
"cpu_vendor": "Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz",
81-
"ram_total": 16384,
82-
"machine_node": "Rotondu.local",
83-
"machine_type": "x86_64",
84-
"machine_arch": "64bit",
85-
"system_info": "Darwin - 18.7.0",
86-
"python_info": "3.8.6 | packaged by conda-forge | (default, Jan 25 2021, 23:22:12) [Clang 11.0.1 ]"
80+
"contexts":
81+
[
82+
{
83+
"context_h": "c4f6fe98a878755644353f2334218677",
84+
"cpu_count": 8,
85+
"cpu_frequency": 2500,
86+
"cpu_type": "i386",
87+
"cpu_vendor": "Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz",
88+
"ram_total": 16384,
89+
"machine_node": "Rotondu.local",
90+
"machine_type": "x86_64",
91+
"machine_arch": "64bit",
92+
"system_info": "Darwin - 18.7.0",
93+
"python_info": "3.8.6 | packaged by conda-forge | (default, Jan 25 2021, 23:22:12) [Clang 11.0.1 ]"
94+
}
95+
]
8796
},
8897
"status_code": 200
8998
}

tests/data/test_get_metrics_from_contexts.service.json

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"/api/v1/contexts/9ae6c23d7c6b4562393385edf6da8500/metrics": {
33
"data": {
4-
"metrics": [ {
4+
"metrics": [
5+
{
56
"session_h": "b83742056ad0ed304d821562b7c209ff",
67
"context_h": "9ae6c23d7c6b4562393385edf6da8500",
78
"item_start_time": "2021-02-09T11:52:55.528818",
@@ -66,17 +67,21 @@
6667
},
6768
"/api/v1/contexts/9ae6c23d7c6b4562393385edf6da8500": {
6869
"data": {
69-
"h": "9ae6c23d7c6b4562393385edf6da8500",
70-
"cpu_count": 8,
71-
"cpu_frequency": 2500,
72-
"cpu_type": "i386",
73-
"cpu_vendor": "Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz",
74-
"ram_total": 16384,
75-
"machine_node": "Rotondu.local",
76-
"machine_type": "x86_64",
77-
"machine_arch": "64bit",
78-
"system_info": "Darwin - 18.7.0",
79-
"python_info": "3.8.6 | packaged by conda-forge | (default, Jan 25 2021, 23:22:12) [Clang 11.0.1 ]"
70+
"contexts": [
71+
{
72+
"context_h": "9ae6c23d7c6b4562393385edf6da8500",
73+
"cpu_count": 8,
74+
"cpu_frequency": 2500,
75+
"cpu_type": "i386",
76+
"cpu_vendor": "Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz",
77+
"ram_total": 16384,
78+
"machine_node": "Rotondu.local",
79+
"machine_type": "x86_64",
80+
"machine_arch": "64bit",
81+
"system_info": "Darwin - 18.7.0",
82+
"python_info": "3.8.6 | packaged by conda-forge | (default, Jan 25 2021, 23:22:12) [Clang 11.0.1 ]"
83+
}
84+
]
8085
},
8186
"status_code": 200
8287
},

tests/data/test_get_metrics_from_sessions.service.json

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"/api/v1/sessions/b83742056ad0ed304d821562b7c209ff/metrics": {
33
"data": {
4-
"metrics": [ {
4+
"metrics": [
5+
{
56
"session_h": "b83742056ad0ed304d821562b7c209ff",
67
"context_h": "9ae6c23d7c6b4562393385edf6da8500",
78
"item_start_time": "2021-02-09T11:52:55.528818",
@@ -66,41 +67,43 @@
6667
},
6768
"/api/v1/sessions/b83742056ad0ed304d821562b7c209ff": {
6869
"data": {
69-
"sessions": {
70-
"session_h": "b83742056ad0ed304d821562b7c209ff",
71-
"run_date": "2021-02-09T13:48:58.923094",
72-
"scm_ref": "4c3b3ca9e975a0a5eacd5d802d03c4ba690e8e41",
73-
"tags": [
74-
{
75-
"name": "pipeline_branch",
76-
"value": "master-py38"
77-
},
78-
{
79-
"name": "pipeline_build_no",
80-
"value": "10"
81-
},
82-
{
83-
"name": "__ci__",
84-
"value": "circleci"
85-
},
86-
{
87-
"name": "version",
88-
"value": "1.4.0"
89-
},
90-
{
91-
"name": "numpy",
92-
"value": "1.20.0"
93-
},
94-
{
95-
"name": "python",
96-
"value": "3.8"
97-
},
98-
{
99-
"name": "origin",
100-
"value": "conda-forge"
101-
}
102-
]
103-
}
70+
"sessions": [
71+
{
72+
"session_h": "b83742056ad0ed304d821562b7c209ff",
73+
"run_date": "2021-02-09T13:48:58.923094",
74+
"scm_ref": "4c3b3ca9e975a0a5eacd5d802d03c4ba690e8e41",
75+
"tags": [
76+
{
77+
"name": "pipeline_branch",
78+
"value": "master-py38"
79+
},
80+
{
81+
"name": "pipeline_build_no",
82+
"value": "10"
83+
},
84+
{
85+
"name": "__ci__",
86+
"value": "circleci"
87+
},
88+
{
89+
"name": "version",
90+
"value": "1.4.0"
91+
},
92+
{
93+
"name": "numpy",
94+
"value": "1.20.0"
95+
},
96+
{
97+
"name": "python",
98+
"value": "3.8"
99+
},
100+
{
101+
"name": "origin",
102+
"value": "conda-forge"
103+
}
104+
]
105+
}
106+
]
104107
},
105108
"status_code": 200
106109
},

0 commit comments

Comments
 (0)