Skip to content

Commit f30679a

Browse files
committed
Merge pull request #3500 from Joshua-Anderson/limit-logs
feat(controller): add a option to limit the number of log lines
2 parents 33d4005 + 1083007 commit f30679a

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

api/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,12 @@ def _default_scale(self, user, release):
337337

338338
self.scale(user, structure)
339339

340-
def logs(self):
340+
def logs(self, log_lines):
341341
"""Return aggregated log data for this application."""
342342
path = os.path.join(settings.DEIS_LOG_DIR, self.id + '.log')
343343
if not os.path.exists(path):
344344
raise EnvironmentError('Could not locate logs')
345-
data = subprocess.check_output(['tail', '-n', str(settings.LOG_LINES), path])
345+
data = subprocess.check_output(['tail', '-n', log_lines, path])
346346
return data
347347

348348
def run(self, user, command):

api/tests/test_app.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ def test_app_actions(self):
121121
HTTP_AUTHORIZATION='token {}'.format(self.token))
122122
self.assertEqual(response.status_code, 200)
123123
self.assertEqual(response.data, FAKE_LOG_DATA)
124+
125+
# test with log_lines
126+
response = self.client.get(url + "?log_lines=1",
127+
HTTP_AUTHORIZATION='token {}'.format(self.token))
128+
self.assertEqual(response.status_code, 200)
129+
self.assertEqual(response.data, FAKE_LOG_DATA.splitlines(True)[4])
130+
124131
os.remove(path)
125132
# TODO: test run needs an initial build
126133

api/views.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ def scale(self, request, **kwargs):
150150
def logs(self, request, **kwargs):
151151
app = self.get_object()
152152
try:
153-
return Response(app.logs(), status=status.HTTP_200_OK, content_type='text/plain')
153+
return Response(app.logs(request.query_params.get('log_lines',
154+
str(settings.LOG_LINES))),
155+
status=status.HTTP_200_OK, content_type='text/plain')
154156
except EnvironmentError:
155157
return Response("No logs for {}".format(app.id),
156158
status=status.HTTP_204_NO_CONTENT,

0 commit comments

Comments
 (0)