From eab526d17cc551b155406be08f0eb1e7967fd7ac Mon Sep 17 00:00:00 2001 From: Chris Martin <101210272+ChrisScotMartin@users.noreply.github.com> Date: Mon, 2 Oct 2023 13:49:41 -0400 Subject: [PATCH] upgrade to go 1.21 --- .circleci/config.yml | 2 +- Makefile | 2 +- go.mod | 45 ++++++++++++++++++++++++++++++++++------- go.sum | 1 - golang.mk | 48 ++++++++++++++++++++++++++++++++++---------- 5 files changed, 77 insertions(+), 21 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index bd65df0..ddc5076 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ jobs: build: working_directory: ~/go/src/github.com/Clever/kinesis-alerts-consumer docker: - - image: cimg/go:1.16 + - image: cimg/go:1.21 environment: GOPRIVATE: github.com/Clever/* CIRCLE_ARTIFACTS: /tmp/circleci-artifacts diff --git a/Makefile b/Makefile index 24c00b5..72cc08f 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ EXECUTABLE = kinesis-consumer PKG = github.com/Clever/kinesis-alerts-consumer PKGS := $(shell go list ./... | grep -v /vendor ) .PHONY: download_jars run build -$(eval $(call golang-version-check,1.16)) +$(eval $(call golang-version-check,1.21)) TMP_DIR := ./tmp-jars JAR_DIR := ./jars diff --git a/go.mod b/go.mod index 09ba395..e121f48 100644 --- a/go.mod +++ b/go.mod @@ -1,23 +1,54 @@ module github.com/Clever/kinesis-alerts-consumer -go 1.16 +go 1.21 require ( github.com/Clever/amazon-kinesis-client-go v1.0.0 github.com/Clever/kayvee-go/v7 v7.4.1 - github.com/Clever/syslogparser v0.0.0-20170816194131-fb28ad3e4340 // indirect github.com/DataDog/datadog-api-client-go v1.14.0 - github.com/a8m/kinesis-producer v0.2.0 // indirect github.com/aws/aws-sdk-go v1.38.68 - github.com/davecgh/go-spew v1.1.1 // indirect github.com/eapache/go-resiliency v1.2.0 - github.com/jeromer/syslogparser v0.0.0-20160906132035-0e4ae46ea3f0 // indirect - github.com/jpillora/backoff v1.0.0 // indirect github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 - github.com/kr/text v0.2.0 // indirect github.com/stretchr/testify v1.7.0 golang.org/x/net v0.0.0-20210614182718-04defd469f4e +) + +require ( + github.com/Clever/syslogparser v0.0.0-20170816194131-fb28ad3e4340 // indirect + github.com/a8m/kinesis-producer v0.2.0 // indirect + github.com/cenkalti/backoff/v4 v4.1.2 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/go-logr/logr v1.2.1 // indirect + github.com/go-logr/stdr v1.2.0 // indirect + github.com/golang/protobuf v1.5.2 // indirect + github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect + github.com/jeromer/syslogparser v0.0.0-20160906132035-0e4ae46ea3f0 // indirect + github.com/jmespath/go-jmespath v0.4.0 // indirect + github.com/jpillora/backoff v1.0.0 // indirect + github.com/kr/text v0.2.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/xeipuuv/gojsonpointer v0.0.0-20170225233418-6fe8760cad35 // indirect + github.com/xeipuuv/gojsonreference v0.0.0-20150808065054-e02fc20de94c // indirect + github.com/xeipuuv/gojsonschema v0.0.0-20171025060643-212d8a0df7ac // indirect + go.opentelemetry.io/otel v1.3.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.3.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.26.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.26.0 // indirect + go.opentelemetry.io/otel/internal/metric v0.26.0 // indirect + go.opentelemetry.io/otel/metric v0.26.0 // indirect + go.opentelemetry.io/otel/sdk v1.3.0 // indirect + go.opentelemetry.io/otel/sdk/export/metric v0.26.0 // indirect + go.opentelemetry.io/otel/sdk/metric v0.26.0 // indirect + go.opentelemetry.io/otel/trace v1.3.0 // indirect + go.opentelemetry.io/proto/otlp v0.11.0 // indirect + golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect + golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect + golang.org/x/text v0.3.6 // indirect golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 // indirect + google.golang.org/appengine v1.4.0 // indirect + google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect + google.golang.org/grpc v1.42.0 // indirect + google.golang.org/protobuf v1.27.1 // indirect gopkg.in/Clever/kayvee-go.v6 v6.27.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index 5dbaf57..4f441dd 100644 --- a/go.sum +++ b/go.sum @@ -167,7 +167,6 @@ golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/golang.mk b/golang.mk index c4b6a4a..db81955 100644 --- a/golang.mk +++ b/golang.mk @@ -1,7 +1,7 @@ # This is the default Clever Golang Makefile. # It is stored in the dev-handbook repo, github.com/Clever/dev-handbook # Please do not alter this file directly. -GOLANG_MK_VERSION := 1.0.1 +GOLANG_MK_VERSION := 1.2.1 SHELL := /bin/bash SYSTEM := $(shell uname -a | cut -d" " -f1 | tr '[:upper:]' '[:lower:]') @@ -47,6 +47,8 @@ golang-ensure-curl-installed: # Golint is a tool for linting Golang code for common errors. # We pin its version because an update could add a new lint check which would make # previously passing tests start failing without changing our code. +# this package is deprecated and frozen +# Infra recomendation is to eventaully move to https://github.com/golangci/golangci-lint so don't fail on linting error for now GOLINT := $(GOPATH)/bin/golint $(GOLINT): go install -mod=readonly golang.org/x/lint/golint@738671d3881b9731cc63024d5d88cf28db875626 @@ -74,14 +76,6 @@ endef # golang-lint-deps-strict requires the golint tool for golang linting. golang-lint-deps-strict: $(GOLINT) $(FGT) -# golang-lint-strict calls golint on all golang files in the pkg and fails if any lint -# errors are found. -# arg1: pkg path -define golang-lint-strict -@echo "LINTING $(1)..." -@PKG_PATH=$$(go list -f '{{.Dir}}' $(1)); find $${PKG_PATH}/*.go -type f | grep -v gen_ | xargs $(FGT) $(GOLINT) -endef - # golang-test-deps is here for consistency golang-test-deps: @@ -102,6 +96,21 @@ define golang-test-strict @go test -v -race $(1) endef +# golang-test-strict-cover-deps is here for consistency +golang-test-strict-cover-deps: + +# golang-test-strict-cover uses the Go toolchain to run all tests in the pkg with the race and cover flag. +# appends coverage results to coverage.txt +# arg1: pkg path +define golang-test-strict-cover +@echo "TESTING $(1)..." +@go test -v -race -cover -coverprofile=profile.tmp -covermode=atomic $(1) +@if [ -f profile.tmp ]; then \ + cat profile.tmp | tail -n +2 >> coverage.txt; \ + rm profile.tmp; \ +fi; +endef + # golang-vet-deps is here for consistency golang-vet-deps: @@ -132,16 +141,29 @@ golang-test-all-strict-deps: golang-fmt-deps golang-lint-deps-strict golang-test # arg1: pkg path define golang-test-all-strict $(call golang-fmt,$(1)) -$(call golang-lint-strict,$(1)) +$(call golang-lint,$(1)) $(call golang-vet,$(1)) $(call golang-test-strict,$(1)) endef +# golang-test-all-strict-cover-deps: installs all dependencies needed for different test cases. +golang-test-all-strict-cover-deps: golang-fmt-deps golang-lint-deps-strict golang-test-strict-cover-deps golang-vet-deps + +# golang-test-all-strict-cover calls fmt, lint, vet and test on the specified pkg with strict and cover +# requirements that no errors are thrown while linting. +# arg1: pkg path +define golang-test-all-strict-cover +$(call golang-fmt,$(1)) +$(call golang-lint,$(1)) +$(call golang-vet,$(1)) +$(call golang-test-strict-cover,$(1)) +endef + # golang-build: builds a golang binary. ensures CGO build is done during CI. This is needed to make a binary that works with a Docker alpine image. # arg1: pkg path # arg2: executable name define golang-build -@echo "BUILDING..." +@echo "BUILDING $(2)..." @if [ -z "$$CI" ]; then \ go build -o bin/$(2) $(1); \ else \ @@ -150,6 +172,10 @@ else \ fi; endef +# golang-setup-coverage: set up the coverage file +golang-setup-coverage: + @echo "mode: atomic" > coverage.txt + # golang-update-makefile downloads latest version of golang.mk golang-update-makefile: @wget https://raw.githubusercontent.com/Clever/dev-handbook/master/make/golang-v1.mk -O /tmp/golang.mk 2>/dev/null