Skip to content

Commit

Permalink
Fix app logs Elasticsearch query (#782)
Browse files Browse the repository at this point in the history
Filter on exact app_name field value instead of searching analyzed text
Re-enable app logs display in template
  • Loading branch information
andyhd authored Nov 26, 2019
1 parent d5c4a86 commit 3f4cece
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 7 additions & 2 deletions controlpanel/api/elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ def app_logs(app, num_hours=None):
conn = Elasticsearch(hosts=settings.ELASTICSEARCH['hosts'])
s = Search(using=conn, index=settings.ELASTICSEARCH['indices']['app-logs'])

s = s.query(
# limit fields returned
s = s.source(['@timestamp', 'message'])

s = s.filter(
Q('exists', field='message')
& Q('match', app_name=f'{app.release_name}-webapp')
& Q('term', **{
"app_name.keyword": f'{app.release_name}-webapp',
})
)

s = s.filter(Range(**{
Expand Down
2 changes: 0 additions & 2 deletions controlpanel/frontend/static/components/app-logs/macro.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
{% macro app_logs(app, kibana_base_url) %}
{# disable app logs temporarily
<div class="app-logs">
<pre>{% for entry in app.get_logs() -%}
<span class="timestamp">{{ entry.timestamp.strftime('%Y-%m-%d %H:%M:%S') }}:</span> <span class="message">{{ entry.message }}</span>
{% endfor %}</pre>
</div>
#}
<p class="govuk-body">
<a href="{{ kibana_link(app, kibana_base_url) }}">View full logs</a>
</p>
Expand Down

0 comments on commit 3f4cece

Please sign in to comment.