Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
brian-dashboard-manager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
geant-swd
brian
brian-dashboard-manager
Commits
0bcc98f9
Commit
0bcc98f9
authored
1 year ago
by
Bjarke Madsen
Browse files
Options
Downloads
Patches
Plain Diff
use requests.Session to reuse TCP connections for Grafana API requests
parent
8b3e9bc3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
brian_dashboard_manager/grafana/utils/request.py
+18
-23
18 additions, 23 deletions
brian_dashboard_manager/grafana/utils/request.py
with
18 additions
and
23 deletions
brian_dashboard_manager/grafana/utils/request.py
+
18
−
23
View file @
0bcc98f9
import
requests
import
logging
from
requests.
model
s
import
HTTP
Erro
r
from
requests.
adapter
s
import
HTTP
Adapte
r
logger
=
logging
.
getLogger
(
__name__
)
class
Request
(
object
):
class
Request
(
requests
.
Session
):
def
__init__
(
self
,
url
,
headers
=
None
):
self
.
headers
=
{
super
().
__init__
()
# allow using up to 16 connections
adapter
=
HTTPAdapter
(
pool_maxsize
=
16
)
self
.
mount
(
url
,
adapter
)
self
.
headers
.
update
({
'
Accept
'
:
'
application/json
'
}
}
)
if
headers
:
self
.
headers
.
update
(
headers
)
self
.
BASE_URL
=
url
def
do_request
(
self
,
method
,
endpoint
,
*
args
,
**
kwargs
):
r
=
requests
.
request
(
method
,
self
.
BASE_URL
+
endpoint
,
*
args
,
**
kwargs
,
headers
=
{
**
kwargs
.
get
(
'
headers
'
,
{}),
**
self
.
headers
})
try
:
r
.
raise_for_status
()
except
HTTPError
as
e
:
if
e
.
response
.
status_code
<
500
:
logger
.
error
(
e
.
response
.
content
.
decode
(
'
utf-8
'
))
raise
e
return
r
.
json
()
def
get
(
self
,
endpoint
:
str
,
*
args
,
**
kwargs
):
return
self
.
do_request
(
'
get
'
,
endpoint
,
*
args
,
**
kwargs
)
def
do_request
(
self
,
method
,
endpoint
,
**
kwargs
)
->
requests
.
Response
:
r
=
self
.
request
(
method
,
self
.
BASE_URL
+
endpoint
,
**
kwargs
)
r
.
raise_for_status
()
return
r
def
get
(
self
,
endpoint
:
str
,
**
kwargs
):
return
self
.
do_request
(
'
get
'
,
endpoint
,
**
kwargs
)
def
post
(
self
,
endpoint
:
str
,
data
=
None
,
**
kwargs
):
return
self
.
do_request
(
'
post
'
,
endpoint
,
data
=
data
,
**
kwargs
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment