Skip to content

Commit ea1b159

Browse files
authored
Merge pull request #4 from opencitations/2025-removing-weblogger
adjust gunicorn worker settings, and comment out web logger usage in …
2 parents 514337c + 98aa67e commit ea1b159

File tree

3 files changed

+31
-20
lines changed

3 files changed

+31
-20
lines changed

docker_version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.4.2sync
1+
1.4.4sync

gunicorn.conf.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33
import subprocess
44

55
# Worker configuration
6-
workers = 4
6+
workers = 5
77
worker_class = "gevent"
88
worker_connections = 200
99
timeout = 1200
10+
graceful_timeout = 180
1011
bind = "0.0.0.0:8080"
1112

13+
max_requests = 1000
14+
max_requests_jitter = 50
15+
1216
# Logging
13-
accesslog = "-"
17+
accesslog = None
1418
errorlog = "-"
1519
loglevel = "info"
1620

sparql_oc.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,26 @@
4646
urls = (
4747
"/", "Main",
4848
"/static/(.*)", "Static",
49+
"/health", "Health",
4950
"/meta", "SparqlMeta",
5051
'/favicon.ico', 'Favicon',
5152
"/index", "SparqlIndex"
5253
)
5354

5455
# Set the web logger
55-
web_logger = WebLogger(env_config["base_url"], env_config["log_dir"], [
56-
"HTTP_X_FORWARDED_FOR", # The IP address of the client
57-
"REMOTE_ADDR", # The IP address of internal balancer
58-
"HTTP_USER_AGENT", # The browser type of the visitor
59-
"HTTP_REFERER", # The URL of the page that called your program
60-
"HTTP_HOST", # The hostname of the page being attempted
61-
"REQUEST_URI", # The interpreted pathname of the requested document
62-
# or CGI (relative to the document root)
63-
"HTTP_AUTHORIZATION", # Access token
64-
],
65-
# comment this line only for test purposes
66-
{"REMOTE_ADDR": ["130.136.130.1", "130.136.2.47", "127.0.0.1"]}
67-
)
56+
# web_logger = WebLogger(env_config["base_url"], env_config["log_dir"], [
57+
# "HTTP_X_FORWARDED_FOR", # The IP address of the client
58+
# "REMOTE_ADDR", # The IP address of internal balancer
59+
# "HTTP_USER_AGENT", # The browser type of the visitor
60+
# "HTTP_REFERER", # The URL of the page that called your program
61+
# "HTTP_HOST", # The hostname of the page being attempted
62+
# "REQUEST_URI", # The interpreted pathname of the requested document
63+
# # or CGI (relative to the document root)
64+
# "HTTP_AUTHORIZATION", # Access token
65+
# ],
66+
# # comment this line only for test purposes
67+
# {"REMOTE_ADDR": ["130.136.130.1", "130.136.2.47", "127.0.0.1"]}
68+
# )
6869

6970
render = web.template.render(c["html"], globals={
7071
'str': str,
@@ -102,6 +103,12 @@ def GET(self):
102103
)
103104
protocol = 'https' if is_https else 'http'
104105
raise web.seeother(f"{protocol}://{web.ctx.host}/static/favicon.ico")
106+
107+
class Health:
108+
"""Lightweight health check endpoint for Kubernetes probes"""
109+
def GET(self):
110+
web.header('Content-Type', 'application/json')
111+
return '{"status": "ok"}'
105112

106113
class Header:
107114
def GET(self):
@@ -116,7 +123,7 @@ def __init__(self, sparql_endpoint, sparql_endpoint_title, yasqe_sparql_endpoint
116123
self.collparam = ["query"]
117124

118125
def GET(self):
119-
web_logger.mes()
126+
#web_logger.mes()
120127
content_type = web.ctx.env.get('CONTENT_TYPE')
121128
return self.__run_query_string(self.sparql_endpoint_title, web.ctx.env.get("QUERY_STRING"), content_type)
122129

@@ -158,7 +165,7 @@ def __contact_tp(self, data, is_post, content_type):
158165
web.header('Content-Type', 'application/sparql-results+json')
159166
else:
160167
web.header('Content-Type', req.headers["content-type"])
161-
web_logger.mes()
168+
#web_logger.mes()
162169
req.encoding = "utf-8"
163170
return req.text
164171
else:
@@ -179,7 +186,7 @@ def __run_query_string(self, active, query_string, is_post=False,
179186
parsed_query = urlparse.parse_qs(query_string)
180187
current_subdomain = web.ctx.host.split('.')[0].lower()
181188
if query_string is None or query_string.strip() == "":
182-
web_logger.mes()
189+
#web_logger.mes()
183190
return getattr(render, self.sparql_endpoint_title)(
184191
active=active,
185192
sp_title=self.sparql_endpoint_title,
@@ -210,7 +217,7 @@ def __run_query_string(self, active, query_string, is_post=False,
210217

211218
class Main:
212219
def GET(self):
213-
web_logger.mes()
220+
#web_logger.mes()
214221
current_subdomain = web.ctx.host.split('.')[0].lower()
215222
return render.sparql(active="", sp_title="", sparql_endpoint="", current_subdomain=current_subdomain, render=render)
216223

0 commit comments

Comments
 (0)