Skip to content

Commit 2943078

Browse files
authored
Merge pull request #217 from rackerlabs/minor-tuning-of-uwsgi-models-and-api-client
Minor tuning of uwsgi models and api client
2 parents ad542bd + be50382 commit 2943078

File tree

6 files changed

+38
-15
lines changed

6 files changed

+38
-15
lines changed

ansible-playbooks/roles/master/templates/etc/nginx/sites-available/scantron_nginx.conf.j2

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,11 @@ server {
4141
location / {
4242
uwsgi_pass scantron;
4343
include uwsgi_params;
44+
uwsgi_read_timeout 600;
4445
}
46+
47+
# client_max_body_size must be the MB value of the max_length of any target type fields in
48+
# master/django_scantron/models.py
49+
# 4194304 bytes --> 4M, assuming each character takes up 1 byte.
50+
client_max_body_size 4M;
4551
}

ansible-playbooks/roles/master/templates/scantron_uwsgi.ini.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ pidfile = /tmp/scantron-master.pid
2727
# Respawn processes taking more than 120 seconds
2828
harakiri = 120
2929

30-
# Respawn processes after serving 5000 requests
31-
max-requests = 5000
30+
# Respawn processes after serving 50 requests
31+
max-requests = 50
3232

3333
# Socket file
3434
socket = /tmp/uwsgi.sock

master/django_scantron/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.33"
1+
__version__ = "1.34"

master/django_scantron/models.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@ class GloballyExcludedTarget(models.Model):
5656
"""Model for globally excluded targets."""
5757

5858
id = models.AutoField(primary_key=True, verbose_name="Globally excluded target ID")
59+
# See the client_max_body_size setting in
60+
# ansible-playbooks/roles/master/templates/etc/nginx/sites-available/scantron_nginx.conf.j2 if the max_length value
61+
# is changed.
5962
globally_excluded_targets = models.CharField(
6063
unique=False,
61-
max_length=1_048_576, # 2^20 = 1048576
64+
max_length=4194304, # 2^22 = 4194304. See note above if this value is changed.
6265
validators=[
6366
RegexValidator(
6467
regex="^[a-zA-Z0-9/\.\:\- ]*$", # Characters to support IPv4, IPv6, and FQDNs only. Space delimited.
@@ -130,9 +133,12 @@ class Site(models.Model):
130133
verbose_name="Site Name",
131134
)
132135
description = models.CharField(unique=False, max_length=255, blank=True, verbose_name="Description")
136+
# See the client_max_body_size setting in
137+
# ansible-playbooks/roles/master/templates/etc/nginx/sites-available/scantron_nginx.conf.j2 if the max_length value
138+
# is changed.
133139
targets = models.CharField(
134140
unique=False,
135-
max_length=1_048_576, # 2^20 = 1048576
141+
max_length=4194304, # 2^22 = 4194304. See note above if this value is changed.
136142
validators=[
137143
RegexValidator(
138144
regex="^[a-zA-Z0-9/\.\:\- ]*$", # Characters to support IPv4, IPv6, and FQDNs only. Space delimited.
@@ -141,10 +147,13 @@ class Site(models.Model):
141147
],
142148
verbose_name="Targets",
143149
)
150+
# See the client_max_body_size setting in
151+
# ansible-playbooks/roles/master/templates/etc/nginx/sites-available/scantron_nginx.conf.j2 if the max_length value
152+
# is changed.
144153
excluded_targets = models.CharField(
145154
unique=False,
146155
blank=True,
147-
max_length=1_048_576, # 2^20 = 1048576
156+
max_length=4194304, # 2^22 = 4194304. See note above if this value is changed.
148157
validators=[
149158
RegexValidator(
150159
regex="^[a-zA-Z0-9/\.\:\- ]*$", # Characters to support IPv4, IPv6, and FQDNs only. Space delimited.
@@ -273,9 +282,12 @@ class ScheduledScan(models.Model):
273282
start_datetime = models.DateTimeField(verbose_name="Scheduled scan start date and time")
274283
scan_binary = models.CharField(max_length=7, default="nmap", verbose_name="Scan binary")
275284
scan_command = models.TextField(unique=False, verbose_name="Scan command")
285+
# See the client_max_body_size setting in
286+
# ansible-playbooks/roles/master/templates/etc/nginx/sites-available/scantron_nginx.conf.j2 if the max_length value
287+
# is changed.
276288
targets = models.CharField(
277289
unique=False,
278-
max_length=1_048_576, # 2^20 = 1048576
290+
max_length=4194304, # 2^22 = 4194304. See note above if this value is changed.
279291
validators=[
280292
RegexValidator(
281293
regex="^[a-zA-Z0-9/\.\: ]*$", # Characters to support IPv4, IPv6, and FQDNs only. Space delimited.
@@ -284,10 +296,13 @@ class ScheduledScan(models.Model):
284296
],
285297
verbose_name="Targets",
286298
)
299+
# See the client_max_body_size setting in
300+
# ansible-playbooks/roles/master/templates/etc/nginx/sites-available/scantron_nginx.conf.j2 if the max_length value
301+
# is changed.
287302
excluded_targets = models.CharField(
288303
unique=False,
289304
blank=True,
290-
max_length=1_048_576, # 2^20 = 1048576
305+
max_length=4194304, # 2^22 = 4194304. See note above if this value is changed.
291306
validators=[
292307
RegexValidator(
293308
regex="^[a-zA-Z0-9/\.\: ]*$", # Characters to support IPv4, IPv6, and FQDNs only. Space delimited.

scantron_api_client/scantron_api_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import utility
1212

1313

14-
__version__ = "1.34"
14+
__version__ = "1.35"
1515

1616

1717
class ScantronClient:
@@ -29,9 +29,9 @@ def __init__(self, secrets_file_location="./scantron_api_secrets.json", **kwargs
2929

3030
# Ensure key/values exist in secrets.json.
3131
try:
32-
self.host = SECRETS["host"]
33-
self.port = SECRETS["port"]
34-
self.token = SECRETS["token"]
32+
self.host = SECRETS["scantron"]["host"]
33+
self.port = SECRETS["scantron"]["port"]
34+
self.token = SECRETS["scantron"]["token"]
3535

3636
except KeyError:
3737
print(f"Error reading key-values in {secrets_file_location} file. Exiting...")
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
2-
"host": "",
3-
"port": 443,
4-
"token": ""
2+
"scantron": {
3+
"host": "",
4+
"port": 443,
5+
"token": ""
6+
}
57
}

0 commit comments

Comments
 (0)