From ab8f538c014373738cd5cbd2307e027cd15f731b Mon Sep 17 00:00:00 2001 From: Alex Arnell Date: Mon, 23 Oct 2023 11:16:35 -0700 Subject: [PATCH 01/12] update golang and linter --- Makefile | 2 +- go.mod | 31 +++++++++++++++------------- go.sum | 62 ++++++++++++++++++++++++++++++++++++++++---------------- 3 files changed, 62 insertions(+), 33 deletions(-) diff --git a/Makefile b/Makefile index 10a93260..77da4cad 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ GOPATH = $(shell go env GOPATH) TOOLS_DIR = $(TOP_LEVEL)/.tools TOOLS_BIN = $(TOOLS_DIR)/bin # Make sure this is in-sync with the version in the circle ci config -GOLANGCI_LINT_VERSION := v1.38.0 +GOLANGCI_LINT_VERSION := v1.55.0 PKG_SPEC := ./... MOD := -mod=readonly GOTEST := go test $(MOD) diff --git a/go.mod b/go.mod index f716fe2d..9e1218d0 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/heroku/x -go 1.17 +go 1.21 require ( contrib.go.opencensus.io/exporter/ocagent v0.6.0 @@ -16,10 +16,10 @@ require ( github.com/go-kit/kit v0.9.0 github.com/gogo/protobuf v1.3.0 // indirect github.com/golang-jwt/jwt/v4 v4.4.2 - github.com/golang/protobuf v1.5.2 + github.com/golang/protobuf v1.5.3 github.com/gomodule/redigo v1.8.9 github.com/google/gops v0.3.22 - github.com/google/uuid v1.1.2 + github.com/google/uuid v1.3.0 github.com/grpc-ecosystem/go-grpc-middleware v1.2.0 github.com/grpc-ecosystem/grpc-gateway v1.16.0 github.com/heroku/rollrus v0.2.0 @@ -48,29 +48,32 @@ require ( go.opentelemetry.io/otel/sdk v1.0.0-RC3 go.opentelemetry.io/otel/sdk/export/metric v0.23.0 go.opentelemetry.io/otel/sdk/metric v0.23.0 - golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 - golang.org/x/sync v0.0.0-20190423024810-112230192c58 - golang.org/x/sys v0.0.0-20211102061401-a2f17f7b995c // indirect + golang.org/x/crypto v0.13.0 + golang.org/x/sync v0.3.0 + golang.org/x/sys v0.12.0 // indirect golang.org/x/time v0.0.0-20181108054448-85acf8d2951c - google.golang.org/grpc v1.40.0 + google.golang.org/grpc v1.58.0 google.golang.org/grpc/examples v0.0.0-20210916203835-567da6b86340 - google.golang.org/protobuf v1.27.1 + google.golang.org/protobuf v1.31.0 gopkg.in/ini.v1 v1.42.0 // indirect gopkg.in/square/go-jose.v2 v2.5.1 ) require ( github.com/cenkalti/backoff/v4 v4.1.1 // indirect - github.com/census-instrumentation/opencensus-proto v0.2.1 // indirect + github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 // indirect github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect go.opentelemetry.io/otel/internal/metric v0.23.0 // indirect go.opentelemetry.io/otel/trace v1.0.0-RC3 // indirect go.opentelemetry.io/proto/otlp v0.9.0 // indirect - golang.org/x/net v0.0.0-20200822124328-c89045814202 // indirect - golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect - golang.org/x/text v0.3.2 // indirect + golang.org/x/net v0.15.0 // indirect + golang.org/x/oauth2 v0.12.0 // indirect + golang.org/x/text v0.13.0 // indirect google.golang.org/api v0.7.0 // indirect - google.golang.org/appengine v1.5.0 // indirect - google.golang.org/genproto v0.0.0-20200806141610-86f49bd18e98 // indirect + google.golang.org/appengine v1.6.7 // indirect + google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect ) diff --git a/go.sum b/go.sum index aed81f09..e3e669bc 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,11 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.38.0 h1:ROfEUZz+Gh5pa62DJWXSaonyu3StP6EA6lPEXPI6mCo= cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +cloud.google.com/go v0.110.6 h1:8uYAkj3YHTP/1iwReuHPxLSbdcyc+dSBbzFMrVwDR6Q= +cloud.google.com/go/compute v1.23.0 h1:tP41Zoavr8ptEqaW6j+LQOnyBBhO7OkOMAGrgLopTwY= +cloud.google.com/go/compute v1.23.0/go.mod h1:4tCnrn48xsqlwSAiLf1HXMQk8CONslYbdiEZc9FEIbM= +cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY= +cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA= contrib.go.opencensus.io/exporter/ocagent v0.6.0 h1:Z1n6UAyr0QwM284yUuh5Zd8JlvxUGAhFZcgMJkMPrGM= contrib.go.opencensus.io/exporter/ocagent v0.6.0/go.mod h1:zmKjrJcdo0aYcVS7bmEeSEBLPA9YJp5bjrofdU3pIXs= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= @@ -22,8 +26,9 @@ github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLj github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/cenkalti/backoff/v4 v4.1.1 h1:G2HAfAmvm/GcKan2oOQpBXOd2tT2G57ZnZGWa1PxPBQ= github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= -github.com/census-instrumentation/opencensus-proto v0.2.1 h1:glEXhBS5PSLLv4IXzLA5yPRVX4bilULVyxxbrfOtDAk= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/census-instrumentation/opencensus-proto v0.4.1 h1:iKLQ0xPNFxR/2hzXZMrBo8f1j86j5WHzznCCQxV/b8g= +github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= @@ -67,6 +72,8 @@ github.com/gogo/protobuf v1.3.0/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXP github.com/golang-jwt/jwt/v4 v4.4.2 h1:rcc4lwaZgFMCZ5jxF9ABolDcIHdBytAFgqFPbSJQAYs= github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/glog v1.1.0 h1:/d3pCKDPWNnvIWe0vVUpNP32qc8U3PDVxySP/y360qE= +github.com/golang/glog v1.1.0/go.mod h1:pfYeQZ3JWZoXTV5sFc986z3HTpwQs9At6P4ImfuP3NQ= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 h1:ZgQEtGgCBiWRM39fZuwSd1LwSqqSW0hOdXCYYDX0R3I= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E= @@ -85,8 +92,9 @@ github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QD github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/gomodule/redigo v1.8.9 h1:Sl3u+2BI/kk+VEatbj0scLdrFhjPmbxOc1myhDP41ws= github.com/gomodule/redigo v1.8.9/go.mod h1:7ArFNvsTjH8GMMzB4uy1snslv2BwmginuMs06a1uzZE= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= @@ -96,14 +104,16 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gops v0.3.22 h1:lyvhDxfPLHAOR2xIYwjPhN387qHxyU21Sk9sz/GhmhQ= github.com/google/gops v0.3.22/go.mod h1:7diIdLsqpCihPSX3fQagksT/Ku/y4RL9LHTlKyEUDl8= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= @@ -112,6 +122,8 @@ github.com/grpc-ecosystem/go-grpc-middleware v1.2.0/go.mod h1:mJzapYve32yjrKlk9G github.com/grpc-ecosystem/grpc-gateway v1.9.4/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 h1:RtRsiaGvWxcwd8y3BiRZxsylPT8hLWZ5SPcfI+3IDNk= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0/go.mod h1:TzP6duP4Py2pHLVPPQp42aoYI92+PCrVotyR5e8Vqlk= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/heroku/rollrus v0.2.0 h1:b3AgcXJKFJNUwbQOC2S69/+mxuTpe4laznem9VJdPEo= @@ -233,8 +245,9 @@ go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck= +golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -252,22 +265,26 @@ golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200505041828-1ed23360d12c/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up98WAHf3f/ulnJ62IyA= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8= +golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d h1:TzXSXBo42m9gQenoE3b9BGiEpg5IG2JkU5FkPIawgtw= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.12.0 h1:smVPGxink+n1ZI5pkQa8y6fZT0RW0MgCO5bFpepy4B4= +golang.org/x/oauth2 v0.12.0/go.mod h1:A74bZ3aGXgCY0qaIC9Ahg6Lglin4AMAco8cIv9baba4= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -282,12 +299,13 @@ golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210816074244-15123e1e1f71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210902050250-f475640dd07b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211102061401-a2f17f7b995c h1:QOfDMdrf/UwlVR0UBq2Mpr58UzNtvgJRXA4BgPfFACs= -golang.org/x/sys v0.0.0-20211102061401-a2f17f7b995c/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= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c h1:fqgJT0MGcGpPgpWU7VRdRjuArfcOvC4AoJmILihzhDg= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -302,15 +320,15 @@ golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3 golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0 h1:9sdfJOzWlkqPltHAuzT2Cp+yrBeY1KRVYgms8soxMwM= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.5.0 h1:KxkO13IPW4Lslp2bz+KHP2E3gtFlrIGNThxkZQ3g+4c= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= +google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20181221175505-bd9b4fb69e2f/go.mod h1:7Ep/1NZk928CDR8SjdVbjWNpdIf6nzjE3BTgJDr2Atg= google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= @@ -321,8 +339,13 @@ google.golang.org/genproto v0.0.0-20190716160619-c506a9f90610/go.mod h1:DMBHOl98 google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto v0.0.0-20200806141610-86f49bd18e98 h1:LCO0fg4kb6WwkXQXRQQgUYsFeFb5taTX5WAx5O/Vt28= google.golang.org/genproto v0.0.0-20200806141610-86f49bd18e98/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 h1:L6iMMGrtzgHsWofoFcihmDEMYeDR9KN/ThbPWGrh++g= +google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5/go.mod h1:oH/ZOT02u4kWEp7oYBGYFFkCdKS/uYR9Z7+0/xuuFp8= +google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d h1:DoPTO70H+bcDXcd39vOqb2viZxgqeBeSGtZ55yZU4/Q= +google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d/go.mod h1:KjSP20unUpOx5kyQUFa7k4OJg0qeJ7DEZflGDu2p6Bk= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d h1:uvYuEyMHKNt+lT4K3bN6fGswmK8qSvcreM3BwjDh+y4= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M= google.golang.org/grpc v1.16.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM= @@ -335,8 +358,9 @@ google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTp google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.37.1/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= google.golang.org/grpc v1.39.0/go.mod h1:PImNr+rS9TWYb2O4/emRugxiyHZ5JyHW5F+RPnDzfrE= -google.golang.org/grpc v1.40.0 h1:AGJ0Ih4mHjSeibYkFGh1dD9KJ/eOtZ93I6hoHhukQ5Q= google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34= +google.golang.org/grpc v1.58.0 h1:32JY8YpPMSR45K+c3o6b8VL73V+rR8k+DeMIr4vRH8o= +google.golang.org/grpc v1.58.0/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= google.golang.org/grpc/examples v0.0.0-20210916203835-567da6b86340 h1:ZST99LW/5hCiDvAXb3KZoOwPz1xXbDfU4Gp1TlmX5l4= google.golang.org/grpc/examples v0.0.0-20210916203835-567da6b86340/go.mod h1:gID3PKrg7pWKntu9Ss6zTLJ0ttC0X9IHgREOCZwbCVU= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= @@ -351,8 +375,9 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= +google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/ini.v1 v1.42.0 h1:7N3gPTt50s8GuLortA00n8AqRTk75qOP98+mTPpgzRk= @@ -364,8 +389,9 @@ gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bl gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ= gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= From 479255cdc61cc51b9a7e573420d15d61654d7fb7 Mon Sep 17 00:00:00 2001 From: Alex Arnell Date: Fri, 20 Oct 2023 15:57:46 -0700 Subject: [PATCH 02/12] fix goimports --- cmdutil/debug/debug.go | 15 ++++++++------- go-kit/runtimemetrics/doc.go | 17 ++++++++--------- logplex/encoding/parser.go | 3 ++- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/cmdutil/debug/debug.go b/cmdutil/debug/debug.go index 71753d74..f8a72306 100644 --- a/cmdutil/debug/debug.go +++ b/cmdutil/debug/debug.go @@ -4,12 +4,12 @@ // trace, profile memory, etc. by running the gops command line connected to // locahost:9999 like: // -// $ gops stack localhost:9999 -// goroutine 50 [running]: -// runtime/pprof.writeGoroutineStacks(0x4a18a20, 0xc000010138, 0x0, 0x0) -// /usr/local/Cellar/go/1.13.5/libexec/src/runtime/pprof/pprof.go:679 +0x9d -// runtime/pprof.writeGoroutine(0x4a18a20, 0xc000010138, 0x2, 0x0, 0x0) -// ... +// $ gops stack localhost:9999 +// goroutine 50 [running]: +// runtime/pprof.writeGoroutineStacks(0x4a18a20, 0xc000010138, 0x0, 0x0) +// /usr/local/Cellar/go/1.13.5/libexec/src/runtime/pprof/pprof.go:679 +0x9d +// runtime/pprof.writeGoroutine(0x4a18a20, 0xc000010138, 0x2, 0x0, 0x0) +// ... // // Learn more about gops at https://github.com/google/gops. package debug @@ -24,7 +24,8 @@ import ( // New inializes a debug server listening on the provided port. // // Connect to the debug server with gops: -// gops stack localhost:PORT +// +// gops stack localhost:PORT func New(l logrus.FieldLogger, port int) *Server { return &Server{ logger: l, diff --git a/go-kit/runtimemetrics/doc.go b/go-kit/runtimemetrics/doc.go index a6475de9..1ee5896b 100644 --- a/go-kit/runtimemetrics/doc.go +++ b/go-kit/runtimemetrics/doc.go @@ -3,13 +3,12 @@ // // It collects the following metrics: // -// go.goroutines - number of goroutines -// go.mem.alloc-bytes - allocated bytes for heap objects -// go.mem.sys-bytes - bytes requested from OS (may not all be used) -// go.mem.total-alloc-bytes - cumulative total allocated bytes for heap objects -// go.mem.mallocs - cumultative number of heap allocations -// go.mem.frees - cumultaive number of freed heap objects -// go.gc.pause-duration - histogram of GC pause durations -// go.gc.next-target-heap-size-bytes - target heap size of the next GC cycle -// +// go.goroutines - number of goroutines +// go.mem.alloc-bytes - allocated bytes for heap objects +// go.mem.sys-bytes - bytes requested from OS (may not all be used) +// go.mem.total-alloc-bytes - cumulative total allocated bytes for heap objects +// go.mem.mallocs - cumultative number of heap allocations +// go.mem.frees - cumultaive number of freed heap objects +// go.gc.pause-duration - histogram of GC pause durations +// go.gc.next-target-heap-size-bytes - target heap size of the next GC cycle package runtimemetrics diff --git a/logplex/encoding/parser.go b/logplex/encoding/parser.go index 44815835..d644ced0 100644 --- a/logplex/encoding/parser.go +++ b/logplex/encoding/parser.go @@ -10,9 +10,10 @@ import ( // SyslogSplitFunc splits the data based on the defined length prefix. // format: -//nolint:lll // 64 <190>1 2019-07-20T17:50:10.879238Z shuttle token shuttle - - 99\n65 <190>1 2019-07-20T17:50:10.879238Z shuttle token shuttle - - 100\n // ^ frame size ^ boundary +// +//nolint:lll func SyslogSplitFunc(data []byte, atEOF bool) (advance int, token []byte, err error) { // first space gives us the frame size sp := bytes.IndexByte(data, ' ') From ac8606265c4e30f596fdbe4cbd4bc9d888da6b42 Mon Sep 17 00:00:00 2001 From: Alex Arnell Date: Fri, 20 Oct 2023 15:58:01 -0700 Subject: [PATCH 03/12] migrate to const --- hmiddleware/httpmetrics/httpmetrics.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/hmiddleware/httpmetrics/httpmetrics.go b/hmiddleware/httpmetrics/httpmetrics.go index 4588df7a..f71bac85 100644 --- a/hmiddleware/httpmetrics/httpmetrics.go +++ b/hmiddleware/httpmetrics/httpmetrics.go @@ -14,13 +14,17 @@ import ( "github.com/heroku/x/go-kit/metricsregistry" ) +const ( + prefix = "http.server." +) + // New returns an HTTP middleware which captures request metrics and reports // them to the given provider. func New(p metrics.Provider) func(http.Handler) http.Handler { reg := metricsregistry.New(p) return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - reg.GetOrRegisterCounter("http.server.all.requests").Add(1) + reg.GetOrRegisterCounter(prefix + "all.requests").Add(1) ww := middleware.NewWrapResponseWriter(w, r.ProtoMajor) @@ -35,8 +39,8 @@ func New(p metrics.Provider) func(http.Handler) http.Handler { } sts := strconv.Itoa(st) - reg.GetOrRegisterHistogram("http.server.all.request-duration.ms", 50).Observe(ms(dur)) - reg.GetOrRegisterCounter("http.server.all.response-statuses." + sts).Add(1) + reg.GetOrRegisterHistogram(prefix+"all.request-duration.ms", 50).Observe(ms(dur)) + reg.GetOrRegisterCounter(prefix + "all.response-statuses." + sts).Add(1) ctx := r.Context() if ctx.Value(chi.RouteCtxKey) == nil { @@ -51,9 +55,9 @@ func New(p metrics.Provider) func(http.Handler) http.Handler { // GET /apps/:foo/bars/:baz_id -> get.apps.foo.bars.baz-id met := strings.ToLower(r.Method) + "." + nameRoutePatterns(rtCtx.RoutePatterns) - reg.GetOrRegisterCounter("http.server." + met + ".requests").Add(1) - reg.GetOrRegisterHistogram("http.server."+met+".request-duration.ms", 50).Observe(ms(dur)) - reg.GetOrRegisterCounter("http.server." + met + ".response-statuses." + sts).Add(1) + reg.GetOrRegisterCounter(prefix + met + ".requests").Add(1) + reg.GetOrRegisterHistogram(prefix+met+".request-duration.ms", 50).Observe(ms(dur)) + reg.GetOrRegisterCounter(prefix + met + ".response-statuses." + sts).Add(1) }) } } From 98971dc044ef91aff8767aef03d0f6bbf8166a0f Mon Sep 17 00:00:00 2001 From: Alex Arnell Date: Fri, 20 Oct 2023 15:59:23 -0700 Subject: [PATCH 04/12] more goimports --- hmetrics/hmetrics.go | 18 ++++++++---------- hredis/redigo/redigo_test.go | 9 +++------ 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/hmetrics/hmetrics.go b/hmetrics/hmetrics.go index c7a1868e..d0c2d542 100644 --- a/hmetrics/hmetrics.go +++ b/hmetrics/hmetrics.go @@ -10,7 +10,7 @@ Package hmetrics is a self-contained client for Heroku Go runtime metrics. Typical usage is through the `github.com/heroku/x/hmetrics/onload` package imported like so: - import _ "github.com/heroku/x/hmetrics/onload" + import _ "github.com/heroku/x/hmetrics/onload" You can find more information about Heroku Go runtime metrics here: https://devcenter.heroku.com/articles/language-runtime-metrics-go @@ -36,15 +36,13 @@ const ( interval = 20 * time.Second ) -var ( - // DefaultEndpoint to report metrics to Heroku. The "HEROKU_METRICS_URL" env - // var is set by the Heroku runtime when the `runtime-heroku-metrics` labs - // flag is enabled. For more info see: - // https://devcenter.heroku.com/articles/language-runtime-metrics - // - // DefaultEndpoint must be changed before Report is called. - DefaultEndpoint = os.Getenv("HEROKU_METRICS_URL") -) +// DefaultEndpoint to report metrics to Heroku. The "HEROKU_METRICS_URL" env +// var is set by the Heroku runtime when the `runtime-heroku-metrics` labs +// flag is enabled. For more info see: +// https://devcenter.heroku.com/articles/language-runtime-metrics +// +// DefaultEndpoint must be changed before Report is called. +var DefaultEndpoint = os.Getenv("HEROKU_METRICS_URL") // AlreadyStarted represents an Error condition of already being started. type AlreadyStarted struct{} diff --git a/hredis/redigo/redigo_test.go b/hredis/redigo/redigo_test.go index 7415ae71..0ee9cd86 100644 --- a/hredis/redigo/redigo_test.go +++ b/hredis/redigo/redigo_test.go @@ -22,9 +22,7 @@ func setup(t *testing.T) (*redigomock.Conn, DialURLFunc, func()) { } } -var ( - errInvalidPassword = errors.New("ERR invalid password") -) +var errInvalidPassword = errors.New("ERR invalid password") func TestPoolBadThenGood(t *testing.T) { mock, dialURL, tearDown := setup(t) @@ -103,14 +101,13 @@ func TestPoolWithNoGoodPasses(t *testing.T) { if err := mock.ExpectationsWereMet(); err != nil { t.Fatalf("got %q, want nil", err) } - } // Note: If this test fails, it can leave the redis with a password different than you // expect. Probably best to run redis with a fresh docker container, like so: // -// docker run --rm -p 127.0.0.1:6379:6379 --name test-redis redis -// REDIS_URL=redis://127.0.0.1:6379 go test -count=1 -v ./hredis/... +// docker run --rm -p 127.0.0.1:6379:6379 --name test-redis redis +// REDIS_URL=redis://127.0.0.1:6379 go test -count=1 -v ./hredis/... func TestIntegrationTest(t *testing.T) { redisURL := os.Getenv("REDIS_URL") if redisURL == "" { From 8bd945fb50170ec4101ff63e5d92c858e4ca9d2d Mon Sep 17 00:00:00 2001 From: Alex Arnell Date: Fri, 20 Oct 2023 16:06:09 -0700 Subject: [PATCH 05/12] nolint all the examples --- hmetrics/example/advanced/main.go | 1 + hmetrics/example/basic/main.go | 1 + hmetrics/example/onload/main.go | 1 + hmetrics/examples_test.go | 3 +++ hmiddleware/example_test.go | 4 +++- 5 files changed, 9 insertions(+), 1 deletion(-) diff --git a/hmetrics/example/advanced/main.go b/hmetrics/example/advanced/main.go index 1380816f..8ebedde9 100644 --- a/hmetrics/example/advanced/main.go +++ b/hmetrics/example/advanced/main.go @@ -40,6 +40,7 @@ func main() { if port == "" { port = "8080" } + //nolint: gosec if err := http.ListenAndServe(":"+port, nil); err != nil { log.Panic(err) } diff --git a/hmetrics/example/basic/main.go b/hmetrics/example/basic/main.go index 503befaa..996a8330 100644 --- a/hmetrics/example/basic/main.go +++ b/hmetrics/example/basic/main.go @@ -23,6 +23,7 @@ func main() { if port == "" { port = "8080" } + //nolint: gosec if err := http.ListenAndServe(":"+port, nil); err != nil { log.Fatal(err) } diff --git a/hmetrics/example/onload/main.go b/hmetrics/example/onload/main.go index ab6d43f9..0c65e40c 100644 --- a/hmetrics/example/onload/main.go +++ b/hmetrics/example/onload/main.go @@ -19,6 +19,7 @@ func main() { if port == "" { port = "8080" } + //nolint: gosec if err := http.ListenAndServe(":"+port, nil); err != nil { log.Fatal(err) } diff --git a/hmetrics/examples_test.go b/hmetrics/examples_test.go index 5869c33e..ced48e0a 100644 --- a/hmetrics/examples_test.go +++ b/hmetrics/examples_test.go @@ -22,6 +22,7 @@ func ExampleReport_basic() { if port == "" { port = "8080" } + //nolint: gosec if err := http.ListenAndServe(":"+port, nil); err != nil { log.Fatal(err) } @@ -37,6 +38,7 @@ func ExampleReport_logging() { } }() } + func ExampleReport_advanced() { ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -62,6 +64,7 @@ func ExampleReport_advanced() { if port == "" { port = "8080" } + //nolint: gosec if err := http.ListenAndServe(":"+port, nil); err != nil { log.Panic(err) } diff --git a/hmiddleware/example_test.go b/hmiddleware/example_test.go index 5c01c21e..6c6229e4 100644 --- a/hmiddleware/example_test.go +++ b/hmiddleware/example_test.go @@ -25,6 +25,7 @@ func ExampleCORS() { var h http.Handler + //nolint: gosec if err := http.ListenAndServe(":"+os.Getenv("PORT"), CORS(h)); err != nil { log.Fatal(err) } @@ -38,6 +39,7 @@ func ExampleDisableKeepalive() { var h http.Handler + //nolint: gosec if err := http.ListenAndServe(":"+os.Getenv("PORT"), DisableKeepalive(h)); err != nil { log.Fatal(err) } @@ -51,6 +53,7 @@ func ExampleEnsureTLS() { var h http.Handler + //nolint: gosec if err := http.ListenAndServe(":"+os.Getenv("PORT"), EnsureTLS(h)); err != nil { log.Fatal(err) } @@ -70,5 +73,4 @@ func ExampleTags() { tags.Extract(r.Context()).Set("foo", "bar") w.WriteHeader(http.StatusOK) }) - } From 52ed954b15ab7bce5e8ae7e5b28cc37923d5b491 Mon Sep 17 00:00:00 2001 From: Alex Arnell Date: Fri, 20 Oct 2023 16:11:14 -0700 Subject: [PATCH 06/12] fixing goimports --- cmd/protoc-gen-loggingtags/doc.go | 20 ++++++++-------- cmd/protoc-gen-loggingtags/golden_test.go | 2 +- grpc/grpchealthcheck/streaminterceptor.go | 5 ++-- grpc/grpcmetrics/doc.go | 29 +++++++++++------------ grpc/grpcserver/payload.go | 6 ++--- hmetrics/onload/init.go | 7 +++--- hmiddleware/httpmetrics/doc.go | 15 ++++++------ tlsconfig/tlsconfig.go | 16 ++++++------- 8 files changed, 48 insertions(+), 52 deletions(-) diff --git a/cmd/protoc-gen-loggingtags/doc.go b/cmd/protoc-gen-loggingtags/doc.go index 5dd011c0..27206881 100644 --- a/cmd/protoc-gen-loggingtags/doc.go +++ b/cmd/protoc-gen-loggingtags/doc.go @@ -3,21 +3,21 @@ // // For example, the following proto file: // -// syntax = "proto3"; -// import "github.com/heroku/x/loggingtags/safe.proto"; +// syntax = "proto3"; +// import "github.com/heroku/x/loggingtags/safe.proto"; // -// package loggingtags.examples; +// package loggingtags.examples; // -// message Sample { -// string safe = 1 [(heroku.loggingtags.safe) = true]; -// string unsafe = 2; -// } +// message Sample { +// string safe = 1 [(heroku.loggingtags.safe) = true]; +// string unsafe = 2; +// } // // will generate a method on the Sample type which implements // -// type loggable interface{ -// LoggingTags() map[string]interface{} -// } +// type loggable interface{ +// LoggingTags() map[string]interface{} +// } // // Calling the LoggingTags() method on Sample will return only the name and // value of the `safe` field. diff --git a/cmd/protoc-gen-loggingtags/golden_test.go b/cmd/protoc-gen-loggingtags/golden_test.go index 72dab29e..d43c01ba 100644 --- a/cmd/protoc-gen-loggingtags/golden_test.go +++ b/cmd/protoc-gen-loggingtags/golden_test.go @@ -105,7 +105,7 @@ func TestSample(t *testing.T) { "--proto_path=" + filepath.Join("internal", "test"), "--proto_path=.", "--loggingtags_out=" + workdir, - filepath.Join("sample.proto"), + "sample.proto", }) goldenPath := filepath.Join("internal", "test", "sample.pb.loggingtags.go") diff --git a/grpc/grpchealthcheck/streaminterceptor.go b/grpc/grpchealthcheck/streaminterceptor.go index b1aedfab..67226402 100644 --- a/grpc/grpchealthcheck/streaminterceptor.go +++ b/grpc/grpchealthcheck/streaminterceptor.go @@ -13,9 +13,8 @@ import ( // which performs server health checks on the given interval // for any stream which is initiated. // -// health := grpchealthcheck.NewStreamInterceptor(30 * time.Second) -// conn, _ := grpc.Dial("server", grpc.WithStreamInterceptor(health)) -// +// health := grpchealthcheck.NewStreamInterceptor(30 * time.Second) +// conn, _ := grpc.Dial("server", grpc.WithStreamInterceptor(health)) func NewStreamInterceptor(interval time.Duration) grpc.StreamClientInterceptor { return func(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (grpc.ClientStream, error) { stream, err := streamer(ctx, desc, cc, method, opts...) diff --git a/grpc/grpcmetrics/doc.go b/grpc/grpcmetrics/doc.go index b576279b..188ed09d 100644 --- a/grpc/grpcmetrics/doc.go +++ b/grpc/grpcmetrics/doc.go @@ -2,28 +2,27 @@ // // Metrics are prefixed with: // -// grpc.{server,client}.. +// grpc.{server,client}.. // // For example: // -// grpc.server.domain-streamer.put-domain -// grpc.client.domain-streamer.stream-updates +// grpc.server.domain-streamer.put-domain +// grpc.client.domain-streamer.stream-updates // // For each endpoint, clients and servers will report: // -// requests - counter of requests -// request-duration.ms - histogram of request durations in milliseconds -// errors - counter of requests which result in errors -// response-codes. - counter of grpc response codes +// requests - counter of requests +// request-duration.ms - histogram of request durations in milliseconds +// errors - counter of requests which result in errors +// response-codes. - counter of grpc response codes // // In addition to these metrics, streams will also report: // -// stream.clients - gauge of connected clients -// stream.sends - counter of sent messages -// stream.sends.errors - counter of message send errors -// stream.send-duration.ms - histogram of send durations in milliseconds -// stream.recvs - counter of received messages -// stream.recvs.errors - counter of message recv errors -// stream.recv-duration.ms - histogram of recv durations in milliseconds -// +// stream.clients - gauge of connected clients +// stream.sends - counter of sent messages +// stream.sends.errors - counter of message send errors +// stream.send-duration.ms - histogram of send durations in milliseconds +// stream.recvs - counter of received messages +// stream.recvs.errors - counter of message recv errors +// stream.recv-duration.ms - histogram of recv durations in milliseconds package grpcmetrics diff --git a/grpc/grpcserver/payload.go b/grpc/grpcserver/payload.go index ab15e29b..9a733909 100644 --- a/grpc/grpcserver/payload.go +++ b/grpc/grpcserver/payload.go @@ -13,9 +13,9 @@ import ( // // A loggable request or response implements this interface // -// type loggable interface { -// LoggingTags() map[string]interface{} -// } +// type loggable interface { +// LoggingTags() map[string]interface{} +// } // // Any request or response implementing this interface will add tags to the // context for logging in success and error cases. diff --git a/hmetrics/onload/init.go b/hmetrics/onload/init.go index b59dc3c9..06433f94 100644 --- a/hmetrics/onload/init.go +++ b/hmetrics/onload/init.go @@ -18,13 +18,12 @@ information). usage: - import ( - _ "github.com/heroku/x/hmetrics/onload" - ) + import ( + _ "github.com/heroku/x/hmetrics/onload" + ) See the package documentation at https://godoc.org/github.com/heroku/x/hmetrics for more info about Heroku Go metrics and advanced usage. - */ package onload diff --git a/hmiddleware/httpmetrics/doc.go b/hmiddleware/httpmetrics/doc.go index b3a3d009..711ec27d 100644 --- a/hmiddleware/httpmetrics/doc.go +++ b/hmiddleware/httpmetrics/doc.go @@ -2,18 +2,17 @@ // // Metrics are prefixed with: // -// http.server.. -// http.server.all +// http.server.. +// http.server.all // // For example, a request to GET /apps/:foo/bars/:bar_id emits metrics prefixed with: // -// http.server.get.apps.foo.bars.bar-id -// http.server.all +// http.server.get.apps.foo.bars.bar-id +// http.server.all // // For each unique path, and under the global all prefix, servers will report: // -// requests - counter of requests -// request-duration.ms - histogram of request durations in milliseconds -// response-statuses. - counter of response status codes, eg 200 -// +// requests - counter of requests +// request-duration.ms - histogram of request durations in milliseconds +// response-statuses. - counter of response status codes, eg 200 package httpmetrics diff --git a/tlsconfig/tlsconfig.go b/tlsconfig/tlsconfig.go index fa506517..7e31d6e3 100644 --- a/tlsconfig/tlsconfig.go +++ b/tlsconfig/tlsconfig.go @@ -5,18 +5,18 @@ // See https://wiki.mozilla.org/Security/Server_Side_TLS // // Prioritized by: -// Key Ex: ECDHE > DH > RSA -// Enc: CHACHA20 > AES-GCM > AES-CBC > 3DES -// MAC: AEAD > SHA256 > SHA384 > SHA1 (SHA) -// AES: 128 > 256 -// Cert Sig: ECDSA > RSA +// +// Key Ex: ECDHE > DH > RSA +// Enc: CHACHA20 > AES-GCM > AES-CBC > 3DES +// MAC: AEAD > SHA256 > SHA384 > SHA1 (SHA) +// AES: 128 > 256 +// Cert Sig: ECDSA > RSA // // Modern: strongest ciphers (PFS-only) & latest TLS version(s) // Default: mix of various strength ciphers & recent TLS versions // Strict: deprecated, Default plus ECDHE+RSA+AES{128,256}+CBC+SHA1 for IE 11 // Legacy: many ciphers & TLS versions for maximum compatibility, less secure // SFAllowed: provides only the ciphers allowed according to SFSS-151. -// package tlsconfig import ( @@ -313,11 +313,11 @@ func (c *CA) NewLeaf(config LeafConfig) (*tls.Certificate, error) { } unsignedCert.ExtraExtensions = []pkix.Extension{ - pkix.Extension{ + { Id: InstanceIdentityDocOID, Value: b64(gz(iid.Doc)), }, - pkix.Extension{ + { Id: InstanceIdentitySigOID, Value: b64(iid.Sig), }, From 39fa353734c25d4a53230a968906500008f7a887 Mon Sep 17 00:00:00 2001 From: Alex Arnell Date: Mon, 23 Oct 2023 10:16:49 -0700 Subject: [PATCH 07/12] fix slowloris and other deprecations --- cmdutil/service/config.go | 8 +++++ cmdutil/service/standard_http.go | 45 +++++++++++++++++---------- cmdutil/service/standard_http_test.go | 14 ++++----- grpc/grpcserver/options.go | 22 +++++++++++-- grpc/grpcserver/server.go | 7 +++-- tlsconfig/tlsconfig.go | 6 ++++ 6 files changed, 74 insertions(+), 28 deletions(-) diff --git a/cmdutil/service/config.go b/cmdutil/service/config.go index f367e9f3..2685d4b9 100644 --- a/cmdutil/service/config.go +++ b/cmdutil/service/config.go @@ -2,6 +2,7 @@ package service import ( "net/url" + "time" "github.com/heroku/x/cmdutil/debug" "github.com/heroku/x/cmdutil/metrics" @@ -80,3 +81,10 @@ type spaceCAConfig struct { // Domain of the service used in the generation of the cert Domain string `env:"DOMAIN"` } + +type timeoutConfig struct { + Read time.Duration `env:"SERVER_READ_TIMEOUT"` + ReadHeader time.Duration `env:"SERVER_READ_HEADER_TIMEOUT,default=30s"` + Write time.Duration `env:"SERVER_WRITE_TIMEOUT"` + Idle time.Duration `env:"SERVER_IDLE_TIMEOUT"` +} diff --git a/cmdutil/service/standard_http.go b/cmdutil/service/standard_http.go index f2b211bd..30d2ff55 100644 --- a/cmdutil/service/standard_http.go +++ b/cmdutil/service/standard_http.go @@ -24,6 +24,7 @@ import ( type httpConfig struct { Platform platformConfig Bypass bypassConfig + Timeouts timeoutConfig } // HTTP returns a standard HTTP server for the provided handler. Port, TLS, and @@ -44,28 +45,29 @@ func HTTP(l logrus.FieldLogger, m metrics.Provider, h http.Handler, opts ...func var srvs []cmdutil.Server if cfg.Platform.Port != 0 { - s := &http.Server{ - Handler: h, - Addr: fmt.Sprintf(":%d", cfg.Platform.Port), - } + + s := httpServerWithTimeouts(cfg.Timeouts) + s.Handler = h + s.Addr = fmt.Sprintf(":%d", cfg.Platform.Port) o.configureServer(s) srvs = append(srvs, standardServer(l, s)) } if cfg.Platform.AdditionalPort != 0 { - s := &http.Server{ - Handler: h, - Addr: fmt.Sprintf(":%d", cfg.Platform.AdditionalPort), - } + s := httpServerWithTimeouts(cfg.Timeouts) + + s.Handler = h + s.Addr = fmt.Sprintf(":%d", cfg.Platform.AdditionalPort) o.configureServer(s) srvs = append(srvs, standardServer(l, s)) } if cfg.Bypass.InsecurePort != 0 { - s := &http.Server{ - Handler: h, - Addr: fmt.Sprintf(":%d", cfg.Bypass.InsecurePort), - } + + s := httpServerWithTimeouts(cfg.Timeouts) + s.Handler = h + s.Addr = fmt.Sprintf(":%d", cfg.Bypass.InsecurePort) + o.configureServer(s) srvs = append(srvs, bypassServer(l, s)) } @@ -76,11 +78,11 @@ func HTTP(l logrus.FieldLogger, m metrics.Provider, h http.Handler, opts ...func tlsConfig = newTLSConfig(cfg.Bypass.TLS) } - s := &http.Server{ - Handler: h, - Addr: fmt.Sprintf(":%d", cfg.Bypass.SecurePort), - TLSConfig: tlsConfig, - } + s := httpServerWithTimeouts(cfg.Timeouts) + s.Handler = h + s.TLSConfig = tlsConfig + s.Addr = fmt.Sprintf(":%d", cfg.Bypass.SecurePort) + o.configureServer(s) srvs = append(srvs, bypassServer(l, s)) } @@ -94,6 +96,15 @@ func HTTP(l logrus.FieldLogger, m metrics.Provider, h http.Handler, opts ...func return cmdutil.MultiServer(srvs...) } +func httpServerWithTimeouts(t timeoutConfig) *http.Server { + return &http.Server{ + ReadTimeout: t.Read, + ReadHeaderTimeout: t.ReadHeader, + WriteTimeout: t.Write, + IdleTimeout: t.Idle, + } +} + type httpOptions struct { skipEnforceHTTPS bool tlsConfig *tls.Config diff --git a/cmdutil/service/standard_http_test.go b/cmdutil/service/standard_http_test.go index 8bbffa81..33c84b56 100644 --- a/cmdutil/service/standard_http_test.go +++ b/cmdutil/service/standard_http_test.go @@ -3,7 +3,6 @@ package service import ( "bufio" "io" - "io/ioutil" "net" "net/http" "os" @@ -15,8 +14,9 @@ import ( func TestStandardHTTPServer(t *testing.T) { l, _ := testlog.New() + //nolint: gosec srv := &http.Server{ - Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + Handler: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { if _, err := io.WriteString(w, "OK"); err != nil { t.Error(err) } @@ -45,7 +45,7 @@ func TestStandardHTTPServer(t *testing.T) { } defer res.Body.Close() - data, _ := ioutil.ReadAll(res.Body) + data, _ := io.ReadAll(res.Body) if string(data) != "OK" { t.Fatalf("want OK got %v", string(data)) } @@ -57,8 +57,9 @@ func TestStandardHTTPServer(t *testing.T) { func TestBypassHTTPServer(t *testing.T) { l, _ := testlog.New() + //nolint: gosec srv := &http.Server{ - Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + Handler: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { if _, err := io.WriteString(w, "OK"); err != nil { t.Error(err) } @@ -86,8 +87,7 @@ func TestBypassHTTPServer(t *testing.T) { } defer conn.Close() - _, err = io.WriteString(conn, "PROXY TCP4 127.0.0.1 127.0.0.1 44444 55555\n") - if err != nil { + if _, err = io.WriteString(conn, "PROXY TCP4 127.0.0.1 127.0.0.1 44444 55555\n"); err != nil { t.Fatal(err) } @@ -103,7 +103,7 @@ func TestBypassHTTPServer(t *testing.T) { } defer res.Body.Close() - data, _ := ioutil.ReadAll(res.Body) + data, _ := io.ReadAll(res.Body) if string(data) != "OK" { t.Fatalf("want OK got %v", string(data)) } diff --git a/grpc/grpcserver/options.go b/grpc/grpcserver/options.go index db44a115..de971629 100644 --- a/grpc/grpcserver/options.go +++ b/grpc/grpcserver/options.go @@ -4,6 +4,7 @@ import ( "context" "crypto/tls" "crypto/x509" + "time" grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware" grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" @@ -21,6 +22,10 @@ import ( "github.com/heroku/x/tlsconfig" ) +const ( + defaultReadHeaderTimeout = 60 * time.Second +) + var defaultLogOpts = []grpc_logrus.Option{ grpc_logrus.WithCodes(ErrorToCode), } @@ -32,12 +37,19 @@ type options struct { authStreamInterceptor grpc.StreamServerInterceptor highCardUnaryInterceptor grpc.UnaryServerInterceptor highCardStreamInterceptor grpc.StreamServerInterceptor + readHeaderTimeout time.Duration useValidateInterceptor bool grpcOptions []grpc.ServerOption } +func defaultOptions() options { + return options{ + readHeaderTimeout: defaultReadHeaderTimeout, + } +} + // ServerOption sets optional fields on the standard gRPC server type ServerOption func(*options) @@ -88,6 +100,12 @@ func WithOCGRPCServerHandler(h *ocgrpc.ServerHandler) ServerOption { } } +func WithReadHeaderTimeout(d time.Duration) ServerOption { + return func(o *options) { + o.readHeaderTimeout = d + } +} + // ValidateInterceptor sets interceptors that will validate every // message that has a receiver of the form `Validate() error` // @@ -207,12 +225,12 @@ func WithPeerValidator(f func(*x509.Certificate) bool) ServerOption { func validatePeer(ctx context.Context, f func(*x509.Certificate) bool) error { cert, ok := getPeerCertFromContext(ctx) if !ok { - //TODO: SA1019: grpc.Errorf is deprecated: use status.Errorf instead. (staticcheck) + // TODO: SA1019: grpc.Errorf is deprecated: use status.Errorf instead. (staticcheck) return grpc.Errorf(codes.Unauthenticated, "unauthenticated") //nolint:staticcheck } if !f(cert) { - //TODO: SA1019: grpc.Errorf is deprecated: use status.Errorf instead. (staticcheck) + // TODO: SA1019: grpc.Errorf is deprecated: use status.Errorf instead. (staticcheck) return grpc.Errorf(codes.PermissionDenied, "forbidden") //nolint:staticcheck } diff --git a/grpc/grpcserver/server.go b/grpc/grpcserver/server.go index 1c853759..65e5c869 100644 --- a/grpc/grpcserver/server.go +++ b/grpc/grpcserver/server.go @@ -84,7 +84,7 @@ func NewStandardServer(logger log.FieldLogger, port int, serverCACerts [][]byte, // standard set of services, and a HTTP server that should be what is served on // a listener. func NewStandardH2C(http11 http.Handler, opts ...ServerOption) (*grpc.Server, *http.Server) { - var o options + o := defaultOptions() for _, so := range opts { so(&o) } @@ -98,7 +98,10 @@ func NewStandardH2C(http11 http.Handler, opts ...ServerOption) (*grpc.Server, *h NonUpgradeHandler: http11, } - hSrv := &http.Server{Handler: h2cSrv} + hSrv := &http.Server{ + Handler: h2cSrv, + ReadHeaderTimeout: o.readHeaderTimeout, + } return gSrv, hSrv } diff --git a/tlsconfig/tlsconfig.go b/tlsconfig/tlsconfig.go index 7e31d6e3..fb81f537 100644 --- a/tlsconfig/tlsconfig.go +++ b/tlsconfig/tlsconfig.go @@ -120,6 +120,7 @@ var ( func Legacy(config *tls.Config) { config.CipherSuites = LegacyCiphers config.MinVersion = tls.VersionTLS10 + //nolint: staticcheck config.PreferServerCipherSuites = true } @@ -127,6 +128,7 @@ func Legacy(config *tls.Config) { func Default(config *tls.Config) { config.CipherSuites = DefaultCiphers config.MinVersion = tls.VersionTLS11 + //nolint: staticcheck config.PreferServerCipherSuites = true } @@ -136,6 +138,7 @@ func Default(config *tls.Config) { func DefaultCommonRuntime(config *tls.Config) { config.CipherSuites = DefaultCiphers config.MinVersion = tls.VersionTLS10 + //nolint: staticcheck config.PreferServerCipherSuites = true } @@ -143,6 +146,7 @@ func DefaultCommonRuntime(config *tls.Config) { func Modern(config *tls.Config) { config.CipherSuites = ModernCiphers config.MinVersion = tls.VersionTLS12 + //nolint: staticcheck config.PreferServerCipherSuites = true } @@ -150,6 +154,7 @@ func Modern(config *tls.Config) { func Strict(config *tls.Config) { config.CipherSuites = StrictCiphers config.MinVersion = tls.VersionTLS13 + //nolint: staticcheck config.PreferServerCipherSuites = true } @@ -157,6 +162,7 @@ func Strict(config *tls.Config) { func SFAllowed(config *tls.Config) { config.CipherSuites = SFCiphers config.MinVersion = tls.VersionTLS12 + //nolint: staticcheck config.PreferServerCipherSuites = true } From ca4df2d73b3bbf86f1b4c177d605c77480ecd756 Mon Sep 17 00:00:00 2001 From: Alex Arnell Date: Mon, 23 Oct 2023 10:43:44 -0700 Subject: [PATCH 08/12] remove uses of ioutil --- cmd/protoc-gen-loggingtags/golden_test.go | 5 ++--- cmd/protoc-gen-loggingtags/internal/gen/generate.go | 6 +++++- cmd/protoc-gen-loggingtags/main.go | 4 ++-- cmd/s3env/main.go | 7 ++----- cmdutil/hypercmd/hyper.go | 7 +++---- cmdutil/svclog/logger.go | 4 ++-- grpc/h2c_e2e_test.go | 4 ++-- healthcheck/tcpserver_test.go | 4 ++-- hmiddleware/logger_test.go | 9 ++------- logplex/encoding/encoder_test.go | 8 +++----- testing/mustcert/example_test.go | 5 ++--- testing/testlog/testlog.go | 4 ++-- 12 files changed, 29 insertions(+), 38 deletions(-) diff --git a/cmd/protoc-gen-loggingtags/golden_test.go b/cmd/protoc-gen-loggingtags/golden_test.go index d43c01ba..309abd4f 100644 --- a/cmd/protoc-gen-loggingtags/golden_test.go +++ b/cmd/protoc-gen-loggingtags/golden_test.go @@ -1,7 +1,6 @@ package main import ( - "io/ioutil" "os" "os/exec" "path/filepath" @@ -60,7 +59,7 @@ func TestGenerate(t *testing.T) { }, } { t.Run(tt.name, func(t *testing.T) { - workdir, err := ioutil.TempDir("", "proto-test") + workdir, err := os.MkdirTemp("", "proto-test") if err != nil { t.Fatal(err) } @@ -95,7 +94,7 @@ func TestGenerate(t *testing.T) { } func TestSample(t *testing.T) { - workdir, err := ioutil.TempDir("", "proto-test") + workdir, err := os.MkdirTemp("", "proto-test") if err != nil { t.Fatal(err) } diff --git a/cmd/protoc-gen-loggingtags/internal/gen/generate.go b/cmd/protoc-gen-loggingtags/internal/gen/generate.go index cfb190d3..8b7deff0 100644 --- a/cmd/protoc-gen-loggingtags/internal/gen/generate.go +++ b/cmd/protoc-gen-loggingtags/internal/gen/generate.go @@ -8,6 +8,8 @@ import ( "unicode" plugin "github.com/golang/protobuf/protoc-gen-go/plugin" + "golang.org/x/text/cases" + "golang.org/x/text/language" "google.golang.org/protobuf/proto" "google.golang.org/protobuf/types/pluginpb" @@ -160,8 +162,10 @@ func toCamelCase(str string) string { s := strings.FieldsFunc(str, split) cc := make([]string, len(s)) + caser := cases.Title(language.AmericanEnglish) + for _, word := range s { - cc = append(cc, strings.Title(word)) + cc = append(cc, caser.String(word)) } return strings.Join(cc, "") diff --git a/cmd/protoc-gen-loggingtags/main.go b/cmd/protoc-gen-loggingtags/main.go index 8a39cccf..61c0740d 100644 --- a/cmd/protoc-gen-loggingtags/main.go +++ b/cmd/protoc-gen-loggingtags/main.go @@ -2,7 +2,7 @@ package main import ( "flag" - "io/ioutil" + "io" "log" "os" "strings" @@ -21,7 +21,7 @@ func main() { if *file != "stdin" { f, _ = os.Open("input.txt") } - input, err := ioutil.ReadAll(f) + input, err := io.ReadAll(f) if err != nil { log.Fatal(err) } diff --git a/cmd/s3env/main.go b/cmd/s3env/main.go index 793b4bff..ad1a2fe3 100644 --- a/cmd/s3env/main.go +++ b/cmd/s3env/main.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "os" "strings" @@ -59,7 +58,7 @@ PREREQUISITES S3ENV_AWS_ACCESS_KEY_ID S3ENV_AWS_REGION S3ENV_AWS_SECRET_ACCESS_KEY - + EXAMPLES s3env config # show all config vars s3env config:set FOO=1 BAR=2 # set two vars @@ -99,7 +98,6 @@ func loadS3Object() { "", ), }) - if err != nil { fmt.Printf("s3env: aws error: %s\n", err) return @@ -166,7 +164,6 @@ func persistVars() error { Body: bytes.NewReader(buf.Bytes()), ServerSideEncryption: aws.String(cfg.ServerSideEncryption), }) - if err != nil { return fmt.Errorf("saving to s3 failed with error: %s", err) } @@ -189,7 +186,7 @@ func input() (io.ReadCloser, error) { buf := new(bytes.Buffer) buf.Write([]byte("{}")) - return ioutil.NopCloser(buf), nil + return io.NopCloser(buf), nil } return nil, err } diff --git a/cmdutil/hypercmd/hyper.go b/cmdutil/hypercmd/hyper.go index f52e8d51..8de6dc18 100644 --- a/cmdutil/hypercmd/hyper.go +++ b/cmdutil/hypercmd/hyper.go @@ -5,7 +5,6 @@ package hypercmd import ( "encoding/json" - "io/ioutil" "os" "github.com/pkg/errors" @@ -19,7 +18,7 @@ func New(name string, fn func()) cli.Command { Name: name, Usage: "Run " + name, Before: serviceEnvLoader(name), - Action: func(c *cli.Context) error { + Action: func(_ *cli.Context) error { fn() return nil }, @@ -29,8 +28,8 @@ func New(name string, fn func()) cli.Command { // serviceEnvLoader will load JSON-format environment files before executing // the service function. func serviceEnvLoader(name string) cli.BeforeFunc { - return func(c *cli.Context) error { - data, err := ioutil.ReadFile(".env." + name) + return func(_ *cli.Context) error { + data, err := os.ReadFile(".env." + name) if err != nil { if os.IsNotExist(err) { return nil diff --git a/cmdutil/svclog/logger.go b/cmdutil/svclog/logger.go index de7f2e0b..29761dd8 100644 --- a/cmdutil/svclog/logger.go +++ b/cmdutil/svclog/logger.go @@ -2,7 +2,7 @@ package svclog import ( - "io/ioutil" + "io" "strings" "time" @@ -95,7 +95,7 @@ func (sl saramaLogger) Printf(format string, args ...interface{}) { // NewNullLogger returns a logger that discards the output useful for testing func NewNullLogger() logrus.FieldLogger { logger := logrus.New() - logger.SetOutput(ioutil.Discard) + logger.SetOutput(io.Discard) return logger } diff --git a/grpc/h2c_e2e_test.go b/grpc/h2c_e2e_test.go index 7c814526..45e69228 100644 --- a/grpc/h2c_e2e_test.go +++ b/grpc/h2c_e2e_test.go @@ -3,7 +3,7 @@ package grpc import ( "context" "fmt" - "io/ioutil" + "io" "net" "net/http" "testing" @@ -51,7 +51,7 @@ func TestH2CContextE2E(t *testing.T) { } defer resp.Body.Close() - bb, err := ioutil.ReadAll(resp.Body) + bb, err := io.ReadAll(resp.Body) if err != nil { t.Errorf("Error reading HTTP/1.1 call to H2C Server body [%+v]", err) } diff --git a/healthcheck/tcpserver_test.go b/healthcheck/tcpserver_test.go index 1633ce7e..e1740072 100644 --- a/healthcheck/tcpserver_test.go +++ b/healthcheck/tcpserver_test.go @@ -1,7 +1,7 @@ package healthcheck import ( - "io/ioutil" + "io" "net" "testing" "time" @@ -37,7 +37,7 @@ func TestTCPServer(t *testing.T) { t.Fatal("unexpected error", err) } - data, err := ioutil.ReadAll(conn) + data, err := io.ReadAll(conn) if err != nil { t.Fatal(err) } diff --git a/hmiddleware/logger_test.go b/hmiddleware/logger_test.go index 23d79c5e..22137810 100644 --- a/hmiddleware/logger_test.go +++ b/hmiddleware/logger_test.go @@ -1,7 +1,7 @@ package hmiddleware import ( - "io/ioutil" + "io" "net/http" "net/http/httptest" "testing" @@ -18,7 +18,6 @@ func TestPreRequestLogger(t *testing.T) { handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) _, err := w.Write([]byte("ok")) - if err != nil { t.Fatal(err) } @@ -55,7 +54,6 @@ func TestPreRequestLoggerDoesNotDoubleWrapTheResponseWriter(t *testing.T) { w.WriteHeader(http.StatusOK) _, err := w.Write([]byte("ok")) - if err != nil { t.Fatal(err) } @@ -82,7 +80,6 @@ func TestPostRequestLogger(t *testing.T) { handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) _, err := w.Write([]byte("ok")) - if err != nil { t.Fatal(err) } @@ -119,7 +116,6 @@ func TestPostRequestLoggerDoesNotDoubleWrapTheResponseWriter(t *testing.T) { w.WriteHeader(http.StatusOK) _, err := w.Write([]byte("ok")) - if err != nil { t.Fatal(err) } @@ -190,7 +186,7 @@ func runPostRequestLoggerTest(t testing.TB, h http.Handler, hook *testlog.Hook) t.Fatalf("StatusCode = %v, want %v", rsp.StatusCode, http.StatusOK) } - if data, _ := ioutil.ReadAll(rsp.Body); string(data) != "ok" { + if data, _ := io.ReadAll(rsp.Body); string(data) != "ok" { t.Fatalf("Body = %v, want %v", string(data), "ok") } @@ -219,7 +215,6 @@ func TestRobotAllLogger(t *testing.T) { handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) _, err := w.Write([]byte("ok")) - if err != nil { t.Fatal(err) } diff --git a/logplex/encoding/encoder_test.go b/logplex/encoding/encoder_test.go index 26b5ebc9..83e8690c 100644 --- a/logplex/encoding/encoder_test.go +++ b/logplex/encoding/encoder_test.go @@ -1,13 +1,11 @@ package encoding import ( + "bytes" "io" - "io/ioutil" "testing" "time" - "bytes" - "github.com/pkg/errors" ) @@ -31,7 +29,7 @@ func TestEncode(t *testing.T) { Timestamp: lockedDate, Message: "hi", }, - writer: ioutil.Discard, + writer: io.Discard, msgSize: int64(77), // "74 " }, @@ -45,7 +43,7 @@ func TestEncode(t *testing.T) { Timestamp: lockedDate, Message: "hi", }, - writer: ioutil.Discard, + writer: io.Discard, err: ErrInvalidMessage, }, diff --git a/testing/mustcert/example_test.go b/testing/mustcert/example_test.go index f9987581..284bc18f 100644 --- a/testing/mustcert/example_test.go +++ b/testing/mustcert/example_test.go @@ -3,7 +3,7 @@ package mustcert import ( "crypto/tls" "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" ) @@ -43,7 +43,6 @@ func Example() { RootCAs: caCertPool, InsecureSkipVerify: true, } - config.BuildNameToCertificate() // Create the HTTP Client client := &http.Client{ @@ -59,7 +58,7 @@ func Example() { } defer resp.Body.Close() - bodyBytes, err := ioutil.ReadAll(resp.Body) + bodyBytes, err := io.ReadAll(resp.Body) if err != nil { fmt.Println(err) } diff --git a/testing/testlog/testlog.go b/testing/testlog/testlog.go index 30153dbc..d351ff45 100644 --- a/testing/testlog/testlog.go +++ b/testing/testlog/testlog.go @@ -3,7 +3,7 @@ package testlog import ( "fmt" - "io/ioutil" + "io" "strconv" "strings" "sync" @@ -22,7 +22,7 @@ type Hook struct { // observe and make assertions about what was logged. func New() (*logrus.Logger, *Hook) { l := logrus.New() - l.Out = ioutil.Discard + l.Out = io.Discard hook := new(Hook) l.Hooks.Add(hook) From f2683376598322d8d05a7d5b83e9bdc325497535 Mon Sep 17 00:00:00 2001 From: Alex Arnell Date: Mon, 23 Oct 2023 10:54:47 -0700 Subject: [PATCH 09/12] remove grpc.WithInsecure --- grpc/grpcclient/h2c.go | 4 ++-- grpc/grpcserver/inprocess.go | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/grpc/grpcclient/h2c.go b/grpc/grpcclient/h2c.go index 7852b046..4ee8f5d2 100644 --- a/grpc/grpcclient/h2c.go +++ b/grpc/grpcclient/h2c.go @@ -10,6 +10,7 @@ import ( "github.com/lstoll/grpce/h2c" "github.com/pkg/errors" "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" ) // DialH2CContext will establish a connection to the grpcserver.NewStandardH2C server @@ -24,7 +25,7 @@ func DialH2CContext(ctx context.Context, serverURL string, opts ...grpc.DialOpti opts = append(opts, grpc.WithContextDialer(h2c.Dialer{URL: u}.DialGRPCContext), // TLS is done at the HTTP/1.1 level, so we never know.... - grpc.WithInsecure(), + grpc.WithTransportCredentials(insecure.NewCredentials()), ) port := u.Port() @@ -41,7 +42,6 @@ func DialH2CContext(ctx context.Context, serverURL string, opts ...grpc.DialOpti return nil, errors.Wrap(err, "Error dialing server") } return conn, nil - } // DialH2C will establish a connection to the grpcserver.NewStandardH2C server diff --git a/grpc/grpcserver/inprocess.go b/grpc/grpcserver/inprocess.go index 435627be..4d084053 100644 --- a/grpc/grpcserver/inprocess.go +++ b/grpc/grpcserver/inprocess.go @@ -6,6 +6,7 @@ import ( "github.com/hydrogen18/memlistener" "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" ) // Local returns an in-process server for the provided gRPC server. @@ -43,7 +44,7 @@ func (s *LocalServer) Conn(opts ...grpc.DialOption) *grpc.ClientConn { grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) { //nolint:staticcheck return s.ln.Dial("mem", "") }), - grpc.WithInsecure(), + grpc.WithTransportCredentials(insecure.NewCredentials()), } conn, _ := grpc.Dial("", append(defaultOptions, opts...)...) From 512a52a8d81e36c402c85935d384beebc88e170a Mon Sep 17 00:00:00 2001 From: Alex Arnell Date: Mon, 23 Oct 2023 10:55:03 -0700 Subject: [PATCH 10/12] no longer need to seed random --- cmdutil/service/standard.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/cmdutil/service/standard.go b/cmdutil/service/standard.go index 4464a6dc..8198a077 100644 --- a/cmdutil/service/standard.go +++ b/cmdutil/service/standard.go @@ -1,10 +1,8 @@ package service import ( - "math/rand" "strings" "syscall" - "time" "github.com/joeshaw/envdecode" "github.com/oklog/run" @@ -37,10 +35,6 @@ type Standard struct { // If appConfig is non-nil, envdecode.MustStrictDecode will be called on it // to ensure that it is processed. func New(appConfig interface{}, ofs ...OptionFunc) *Standard { - // Initialize the pseudo-random number generator with a unique value so we - // get unique sequences across runs. - rand.Seed(time.Now().UnixNano()) - var sc standardConfig envdecode.MustStrictDecode(&sc) From d919a9d28ae1f56c2dfe8a788bf8b6abb89e3ff1 Mon Sep 17 00:00:00 2001 From: Alex Arnell Date: Mon, 23 Oct 2023 11:00:21 -0700 Subject: [PATCH 11/12] Temporary is deprecated --- healthcheck/tcpserver.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/healthcheck/tcpserver.go b/healthcheck/tcpserver.go index b101ae44..ba2facd6 100644 --- a/healthcheck/tcpserver.go +++ b/healthcheck/tcpserver.go @@ -67,7 +67,7 @@ func (s *TCPServer) serve() error { for { conn, err := s.ln.Accept() if err != nil { - if e, ok := err.(net.Error); ok && e.Temporary() { + if e, ok := err.(net.Error); ok && e.Timeout() { s.logger. WithField("at", "accept"). WithError(err). From 145ef16067898dd4c7ded479bbce7f280009d456 Mon Sep 17 00:00:00 2001 From: Alex Arnell Date: Mon, 23 Oct 2023 12:00:31 -0700 Subject: [PATCH 12/12] increase linter timeout and update gh actions --- .github/workflows/ci.yaml | 4 ++-- .golangci.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a57d66b6..2739b1ff 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -9,8 +9,8 @@ jobs: matrix: target: [ test, lint ] steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 with: go-version-file: go.mod - name: run ${{ matrix.target }} diff --git a/.golangci.yml b/.golangci.yml index 7ea7259b..42d66787 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,6 +1,6 @@ # See https://github.com/golangci/golangci-lint#config-file run: - deadline: 1m #Default + deadline: 2m #Default issues-exit-code: 1 #Default tests: true #Default