Skip to content

Commit 6d4fe19

Browse files
committed
Push agent v2 logs to QE grafana
1 parent 96836f0 commit 6d4fe19

File tree

8 files changed

+304
-3
lines changed

8 files changed

+304
-3
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Start Promtail
2+
description: Start promtail in a Docker container to send test results to loki
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Start Promtail container
7+
shell: bash
8+
run: |
9+
docker run -d \
10+
--name=promtail \
11+
-v "${{ github.workspace }}/test/dashboard/prep/promtail.yaml:/etc/promtail/config.yaml" \
12+
-v "${{ github.workspace }}/test/dashboard/logs:/var/log" \
13+
-e TEST_OUTDIR=test/dashboard/logs \
14+
-e GITHUB_RUN_ID=${{ github.run_id }} \
15+
-e GITHUB_JOB=${{ github.job }} \
16+
-e GITHUB_WORKFLOW=${{ github.workflow }} \
17+
-e GITHUB_EVENT_NAME=${{ github.event_name }} \
18+
-e GITHUB_SERVER_URL=${{ github.server_url }} \
19+
-e GITHUB_REPOSITORY=${{ github.repository }} \
20+
-e GITHUB_HEAD_REF=${{ github.head_ref }} \
21+
-e GITHUB_SHA=${{ github.sha }} \
22+
-e GITHUB_ACTOR=${{ github.actor }} \
23+
grafana/promtail:3.4.4 \
24+
-config.file=/etc/promtail/config.yaml \
25+
-config.expand-env=true

.github/workflows/ci.yml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,20 @@ jobs:
161161
with:
162162
name: nginx-agent-unsigned-snapshots
163163
path: build
164+
- name: Set Start Time
165+
run: echo "START_TIME=$(date +"%Y-%m-%dT%H:%M:%S.%NZ")" >> ${GITHUB_ENV}
166+
- name: Create Directory for Results
167+
run: mkdir -p ${{github.workspace}}/test/dashboard/logs/${{github.job}}/
168+
- name: Start Promtail
169+
uses: ./.github/actions/start-promtail
164170
- name: Run Integration Tests
165171
run: |
166172
go install github.com/goreleaser/nfpm/v2/cmd/nfpm@${{ env.NFPM_VERSION }}
167173
OS_RELEASE="${{ matrix.container.image }}" OS_VERSION="${{ matrix.container.version }}" \
168-
make integration-test
174+
make integration-test | tee ${{github.workspace}}/test/dashboard/logs/${{github.job}}-${{matrix.container.image}}-${{matrix-container-version}}/raw_logs.log && exit "${PIPESTATUS[0]}"
175+
- name: Generate Test Results
176+
if: always()
177+
run: bash ./scripts/workflow/generate_results.sh ${{job.status}} ${{env.START_TIME}} ${{github.job}}
169178
- name: Container Output Logs
170179
if: failure()
171180
run: |
@@ -209,6 +218,12 @@ jobs:
209218
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
210219
with:
211220
go-version-file: 'go.mod'
221+
- name: Set Start Time
222+
run: echo "START_TIME=$(date +"%Y-%m-%dT%H:%M:%S.%NZ")" >> ${GITHUB_ENV}
223+
- name: Create Directory for Results
224+
run: mkdir -p ${{github.workspace}}/test/dashboard/logs/${{github.job}}/
225+
- name: Start Promtail
226+
uses: ./.github/actions/start-promtail
212227
- name: Download Packages
213228
uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7
214229
with:
@@ -218,7 +233,10 @@ jobs:
218233
run: |
219234
go install github.com/goreleaser/nfpm/v2/cmd/nfpm@${{ env.NFPM_VERSION }}
220235
CONTAINER_NGINX_IMAGE_REGISTRY="${{ env.NGINX_OSS_REGISTRY }}" TAG="${{ matrix.container.version }}-${{ matrix.container.image }}" OS_RELEASE="${{ matrix.container.release }}"\
221-
make official-image-integration-test
236+
make official-image-integration-test | tee ${{github.workspace}}/test/dashboard/logs/${{github.job}}-${{matrix.container.image}}-${{matrix-container-version}}/raw_logs.log && exit "${PIPESTATUS[0]}"
237+
- name: Generate Test Results
238+
if: always()
239+
run: bash ./scripts/workflow/generate_results.sh ${{job.status}} ${{env.START_TIME}} ${{github.job}}
222240
- name: Container Output Logs
223241
if: failure()
224242
run: |
@@ -275,6 +293,12 @@ jobs:
275293
with:
276294
name: nginx-agent-unsigned-snapshots
277295
path: build
296+
- name: Set Start Time
297+
run: echo "START_TIME=$(date +"%Y-%m-%dT%H:%M:%S.%NZ")" >> ${GITHUB_ENV}
298+
- name: Create Directory for Results
299+
run: mkdir -p ${{github.workspace}}/test/dashboard/logs/${{github.job}}/
300+
- name: Start Promtail
301+
uses: ./.github/actions/start-promtail
278302
- name: Login to Docker Registry
279303
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
280304
with:
@@ -286,7 +310,10 @@ jobs:
286310
go install github.com/goreleaser/nfpm/v2/cmd/nfpm@${{ env.NFPM_VERSION }}
287311
CONTAINER_NGINX_IMAGE_REGISTRY="${{ secrets.REGISTRY_URL }}" TAG="${{ matrix.container.plus }}-${{ matrix.container.image }}-${{ matrix.container.version }}" \
288312
OS_RELEASE="${{ matrix.container.release }}" IMAGE_PATH="${{ matrix.container.path }}" \
289-
make official-image-integration-test
313+
make official-image-integration-test | tee ${{github.workspace}}/test/dashboard/logs/${{github.job}}-${{matrix.container.image}}-${{matrix-container-version}}/raw_logs.log && exit "${PIPESTATUS[0]}"
314+
- name: Generate Test Results
315+
if: always()
316+
run: bash ./scripts/workflow/generate_results.sh ${{job.status}} ${{env.START_TIME}} ${{github.job}}
290317
- name: Container Output Logs
291318
if: failure()
292319
run: |
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/bin/bash
2+
3+
# TODO: `start_time` and `end_time`, separate test name from `$line`
4+
5+
JOB_RESULT="$1"
6+
START_TIME="$2"
7+
TEST_TYPE="$3"
8+
9+
INPUT_FILE="./test/dashboard/logs/$TEST_TYPE/raw_logs.log"
10+
JOB_OUTPUT_FILE="./test/dashboard/logs/$TEST_TYPE/result.json"
11+
LOG_OUTPUT_FILE="./test/dashboard/logs/$TEST_TYPE/test.log"
12+
OUTPUT_PATH="./test/dashboard/logs/$TEST_TYPE/"
13+
14+
END_TIME="`date "+%Y-%m-%dT%H:%M:%S.%NZ"`"
15+
START_SECONDS=$(date -d "$START_TIME" +%s.%N)
16+
END_SECONDS=$(date -d "$END_TIME" +%s.%N)
17+
DURATION=$(echo "$END_SECONDS - $START_SECONDS" | bc)
18+
19+
MSG="" # individual test msg
20+
FAIL_MSG="" # msg for entire job run
21+
RESULT=""
22+
HAS_FAILED=false
23+
IS_RUNNING=false
24+
25+
load_job_status(){
26+
if [ $JOB_RESULT == "success" ]; then
27+
RESULT="pass"
28+
elif [ $JOB_RESULT == "failure" ]; then
29+
RESULT="fail"
30+
else
31+
RESULT="skip"
32+
fi
33+
}
34+
35+
format_logs_to_json(){
36+
local LINE="$1"
37+
local JSON="{"
38+
local key value
39+
40+
while [[ "$line" =~ ([a-zA-Z0-9_]+)=((\"[^\"]*\")|([:space:]]+)) ]]; do
41+
key="${BASH_REMATCH[1]}"
42+
value="${BASH_REMATCH[2]}"
43+
LINE="${line#*${BASH_REMATCH[0]}}"
44+
json+="\"$key\": \"$value\", "
45+
done
46+
47+
json="${json%, }"
48+
json+="}"
49+
50+
echo "$json"
51+
}
52+
53+
format_results(){
54+
while IFS= read -r line; do
55+
56+
if [[ "$line" =~ ^===\ RUN[[:space:]]+(.+) ]]; then
57+
TEST_NAME="${BASH_REMATCH[1]}"
58+
IS_RUNNING=true
59+
MSG=""
60+
TEST_START=""
61+
TEST_END=""
62+
OUTPUT_FILE="${OUTPUT_PATH}${TEST_NAME}/result.json"
63+
elif [[ "$line" =~ ([0-9T:\.\-Z]+)[[:space:]]+testing ]]; then
64+
TEST_START="${BASH_REMATCH[1]}"
65+
elif [[ "$line" =~ ([0-9T:\.\-Z]+)[[:space:]]+finished testing ]]; then
66+
TEST_END="${BASH_REMATCH[1]}"
67+
elif [[ "$line" == "FAIL" ]]; then
68+
HAS_FAILED=false
69+
MSG="$MSG_STR"
70+
FAIL_MSG+="$MSG"
71+
HAS_FAILED=false
72+
echo "{\"start_at\": \"$START_TIME\", \"end_at\": \"$END_TIME\", \"duration_seconds\": \"$DURATION\", \"result\": \"$TEST_RES\", \"msg\": \"$MSG\"}" > $OUTPUT_FILE
73+
elif [[ "$line" == "--- PASS"* ]]; then
74+
TEST_RES="pass"
75+
IS_RUNNING=false
76+
echo "{\"start_at\": \"$START_TIME\", \"end_at\": \"$END_TIME\", \"duration_seconds\": \"$DURATION\", \"result\": \"$TEST_RES\", \"msg\": \"$MSG\"}" > $OUTPUT_FILE
77+
elif [[ "$line" == "--- FAIL"* ]]; then
78+
TEST_RES="fail"
79+
HAS_FAILED=true
80+
IS_RUNNING=false
81+
elif [[ "$line" == time=* && "$line" == *level=* ]]; then
82+
LOG_LINE=$(format_logs_to_json "$line")
83+
echo "$LOG_LINE" >> "$LOG_OUTPUT_FILE"
84+
fi
85+
86+
if [ $HAS_FAILED == true ]; then
87+
MSG_STR+="$line"
88+
fi
89+
90+
done < "$INPUT_FILE"
91+
92+
# Store the result of the whole job
93+
echo "{\"start_at\": \"$START_TIME\", \"end_at\": \"$END_TIME\", \"duration_seconds\": \"$DURATION\", \"result\": \"$RESULT\", \"msg\": \"$FAIL_MSG\"}" > $JOB_OUTPUT_FILE
94+
}
95+
96+
# Main body of the script
97+
{
98+
load_job_status
99+
format_results
100+
}

test/dashboard/prep/promtail.yaml

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
server:
2+
http_listen_port: 9080
3+
grpc_listen_port: 0
4+
log_level: info
5+
6+
positions:
7+
filename: /tmp/positions.yaml
8+
sync_period: "10s"
9+
10+
clients:
11+
- url: ${{ secrets.LOKI_DASHBOARD_URL }}
12+
external_labels:
13+
systest_project: agent_v2
14+
systest_type: ${GITHUB_JOB}
15+
timeout: 30s
16+
backoff_config:
17+
min_period: 500ms
18+
max_period: 5s
19+
max_retries: 5
20+
21+
scrape_configs:
22+
- job_name: test-results
23+
static_configs:
24+
- targets:
25+
- localhost
26+
labels:
27+
systest_job: test-results
28+
__path__: /var/log/**/result.json
29+
pipeline_stages:
30+
- json:
31+
expressions:
32+
time:
33+
- timestamp:
34+
source: time
35+
format: RFC3339Nano
36+
- template:
37+
source: ci_pipeline_id
38+
template: "${GITHUB_RUN_ID}"
39+
- template:
40+
source: ci_pipeline_url
41+
template: "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
42+
- template:
43+
source: ci_pipeline_name
44+
template: "${WORKFLOW}"
45+
- template:
46+
source: ci_pipeline_source
47+
template: "${GITHUB_EVENT_NAME}"
48+
- template:
49+
source: ci_job_name
50+
template: "${GITHUB_JOB}"
51+
- template:
52+
source: ci_commit_ref
53+
template: "${GITHUB_HEAD_REF}"
54+
- template:
55+
source: ci_commit_sha
56+
template: "${GITHUB_SHA}"
57+
- template:
58+
source: ci_commit_author
59+
template: "${GITHUB_ACTOR}"
60+
- template:
61+
source: systest_path
62+
template: '{{ trimPrefix "${TEST_OUTDIR}/" .filename | dir | replace "." "/" }}'
63+
64+
- structured_metadata:
65+
ci_pipeline_id:
66+
ci_pipeline_url:
67+
ci_pipeline_name:
68+
ci_pipeline_source:
69+
ci_job_name:
70+
ci_commit_ref:
71+
ci_commit_sha:
72+
ci_commit_author:
73+
filename:
74+
systest_path:
75+
76+
- labeldrop:
77+
- filename
78+
79+
80+
- job_name: test-logs
81+
static_configs:
82+
- targets:
83+
- localhost
84+
labels:
85+
systest_job: test-logs
86+
__path__: /var/log/**/test.log
87+
pipeline_stages:
88+
- json:
89+
expressions:
90+
time:
91+
- timestamp:
92+
source: time
93+
format: RFC3339Nano
94+
- template:
95+
source: ci_pipeline_id
96+
template: "${GITHUB_RUN_ID}"
97+
- template:
98+
source: ci_pipeline_url
99+
template: "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
100+
- template:
101+
source: ci_pipeline_name
102+
template: "${WORKFLOW}"
103+
- template:
104+
source: ci_pipeline_source
105+
template: "${GITHUB_EVENT_NAME}"
106+
- template:
107+
source: ci_job_name
108+
template: "${GITHUB_JOB}"
109+
- template:
110+
source: ci_commit_ref
111+
template: "${GITHUB_HEAD_REF}"
112+
- template:
113+
source: ci_commit_sha
114+
template: "${GITHUB_SHA}"
115+
- template:
116+
source: ci_commit_author
117+
template: "${GITHUB_ACTOR}"
118+
- template:
119+
source: systest_path
120+
template: '{{ trimPrefix "${TEST_OUTDIR}/" .filename | dir | replace "." "/" }}'
121+
122+
- structured_metadata:
123+
ci_pipeline_id:
124+
ci_pipeline_url:
125+
ci_pipeline_name:
126+
ci_pipeline_source:
127+
ci_job_name:
128+
ci_commit_ref:
129+
ci_commit_sha:
130+
ci_commit_author:
131+
filename:
132+
systest_path:
133+
134+
- labeldrop:
135+
- filename

test/integration/api/api_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
var delay = time.Duration(5 * time.Second)
2626

2727
func TestAPI_Nginx(t *testing.T) {
28+
t.Log("testing nginx api")
2829
ctx := context.Background()
2930
containerNetwork := utils.CreateContainerNetwork(ctx, t)
3031

@@ -80,9 +81,11 @@ func TestAPI_Nginx(t *testing.T) {
8081
assert.Equal(t, "/etc/nginx/nginx.conf", nginxDetailsResponse[0].ConfPath)
8182

8283
utils.TestAgentHasNoErrorLogs(t, testContainer)
84+
t.Log("finished testing nginx api")
8385
}
8486

8587
func TestAPI_Metrics(t *testing.T) {
88+
t.Log("testing metrics api")
8689
ctx := context.Background()
8790
containerNetwork := utils.CreateContainerNetwork(ctx, t)
8891

@@ -157,4 +160,5 @@ func TestAPI_Metrics(t *testing.T) {
157160
}
158161

159162
utils.TestAgentHasNoErrorLogs(t, testContainer)
163+
t.Log("finished testing metrics api")
160164
}

test/integration/features/features_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
)
1212

1313
func TestFeatures_NginxCountingEnabled(t *testing.T) {
14+
t.Log("testing nginx counting enabled")
1415
enabledFeatureLogs := []string{
1516
"level=info msg=\"NGINX Counter initializing", "level=info msg=\"MetricsThrottle initializing\"", "level=info msg=\"DataPlaneStatus initializing\"",
1617
"level=info msg=\"OneTimeRegistration initializing\"", "level=info msg=\"Metrics initializing\"",
@@ -56,9 +57,11 @@ func TestFeatures_NginxCountingEnabled(t *testing.T) {
5657
for _, logLine := range disabledFeatureLogs {
5758
assert.NotContains(t, string(agentLogContent), logLine, "agent log file contains disabled feature log")
5859
}
60+
t.Log("finished testing nginx counting enabled")
5961
}
6062

6163
func TestFeatures_MetricsEnabled(t *testing.T) {
64+
t.Log("testing metrics enabled")
6265
enabledFeatureLogs := []string{"level=info msg=\"Metrics initializing\"", "level=info msg=\"MetricsThrottle initializing\"", "level=info msg=\"DataPlaneStatus initializing\""}
6366
disabledFeatureLogs := []string{"level=info msg=\"OneTimeRegistration initializing\"", "level=info msg=\"Events initializing\"", "level=info msg=\"Agent API initializing\""}
6467

@@ -101,9 +104,11 @@ func TestFeatures_MetricsEnabled(t *testing.T) {
101104
for _, logLine := range disabledFeatureLogs {
102105
assert.NotContains(t, string(agentLogContent), logLine, "agent log file contains disabled feature log")
103106
}
107+
t.Log("finished testing metrics enabled")
104108
}
105109

106110
func TestFeatures_ConfigEnabled(t *testing.T) {
111+
t.Log("testing config enabled")
107112
enabledFeatureLogs := []string{"level=info msg=\"DataPlaneStatus initializing\""}
108113
disabledFeatureLogs := []string{"level=info msg=\"Events initializing\"", "level=info msg=\"Agent API initializing\"", "level=info msg=\"Metrics initializing\"", "level=info msg=\"MetricsThrottle initializing\""}
109114

@@ -146,4 +151,5 @@ func TestFeatures_ConfigEnabled(t *testing.T) {
146151
for _, logLine := range disabledFeatureLogs {
147152
assert.NotContains(t, string(agentLogContent), logLine, "agent log file contains disabled feature log")
148153
}
154+
t.Log("finished testing config enabled")
149155
}

0 commit comments

Comments
 (0)