Skip to content

Commit

Permalink
grpc/nats: log body of requests/responds/messages (#849)
Browse files Browse the repository at this point in the history
- added log.dumpBody to all grpc services
- grpc unary/stream calls logs request/responds/stream messages
- nats publish logs messages
  • Loading branch information
jkralik authored Jan 17, 2023
1 parent 0cd5c96 commit d7b1641
Show file tree
Hide file tree
Showing 53 changed files with 676 additions and 265 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/measureMemory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ jobs:
- name: Run a test
continue-on-error: true
run: |
make test/mem TEST_MEMORY_COAP_GATEWAY_RESOURCE_DATA_SIZE=${{ matrix.resourceDataSize }} TEST_MEMORY_COAP_GATEWAY_TIMEOUT=${{ matrix.timeout }} TEST_MEMORY_COAP_GATEWAY_NUM_DEVICES=${{ matrix.numDevices }} TEST_MEMORY_COAP_GATEWAY_NUM_RESOURCES=${{ matrix.numResources }} | tee >(grep "TestMemoryWithDevices.result:" | sed -e "s/.*TestMemoryWithDevices.result://g" | jq -r -c > out.json)
make test/mem TEST_MEMORY_COAP_GATEWAY_RESOURCE_DATA_SIZE=${{ matrix.resourceDataSize }} TEST_TIMEOUT=${{ matrix.timeout }} TEST_MEMORY_COAP_GATEWAY_NUM_DEVICES=${{ matrix.numDevices }} TEST_MEMORY_COAP_GATEWAY_NUM_RESOURCES=${{ matrix.numResources }} | tee >(grep "TestMemoryWithDevices.result:" | sed -e "s/.*TestMemoryWithDevices.result://g" | jq -r -c > out.json)
- name: Dump file
if: success()
Expand Down
88 changes: 73 additions & 15 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,42 @@ jobs:
fail-fast: false
matrix:
include:
# test with check race with coverage and sonarcloud
- name: test
cmd: test
codecov: "true"
sonarcloud: "true"
checkRace: "true"
coapGateway:
log:
level: "debug"
dumpBody: "true"

# test without check race
- name: test/norace
cmd: test/norace
cmd: test
coapGateway:
log:
level: "debug"
dumpBody: "true"

# test without check race with logs from all services
- name: test/norace/logs
cmd: test
coapGateway:
log:
level: "debug"
dumpBody: "true"
grpcGateway:
log:
level: "debug"
dumpBody: "true"
resourceAggregate:
log:
level: "debug"
dumpBody: "true"
identityStore:
log:
level: "debug"
dumpBody: "true"

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand All @@ -41,27 +71,55 @@ jobs:
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

- name: Setup kernel for multicast messages, increase read buffer to 8MB
run: sudo sysctl -w net.core.rmem_max=8388608
- name: Run a test
run: |
make ${{ matrix.cmd }} TEST_CHECK_RACE=${{ matrix.checkRace }} \
TEST_COAP_GATEWAY_LOG_LEVEL=${{ matrix.coapGateway.log.level }} TEST_COAP_GATEWAY_LOG_DUMP_BODY=${{ matrix.coapGateway.log.dumpBody }} \
TEST_RESOURCE_AGGREGATE_LOG_LEVEL=${{ matrix.resourceAggregate.log.level }} TEST_RESOURCE_AGGREGATE_LOG_DUMP_BODY=${{ matrix.resourceAggregate.log.dumpBody }} \
TEST_GRPC_GATEWAY_LOG_LEVEL=${{ matrix.grpcGateway.log.level }} TEST_GRPC_GATEWAY_LOG_DUMP_BODY=${{ matrix.grpcGateway.log.dumpBody }} \
TEST_IDENTITY_STORE_LOG_LEVEL=${{ matrix.identityStore.log.level }} TEST_IDENTITY_STORE_LOG_DUMP_BODY=${{ matrix.identityStore.log.dumpBody }}
- name: Get file limit
run: sudo sysctl fs.file-max
- name: Prepare upload files
run: |
mkdir -p ./outputs
cp -r .tmp/coverage ./outputs/
cp -r .tmp/report ./outputs/
- name: Upload coverage and report files
uses: actions/upload-artifact@v3
with:
name: ${{ hashFiles('./outputs') || 'none' }}
path: ./outputs
retention-days: 1
if-no-files-found: warn

- name: Get hard ulimits
run: ulimit -a
coverage-sonar-cloud-scan:
needs: test
# The type of runner that the job will run on
runs-on: ubuntu-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

- name: Get soft ulimits open files
run: ulimit -S
- name: Download artifacts
uses: actions/download-artifact@v3
with:
path: ./outputs

- name: Run a test
run: make ${{ matrix.cmd }} ${{ matrix.args }}
- name: Prepare coverage and report files
run: |
mkdir -p .tmp/coverage
mkdir -p .tmp/report
find ./outputs -name "*.coverage.txt" -exec sh -c 'cp $1 .tmp/coverage/$(echo $1 | sed "s/[\/.]/-/g" ).coverage.txt' _ {} \;
find ./outputs -name "*.report.json" -exec sh -c 'cp $1 .tmp/report/$(echo $1 | sed "s/[\/.]/-/g" ).report.json' _ {} \;
- name: Publish the coverage for main branch
if: ${{ github.ref == 'refs/heads/main' && matrix.codecov == 'true' }}
if: ${{ github.ref == 'refs/heads/main' }}
run: bash <(curl -s https://codecov.io/bash)

- name: SonarCloud Scan
if: ${{ matrix.sonarcloud == 'true' }}
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
10 changes: 8 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@
"TEST_MEMORY_COAP_GATEWAY_NUM_DEVICES": "1",
"TEST_MEMORY_COAP_GATEWAY_NUM_RESOURCES": "1",
"TEST_MEMORY_COAP_GATEWAY_EXPECTED_RSS_IN_MB": "1000",
"TEST_MEMORY_COAP_GATEWAY_LOG_LEVEL": "info",
"TEST_MEMORY_COAP_GATEWAY_LOG_DUMP_BODY": "false",
"TEST_MEMORY_COAP_GATEWAY_RESOURCE_DATA_SIZE": "200",
"TEST_COAP_GATEWAY_LOG_LEVEL": "info",
"TEST_COAP_GATEWAY_LOG_DUMP_BODY": "false",
"TEST_RESOURCE_AGGREGATE_LOG_LEVEL": "info",
"TEST_RESOURCE_AGGREGATE_LOG_DUMP_BODY": "false",
"TEST_GRPC_GATEWAY_LOG_LEVEL": "info",
"TEST_GRPC_GATEWAY_LOG_DUMP_BODY": "false",
"TEST_IDENTITY_STORE_LOG_LEVEL": "info",
"TEST_IDENTITY_STORE_LOG_DUMP_BODY": "false",
// "GODEBUG": "scavtrace=1",
// "TEST_COAP_GATEWAY_UDP_ENABLED": "true",
// "GOMAXPROCS": 1,
Expand Down
50 changes: 36 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,26 @@ GOPATH ?= $(shell go env GOPATH)
WORKING_DIRECTORY := $(shell pwd)
USER_ID := $(shell id -u)
GROUP_ID := $(shell id -g)
TEST_MEMORY_COAP_GATEWAY_LOG_LEVEL ?= info
TEST_MEMORY_COAP_GATEWAY_LOG_DUMP_BODY ?= false
TEST_CHECK_RACE ?= false
ifeq ($(TEST_CHECK_RACE),true)
GO_BUILD_ARG := -race
else
GO_BUILD_ARG := $(GO_BUILD_ARG)
endif
TEST_TIMEOUT ?= 45m
TEST_COAP_GATEWAY_UDP_ENABLED ?= true
TEST_COAP_GATEWAY_LOG_LEVEL ?= info
TEST_COAP_GATEWAY_LOG_DUMP_BODY ?= false
TEST_RESOURCE_AGGREGATE_LOG_LEVEL ?= info
TEST_RESOURCE_AGGREGATE_LOG_DUMP_BODY ?= false
TEST_GRPC_GATEWAY_LOG_LEVEL ?= info
TEST_GRPC_GATEWAY_LOG_DUMP_BODY ?= false
TEST_IDENTITY_STORE_LOG_LEVEL ?= info
TEST_IDENTITY_STORE_LOG_DUMP_BODY ?= false
TEST_MEMORY_COAP_GATEWAY_NUM_DEVICES ?= 1
TEST_MEMORY_COAP_GATEWAY_NUM_RESOURCES ?= 1
TEST_MEMORY_COAP_GATEWAY_EXPECTED_RSS_IN_MB ?= 50
TEST_MEMORY_COAP_GATEWAY_RESOURCE_DATA_SIZE ?= 200
TEST_MEMORY_COAP_GATEWAY_TIMEOUT ?= 120m

#$(error MY_FLAG=$(BUILD_TAG)AAA)

Expand Down Expand Up @@ -204,23 +217,32 @@ test: env
@mkdir -p $(WORKING_DIRECTORY)/.tmp/home
@mkdir -p $(WORKING_DIRECTORY)/.tmp/home/certificate-authority
@mkdir -p $(WORKING_DIRECTORY)/.tmp/report
@$(call RUN-TESTS,hub,./...,-timeout=45m -race -p 1 -v -tags=test,"")
@$(call RUN-TESTS,grpc-gateway-dtls,./grpc-gateway/service,-timeout=45m -race -p 1 -v -tags=test,"TEST_COAP_GATEWAY_UDP_ENABLED=true")
@$(call RUN-TESTS,hub,./...,-timeout=$(TEST_TIMEOUT) $(GO_BUILD_ARG) -p 1 -v -tags=test,\
TEST_COAP_GATEWAY_LOG_LEVEL=$(TEST_COAP_GATEWAY_LOG_LEVEL) TEST_COAP_GATEWAY_LOG_DUMP_BODY=$(TEST_COAP_GATEWAY_LOG_DUMP_BODY) \
TEST_RESOURCE_AGGREGATE_LEVEL=$(TEST_RESOURCE_AGGREGATE_LEVEL) TEST_RESOURCE_AGGREGATE_LOG_DUMP_BODY=$(TEST_RESOURCE_AGGREGATE_LOG_DUMP_BODY) \
TEST_GRPC_GATEWAY_LOG_LEVEL=$(TEST_GRPC_GATEWAY_LOG_LEVEL) TEST_GRPC_GATEWAY_LOG_DUMP_BODY=$(TEST_GRPC_GATEWAY_LOG_DUMP_BODY) \
TEST_IDENTITY_STORE_LOG_LEVEL=$(TEST_IDENTITY_STORE_LOG_LEVEL) TEST_IDENTITY_STORE_LOG_DUMP_BODY=$(TEST_IDENTITY_STORE_LOG_DUMP_BODY))
@$(call RUN-TESTS,grpc-gateway-dtls,./grpc-gateway/service,-timeout=$(TEST_TIMEOUT) $(GO_BUILD_ARG) -p 1 -v -tags=test,\
TEST_COAP_GATEWAY_UDP_ENABLED=$(TEST_COAP_GATEWAY_UDP_ENABLED) \
TEST_COAP_GATEWAY_LOG_LEVEL=$(TEST_COAP_GATEWAY_LOG_LEVEL) TEST_COAP_GATEWAY_LOG_DUMP_BODY=$(TEST_COAP_GATEWAY_LOG_DUMP_BODY) \
TEST_RESOURCE_AGGREGATE_LEVEL=$(TEST_RESOURCE_AGGREGATE_LEVEL) TEST_RESOURCE_AGGREGATE_LOG_DUMP_BODY=$(TEST_RESOURCE_AGGREGATE_LOG_DUMP_BODY) \
TEST_GRPC_GATEWAY_LOG_LEVEL=$(TEST_GRPC_GATEWAY_LOG_LEVEL) TEST_GRPC_GATEWAY_LOG_DUMP_BODY=$(TEST_GRPC_GATEWAY_LOG_DUMP_BODY) \
TEST_IDENTITY_STORE_LOG_LEVEL=$(TEST_IDENTITY_STORE_LOG_LEVEL) TEST_IDENTITY_STORE_LOG_DUMP_BODY=$(TEST_IDENTITY_STORE_LOG_DUMP_BODY))
.PHONY: test

test/norace: env
@mkdir -p $(WORKING_DIRECTORY)/.tmp/home
@mkdir -p $(WORKING_DIRECTORY)/.tmp/home/certificate-authority
@mkdir -p $(WORKING_DIRECTORY)/.tmp/report
@$(call RUN-TESTS,hub,./...,-timeout=45m -p 1 -v,"")
@$(call RUN-TESTS,grpc-gateway-dtls,./grpc-gateway/service,-timeout=45m -p 1 -v -tags=test,"TEST_COAP_GATEWAY_UDP_ENABLED=true")
.PHONY: test/norace

test/mem: env/test/mem
@mkdir -p $(WORKING_DIRECTORY)/.tmp/home
@mkdir -p $(WORKING_DIRECTORY)/.tmp/home/certificate-authority
@mkdir -p $(WORKING_DIRECTORY)/.tmp/report
@$(call RUN-TESTS,coap-gateway-mem,./coap-gateway/service,-timeout=$(TEST_MEMORY_COAP_GATEWAY_TIMEOUT) -p 1 -v -tags=test_mem,TEST_MEMORY_COAP_GATEWAY_NUM_DEVICES=$(TEST_MEMORY_COAP_GATEWAY_NUM_DEVICES) TEST_MEMORY_COAP_GATEWAY_NUM_RESOURCES=$(TEST_MEMORY_COAP_GATEWAY_NUM_RESOURCES) TEST_MEMORY_COAP_GATEWAY_EXPECTED_RSS_IN_MB=$(TEST_MEMORY_COAP_GATEWAY_EXPECTED_RSS_IN_MB) TEST_MEMORY_COAP_GATEWAY_LOG_LEVEL=$(TEST_MEMORY_COAP_GATEWAY_LOG_LEVEL) TEST_MEMORY_COAP_GATEWAY_LOG_DUMP_BODY=$(TEST_MEMORY_COAP_GATEWAY_LOG_DUMP_BODY) TEST_MEMORY_COAP_GATEWAY_RESOURCE_DATA_SIZE=$(TEST_MEMORY_COAP_GATEWAY_RESOURCE_DATA_SIZE))
@$(call RUN-TESTS,coap-gateway-mem,./coap-gateway/service,-timeout=$(TEST_TIMEOUT) -p 1 -v -tags=test_mem,\
TEST_MEMORY_COAP_GATEWAY_NUM_DEVICES=$(TEST_MEMORY_COAP_GATEWAY_NUM_DEVICES) \
TEST_MEMORY_COAP_GATEWAY_NUM_RESOURCES=$(TEST_MEMORY_COAP_GATEWAY_NUM_RESOURCES) \
TEST_MEMORY_COAP_GATEWAY_EXPECTED_RSS_IN_MB=$(TEST_MEMORY_COAP_GATEWAY_EXPECTED_RSS_IN_MB) \
TEST_MEMORY_COAP_GATEWAY_RESOURCE_DATA_SIZE=$(TEST_MEMORY_COAP_GATEWAY_RESOURCE_DATA_SIZE) \
TEST_COAP_GATEWAY_LOG_LEVEL=$(TEST_COAP_GATEWAY_LOG_LEVEL) TEST_COAP_GATEWAY_LOG_DUMP_BODY=$(TEST_COAP_GATEWAY_LOG_DUMP_BODY) \
TEST_RESOURCE_AGGREGATE_LEVEL=$(TEST_RESOURCE_AGGREGATE_LEVEL) TEST_RESOURCE_AGGREGATE_LOG_DUMP_BODY=$(TEST_RESOURCE_AGGREGATE_LOG_DUMP_BODY) \
TEST_GRPC_GATEWAY_LOG_LEVEL=$(TEST_GRPC_GATEWAY_LOG_LEVEL) TEST_GRPC_GATEWAY_LOG_DUMP_BODY=$(TEST_GRPC_GATEWAY_LOG_DUMP_BODY) \
TEST_IDENTITY_STORE_LOG_LEVEL=$(TEST_IDENTITY_STORE_LOG_LEVEL) TEST_IDENTITY_STORE_LOG_DUMP_BODY=$(TEST_IDENTITY_STORE_LOG_DUMP_BODY))
.PHONY: test/mem

test-targets := $(addprefix test-,$(patsubst ./%/,%,$(DIRECTORIES)))
Expand Down
Loading

0 comments on commit d7b1641

Please sign in to comment.