Skip to content

feat: log usage metrics #57

feat: log usage metrics

feat: log usage metrics #57

Workflow file for this run

name: Tests
on:
- pull_request
env:
IMAGE_TAGGED: coap:${{ github.sha }}
REPO_IMAGE_TAGGED: ${{ vars.REGISTRY_LOGIN_SERVER }}/coap:${{ github.sha }}
REPO_IMAGE_LATEST: ${{ vars.REGISTRY_LOGIN_SERVER }}/coap:latest
jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.22.1
- name: Build client
working-directory: client
run: go build
- name: Build server
working-directory: server
run: go build
- name: Build image
run: |
docker build -t ${{ env.IMAGE_TAGGED }} .
- name: Run image
env:
STORAGE_CONNECTION_STRING: ${{ secrets.STORAGE_CONNECTION_STRING }}
STORAGE_CONTAINER_NAME: ${{ vars.STORAGE_CONTAINER_NAME }}
run: |
docker run --cidfile container.cid --network=host -p 5683:5683/udp -p 5684:5684/udp -p 5688:5688/udp -p 5689:5689/udp -e STORAGE_CONNECTION_STRING -e STORAGE_CONTAINER_NAME -d ${{ env.IMAGE_TAGGED }}
CID=`cat container.cid`
echo "CID=${CID}" >> $GITHUB_ENV
- name: Get container ID
run: |
CONTAINER_ID=$(docker ps -q --filter "ancestor=${{ env.IMAGE_TAGGED }}")
echo "CONTAINER_ID=$CONTAINER_ID" >> $GITHUB_ENV
- run: docker container logs ${{ env.CID }}
- name: Run test client (IPv4, old ports)
working-directory: client
run: ./coap-client -udpPort 5688 -dTLSPort 5689
- name: Run test client (IPv6, old ports)
working-directory: client
run: ./coap-client -udp6 -udpPort 5688 -dTLSPort 5689
- name: Run test client (IPv4, new ports)
working-directory: client
run: ./coap-client -udpPort 5683 -dTLSPort 5684
- name: Run test client (IPv6, new ports)
working-directory: client
run: ./coap-client -udp6 -udpPort 5683 -dTLSPort 5684
- name: Get log file
run: |
LOG_FILES=`docker exec ${{ env.CONTAINER_ID }} bash -c 'ls /var/log/academy/'`
for file in "${LOG_FILES[@]}"; do
docker cp ${{ env.CONTAINER_ID }}:/var/log/academy/$file ./
done
- name: Test log file
run: |
LOG_FILE=(*-coap.log)
if [[ -f $LOG_FILE ]]; then
echo "Log file exists: $LOG_FILE"
else
echo "Log file does not exist: $LOG_FILE"
# exit 1
fi
grep -E "^20[0-9]{2}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]+[^,]+,dTLS:udp6,request$" $LOG_FILE
grep -E "^20[0-9]{2}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]+[^,]+,UDP:udp6,request$" $LOG_FILE
grep -E "^20[0-9]{2}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]+[^,]+,dTLS:udp4,request$" $LOG_FILE
grep -E "^20[0-9]{2}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]+[^,]+,UDP:udp4,request$" $LOG_FILE
- uses: actions/upload-artifact@v4
with:
name: metric-logs-${{ github.sha }}
path: |
*-coap.log
- name: Docker logs
if: always()
run: docker container logs ${{ env.CID }}
- name: Push image to the infrastructure container registry as latest
if: github.ref == 'refs/heads/saga'
run: |
docker login -u ${{ vars.REGISTRY_USERNAME }} -p ${{ secrets.REGISTRY_PASSWORD }} ${{ vars.REGISTRY_LOGIN_SERVER }}
docker tag ${{ env.IMAGE_TAGGED }} ${{ env.REPO_IMAGE_TAGGED }}
docker push ${{ env.REPO_IMAGE_TAGGED }}
docker tag ${{ env.IMAGE_TAGGED }} ${{ env.REPO_IMAGE_LATEST }}
docker push ${{ env.REPO_IMAGE_LATEST }}