Skip to content

Commit 0a77051

Browse files
authored
send logs to elk #1188 (#1248)
1 parent 1c5d1e5 commit 0a77051

File tree

2 files changed

+110
-14
lines changed

2 files changed

+110
-14
lines changed

.github/workflows/build-and-run-tests-from-branch.yml

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ env:
2020
DOCKERFILE_PATH: docker/Dockerfile_java_cli
2121
# Environment variable setting gradle options.
2222
GRADLE_OPTS: "-XX:MaxHeapSize=2048m -Dorg.gradle.jvmargs='-XX:MaxHeapSize=2048m -XX:MaxPermSize=512m -Dorg.gradle.daemon=false' -Dorg.gradle.daemon=false"
23+
PUSHGATEWAY_HOSTNAME: monitoring.utbot.org
24+
ELK_HOSTNAME: logs.utbot.org
25+
FILEBEAT_DIR: /tmp/filebeat
2326

2427
jobs:
2528
prepare-matrices:
@@ -59,7 +62,11 @@ jobs:
5962
fail-fast: false
6063
matrix: ${{ fromJson(needs.prepare-matrices.outputs.framework-tests-matrix) }}
6164
runs-on: ubuntu-20.04
62-
container: unittestbot/java-env:java11-zulu-jdk-gradle7.4.2-kotlinc1.7.0
65+
container:
66+
image: unittestbot/java-env:java11-zulu-jdk-gradle7.4.2-kotlinc1.7.0
67+
volumes:
68+
- "/home/runner/runners:/home/runner/runners"
69+
- "/tmp/filebeat:/tmp/filebeat"
6370
steps:
6471
- name: Print environment variables
6572
run: printenv
@@ -74,10 +81,19 @@ jobs:
7481
git checkout ${{ github.event.inputs.commit_sha }}
7582
7683
- name: Run monitoring
84+
# secret uploaded using base64 encoding to have one-line output:
85+
# cat file | base64 -w 0
7786
run: |
78-
echo Find your Prometheus metrics using label {instance=\"${GITHUB_RUN_ID}-${HOSTNAME}\"}
7987
chmod +x ./scripts/project/monitoring.sh
80-
./scripts/project/monitoring.sh ${{ secrets.PUSHGATEWAY_HOSTNAME }} ${{ secrets.PUSHGATEWAY_USER }} ${{ secrets.PUSHGATEWAY_PASSWORD }}
88+
./scripts/project/monitoring.sh "${PUSHGATEWAY_HOSTNAME}" "${{ secrets.PUSHGATEWAY_USER }}" "${{ secrets.PUSHGATEWAY_PASSWORD }}"
89+
echo "Please visit Grafana to check metrics: https://${PUSHGATEWAY_HOSTNAME}/d/rYdddlPWk/node-exporter-full?orgId=1&from=now-1h&to=now&var-service=github&var-instance=${GITHUB_RUN_ID}-${HOSTNAME}&refresh=1m"
90+
echo ---
91+
printf ${{ secrets.CA_CERT }} | base64 -d > ${{ env.FILEBEAT_DIR }}/ca.crt
92+
printf ${{ secrets.CLIENT_CRT }} | base64 -d > ${{ env.FILEBEAT_DIR }}/client.crt
93+
printf ${{ secrets.CLIENT_KEY }} | base64 -d > ${{ env.FILEBEAT_DIR }}/client.key
94+
chmod +x ./scripts/project/logging.sh
95+
./scripts/project/logging.sh "${FILEBEAT_DIR}" "${{ secrets.ELK_HOST }}:5044"
96+
echo "Please visit ELK to check logs https://logs.utbot.org/app/discover#/ using the following search pattern: github.env.HOSTNAME:\"${HOSTNAME}\" and github.env.GITHUB_RUN_ID:\"${GITHUB_RUN_ID}\" and not github.log_level:\"INFO\""
8197
8298
# cache will use the key you provided and contains the files you specify in path.
8399
#
@@ -125,17 +141,21 @@ jobs:
125141

126142
combined-projects:
127143
# This job does not need to wait for 'prepare-tests-matrix' result.
128-
# GitHub allocates runners portionally. Framework tests are time consuming. That's why we want to force them
144+
# GitHub allocates runners portionally. Framework tests are time consuming. That's why we want to force them
129145
# to start execution early.
130146
needs: prepare-matrices
131-
# Using matrices let create multiple jobs runs based on the combinations of the variables from matrices.
147+
# Using matrices let create multiple jobs runs based on the combinations of the variables from matrices.
132148
# https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs
133149
strategy:
134150
# The option forces to execute all jobs even though some of them have failed.
135151
fail-fast: false
136152
matrix: ${{ fromJson(needs.prepare-matrices.outputs.combined-projects-matrix) }}
137153
runs-on: ubuntu-20.04
138-
container: unittestbot/java-env:java11-zulu-jdk-gradle7.4.2-kotlinc1.7.0
154+
container:
155+
image: unittestbot/java-env:java11-zulu-jdk-gradle7.4.2-kotlinc1.7.0
156+
volumes:
157+
- "/home/runner/runners:/home/runner/runners"
158+
- "/tmp/filebeat:/tmp/filebeat"
139159
steps:
140160
- name: Print environment variables
141161
run: printenv
@@ -151,9 +171,16 @@ jobs:
151171
152172
- name: Run monitoring
153173
run: |
154-
echo Find your Prometheus metrics using label {instance=\"${GITHUB_RUN_ID}-${HOSTNAME}\"}
155174
chmod +x ./scripts/project/monitoring.sh
156-
./scripts/project/monitoring.sh ${{ secrets.PUSHGATEWAY_HOSTNAME }} ${{ secrets.PUSHGATEWAY_USER }} ${{ secrets.PUSHGATEWAY_PASSWORD }}
175+
./scripts/project/monitoring.sh "${PUSHGATEWAY_HOSTNAME}" "${{ secrets.PUSHGATEWAY_USER }}" "${{ secrets.PUSHGATEWAY_PASSWORD }}"
176+
echo "Please visit Grafana to check metrics: https://${PUSHGATEWAY_HOSTNAME}/d/rYdddlPWk/node-exporter-full?orgId=1&from=now-1h&to=now&var-service=github&var-instance=${GITHUB_RUN_ID}-${HOSTNAME}&refresh=1m"
177+
echo ---
178+
printf ${{ secrets.CA_CERT }} | base64 -d > ${{ env.FILEBEAT_DIR }}/ca.crt
179+
printf ${{ secrets.CLIENT_CRT }} | base64 -d > ${{ env.FILEBEAT_DIR }}/client.crt
180+
printf ${{ secrets.CLIENT_KEY }} | base64 -d > ${{ env.FILEBEAT_DIR }}/client.key
181+
chmod +x ./scripts/project/logging.sh
182+
./scripts/project/logging.sh "${FILEBEAT_DIR}" "${{ secrets.ELK_HOST }}:5044"
183+
echo "Please visit ELK to check logs https://logs.utbot.org/app/discover#/ using the following search pattern: github.env.HOSTNAME:\"${HOSTNAME}\" and github.env.GITHUB_RUN_ID:\"${GITHUB_RUN_ID}\" and not github.log_level:\"INFO\""
157184
158185
- uses: actions/cache@v3
159186
with:
@@ -185,22 +212,26 @@ jobs:
185212
with:
186213
name: test_report ${{ matrix.projects.second }}
187214
path: ${{ matrix.projects.second }}/build/reports/tests/test/*
188-
215+
189216

190217
single-project:
191218
# This job does not need to wait for 'prepare-tests-matrix' result.
192-
# GitHub allocates runners portionally. Framework tests are time consuming. That's why we want to force them
219+
# GitHub allocates runners portionally. Framework tests are time consuming. That's why we want to force them
193220
# to start execution early.
194221
needs: prepare-matrices
195-
# Using matrices let create multiple jobs runs based on the combinations of the variables from matrices.
222+
# Using matrices let create multiple jobs runs based on the combinations of the variables from matrices.
196223
# https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs
197224
strategy:
198225
# The option forces to execute all jobs even though some of them have failed.
199226
fail-fast: false
200227
matrix:
201228
project: [utbot-core, utbot-fuzzers, utbot-gradle, utbot-junit-contest, utbot-sample]
202229
runs-on: ubuntu-20.04
203-
container: unittestbot/java-env:java11-zulu-jdk-gradle7.4.2-kotlinc1.7.0
230+
container:
231+
image: unittestbot/java-env:java11-zulu-jdk-gradle7.4.2-kotlinc1.7.0
232+
volumes:
233+
- "/home/runner/runners:/home/runner/runners"
234+
- "/tmp/filebeat:/tmp/filebeat"
204235
steps:
205236
- name: Print environment variables
206237
run: printenv
@@ -216,9 +247,16 @@ jobs:
216247
217248
- name: Run monitoring
218249
run: |
219-
echo Find your Prometheus metrics using label {instance=\"${GITHUB_RUN_ID}-${HOSTNAME}\"}
220250
chmod +x ./scripts/project/monitoring.sh
221-
./scripts/project/monitoring.sh ${{ secrets.PUSHGATEWAY_HOSTNAME }} ${{ secrets.PUSHGATEWAY_USER }} ${{ secrets.PUSHGATEWAY_PASSWORD }}
251+
./scripts/project/monitoring.sh "${PUSHGATEWAY_HOSTNAME}" "${{ secrets.PUSHGATEWAY_USER }}" "${{ secrets.PUSHGATEWAY_PASSWORD }}"
252+
echo "Please visit Grafana to check metrics: https://${PUSHGATEWAY_HOSTNAME}/d/rYdddlPWk/node-exporter-full?orgId=1&from=now-1h&to=now&var-service=github&var-instance=${GITHUB_RUN_ID}-${HOSTNAME}&refresh=1m"
253+
echo ---
254+
printf ${{ secrets.CA_CERT }} | base64 -d > ${{ env.FILEBEAT_DIR }}/ca.crt
255+
printf ${{ secrets.CLIENT_CRT }} | base64 -d > ${{ env.FILEBEAT_DIR }}/client.crt
256+
printf ${{ secrets.CLIENT_KEY }} | base64 -d > ${{ env.FILEBEAT_DIR }}/client.key
257+
chmod +x ./scripts/project/logging.sh
258+
./scripts/project/logging.sh "${FILEBEAT_DIR}" "${{ secrets.ELK_HOST }}:5044"
259+
echo "Please visit ELK to check logs https://logs.utbot.org/app/discover#/ using the following search pattern: github.env.HOSTNAME:\"${HOSTNAME}\" and github.env.GITHUB_RUN_ID:\"${GITHUB_RUN_ID}\" and not github.log_level:\"INFO\""
222260
223261
- uses: actions/cache@v3
224262
with:

scripts/project/logging.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
3+
FILEBEAT_DIR=${1}
4+
LOGSTASH_HOST=${2}
5+
6+
cat > ${FILEBEAT_DIR}/filebeat.yml <<EOF
7+
filebeat.inputs:
8+
- type: filestream
9+
id: ${GITHUB_RUN_ID}-${HOSTNAME}
10+
paths:
11+
- "$(find /home/runner/runners -type f -name "Worker*.log")"
12+
parsers:
13+
- multiline:
14+
type: pattern
15+
pattern: '^\['
16+
negate: true
17+
match: after
18+
processors:
19+
- add_fields:
20+
target: "@metadata"
21+
fields:
22+
service: github
23+
team: utbot
24+
- add_fields:
25+
target: "github"
26+
fields:
27+
env.GITHUB_ACTIONS: "${GITHUB_ACTIONS}"
28+
env.GITHUB_ACTOR: "${GITHUB_ACTOR}"
29+
env.GITHUB_EVENT_NAME: "${GITHUB_EVENT_NAME}"
30+
env.GITHUB_JOB: "${GITHUB_JOB}"
31+
env.GITHUB_HEAD_REF: "${GITHUB_HEAD_REF}"
32+
env.GITHUB_REF: "${GITHUB_REF}"
33+
env.GITHUB_REF_NAME: "${GITHUB_REF_NAME}"
34+
env.GITHUB_REF_PROTECTED: "${GITHUB_REF_PROTECTED}"
35+
env.GITHUB_REF_TYPE: "${GITHUB_REF_TYPE}"
36+
env.GITHUB_REPOSITORY: "${GITHUB_REPOSITORY}"
37+
env.GITHUB_REPOSITORY_OWNER: "${GITHUB_REPOSITORY_OWNER}"
38+
env.GITHUB_RETENTION_DAYS: "${GITHUB_RETENTION_DAYS}"
39+
env.GITHUB_RUN_ATTEMPT: "${GITHUB_RUN_ATTEMPT}"
40+
env.GITHUB_RUN_ID: "${GITHUB_RUN_ID}"
41+
env.GITHUB_RUN_NUMBER: "${GITHUB_RUN_NUMBER}"
42+
env.GITHUB_SHA: "${GITHUB_SHA}"
43+
env.GITHUB_TRIGGERING_ACTOR: "${GITHUB_TRIGGERING_ACTOR}"
44+
env.GITHUB_WORKFLOW: "${GITHUB_WORKFLOW}"
45+
env.HOSTNAME: "${HOSTNAME}"
46+
env.RUNNER_NAME: "${RUNNER_NAME}"
47+
output.logstash:
48+
hosts: ["${LOGSTASH_HOST}"]
49+
ssl.certificate_authorities: ["${FILEBEAT_DIR}/ca.crt"]
50+
ssl.certificate: "${FILEBEAT_DIR}/client.crt"
51+
ssl.key: "${FILEBEAT_DIR}/client.key"
52+
EOF
53+
54+
docker run -d --rm --name filebeat_7.17.6 \
55+
-v "${FILEBEAT_DIR}:${FILEBEAT_DIR}" \
56+
-v "/home/runner/runners:/home/runner/runners" \
57+
docker.elastic.co/beats/filebeat:7.17.6 \
58+
filebeat -c ${FILEBEAT_DIR}/filebeat.yml -e -v

0 commit comments

Comments
 (0)