Skip to content
This repository has been archived by the owner on Feb 21, 2022. It is now read-only.

Cloud gov enhancements #5

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
__pycache__
*.pyc
*.csv
*.txt
ckan.access*.log
*.tgz
*.gz
.vscode/
1 change: 1 addition & 0 deletions locust/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
apache.log
result*
ckan.access*.log
Binary file removed locust/__pycache__/base.cpython-38.pyc
Binary file not shown.
Binary file removed locust/__pycache__/from_apache.cpython-38.pyc
Binary file not shown.
Binary file removed locust/__pycache__/locustfile.cpython-38.pyc
Binary file not shown.
10 changes: 8 additions & 2 deletions locust/advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ def random_organizations(self):
return None
results = data.get('result', [])
# pick just some organizations randmonly
random_results = sample(results, 5)
if len(results) < 5:
random_results = results
else:
random_results = sample(results, 5)
for org in random_results:
url = f'/organization/{org}'
self.pending_organizations.append(url)
Expand All @@ -163,7 +166,10 @@ def all_groups(self):
return None
results = data.get('result', [])
# pick just some organizations randmonly
random_results = sample(results, 5)
if len(results) < 5:
random_results = results
else:
random_results = sample(results, 5)
for group in random_results:
url = f'/group/{group}'
self.pending_groups.append(url)
Expand Down
4 changes: 4 additions & 0 deletions locust/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ def orgs(self):
@task
def groups(self):
self.client.get('/group')

@task
def dataset(self):
self.client.get('/dataset')
20 changes: 17 additions & 3 deletions locust/parse_apache_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def process_line(data):
if data['request_path'].startswith(ss):
return None

if data['method'] != 'GET':
if data['method'] not in ['GET', 'POST']:
return None

return data
Expand All @@ -59,9 +59,9 @@ def parse_file(apache_log_path, output_path='results.txt', limit=0):
'harvests':
{'regex': re.compile(r'(\/[A-Za-z_]+)?\/harvest(\/)?$'), 'total': 0},
'api-pkg-search':
{'regex': re.compile(r'/api/(3)?/action/package_search.*'), 'total': 0},
{'regex': re.compile(r'/api(/3)?/action/package_search.*'), 'total': 0},
'api-pkg-show':
{'regex': re.compile(r'/api/(3)?/action/package_show.*'), 'total': 0},
{'regex': re.compile(r'/api(/3)?/action/package_show.*'), 'total': 0},
'api-search':
{'regex': re.compile(r'/api/search.*'), 'total': 0},
'organization':
Expand All @@ -76,10 +76,18 @@ def parse_file(apache_log_path, output_path='results.txt', limit=0):
{'regex': re.compile(r'(\/[A-Za-z_]+)?\/group\?(.*)'), 'total': 0},
'groups':
{'regex': re.compile(r'(\/[A-Za-z_]+)?\/group(\/)?$'), 'total': 0},
'status-show':
{'regex': re.compile(r'/api/action/status_show'), 'total': 0},
'tracking':
{'regex': re.compile(r'/\_tracking'), 'total': 0},
'csw':
{'regex': re.compile(r'/csw(-all)?\?[A-Za-z_&=]+'), 'total': 0},
'home':
{'regex': re.compile(r'(\/[A-Za-z_]+)?\/$'), 'total': 0},
}

status_code = {}

c = 0
for line in f:
c += 1
Expand All @@ -91,6 +99,11 @@ def parse_file(apache_log_path, output_path='results.txt', limit=0):
continue
out.write(data['request_path'] + "\n")

if data['status_code'] not in status_code:
status_code[data['status_code']] = 1
else:
status_code[data['status_code']] += 1

found = False
for name in weigths:
print(name)
Expand All @@ -110,6 +123,7 @@ def parse_file(apache_log_path, output_path='results.txt', limit=0):
nf.close()

print([{k: weigths[k]['total']} for k in weigths])
print(status_code)


parser = argparse.ArgumentParser()
Expand Down