Skip to content

Commit 1b74f8d

Browse files
authored
Merge pull request #203 from reportportal/ga4
Ga4
2 parents 265036b + af7bab7 commit 1b74f8d

26 files changed

+414
-1279
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
### Fixed
55
- Issue [#198](https://github.com/reportportal/client-Python/issues/198): Python 3.8+ logging issue, by @HardNorth
66
- Issue [#200](https://github.com/reportportal/client-Python/issues/200): max_pool_size not worked without retries setting, by @ericscobell
7+
- Issue [#202](https://github.com/reportportal/client-Python/issues/202): TypeError on request make, by @HardNorth
8+
### Changed
9+
- Statistics service rewrite, by @HardNorth
10+
### Removed
11+
- Deprecated code, `service.py` and `LogManager` in `core` package, by @HardNorth
712

813
## [5.2.5]
914
### Fixed

reportportal_client/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@
1616

1717
from ._local import current
1818
from .logs import RPLogger, RPLogHandler
19-
from .service import ReportPortalService
2019
from .client import RPClient
2120
from .steps import step
2221

2322
__all__ = [
2423
'current',
2524
'RPLogger',
2625
'RPLogHandler',
27-
'ReportPortalService',
2826
'RPClient',
2927
'step',
3028
]

reportportal_client/client.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# limitations under the License
1515

1616
import logging
17+
from os import getenv
18+
1719
import requests
1820
from requests.adapters import HTTPAdapter, Retry, DEFAULT_RETRIES
1921

@@ -27,6 +29,7 @@
2729
)
2830
from .helpers import uri_join, verify_value_length
2931
from .logs.log_manager import LogManager, MAX_LOG_BATCH_PAYLOAD_SIZE
32+
from .services.statistics import send_event
3033
from .static.defines import NOT_FOUND
3134
from .steps import StepReporter
3235

@@ -100,6 +103,7 @@ def __init__(self,
100103
self.step_reporter = StepReporter(self)
101104
self._item_stack = []
102105
self.mode = mode
106+
self._skip_analytics = getenv('AGENT_NO_ANALYTICS')
103107

104108
retry_strategy = Retry(
105109
total=retries,
@@ -108,6 +112,7 @@ def __init__(self,
108112
) if retries else DEFAULT_RETRIES
109113
self.session.mount('https://', HTTPAdapter(
110114
max_retries=retry_strategy, pool_maxsize=max_pool_size))
115+
# noinspection HttpUrlsUsage
111116
self.session.mount('http://', HTTPAdapter(
112117
max_retries=retry_strategy, pool_maxsize=max_pool_size))
113118
self.session.headers['Authorization'] = 'bearer {0}'.format(self.token)
@@ -300,9 +305,9 @@ def start_launch(self,
300305
:param start_time: Launch start time
301306
:param description: Launch description
302307
:param attributes: Launch attributes
303-
:param rerun: Enables launch rerun mode
304-
:param rerun_of: Rerun mode. Specifies launch to be re-runned.
305-
Should be used with the 'rerun' option.
308+
:param rerun: Start launch in rerun mode
309+
:param rerun_of: For rerun mode specifies which launch will be
310+
re-run. Should be used with the 'rerun' option.
306311
"""
307312
url = uri_join(self.base_url_v2, 'launch')
308313

@@ -333,6 +338,17 @@ def start_launch(self,
333338
verify_ssl=self.verify_ssl).make()
334339
if not response:
335340
return
341+
342+
if not self._skip_analytics:
343+
agent_name, agent_version = None, None
344+
345+
agent_attribute = [a for a in attributes if
346+
a.get('key') == 'agent'] if attributes else []
347+
if len(agent_attribute) > 0 and agent_attribute[0].get('value'):
348+
agent_name, agent_version = agent_attribute[0]['value'].split(
349+
'|')
350+
send_event('start_launch', agent_name, agent_version)
351+
336352
self._log_manager.launch_id = self.launch_id = response.id
337353
logger.debug('start_launch - ID: %s', self.launch_id)
338354
return self.launch_id

reportportal_client/client.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ from typing import Any, Dict, List, Optional, Text, Tuple, Union
22

33
from requests import Session
44

5-
from reportportal_client.logs.log_manager import LogManager as LogManager
65
from reportportal_client.core.rp_issues import Issue as Issue
6+
from reportportal_client.logs.log_manager import LogManager as LogManager
77
from reportportal_client.steps import StepReporter
88

99

@@ -28,6 +28,7 @@ class RPClient:
2828
session: Session = ...
2929
step_reporter: StepReporter = ...
3030
mode: str = ...
31+
_skip_analytics: Text = ...
3132

3233
def __init__(
3334
self,
@@ -103,3 +104,5 @@ class RPClient:
103104
description: Optional[Text]) -> Text: ...
104105

105106
def current_item(self) -> Text: ...
107+
108+
def start(self) -> None : ...

reportportal_client/core/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,3 @@
1212
# limitations under the License
1313

1414
"""This package contains core reportportal-client modules."""
15-
16-
from reportportal_client.logs import log_manager
17-
18-
__all__ = [
19-
'log_manager'
20-
]

reportportal_client/core/log_manager.py

Lines changed: 0 additions & 36 deletions
This file was deleted.

reportportal_client/core/rp_requests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def make(self):
7676
timeout=self.http_timeout)
7777
)
7878
# https://github.com/reportportal/client-Python/issues/39
79-
except (KeyError, IOError, ValueError) as exc:
79+
except (KeyError, IOError, ValueError, TypeError) as exc:
8080
logger.warning(
8181
"Report Portal %s request failed",
8282
self.name,

reportportal_client/core/rp_responses.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,7 @@ def _get_json(data):
7171
:param data: requests.Response object
7272
:return: dict
7373
"""
74-
if not data.text:
75-
return {}
76-
try:
77-
return data.json()
78-
except ValueError as error:
79-
logger.warning('Invalid response: {0}: {1}'
80-
.format(error, data.text),
81-
exc_info=error)
82-
return {}
74+
return data.json()
8375

8476
@property
8577
def id(self):

reportportal_client/external/__init__.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

reportportal_client/external/constants.py

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)