Skip to content

Commit 36a2386

Browse files
sjoebooamotl
authored andcommitted
add session_pool_size
1 parent 49226b0 commit 36a2386

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

grafana_client/api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import niquests.auth
99
from urllib3.exceptions import InsecureRequestWarning
1010

11-
from .client import DEFAULT_TIMEOUT, AsyncGrafanaClient, GrafanaClient
11+
from .client import DEFAULT_SESSION_POOL_SIZE, DEFAULT_TIMEOUT, AsyncGrafanaClient, GrafanaClient
1212
from .elements import (
1313
Admin,
1414
Alerting,
@@ -72,6 +72,7 @@ def __init__(
7272
timeout=DEFAULT_TIMEOUT,
7373
user_agent: str = None,
7474
organization_id: int = None,
75+
session_pool_size=DEFAULT_SESSION_POOL_SIZE,
7576
):
7677
self.client = GrafanaClient(
7778
auth,
@@ -83,6 +84,7 @@ def __init__(
8384
timeout=timeout,
8485
user_agent=user_agent,
8586
organization_id=organization_id,
87+
session_pool_size=session_pool_size,
8688
)
8789
self.url = None
8890
self.admin = Admin(self.client)

grafana_client/client.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def __init__(
8888
timeout=DEFAULT_TIMEOUT,
8989
user_agent: str = None,
9090
organization_id: int = None,
91+
session_pool_size=DEFAULT_SESSION_POOL_SIZE,
9192
):
9293
self.auth = auth
9394
self.verify = verify
@@ -96,6 +97,7 @@ def __init__(
9697
self.url_port = port
9798
self.url_path_prefix = url_path_prefix
9899
self.url_protocol = protocol
100+
self.session_pool_size = session_pool_size
99101

100102
def construct_api_url():
101103
params = {
@@ -118,7 +120,7 @@ def construct_api_url():
118120

119121
self.user_agent = user_agent or f"{__appname__}/{__version__}"
120122

121-
self.s = niquests.Session()
123+
self.s = niquests.Session(pool_maxsize=session_pool_size)
122124
self.s.headers["User-Agent"] = self.user_agent
123125

124126
self.organization_id = organization_id
@@ -230,6 +232,7 @@ def __init__(
230232
timeout=DEFAULT_TIMEOUT,
231233
user_agent: str = None,
232234
organization_id: int = None,
235+
session_pool_size=DEFAULT_SESSION_POOL_SIZE,
233236
):
234237
super().__init__(
235238
auth,
@@ -241,8 +244,9 @@ def __init__(
241244
timeout=timeout,
242245
user_agent=user_agent,
243246
organization_id=organization_id,
247+
session_pool_size=session_pool_size,
244248
)
245-
self.s = niquests.AsyncSession()
249+
self.s = niquests.AsyncSession(pool_maxsize=session_pool_size)
246250
self.s.headers.setdefault("Connection", "keep-alive")
247251

248252
def __getattr__(self, item):

0 commit comments

Comments
 (0)