- 
                Notifications
    You must be signed in to change notification settings 
- Fork 23
chore: reduce info log verbosity with structured logging #2168
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -21,6 +21,10 @@ spec: | |
| spec: | ||
| backoffLimit: 0 | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app: {{ template "batch-server.name" $ }} | ||
| job-type: cronjob | ||
| spec: | ||
| volumes: | ||
| - name: service-cert-secret | ||
|  | @@ -43,18 +47,34 @@ spec: | |
| env: | ||
| - name: WEB_GATEWAY_ADDRESS | ||
| value: "{{ $.Values.cronjob.webGatewayAddress }}" | ||
| - name: JOB_NAME | ||
| value: "{{ .name }}" | ||
| - name: JOB_ID | ||
| value: "{{ .jobId }}" | ||
| command: | ||
| - /bin/sh | ||
| args: | ||
| - -c | ||
| - | | ||
| echo "Start {{ .name }} job." | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed the start log and implemented the elapsed time to be reported in the success log. | ||
| START_TIME=$(date +%s) | ||
| ENDPOINT="${WEB_GATEWAY_ADDRESS}/bucketeer.batch.BatchService/ExecuteBatchJob" | ||
| TOKEN=`cat /usr/local/service-token/token` | ||
| RES=`curl -X POST -m 3600 --cacert /usr/local/certs/service/tls.crt -d '{"job": "{{ .jobId }}"}' -H "authorization: bearer ${TOKEN}" -H "Content-Type: application/json" -s -o /dev/null -w '%{http_code}\\n' ${ENDPOINT}` | ||
| echo "{{ .name }} job result: ${RES}" | ||
| if [ "$RES" = 200 ] || [ "$RES" = 503 ] || [ "$RES" = 000 ] | ||
| then | ||
| RESPONSE=$(mktemp) | ||
| RES=$(curl -X POST -m 3600 --cacert /usr/local/certs/service/tls.crt -d '{"job": "'${JOB_ID}'"}' -H "authorization: bearer ${TOKEN}" -H "Content-Type: application/json" -s -o ${RESPONSE} -w '%{http_code}' ${ENDPOINT}) | ||
| BODY=$(cat ${RESPONSE}) | ||
| rm -f ${RESPONSE} | ||
| END_TIME=$(date +%s) | ||
| DURATION=$((END_TIME - START_TIME)) | ||
| # API returns empty {} on success, or error details on failure | ||
| if [ "${RES}" = "200" ]; then | ||
| # Success - use DEBUG to avoid verbose logs | ||
| echo '{"severity":"DEBUG","message":"'${JOB_NAME}' job completed successfully","job":"'${JOB_NAME}'","jobId":"'${JOB_ID}'","statusCode":'${RES}',"durationSeconds":'${DURATION}'}' | ||
| else | ||
| # Failure - log as ERROR with response details for debugging | ||
| BODY_ESCAPED=$(echo "${BODY}" | sed 's/\\/\\\\/g; s/"/\\"/g' | tr '\n\r\t' ' ') | ||
| echo '{"severity":"ERROR","message":"'${JOB_NAME}' job failed","job":"'${JOB_NAME}'","jobId":"'${JOB_ID}'","statusCode":'${RES}',"durationSeconds":'${DURATION}',"responseBody":"'${BODY_ESCAPED}'"}' | ||
| 
      Comment on lines
    
      +71
     to 
      +75
    
   There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The debug logs were always reported as INFO level to GCP, so I formatted them using JSON format. | ||
| fi | ||
| if [ "${RES}" = "200" ] || [ "${RES}" = "503" ] || [ "${RES}" = "000" ]; then | ||
| exit 0 | ||
| else | ||
| exit 1 | ||
|  | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented it to report the logs as
batch-serverfor easy tracking on the GCP console.