From c77e1d597abd29bc5bf03e6e553ff7f401a45933 Mon Sep 17 00:00:00 2001 From: Aleksandr Nekrasov Date: Mon, 12 Feb 2024 13:19:04 +0700 Subject: [PATCH 1/4] chore: added ci --- .github/workflows/ci.yml | 40 +++++++++++++++++++++++++++++++++++ otelslog/otel_handler_test.go | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..edb6db6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,40 @@ +name: ci +on: + push: + branches: + - main + pull_request: +env: + # Path to where test results will be saved. + TEST_RESULTS: /tmp/test-results + # Default version of Go to use by CI workflows. This should be the latest + # release of Go; developers likely use the latest release in development and + # we want to catch any bugs (e.g. lint errors, race detection) with this + # release before they are merged. The Go compatibility guarantees ensure + # backwards compatibility with the previous two minor releases and we + # explicitly test our code for these versions so keeping this at prior + # versions does not add value. + DEFAULT_GO_VERSION: "1.21" + +jobs: + test-coverage: + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@v3 + - name: Setup Environment + run: | + echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV + echo "$(go env GOPATH)/bin" >> $GITHUB_PATH + - name: Install Go + uses: actions/setup-go@v4 + with: + go-version: ${{ env.DEFAULT_GO_VERSION }} + cache-dependency-path: "**/go.sum" + - name: Run coverage tests + run: | + make test-coverage + - name: Upload coverage reports to codecov + uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file diff --git a/otelslog/otel_handler_test.go b/otelslog/otel_handler_test.go index eeafb87..795cf04 100644 --- a/otelslog/otel_handler_test.go +++ b/otelslog/otel_handler_test.go @@ -42,7 +42,7 @@ func TestNewOtelHandler(t *testing.T) { ) handler := NewOtelHandler(loggerProvider, &HandlerOptions{ - level: slog.LevelInfo, + Level: slog.LevelInfo, }). WithAttrs([]slog.Attr{slog.String("first", "value1")}). WithGroup("group1"). From abe44998f4ce20310a545d3c168435cf173f9c58 Mon Sep 17 00:00:00 2001 From: Aleksandr Nekrasov Date: Mon, 12 Feb 2024 13:27:12 +0700 Subject: [PATCH 2/4] makefile --- Makefile | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c9a403f --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +.PHONY: test-coverage + +test-coverage: + go test -coverprofile=coverage.out ./... + go tool cover -html=coverage.out -o coverage.html From 6725fb1007fa6d759ddcb6a7bb69624ba8a2ac01 Mon Sep 17 00:00:00 2001 From: Aleksandr Nekrasov Date: Mon, 12 Feb 2024 13:50:48 +0700 Subject: [PATCH 3/4] run tests in submodules --- Makefile | 2 +- otelzap/go.sum | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index c9a403f..6fbe5aa 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ .PHONY: test-coverage test-coverage: - go test -coverprofile=coverage.out ./... + find . -name go.mod -execdir go test -coverprofile=coverage.out ./... \; go tool cover -html=coverage.out -o coverage.html diff --git a/otelzap/go.sum b/otelzap/go.sum index e8decca..03ee8bf 100644 --- a/otelzap/go.sum +++ b/otelzap/go.sum @@ -1,18 +1,27 @@ -github.com/agoda-com/opentelemetry-logs-go v0.2.0/go.mod h1:bjUiOkH82zqgjLmxk0v9axmV5b9Ty+1qlixsrAMTLwQ= +github.com/agoda-com/opentelemetry-logs-go v0.3.0 h1:d2lMVUfCDeLzVgTxMeSU8IWaMXjwD4sVKigEZBGwcsw= github.com/agoda-com/opentelemetry-logs-go v0.3.0/go.mod h1:k3QR1O5AOl+dFC7pkrK9wWmoD72jjDONPFHi9dAgLJc= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= -go.opentelemetry.io/otel v1.17.0/go.mod h1:I2vmBGtFaODIVMBSTPVDlJSzBDNf93k60E6Ft0nyjo0= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +go.opentelemetry.io/otel v1.18.0 h1:TgVozPGZ01nHyDZxK5WGPFB9QexeTMXEH7+tIClWfzs= go.opentelemetry.io/otel v1.18.0/go.mod h1:9lWqYO0Db579XzVuCKFNPDl4s73Voa+zEck3wHaAYQI= -go.opentelemetry.io/otel/metric v1.17.0/go.mod h1:h4skoxdZI17AxwITdmdZjjYJQH5nzijUUjm+wtPph5o= +go.opentelemetry.io/otel/metric v1.18.0 h1:JwVzw94UYmbx3ej++CwLUQZxEODDj/pOuTCvzhtRrSQ= go.opentelemetry.io/otel/metric v1.18.0/go.mod h1:nNSpsVDjWGfb7chbRLUNW+PBNdcSTHD4Uu5pfFMOI0k= -go.opentelemetry.io/otel/sdk v1.17.0/go.mod h1:U87sE0f5vQB7hwUoW98pW5Rz4ZDuCFBZFNUBlSgmDFQ= +go.opentelemetry.io/otel/sdk v1.18.0 h1:e3bAB0wB3MljH38sHzpV/qWrOTCFrdZF2ct9F8rBkcY= go.opentelemetry.io/otel/sdk v1.18.0/go.mod h1:1RCygWV7plY2KmdskZEDDBs4tJeHG92MdHZIluiYs/M= -go.opentelemetry.io/otel/trace v1.17.0/go.mod h1:I/4vKTgFclIsXRVucpH25X0mpFSczM7aHeaz0ZBLWjY= +go.opentelemetry.io/otel/trace v1.18.0 h1:NY+czwbHbmndxojTEKiSMHkG2ClNH2PwmcHrdo0JY10= go.opentelemetry.io/otel/trace v1.18.0/go.mod h1:T2+SGJGuYZY3bjj5rgh/hN7KIrlpWC5nS8Mjvzckz+0= +go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= +go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ= go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= -go.uber.org/zap v1.25.0/go.mod h1:JIAUzQIH94IC4fOJQm7gMmBJP5k7wQfdcnYdPoEXJYk= +go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so= -golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= From dfcaf3a95e21f760bc099e6a3b8e0f6d02cf4e34 Mon Sep 17 00:00:00 2001 From: Aleksandr Nekrasov Date: Mon, 12 Feb 2024 14:00:23 +0700 Subject: [PATCH 4/4] cov merge --- Makefile | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 6fbe5aa..3c1afc2 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,26 @@ .PHONY: test-coverage -test-coverage: - find . -name go.mod -execdir go test -coverprofile=coverage.out ./... \; - go tool cover -html=coverage.out -o coverage.html +ALL_GO_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | sort) + +TOOLS = $(CURDIR)/.tools + +$(TOOLS): + @mkdir -p $@ +$(TOOLS)/%: | $(TOOLS) + cd $(TOOLS_MOD_DIR) && \ + $(GO) build -o $@ $(PACKAGE) + +GOCOVMERGE = $(TOOLS)/gocovmerge +$(TOOLS)/gocovmerge: PACKAGE=github.com/wadey/gocovmerge + +.PHONY: tools +tools: $(GOCOVMERGE) + + +test-coverage: | $(GOCOVMERGE) + @set -e; \ + for dir in $(ALL_COVERAGE_MOD_DIRS); do \ + (cd "$${dir}" && go test -coverprofile=coverage.out ./... && \ + go tool cover -html=coverage.out -o coverage.html); \ + done; \ + $(GOCOVMERGE) $$(find . -name coverage.out) > coverage.txt