Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INF-93] Remove rsyslog implementation and build Logspout sidecar container #3124

Merged
merged 59 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
1cceeb3
Build a custom Logspout container for SPs
joaquincasares May 19, 2022
6c288f3
rm rsyslog
joaquincasares May 19, 2022
cb893e3
stop tee'ing to logger
joaquincasares May 19, 2022
2609fa0
separate one process per container
joaquincasares May 19, 2022
ecd0ea3
missing audius_service envar
joaquincasares May 19, 2022
74ad707
mild fixes before revert
joaquincasares May 19, 2022
3352db8
Revert "breaking up dp container"
joaquincasares May 19, 2022
439d298
Revert "missing audius_service envar"
joaquincasares May 19, 2022
8b854a4
Revert "separate one process per container"
joaquincasares May 19, 2022
304bfbc
rm last syslog calls
joaquincasares May 19, 2022
c990c7d
use audius_loggly_token everywhere
joaquincasares May 19, 2022
51a57b4
background job
joaquincasares May 19, 2022
db1969c
image tagging
joaquincasares May 19, 2022
d2be85c
update build command
joaquincasares May 19, 2022
49f226d
Dockerfile update
joaquincasares May 19, 2022
d4a6104
th
joaquincasares May 19, 2022
809d593
kansas city shuffle
joaquincasares May 19, 2022
6401146
fix building
joaquincasares May 19, 2022
41607dd
remove healthcheck
joaquincasares May 20, 2022
1608ad6
fix Dockerfile ordering and loggly tagging
joaquincasares May 20, 2022
b6fab4a
fix circleci param
joaquincasares May 20, 2022
28846e9
fix shuffle
joaquincasares May 20, 2022
4ec475a
set tags correctly
joaquincasares May 20, 2022
877e229
sh not bash
joaquincasares May 20, 2022
a072a68
Add more log tags
joaquincasares May 20, 2022
a903897
default logspout-tag
joaquincasares May 23, 2022
51def1a
quotes
joaquincasares May 23, 2022
083e3c5
no logspout test
joaquincasares May 23, 2022
763a802
true string
joaquincasares May 23, 2022
b7dd61e
dir
joaquincasares May 23, 2022
cf44fe0
mv logging/logspout logspout
joaquincasares May 23, 2022
b4fedaa
repo: logspout
joaquincasares May 23, 2022
a629a87
mv logging/logspout logspout
joaquincasares May 23, 2022
b3c5535
remove redundant tagging
joaquincasares May 23, 2022
7518460
add hostname, if it exists
joaquincasares May 23, 2022
f502102
Update default_config.ini
joaquincasares May 23, 2022
46f28b7
Update helpers.py
joaquincasares May 24, 2022
17df0cb
gate rsyslog
joaquincasares May 25, 2022
0464f73
restore discovery-provider/scripts/rotate-log.sh
joaquincasares May 25, 2022
2184206
chmod 755
joaquincasares May 25, 2022
b8d863d
gate for dp
joaquincasares May 25, 2022
4b27c73
gate rsyslog
joaquincasares May 25, 2022
8ed1fe4
keep rsyslog integration with circleci
joaquincasares May 25, 2022
da1bac7
fix newlines
joaquincasares May 25, 2022
0692511
ordering
joaquincasares May 25, 2022
11fbef2
restore dockerfiles
joaquincasares May 25, 2022
5e79962
add manual approval req for logstash image building
joaquincasares May 26, 2022
68686be
use true/false instead of 0/1 for envars
joaquincasares May 26, 2022
0dda68c
default local to DEBUG logs
joaquincasares May 26, 2022
75a8932
extract hostname from cn and dp nodes
joaquincasares May 26, 2022
6fd3ffd
audius_discprov_loglevel_flask
joaquincasares May 26, 2022
c499c7f
formatting
joaquincasares May 26, 2022
c239f62
Update README.md
joaquincasares May 31, 2022
a516b7e
Update start.sh
joaquincasares May 31, 2022
85b772c
revert changes for identity service
joaquincasares Jun 1, 2022
3618c91
add additional comment
joaquincasares Jun 1, 2022
727c30a
address PR comment
joaquincasares Jun 1, 2022
9fa4ae4
add README context
joaquincasares Jun 1, 2022
427debf
Merge branch 'master' of github.com:AudiusProject/audius-protocol int…
joaquincasares Jun 1, 2022
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
23 changes: 17 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,8 @@ jobs:
parameters:
repo:
type: string
logspout-tag:
type: string
steps:
- checkout
- setup_remote_docker:
Expand All @@ -643,10 +645,11 @@ jobs:
name: Get tag or latest
command: |
# order of precendence for IMAGE tag is:
# 1. CIRCLE_TAG if defined,
# 2. Branch name if 'hotfix' in branch name (branch name passed in via $CIRCLE_BRANCH)
# 3. 'latest', which is the default
echo "export IMAGE_TAG=`[ $CIRCLE_TAG ] && echo $(echo $CIRCLE_TAG | cut -d@ -f3) || [[ "$CIRCLE_BRANCH" =~ (hotfix) ]] && echo $CIRCLE_BRANCH || echo "latest" `" | tee -a $BASH_ENV
# 1. $(head -n1 logging/logspout/Dockerfile) if << parameters.logspout-tag >> defined,
# 2. CIRCLE_TAG if defined,
# 3. Branch name if 'hotfix' in branch name (branch name passed in via $CIRCLE_BRANCH)
# 4. 'latest', which is the default
echo "export IMAGE_TAG=`[ << parameters.logspout-tag >> ] && echo $(head -n1 logging/logspout/Dockerfile | cut -f 2 -d ':') || [ $CIRCLE_TAG ] && echo $(echo $CIRCLE_TAG | cut -d@ -f3) || [[ "$CIRCLE_BRANCH" =~ (hotfix) ]] && echo $CIRCLE_BRANCH || echo "latest" `" | tee -a $BASH_ENV
- run:
name: Docker login
command: |
Expand All @@ -655,7 +658,8 @@ jobs:
name: Docker build << parameters.repo >>
command: |
cd << parameters.repo >>
docker build -t audius/<< parameters.repo >>:$IMAGE_TAG -t audius/<< parameters.repo>>:$(git rev-parse HEAD) --build-arg git_sha=$(git rev-parse HEAD) --build-arg audius_loggly_disable=$audius_loggly_disable --build-arg audius_loggly_token=$audius_loggly_token --build-arg audius_loggly_tags=$audius_loggly_tags --build-arg BUILD_NUM=$CIRCLE_BUILD_NUM .
audius_loggly_token_b64=$(echo ${audius_loggly_token} | base64)
docker build -t audius/<< parameters.repo >>:$IMAGE_TAG -t audius/<< parameters.repo>>:$(git rev-parse HEAD) --build-arg git_sha=$(git rev-parse HEAD) --build-arg audius_loggly_token=$audius_loggly_token_b64 --build-arg BUILD_NUM=$CIRCLE_BUILD_NUM .
docker image prune --filter label=prune=true --filter label=build=$CIRCLE_BUILD_NUM --force
- run:
name: Docker push << parameters.repo >>
Expand Down Expand Up @@ -690,7 +694,7 @@ jobs:
name: Docker build << parameters.repo >>
command: |
cd << parameters.repo >>
docker build -t audius/<< parameters.repo >>:$IMAGE_TAG -t audius/<< parameters.repo>>:$(git rev-parse HEAD) --build-arg git_sha=$(git rev-parse HEAD) --build-arg audius_loggly_disable=$audius_loggly_disable --build-arg audius_loggly_token=$audius_loggly_token --build-arg audius_loggly_tags=$audius_loggly_tags .
docker build -t audius/<< parameters.repo >>:$IMAGE_TAG -t audius/<< parameters.repo>>:$(git rev-parse HEAD) --build-arg git_sha=$(git rev-parse HEAD) --build-arg audius_loggly_token=$audius_loggly_token .
- run:
name: Docker push << parameters.repo >>
command: |
Expand Down Expand Up @@ -737,6 +741,13 @@ workflows:
name: build-identity-service
repo: identity-service

- test-logspout:
name: test-logspout
- docker-build-and-push:
dmanjunath marked this conversation as resolved.
Show resolved Hide resolved
name: build-logspout
repo: logspout/logspout
logspout-tag: true

- test-solana-programs:
name: test-solana-programs
- test-solana-programs-anchor:
Expand Down
7 changes: 0 additions & 7 deletions creator-node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,7 @@ VOLUME "/file_storage"
ENV storagePath=/file_storage

ARG git_sha
ARG audius_loggly_disable
ARG audius_loggly_token
ARG audius_loggly_tags

ENV GIT_SHA=$git_sha
ENV logglyDisable=$audius_loggly_disable
ENV logglyToken=$audius_loggly_token
ENV logglyTags=$audius_loggly_tags

HEALTHCHECK --interval=5s --timeout=5s --start-period=5m --retries=12 \
CMD curl -f http://localhost:4000/health_check || exit 1
Expand Down
28 changes: 3 additions & 25 deletions creator-node/scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,6 @@ if [[ "$WAIT_HOSTS" != "" ]]; then
/usr/bin/wait
fi

if [[ -z "$logglyDisable" ]]; then
if [[ -n "$logglyToken" ]]; then
logglyTags=$(echo $logglyTags | python3 -c "print(' '.join(f'tag=\\\\\"{i}\\\\\"' for i in input().split(',')))")
mkdir -p /var/spool/rsyslog
mkdir -p /etc/rsyslog.d
sed -i '1s|^|$MaxMessageSize 64k\n|' /etc/rsyslog.conf
cat >/etc/rsyslog.d/22-loggly.conf <<EOF
\$WorkDirectory /var/spool/rsyslog # where to place spool files
\$ActionQueueFileName fwdRule1 # unique name prefix for spool files
\$ActionQueueMaxDiskSpace 1g # 1gb space limit (use as much as possible)
\$ActionQueueSaveOnShutdown on # save messages to disk on shutdown
\$ActionQueueType LinkedList # run asynchronously
\$ActionResumeRetryCount -1 # infinite retries if host is down
template(name="LogglyFormat" type="string"
string="<%pri%>%protocol-version% %timestamp:::date-rfc3339% %HOSTNAME% %app-name% %procid% %msgid% [$logglyToken@41058 $logglyTags \\"$creatorNodeEndpoint\\"] %msg%\n")
# Send messages to Loggly over TCP using the template.
action(type="omfwd" protocol="tcp" target="logs-01.loggly.com" port="514" template="LogglyFormat")
EOF
rsyslogd
fi
fi

if [ -z "$redisHost" ]; then
redis-server --daemonize yes
export redisHost=localhost
Expand Down Expand Up @@ -68,12 +46,12 @@ if [[ "$devMode" == "true" ]]; then
npm link
cd ../app
npm link @audius/libs
npx nodemon --exec 'node --inspect=0.0.0.0:${debuggerPort} --require ts-node/register src/index.ts' --watch src/ --watch ../audius-libs/ | tee >(logger) | ./node_modules/.bin/bunyan
npx nodemon --exec 'node --inspect=0.0.0.0:${debuggerPort} --require ts-node/register src/index.ts' --watch src/ --watch ../audius-libs/ | ./node_modules/.bin/bunyan
else
npx nodemon --exec 'node --inspect=0.0.0.0:${debuggerPort} --require ts-node/register src/index.ts' --watch src/ | tee >(logger) | ./node_modules/.bin/bunyan
npx nodemon --exec 'node --inspect=0.0.0.0:${debuggerPort} --require ts-node/register src/index.ts' --watch src/ | ./node_modules/.bin/bunyan
fi
else
node build/src/index.js | tee >(logger)
node build/src/index.js
docker run -d --name watchtower -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower --interval 10
fi

Expand Down
7 changes: 0 additions & 7 deletions discovery-provider/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,7 @@ COPY --from=contracts /usr/src/app/build/contracts/ ./build/contracts/
RUN bash scripts/init-db.sh

ARG git_sha
ARG audius_loggly_disable
ARG audius_loggly_token
ARG audius_loggly_tags

ENV GIT_SHA=$git_sha
ENV audius_loggly_disable=$audius_loggly_disable
ENV audius_loggly_token=$audius_loggly_token
ENV audius_loggly_tags=$audius_loggly_tags

ENV PROMETHEUS_MULTIPROC_DIR /prometheus_data
RUN mkdir -p ${PROMETHEUS_MULTIPROC_DIR}
Expand Down
8 changes: 0 additions & 8 deletions discovery-provider/scripts/rotate-log.sh

This file was deleted.

76 changes: 6 additions & 70 deletions discovery-provider/scripts/start.sh
Original file line number Diff line number Diff line change
@@ -1,66 +1,6 @@
#!/bin/bash
set -e

mkdir -p /var/log
mkdir -p /var/spool/rsyslog
mkdir -p /etc/rsyslog.d

if [[ -z "$audius_loggly_disable" ]]; then
if [[ -n "$audius_loggly_token" ]]; then
# use regex to extract domain in url (source: https://stackoverflow.com/a/2506635/8674706)
audius_discprov_hostname=$(echo $audius_discprov_url | sed -e 's/[^/]*\/\/\([^@]*@\)\?\([^:/]*\).*/\2/')
joaquincasares marked this conversation as resolved.
Show resolved Hide resolved

# add hostname to loggly tags
if [[ "$audius_discprov_hostname" != "" ]]; then
if [[ "$audius_loggly_tags" != "" ]]; then
audius_loggly_tags="$audius_loggly_tags,$audius_discprov_hostname"
else
audius_loggly_tags="$audius_discprov_hostname"
fi
fi

if [[ "$audius_loggly_tags" != "" ]]; then
audius_loggly_tags="tag=\\\"${audius_loggly_tags//,/\\\" tag=\\\"}\\\""
# ${audius_loggly_tags//,/\\\" tag=\\\"} replaces , with \" tag=\"
# then we add tag=\" to the start and \" to the end
fi

cat >/etc/rsyslog.d/10-loggly.conf <<EOF
\$WorkDirectory /var/spool/rsyslog # where to place spool files
\$ActionQueueFileName loggly # unique name prefix for spool files
\$ActionQueueMaxDiskSpace 1g # 1gb space limit (use as much as possible)
\$ActionQueueSaveOnShutdown on # save messages to disk on shutdown
\$ActionQueueType LinkedList # run asynchronously
\$ActionResumeRetryCount -1 # infinite retries if host is down

template(name="LogglyFormat" type="string"
string="<%pri%>%protocol-version% %timestamp:::date-rfc3339% %HOSTNAME% %app-name% %procid% %msgid% [$audius_loggly_token@41058 $audius_loggly_tags] %msg%\n")

# Send messages to Loggly over TCP using the template.
action(type="omfwd" protocol="tcp" target="logs-01.loggly.com" port="514" template="LogglyFormat")
EOF
fi
fi

cat >/etc/rsyslog.d/20-file.conf <<EOF
\$WorkDirectory /var/spool/rsyslog # where to place spool files
\$ActionQueueFileName file # unique name prefix for spool files
\$ActionQueueMaxDiskSpace 1g # 1gb space limit (use as much as possible)
\$ActionQueueSaveOnShutdown on # save messages to disk on shutdown
\$ActionQueueType LinkedList # run asynchronously
\$ActionResumeRetryCount -1 # infinite retries if host is down

\$outchannel server_log,/var/log/discprov-server.log, 52428800,/audius-discovery-provider/scripts/rotate-log.sh
\$outchannel worker_log,/var/log/discprov-worker.log, 52428800,/audius-discovery-provider/scripts/rotate-log.sh
\$outchannel beat_log,/var/log/discprov-beat.log, 52428800,/audius-discovery-provider/scripts/rotate-log.sh
joaquincasares marked this conversation as resolved.
Show resolved Hide resolved

if \$programname == 'server' then :omfile:\$server_log
if \$programname == 'worker' then :omfile:\$worker_log
if \$programname == 'beat' then :omfile:\$beat_log
EOF

rsyslogd

if [ -z "$audius_redis_url" ]; then
redis-server --daemonize yes
export audius_redis_url="redis://localhost:6379/00"
Expand Down Expand Up @@ -106,20 +46,16 @@ if [[ "$audius_discprov_dev_mode" == "true" ]]; then
echo "Finished running migrations"
fi

# filter tail to server/worker/beat logs with
# docker exec -it <container> tail -f /var/log/discprov-server.log
# docker exec -it <container> tail -f /var/log/discprov-worker.log
# docker exec -it <container> tail -f /var/log/discprov-beat.log
./scripts/dev-server.sh 2>&1 | tee >(logger -t server) &
joaquincasares marked this conversation as resolved.
Show resolved Hide resolved
./scripts/dev-server.sh &
if [[ "$audius_no_workers" != "true" ]] && [[ "$audius_no_workers" != "1" ]]; then
watchmedo auto-restart --directory ./ --pattern=*.py --recursive -- celery -A src.worker.celery worker --loglevel $audius_discprov_loglevel 2>&1 | tee >(logger -t worker) &
celery -A src.worker.celery beat --loglevel $audius_discprov_loglevel 2>&1 | tee >(logger -t beat) &
watchmedo auto-restart --directory ./ --pattern=*.py --recursive -- celery -A src.worker.celery worker --loglevel $audius_discprov_loglevel &
celery -A src.worker.celery beat --loglevel $audius_discprov_loglevel &
fi
else
./scripts/prod-server.sh 2>&1 | tee >(logger -t server) &
./scripts/prod-server.sh &
if [[ "$audius_no_workers" != "true" ]] && [[ "$audius_no_workers" != "1" ]]; then
celery -A src.worker.celery worker --loglevel $audius_discprov_loglevel 2>&1 | tee >(logger -t worker) &
celery -A src.worker.celery beat --loglevel $audius_discprov_loglevel 2>&1 | tee >(logger -t beat) &
celery -A src.worker.celery worker --loglevel $audius_discprov_loglevel &
celery -A src.worker.celery beat --loglevel $audius_discprov_loglevel &
fi
fi

Expand Down
7 changes: 0 additions & 7 deletions identity-service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,7 @@ RUN apk update && \
EXPOSE 7000

ARG git_sha
ARG audius_loggly_disable
ARG audius_loggly_token
ARG audius_loggly_tags

ENV GIT_SHA=$git_sha
ENV logglyDisable=$audius_loggly_disable
ENV logglyToken=$audius_loggly_token
ENV logglyTags=$audius_loggly_tags

HEALTHCHECK --interval=5s --timeout=5s \
CMD curl -f http://localhost:7000/health_check || exit 1
Expand Down
23 changes: 1 addition & 22 deletions identity-service/scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,4 @@

/usr/bin/wait

if [[ -z "$logglyDisable" ]]; then
if [[ -n "$logglyToken" ]]; then
logglyTags=$(echo $logglyTags | python3 -c "print(' '.join(f'tag=\\\\\"{i}\\\\\"' for i in input().split(',')))")
mkdir -p /var/spool/rsyslog
mkdir -p /etc/rsyslog.d
cat >/etc/rsyslog.d/22-loggly.conf <<EOF
\$WorkDirectory /var/spool/rsyslog # where to place spool files
\$ActionQueueFileName fwdRule1 # unique name prefix for spool files
\$ActionQueueMaxDiskSpace 1g # 1gb space limit (use as much as possible)
\$ActionQueueSaveOnShutdown on # save messages to disk on shutdown
\$ActionQueueType LinkedList # run asynchronously
\$ActionResumeRetryCount -1 # infinite retries if host is down
template(name="LogglyFormat" type="string"
string="<%pri%>%protocol-version% %timestamp:::date-rfc3339% %HOSTNAME% %app-name% %procid% %msgid% [$logglyToken@41058 $logglyTags] %msg%\n")
# Send messages to Loggly over TCP using the template.
action(type="omfwd" protocol="tcp" target="logs-01.loggly.com" port="514" template="LogglyFormat")
EOF
rsyslogd
fi
fi

node src/index.js | tee >(logger)
node src/index.js
2 changes: 2 additions & 0 deletions logging/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env

18 changes: 18 additions & 0 deletions logging/logspout/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM gliderlabs/logspout:v3.2.14

# ignores previously log on startup
# could be lossy if the container restarts
# could send double logs upon container restarts if we remove this
ENV BACKLOG false

ARG git_sha
ENV GIT_SHA=${git_sha}

ARG audius_loggly_token
ENV audius_loggly_token ${audius_loggly_token}

ENTRYPOINT []
CMD audius_loggly_token_64=$(echo ${audius_loggly_token} | base64 -d) \
&& export SYSLOG_STRUCTURED_DATA="${audius_loggly_token_64}@41058 tag=\"logspout\"" \
joaquincasares marked this conversation as resolved.
Show resolved Hide resolved
&& echo SYSLOG_STRUCTURED_DATA=${SYSLOG_STRUCTURED_DATA} \
&& /bin/logspout multiline+syslog+tcp://logs-01.loggly.com:514
16 changes: 16 additions & 0 deletions logging/logspout/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Build Custom Audius Logstash Sidecar Container

```bash
# .env contains: audius_loggly_token=xxx
. .env

LOGSPOUT_VERSION=$(head -n1 Dockerfile | cut -f 2 -d ':')
[ ${audius_loggly_token} ] \
&& audius_loggly_token_64=$(echo ${audius_loggly_token} | base64) \
&& docker build \
-t audius/logspout:${LOGSPOUT_VERSION} \
--build-arg git_sha=$(git rev-parse HEAD) \
--build-arg audius_loggly_token=${audius_loggly_token_64} \
. \
&& docker push audius/logspout:${LOGSPOUT_VERSION}
```
13 changes: 13 additions & 0 deletions logging/logspout/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh
# https://github.com/gliderlabs/logspout/blob/818dd8260e52d2c148280d86170bdf5267b5c637/build.sh

set -e
apk add --update go build-base git mercurial ca-certificates
cd /src
go build -ldflags "-X main.Version=$1" -o /bin/logspout
apk del go git mercurial build-base
rm -rf /root/go /var/cache/apk/*

# backwards compatibility
ln -fs /tmp/docker.sock /var/run/docker.sock

15 changes: 15 additions & 0 deletions logging/logspout/modules.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// https://github.com/gliderlabs/logspout/blob/818dd8260e52d2c148280d86170bdf5267b5c637/modules.go

package main

import (
_ "github.com/gliderlabs/logspout/adapters/multiline"
_ "github.com/gliderlabs/logspout/adapters/raw"
_ "github.com/gliderlabs/logspout/adapters/syslog"
_ "github.com/gliderlabs/logspout/healthcheck"
_ "github.com/gliderlabs/logspout/httpstream"
_ "github.com/gliderlabs/logspout/routesapi"
_ "github.com/gliderlabs/logspout/transports/tcp"
_ "github.com/gliderlabs/logspout/transports/tls"
_ "github.com/gliderlabs/logspout/transports/udp"
)