Skip to content

Commit

Permalink
chore: add some scripts to look at logs
Browse files Browse the repository at this point in the history
  • Loading branch information
rix0rrr committed May 15, 2021
1 parent cd182e9 commit de21343
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
28 changes: 28 additions & 0 deletions doc/logs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# How to access query logs?


## Prerequisites

Ask someone in the team for the credentials of the `hedy-logs-viewer` IAM user. Add the following to the
`~/.aws/credentials` file:

```
[hedy-logs-viewer]
aws_access_key_id = AKIA**********
aws_secret_access_key = ***********
```

Install The Log File Navigator (`lnav`) using one of the methods described [here](http://lnav.org/downloads).

Install the [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv1.html).

## Usage

Run:

```
$ tools/view-logs <APP> <YYYY-MM-DD>
# Example:
$ tools/view-logs hedy-beta 2021-05-10
```
31 changes: 31 additions & 0 deletions tools/jsonlines_fmt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"request": {
"title": "JSON Request Log",
"description": "Log format for JSON request logs",
"json": true,
"file-pattern": "\\.jsonl$",
"line-format": [
{ "field": "start_time" },
" ",
{ "field": "method" },
" ",
{ "field": "path" },
": ",
{ "field": "duration_ms" }
],
"level-field": "fault",
"level": {
"error": 1,
"info": 0
},
"timestamp-field": "start_time",
"body-field": "path",
"value": {
"start_time": { "kind": "string" },
"path": { "kind": "string" },
"method": { "kind": "string" },
"duration_ms": { "kind": "integer" },
"fault": { "kind": "integer" }
}
}
}
31 changes: 31 additions & 0 deletions tools/view-logs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
set -eu
scriptdir=$(cd $(dirname $0) && pwd)

if ! type lnav > /dev/null; then
echo "Install 'lnav' before running this script! (http://lnav.org)" >&2
exit 1
fi

hedy_env=$1
day=$2

cache_root=~/.cache/hedy-logs/${hedy_env}
cache_dir=${cache_root}/${day}
mkdir -p "$cache_dir"

export AWS_DEFAULT_REGION=eu-central-1
export AWS_PROFILE=hedy-logs-viewer
bucket=hedy-query-logs

aws s3 sync s3://${bucket}/${hedy_env}/${day} $cache_dir

# Need to make sure every file ends in a newline
sed -i -e '$a\' $cache_dir/*

#finalfile=$cache_root/$day.jsonl
#rm -f $finalfile
#for f in $cache_dir/*; do (cat "${f}"; echo) >> $finalfile; done

lnav -i $scriptdir/jsonlines_fmt.json
lnav -r $cache_dir

0 comments on commit de21343

Please sign in to comment.