From 3a5aac4414bd6467995cde93772d05a288180dd8 Mon Sep 17 00:00:00 2001 From: Josh van Leeuwen Date: Fri, 17 Feb 2023 01:13:42 +0000 Subject: [PATCH] Graceful Shutdown: Updates function signatures to match new API, and add context.TODO()s (#5831) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Updates function signatures to match new API, and add context.TODO()s Signed-off-by: joshvanl * Revert state Features to not take a context.Context, see https://github.com/dapr/components-contrib/pull/2474#discussion_r1093902890 Signed-off-by: joshvanl * Update config interface to satisfy contrib requirements Signed-off-by: joshvanl * Updated pinned components-contrib Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com> * 💄 Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com> --------- Signed-off-by: joshvanl Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com> Co-authored-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com> --- .github/workflows/dapr.yml | 2 +- .golangci.yml | 1 + Makefile | 4 +-- ...ing_alicloud_dubbo.go => binding_dubbo.go} | 4 +-- .../components/middleware_http_bearer.go | 4 ++- .../components/middleware_http_oauth2.go | 4 ++- ...middleware_http_oauth2clientcredentials.go | 4 ++- cmd/daprd/components/middleware_http_opa.go | 4 ++- .../components/middleware_http_ratelimit.go | 4 ++- .../components/middleware_http_routeralias.go | 4 ++- .../middleware_http_routerchecker.go | 4 ++- .../components/middleware_http_sentinel.go | 4 ++- .../components/middleware_http_webassembly.go | 4 ++- docker/Dockerfile-dev | 2 +- docker/custom-scripts/install-dapr-tools.sh | 2 +- docs/development/developing-dapr.md | 2 +- .../development/setup-dapr-development-env.md | 2 +- go.mod | 2 +- go.sum | 4 +-- pkg/actors/actors_test.go | 2 +- pkg/channel/http/http_channel.go | 2 +- pkg/components/bindings/input_pluggable.go | 33 +++++++++++++++++-- .../bindings/input_pluggable_test.go | 2 +- pkg/components/bindings/output_pluggable.go | 2 +- .../bindings/output_pluggable_test.go | 2 +- pkg/components/pubsub/pluggable.go | 2 +- pkg/components/pubsub/pluggable_test.go | 2 +- pkg/components/state/pluggable.go | 2 +- pkg/components/state/pluggable_test.go | 4 +-- pkg/encryption/encryption_test.go | 6 ++-- pkg/grpc/api_test.go | 2 +- pkg/http/api_test.go | 6 ++-- pkg/runtime/runtime.go | 14 ++++---- pkg/runtime/runtime_test.go | 20 +++++------ pkg/runtime/wfengine/wfengine_test.go | 2 +- pkg/testing/bindings_mock.go | 4 +-- pkg/testing/lock_mock.go | 4 +-- pkg/testing/pubsub_mock.go | 6 ++-- pkg/testing/secrets_mock.go | 4 +-- pkg/testing/state_mock.go | 4 +-- pkg/testing/store_mock.go | 4 +-- 41 files changed, 119 insertions(+), 71 deletions(-) rename cmd/daprd/components/{binding_alicloud_dubbo.go => binding_dubbo.go} (88%) diff --git a/.github/workflows/dapr.yml b/.github/workflows/dapr.yml index ffc298de28e..b58ef9fc231 100644 --- a/.github/workflows/dapr.yml +++ b/.github/workflows/dapr.yml @@ -35,7 +35,7 @@ jobs: runs-on: ${{ matrix.os }} env: GOVER: "^1.19.2" - GOLANGCILINT_VER: v1.50.1 + GOLANGCILINT_VER: "v1.51.1" PROTOC_VERSION: "21.12" GOOS: ${{ matrix.target_os }} GOARCH: ${{ matrix.target_arch }} diff --git a/.golangci.yml b/.golangci.yml index a543cdb5914..7f45047409d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -233,6 +233,7 @@ linters: disable: # TODO Enforce the below linters later - nosnakecase + - musttag - dupl - errcheck - funlen diff --git a/Makefile b/Makefile index 2300849ef87..1bcb09ad36d 100644 --- a/Makefile +++ b/Makefile @@ -333,8 +333,8 @@ test-race: ################################################################################ # Target: lint # ################################################################################ -# Please use golangci-lint version v1.50.1 , otherwise you might encounter errors. -# You can download version v1.50.1 at https://github.com/golangci/golangci-lint/releases/tag/v1.50.1 +# Please use golangci-lint version v1.51.1 , otherwise you might encounter errors. +# You can download version v1.51.1 at https://github.com/golangci/golangci-lint/releases/tag/v1.51.1 .PHONY: lint lint: $(GOLANGCI_LINT) run --timeout=20m diff --git a/cmd/daprd/components/binding_alicloud_dubbo.go b/cmd/daprd/components/binding_dubbo.go similarity index 88% rename from cmd/daprd/components/binding_alicloud_dubbo.go rename to cmd/daprd/components/binding_dubbo.go index e9214b6314e..017242885a3 100644 --- a/cmd/daprd/components/binding_alicloud_dubbo.go +++ b/cmd/daprd/components/binding_dubbo.go @@ -14,10 +14,10 @@ limitations under the License. package components import ( - "github.com/dapr/components-contrib/bindings/alicloud/dubbo" + "github.com/dapr/components-contrib/bindings/dubbo" bindingsLoader "github.com/dapr/dapr/pkg/components/bindings" ) func init() { - bindingsLoader.DefaultRegistry.RegisterOutputBinding(dubbo.NewDubboOutput, "alicloud.dubbo") + bindingsLoader.DefaultRegistry.RegisterOutputBinding(dubbo.NewDubboOutput, "dubbo", "alicloud.dubbo") } diff --git a/cmd/daprd/components/middleware_http_bearer.go b/cmd/daprd/components/middleware_http_bearer.go index 3858a10d6b7..b510366015e 100644 --- a/cmd/daprd/components/middleware_http_bearer.go +++ b/cmd/daprd/components/middleware_http_bearer.go @@ -14,6 +14,8 @@ limitations under the License. package components import ( + "context" + "github.com/dapr/components-contrib/middleware" "github.com/dapr/components-contrib/middleware/http/bearer" httpMiddlewareLoader "github.com/dapr/dapr/pkg/components/middleware/http" @@ -24,7 +26,7 @@ import ( func init() { httpMiddlewareLoader.DefaultRegistry.RegisterComponent(func(log logger.Logger) httpMiddlewareLoader.FactoryMethod { return func(metadata middleware.Metadata) (httpMiddleware.Middleware, error) { - return bearer.NewBearerMiddleware(log).GetHandler(metadata) + return bearer.NewBearerMiddleware(log).GetHandler(context.TODO(), metadata) } }, "bearer") } diff --git a/cmd/daprd/components/middleware_http_oauth2.go b/cmd/daprd/components/middleware_http_oauth2.go index 7bf91a6acde..b7e7cae84d0 100644 --- a/cmd/daprd/components/middleware_http_oauth2.go +++ b/cmd/daprd/components/middleware_http_oauth2.go @@ -14,6 +14,8 @@ limitations under the License. package components import ( + "context" + "github.com/dapr/components-contrib/middleware" "github.com/dapr/components-contrib/middleware/http/oauth2" httpMiddlewareLoader "github.com/dapr/dapr/pkg/components/middleware/http" @@ -24,7 +26,7 @@ import ( func init() { httpMiddlewareLoader.DefaultRegistry.RegisterComponent(func(log logger.Logger) httpMiddlewareLoader.FactoryMethod { return func(metadata middleware.Metadata) (httpMiddleware.Middleware, error) { - return oauth2.NewOAuth2Middleware(log).GetHandler(metadata) + return oauth2.NewOAuth2Middleware(log).GetHandler(context.TODO(), metadata) } }, "oauth2") } diff --git a/cmd/daprd/components/middleware_http_oauth2clientcredentials.go b/cmd/daprd/components/middleware_http_oauth2clientcredentials.go index 6d78d942bdb..37e579dccb9 100644 --- a/cmd/daprd/components/middleware_http_oauth2clientcredentials.go +++ b/cmd/daprd/components/middleware_http_oauth2clientcredentials.go @@ -14,6 +14,8 @@ limitations under the License. package components import ( + "context" + "github.com/dapr/components-contrib/middleware" "github.com/dapr/components-contrib/middleware/http/oauth2clientcredentials" httpMiddlewareLoader "github.com/dapr/dapr/pkg/components/middleware/http" @@ -24,7 +26,7 @@ import ( func init() { httpMiddlewareLoader.DefaultRegistry.RegisterComponent(func(log logger.Logger) httpMiddlewareLoader.FactoryMethod { return func(metadata middleware.Metadata) (httpMiddleware.Middleware, error) { - return oauth2clientcredentials.NewOAuth2ClientCredentialsMiddleware(log).GetHandler(metadata) + return oauth2clientcredentials.NewOAuth2ClientCredentialsMiddleware(log).GetHandler(context.TODO(), metadata) } }, "oauth2clientcredentials") } diff --git a/cmd/daprd/components/middleware_http_opa.go b/cmd/daprd/components/middleware_http_opa.go index 47a13d1e935..e020bf35a74 100644 --- a/cmd/daprd/components/middleware_http_opa.go +++ b/cmd/daprd/components/middleware_http_opa.go @@ -14,6 +14,8 @@ limitations under the License. package components import ( + "context" + "github.com/dapr/components-contrib/middleware" "github.com/dapr/components-contrib/middleware/http/opa" httpMiddlewareLoader "github.com/dapr/dapr/pkg/components/middleware/http" @@ -24,7 +26,7 @@ import ( func init() { httpMiddlewareLoader.DefaultRegistry.RegisterComponent(func(log logger.Logger) httpMiddlewareLoader.FactoryMethod { return func(metadata middleware.Metadata) (httpMiddleware.Middleware, error) { - return opa.NewMiddleware(log).GetHandler(metadata) + return opa.NewMiddleware(log).GetHandler(context.TODO(), metadata) } }, "opa") } diff --git a/cmd/daprd/components/middleware_http_ratelimit.go b/cmd/daprd/components/middleware_http_ratelimit.go index 5545b60854b..fa953432a25 100644 --- a/cmd/daprd/components/middleware_http_ratelimit.go +++ b/cmd/daprd/components/middleware_http_ratelimit.go @@ -14,6 +14,8 @@ limitations under the License. package components import ( + "context" + "github.com/dapr/components-contrib/middleware" "github.com/dapr/components-contrib/middleware/http/ratelimit" httpMiddlewareLoader "github.com/dapr/dapr/pkg/components/middleware/http" @@ -24,7 +26,7 @@ import ( func init() { httpMiddlewareLoader.DefaultRegistry.RegisterComponent(func(log logger.Logger) httpMiddlewareLoader.FactoryMethod { return func(metadata middleware.Metadata) (httpMiddleware.Middleware, error) { - return ratelimit.NewRateLimitMiddleware(log).GetHandler(metadata) + return ratelimit.NewRateLimitMiddleware(log).GetHandler(context.TODO(), metadata) } }, "ratelimit") } diff --git a/cmd/daprd/components/middleware_http_routeralias.go b/cmd/daprd/components/middleware_http_routeralias.go index 737d1ee782b..e5edad5bbac 100644 --- a/cmd/daprd/components/middleware_http_routeralias.go +++ b/cmd/daprd/components/middleware_http_routeralias.go @@ -14,6 +14,8 @@ limitations under the License. package components import ( + "context" + "github.com/dapr/components-contrib/middleware" "github.com/dapr/components-contrib/middleware/http/routeralias" httpMiddlewareLoader "github.com/dapr/dapr/pkg/components/middleware/http" @@ -24,7 +26,7 @@ import ( func init() { httpMiddlewareLoader.DefaultRegistry.RegisterComponent(func(log logger.Logger) httpMiddlewareLoader.FactoryMethod { return func(metadata middleware.Metadata) (httpMiddleware.Middleware, error) { - return routeralias.NewMiddleware(log).GetHandler(metadata) + return routeralias.NewMiddleware(log).GetHandler(context.TODO(), metadata) } }, "routeralias") } diff --git a/cmd/daprd/components/middleware_http_routerchecker.go b/cmd/daprd/components/middleware_http_routerchecker.go index 80b0e577a6f..cb0622d6b88 100644 --- a/cmd/daprd/components/middleware_http_routerchecker.go +++ b/cmd/daprd/components/middleware_http_routerchecker.go @@ -14,6 +14,8 @@ limitations under the License. package components import ( + "context" + "github.com/dapr/components-contrib/middleware" "github.com/dapr/components-contrib/middleware/http/routerchecker" httpMiddlewareLoader "github.com/dapr/dapr/pkg/components/middleware/http" @@ -24,7 +26,7 @@ import ( func init() { httpMiddlewareLoader.DefaultRegistry.RegisterComponent(func(log logger.Logger) httpMiddlewareLoader.FactoryMethod { return func(metadata middleware.Metadata) (httpMiddleware.Middleware, error) { - return routerchecker.NewMiddleware(log).GetHandler(metadata) + return routerchecker.NewMiddleware(log).GetHandler(context.TODO(), metadata) } }, "routerchecker") } diff --git a/cmd/daprd/components/middleware_http_sentinel.go b/cmd/daprd/components/middleware_http_sentinel.go index 35c7be718d9..1a0b564266f 100644 --- a/cmd/daprd/components/middleware_http_sentinel.go +++ b/cmd/daprd/components/middleware_http_sentinel.go @@ -14,6 +14,8 @@ limitations under the License. package components import ( + "context" + "github.com/dapr/components-contrib/middleware" "github.com/dapr/components-contrib/middleware/http/sentinel" httpMiddlewareLoader "github.com/dapr/dapr/pkg/components/middleware/http" @@ -24,7 +26,7 @@ import ( func init() { httpMiddlewareLoader.DefaultRegistry.RegisterComponent(func(log logger.Logger) httpMiddlewareLoader.FactoryMethod { return func(metadata middleware.Metadata) (httpMiddleware.Middleware, error) { - return sentinel.NewMiddleware(log).GetHandler(metadata) + return sentinel.NewMiddleware(log).GetHandler(context.TODO(), metadata) } }, "sentinel") } diff --git a/cmd/daprd/components/middleware_http_webassembly.go b/cmd/daprd/components/middleware_http_webassembly.go index a9fae917431..546b0697060 100644 --- a/cmd/daprd/components/middleware_http_webassembly.go +++ b/cmd/daprd/components/middleware_http_webassembly.go @@ -14,6 +14,8 @@ limitations under the License. package components import ( + "context" + "github.com/dapr/components-contrib/middleware" "github.com/dapr/components-contrib/middleware/http/wasm" httpMiddlewareLoader "github.com/dapr/dapr/pkg/components/middleware/http" @@ -24,7 +26,7 @@ import ( func init() { httpMiddlewareLoader.DefaultRegistry.RegisterComponent(func(log logger.Logger) httpMiddlewareLoader.FactoryMethod { return func(metadata middleware.Metadata) (httpMiddleware.Middleware, error) { - return wasm.NewMiddleware(log).GetHandler(metadata) + return wasm.NewMiddleware(log).GetHandler(context.TODO(), metadata) } }, "wasm") } diff --git a/docker/Dockerfile-dev b/docker/Dockerfile-dev index 5e01747a2ff..4909f6f15c6 100644 --- a/docker/Dockerfile-dev +++ b/docker/Dockerfile-dev @@ -15,7 +15,7 @@ ARG DAPR_CLI_VERSION="latest" ARG PROTOC_VERSION="21.12" ARG PROTOC_GEN_GO_VERSION="1.28.1" ARG PROTOC_GEN_GO_GRPC_VERSION="1.2.0" -ARG GOLANGCI_LINT_VERSION="1.50.1" +ARG GOLANGCI_LINT_VERSION="1.51.1" # This Dockerfile adds a non-root 'dapr' user with sudo access. However, for Linux, # this user's GID/UID must match your local user UID/GID to avoid permission issues diff --git a/docker/custom-scripts/install-dapr-tools.sh b/docker/custom-scripts/install-dapr-tools.sh index c9d02db5e91..dba6b5413e9 100644 --- a/docker/custom-scripts/install-dapr-tools.sh +++ b/docker/custom-scripts/install-dapr-tools.sh @@ -21,7 +21,7 @@ DAPR_CLI_VERSION=${4:-""} PROTOC_VERSION=${5:-"21.12"} PROTOC_GEN_GO_VERSION=${6:-"1.28.1"} PROTOC_GEN_GO_GRPC_VERSION=${7:-"1.2.0"} -GOLANGCI_LINT_VERSION=${8:-"1.50.1"} +GOLANGCI_LINT_VERSION=${8:-"1.51.1"} set -e diff --git a/docs/development/developing-dapr.md b/docs/development/developing-dapr.md index c8168473732..6ccdcfc3504 100644 --- a/docs/development/developing-dapr.md +++ b/docs/development/developing-dapr.md @@ -63,7 +63,7 @@ This command will: - format, test and lint all the code - check if you forgot to `git commit` something -Note: To run linter locally, please use golangci-lint version v1.50.1, otherwise you might encounter errors. You can download version v1.50.1 [here](https://github.com/golangci/golangci-lint/releases/tag/v1.50.1). +Note: To run linter locally, please use golangci-lint version v1.51.1, otherwise you might encounter errors. You can download version v1.51.1 [here](https://github.com/golangci/golangci-lint/releases/tag/v1.51.1). ## Debug Dapr diff --git a/docs/development/setup-dapr-development-env.md b/docs/development/setup-dapr-development-env.md index 91dd65c61c7..b423adf2e4c 100644 --- a/docs/development/setup-dapr-development-env.md +++ b/docs/development/setup-dapr-development-env.md @@ -27,7 +27,7 @@ This document helps you get started developing Dapr. If you find any problems wh 2. Install [Delve](https://github.com/go-delve/delve/tree/master/Documentation/installation) for Go debugging, if desired. -3. Install [golangci-lint](https://golangci-lint.run/usage/install) version 1.50.1. +3. Install [golangci-lint](https://golangci-lint.run/usage/install) version 1.51.1. ## Setup a Kubernetes development environment diff --git a/go.mod b/go.mod index 59ed05586ce..04cfea01972 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/PuerkitoBio/purell v1.2.0 github.com/benbjohnson/clock v1.3.0 github.com/cenkalti/backoff/v4 v4.2.0 - github.com/dapr/components-contrib v1.10.0-rc.1 + github.com/dapr/components-contrib v1.10.0-rc.1.0.20230216221835-d098e38d6a4c github.com/dapr/kit v0.0.4 github.com/fasthttp/router v1.4.15 github.com/ghodss/yaml v1.0.0 diff --git a/go.sum b/go.sum index 9a45f748c9b..8e6948d5316 100644 --- a/go.sum +++ b/go.sum @@ -716,8 +716,8 @@ github.com/dancannon/gorethink v4.0.0+incompatible h1:KFV7Gha3AuqT+gr0B/eKvGhbjm github.com/dancannon/gorethink v4.0.0+incompatible/go.mod h1:BLvkat9KmZc1efyYwhz3WnybhRZtgF1K929FD8z1avU= github.com/danieljoos/wincred v1.1.2 h1:QLdCxFs1/Yl4zduvBdcHB8goaYk9RARS2SgLLRuAyr0= github.com/danieljoos/wincred v1.1.2/go.mod h1:GijpziifJoIBfYh+S7BbkdUTU4LfM+QnGqR5Vl2tAx0= -github.com/dapr/components-contrib v1.10.0-rc.1 h1:ZkUzIe+D4HcDVu06c5FPfNdJvmrt1Xl6i8BNkQfYkos= -github.com/dapr/components-contrib v1.10.0-rc.1/go.mod h1:8OvVS4m3kK/ocDqhVYKdu4j7OS4gPlbXMi+eRjlPAwc= +github.com/dapr/components-contrib v1.10.0-rc.1.0.20230216221835-d098e38d6a4c h1:gqj+iTHX9zcsQxlDEqht79e8f5K7DsEg6YxGpUe4InY= +github.com/dapr/components-contrib v1.10.0-rc.1.0.20230216221835-d098e38d6a4c/go.mod h1:xe+Gh1MW0GFqzidHR66W77KF6kKTRpCdNatA0bpxOHI= github.com/dapr/kit v0.0.4 h1:i+7TIN4crC1Mo0JFyWpIkwAE8orlliA0O6/ibvs2AaE= github.com/dapr/kit v0.0.4/go.mod h1:RFN6r5pZzhrelB0SUr8Dha44ckRBl7t+B01X5aw8WeE= github.com/dave/jennifer v1.4.0/go.mod h1:fIb+770HOpJ2fmN9EPPKOqm1vMGhB+TwXKMZhrIygKg= diff --git a/pkg/actors/actors_test.go b/pkg/actors/actors_test.go index d494fe8121c..7ddcaf4d8fc 100644 --- a/pkg/actors/actors_test.go +++ b/pkg/actors/actors_test.go @@ -173,7 +173,7 @@ func (f *fakeStateStore) newItem(data []byte) *fakeStateStoreItem { } } -func (f *fakeStateStore) Init(metadata state.Metadata) error { +func (f *fakeStateStore) Init(ctx context.Context, metadata state.Metadata) error { return nil } diff --git a/pkg/channel/http/http_channel.go b/pkg/channel/http/http_channel.go index fc40e5b67d7..abf03631eef 100644 --- a/pkg/channel/http/http_channel.go +++ b/pkg/channel/http/http_channel.go @@ -260,7 +260,7 @@ func (h *Channel) invokeMethodV1(ctx context.Context, req *invokev1.InvokeMethod } })) execPipeline.ServeHTTP(rw, channelReq) - resp = rw.Result() + resp = rw.Result() //nolint:bodyclose } else { // Send request to user application // (Body is closed below, but linter isn't detecting that) diff --git a/pkg/components/bindings/input_pluggable.go b/pkg/components/bindings/input_pluggable.go index c2a2fec4783..b2d06df93bb 100644 --- a/pkg/components/bindings/input_pluggable.go +++ b/pkg/components/bindings/input_pluggable.go @@ -18,6 +18,7 @@ import ( "fmt" "io" "sync" + "sync/atomic" "github.com/dapr/components-contrib/bindings" "github.com/dapr/dapr/pkg/components/pluggable" @@ -30,10 +31,14 @@ type grpcInputBinding struct { *pluggable.GRPCConnector[proto.InputBindingClient] bindings.InputBinding logger logger.Logger + + closed atomic.Bool + wg sync.WaitGroup + closeCh chan struct{} } // Init initializes the grpc inputbinding passing out the metadata to the grpc component. -func (b *grpcInputBinding) Init(metadata bindings.Metadata) error { +func (b *grpcInputBinding) Init(ctx context.Context, metadata bindings.Metadata) error { if err := b.Dial(metadata.Name); err != nil { return err } @@ -104,7 +109,18 @@ func (b *grpcInputBinding) Read(ctx context.Context, handler bindings.Handler) e streamCtx, cancel := context.WithCancel(readStream.Context()) handle := b.adaptHandler(streamCtx, readStream, handler) + b.wg.Add(2) + // Cancel on input binding close. + go func() { + defer b.wg.Done() + defer cancel() + select { + case <-b.closeCh: + case <-streamCtx.Done(): + } + }() go func() { + defer b.wg.Done() defer cancel() for { msg, err := readStream.Recv() @@ -117,13 +133,25 @@ func (b *grpcInputBinding) Read(ctx context.Context, handler bindings.Handler) e b.logger.Errorf("failed to receive message: %v", err) return } - go handle(msg) + b.wg.Add(1) + go func() { + defer b.wg.Done() + handle(msg) + }() } }() return nil } +func (b *grpcInputBinding) Close() error { + defer b.wg.Wait() + if b.closed.CompareAndSwap(false, true) { + close(b.closeCh) + } + return b.InputBinding.Close() +} + // Returns the component metadata options func (b *grpcInputBinding) GetComponentMetadata() map[string]string { // GetComponentMetadata does not apply to pluggable components as there is no standard metadata to return @@ -135,6 +163,7 @@ func inputFromConnector(l logger.Logger, connector *pluggable.GRPCConnector[prot return &grpcInputBinding{ GRPCConnector: connector, logger: l, + closeCh: make(chan struct{}), } } diff --git a/pkg/components/bindings/input_pluggable_test.go b/pkg/components/bindings/input_pluggable_test.go index 64c35d92fbc..b8d94ffdbff 100644 --- a/pkg/components/bindings/input_pluggable_test.go +++ b/pkg/components/bindings/input_pluggable_test.go @@ -125,7 +125,7 @@ func TestInputBindingCalls(t *testing.T) { }() conn := inputFromConnector(testLogger, connector) - err = conn.Init(bindings.Metadata{ + err = conn.Init(context.Background(), bindings.Metadata{ Base: contribMetadata.Base{}, }) diff --git a/pkg/components/bindings/output_pluggable.go b/pkg/components/bindings/output_pluggable.go index 4144a192355..2b10695f991 100644 --- a/pkg/components/bindings/output_pluggable.go +++ b/pkg/components/bindings/output_pluggable.go @@ -30,7 +30,7 @@ type grpcOutputBinding struct { } // Init initializes the grpc outputbinding passing out the metadata to the grpc component. -func (b *grpcOutputBinding) Init(metadata bindings.Metadata) error { +func (b *grpcOutputBinding) Init(ctx context.Context, metadata bindings.Metadata) error { if err := b.Dial(metadata.Name); err != nil { return err } diff --git a/pkg/components/bindings/output_pluggable_test.go b/pkg/components/bindings/output_pluggable_test.go index c9e43fc6c70..637abd55e20 100644 --- a/pkg/components/bindings/output_pluggable_test.go +++ b/pkg/components/bindings/output_pluggable_test.go @@ -127,7 +127,7 @@ func TestOutputBindingCalls(t *testing.T) { }() conn := outputFromConnector(testLogger, connector) - err = conn.Init(bindings.Metadata{ + err = conn.Init(context.Background(), bindings.Metadata{ Base: contribMetadata.Base{}, }) diff --git a/pkg/components/pubsub/pluggable.go b/pkg/components/pubsub/pluggable.go index 4df77c61238..64571db1644 100644 --- a/pkg/components/pubsub/pluggable.go +++ b/pkg/components/pubsub/pluggable.go @@ -35,7 +35,7 @@ type grpcPubSub struct { // Init initializes the grpc pubsub passing out the metadata to the grpc component. // It also fetches and set the component features. -func (p *grpcPubSub) Init(metadata pubsub.Metadata) error { +func (p *grpcPubSub) Init(ctx context.Context, metadata pubsub.Metadata) error { if err := p.Dial(metadata.Name); err != nil { return err } diff --git a/pkg/components/pubsub/pluggable_test.go b/pkg/components/pubsub/pluggable_test.go index c4c262909b8..5a9dd4c2f6c 100644 --- a/pkg/components/pubsub/pluggable_test.go +++ b/pkg/components/pubsub/pluggable_test.go @@ -149,7 +149,7 @@ func TestPubSubPluggableCalls(t *testing.T) { }() ps := fromConnector(testLogger, connector) - err = ps.Init(pubsub.Metadata{ + err = ps.Init(context.Background(), pubsub.Metadata{ Base: contribMetadata.Base{}, }) diff --git a/pkg/components/state/pluggable.go b/pkg/components/state/pluggable.go index 0773f0a66ed..33b6504881c 100644 --- a/pkg/components/state/pluggable.go +++ b/pkg/components/state/pluggable.go @@ -149,7 +149,7 @@ type grpcStateStore struct { // Init initializes the grpc state passing out the metadata to the grpc component. // It also fetches and set the current components features. -func (ss *grpcStateStore) Init(metadata state.Metadata) error { +func (ss *grpcStateStore) Init(ctx context.Context, metadata state.Metadata) error { if err := ss.Dial(metadata.Name); err != nil { return err } diff --git a/pkg/components/state/pluggable_test.go b/pkg/components/state/pluggable_test.go index ff91545cb67..9e04652ce14 100644 --- a/pkg/components/state/pluggable_test.go +++ b/pkg/components/state/pluggable_test.go @@ -177,7 +177,7 @@ func TestComponentCalls(t *testing.T) { return dialer(ctx, opts...) }) client := clientFactory(testLogger).(*grpcStateStore) - require.NoError(t, client.Init(state.Metadata{})) + require.NoError(t, client.Init(context.Background(), state.Metadata{})) return client, cleanup, err } @@ -211,7 +211,7 @@ func TestComponentCalls(t *testing.T) { }() ps := fromConnector(testLogger, connector) - err = ps.Init(state.Metadata{ + err = ps.Init(context.Background(), state.Metadata{ Base: contribMetadata.Base{}, }) diff --git a/pkg/encryption/encryption_test.go b/pkg/encryption/encryption_test.go index 24dbfcaaa65..9f1f73aeca4 100644 --- a/pkg/encryption/encryption_test.go +++ b/pkg/encryption/encryption_test.go @@ -33,7 +33,7 @@ type mockSecretStore struct { secondaryKey string } -func (m *mockSecretStore) Init(metadata secretstores.Metadata) error { +func (m *mockSecretStore) Init(ctx context.Context, metadata secretstores.Metadata) error { if val, ok := metadata.Properties["primaryKey"]; ok { m.primaryKey = val } @@ -92,7 +92,7 @@ func TestComponentEncryptionKey(t *testing.T) { secondaryKey := hex.EncodeToString(bytes[:16]) // 128-bit key secretStore := &mockSecretStore{} - secretStore.Init(secretstores.Metadata{Base: metadata.Base{ + secretStore.Init(context.Background(), secretstores.Metadata{Base: metadata.Base{ Properties: map[string]string{ "primaryKey": primaryKey, "secondaryKey": secondaryKey, @@ -156,7 +156,7 @@ func TestComponentEncryptionKey(t *testing.T) { func TestTryGetEncryptionKeyFromMetadataItem(t *testing.T) { t.Run("no secretRef on valid item", func(t *testing.T) { secretStore := &mockSecretStore{} - secretStore.Init(secretstores.Metadata{Base: metadata.Base{ + secretStore.Init(context.Background(), secretstores.Metadata{Base: metadata.Base{ Properties: map[string]string{ "primaryKey": "123", "secondaryKey": "456", diff --git a/pkg/grpc/api_test.go b/pkg/grpc/api_test.go index cbfdc66df73..8d026e74e83 100644 --- a/pkg/grpc/api_test.go +++ b/pkg/grpc/api_test.go @@ -3369,7 +3369,7 @@ func TestServiceInvocationWithResiliency(t *testing.T) { type mockConfigStore struct{} -func (m *mockConfigStore) Init(metadata configuration.Metadata) error { +func (m *mockConfigStore) Init(ctx context.Context, metadata configuration.Metadata) error { return nil } diff --git a/pkg/http/api_test.go b/pkg/http/api_test.go index ec7c28d483d..4c8c6d20edc 100644 --- a/pkg/http/api_test.go +++ b/pkg/http/api_test.go @@ -3941,7 +3941,7 @@ func (c fakeStateStore) BulkGet(ctx context.Context, req []state.GetRequest) (bo return false, nil, nil } -func (c fakeStateStore) Init(metadata state.Metadata) error { +func (c fakeStateStore) Init(ctx context.Context, metadata state.Metadata) error { c.counter = 0 //nolint:staticcheck return nil } @@ -4266,7 +4266,7 @@ func (c fakeConfigurationStore) Get(ctx context.Context, req *configuration.GetR return nil, errors.New("get key error: value not found") } -func (c fakeConfigurationStore) Init(metadata configuration.Metadata) error { +func (c fakeConfigurationStore) Init(ctx context.Context, metadata configuration.Metadata) error { c.counter = 0 //nolint:staticcheck return nil } @@ -4288,7 +4288,7 @@ func (l fakeLockStore) Ping() error { return nil } -func (l *fakeLockStore) InitLockStore(metadata lock.Metadata) error { +func (l *fakeLockStore) InitLockStore(ctx context.Context, metadata lock.Metadata) error { return nil } diff --git a/pkg/runtime/runtime.go b/pkg/runtime/runtime.go index ed9dd25fce5..77d277ed55c 100644 --- a/pkg/runtime/runtime.go +++ b/pkg/runtime/runtime.go @@ -1595,7 +1595,7 @@ func (a *DaprRuntime) initInputBinding(c componentsV1alpha1.Component) error { diag.DefaultMonitoring.ComponentInitFailed(c.Spec.Type, "creation", c.ObjectMeta.Name) return NewInitError(CreateComponentFailure, fName, err) } - err = binding.Init(bindings.Metadata{Base: a.toBaseMetadata(c)}) + err = binding.Init(context.TODO(), bindings.Metadata{Base: a.toBaseMetadata(c)}) if err != nil { diag.DefaultMonitoring.ComponentInitFailed(c.Spec.Type, "init", c.ObjectMeta.Name) return NewInitError(InitComponentFailure, fName, err) @@ -1622,7 +1622,7 @@ func (a *DaprRuntime) initOutputBinding(c componentsV1alpha1.Component) error { } if binding != nil { - err := binding.Init(bindings.Metadata{Base: a.toBaseMetadata(c)}) + err := binding.Init(context.TODO(), bindings.Metadata{Base: a.toBaseMetadata(c)}) if err != nil { diag.DefaultMonitoring.ComponentInitFailed(c.Spec.Type, "init", c.ObjectMeta.Name) return NewInitError(InitComponentFailure, fName, err) @@ -1642,7 +1642,7 @@ func (a *DaprRuntime) initConfiguration(s componentsV1alpha1.Component) error { return NewInitError(CreateComponentFailure, fName, err) } if store != nil { - err := store.Init(configuration.Metadata{Base: a.toBaseMetadata(s)}) + err := store.Init(context.TODO(), configuration.Metadata{Base: a.toBaseMetadata(s)}) if err != nil { diag.DefaultMonitoring.ComponentInitFailed(s.Spec.Type, "init", s.ObjectMeta.Name) return NewInitError(InitComponentFailure, fName, err) @@ -1669,7 +1669,7 @@ func (a *DaprRuntime) initLock(s componentsV1alpha1.Component) error { // initialization baseMetadata := a.toBaseMetadata(s) props := baseMetadata.Properties - err = store.InitLockStore(lock.Metadata{Base: baseMetadata}) + err = store.InitLockStore(context.TODO(), lock.Metadata{Base: baseMetadata}) if err != nil { diag.DefaultMonitoring.ComponentInitFailed(s.Spec.Type, "init", s.ObjectMeta.Name) return NewInitError(InitComponentFailure, fName, err) @@ -1742,7 +1742,7 @@ func (a *DaprRuntime) initState(s componentsV1alpha1.Component) error { baseMetadata := a.toBaseMetadata(s) props := baseMetadata.Properties - err = store.Init(state.Metadata{Base: baseMetadata}) + err = store.Init(context.TODO(), state.Metadata{Base: baseMetadata}) if err != nil { diag.DefaultMonitoring.ComponentInitFailed(s.Spec.Type, "init", s.ObjectMeta.Name) return NewInitError(InitComponentFailure, fName, err) @@ -1928,7 +1928,7 @@ func (a *DaprRuntime) initPubSub(c componentsV1alpha1.Component) error { } properties["consumerID"] = consumerID - err = pubSub.Init(pubsub.Metadata{Base: baseMetadata}) + err = pubSub.Init(context.TODO(), pubsub.Metadata{Base: baseMetadata}) if err != nil { diag.DefaultMonitoring.ComponentInitFailed(c.Spec.Type, "init", c.ObjectMeta.Name) return NewInitError(InitComponentFailure, fName, err) @@ -2964,7 +2964,7 @@ func (a *DaprRuntime) initSecretStore(c componentsV1alpha1.Component) error { return NewInitError(CreateComponentFailure, fName, err) } - err = secretStore.Init(secretstores.Metadata{Base: a.toBaseMetadata(c)}) + err = secretStore.Init(context.TODO(), secretstores.Metadata{Base: a.toBaseMetadata(c)}) if err != nil { diag.DefaultMonitoring.ComponentInitFailed(c.Spec.Type, "init", c.ObjectMeta.Name) return NewInitError(InitComponentFailure, fName, err) diff --git a/pkg/runtime/runtime_test.go b/pkg/runtime/runtime_test.go index a4ef30c21be..27a65bb8503 100644 --- a/pkg/runtime/runtime_test.go +++ b/pkg/runtime/runtime_test.go @@ -172,7 +172,7 @@ type MockKubernetesStateStore struct { callback func() } -func (m *MockKubernetesStateStore) Init(metadata secretstores.Metadata) error { +func (m *MockKubernetesStateStore) Init(ctx context.Context, metadata secretstores.Metadata) error { if m.callback != nil { m.callback() } @@ -349,7 +349,7 @@ func TestDoProcessComponent(t *testing.T) { // setup ctrl := gomock.NewController(t) mockLockStore := daprt.NewMockStore(ctrl) - mockLockStore.EXPECT().InitLockStore(gomock.Any()).Return(assert.AnError) + mockLockStore.EXPECT().InitLockStore(context.Background(), gomock.Any()).Return(assert.AnError) rt.lockStoreRegistry.RegisterComponent( func(_ logger.Logger) lock.Store { @@ -393,7 +393,7 @@ func TestDoProcessComponent(t *testing.T) { // setup ctrl := gomock.NewController(t) mockLockStore := daprt.NewMockStore(ctrl) - mockLockStore.EXPECT().InitLockStore(gomock.Any()).Return(nil) + mockLockStore.EXPECT().InitLockStore(context.Background(), gomock.Any()).Return(nil) rt.lockStoreRegistry.RegisterComponent( func(_ logger.Logger) lock.Store { @@ -421,7 +421,7 @@ func TestDoProcessComponent(t *testing.T) { // setup ctrl := gomock.NewController(t) mockLockStore := daprt.NewMockStore(ctrl) - mockLockStore.EXPECT().InitLockStore(gomock.Any()).Return(nil) + mockLockStore.EXPECT().InitLockStore(context.Background(), gomock.Any()).Return(nil) rt.lockStoreRegistry.RegisterComponent( func(_ logger.Logger) lock.Store { @@ -3732,7 +3732,7 @@ type mockSubscribePubSub struct { // type BulkSubscribeResponse struct { // Init is a mock initialization method. -func (m *mockSubscribePubSub) Init(metadata pubsub.Metadata) error { +func (m *mockSubscribePubSub) Init(ctx context.Context, metadata pubsub.Metadata) error { m.bulkHandlers = make(map[string]pubsub.BulkHandler) m.handlers = make(map[string]pubsub.Handler) m.pubCount = make(map[string]int) @@ -4136,7 +4136,7 @@ type mockBinding struct { closeErr error } -func (b *mockBinding) Init(metadata bindings.Metadata) error { +func (b *mockBinding) Init(ctx context.Context, metadata bindings.Metadata) error { return nil } @@ -4554,7 +4554,7 @@ type mockPublishPubSub struct { } // Init is a mock initialization method. -func (m *mockPublishPubSub) Init(metadata pubsub.Metadata) error { +func (m *mockPublishPubSub) Init(ctx context.Context, metadata pubsub.Metadata) error { return nil } @@ -4934,7 +4934,7 @@ type mockPubSub struct { closeErr error } -func (p *mockPubSub) Init(metadata pubsub.Metadata) error { +func (p *mockPubSub) Init(ctx context.Context, metadata pubsub.Metadata) error { return nil } @@ -4947,7 +4947,7 @@ type mockStateStore struct { closeErr error } -func (s *mockStateStore) Init(metadata state.Metadata) error { +func (s *mockStateStore) Init(ctx context.Context, metadata state.Metadata) error { return nil } @@ -4970,7 +4970,7 @@ func (s *mockSecretStore) GetSecret(ctx context.Context, req secretstores.GetSec }, nil } -func (s *mockSecretStore) Init(metadata secretstores.Metadata) error { +func (s *mockSecretStore) Init(ctx context.Context, metadata secretstores.Metadata) error { return nil } diff --git a/pkg/runtime/wfengine/wfengine_test.go b/pkg/runtime/wfengine/wfengine_test.go index 4906d858208..0b979b7a820 100644 --- a/pkg/runtime/wfengine/wfengine_test.go +++ b/pkg/runtime/wfengine/wfengine_test.go @@ -72,7 +72,7 @@ func (f *fakeStateStore) newItem(data []byte) *fakeStateStoreItem { } } -func (f *fakeStateStore) Init(metadata state.Metadata) error { +func (f *fakeStateStore) Init(ctx context.Context, metadata state.Metadata) error { return nil } diff --git a/pkg/testing/bindings_mock.go b/pkg/testing/bindings_mock.go index 9838b946603..afdff189b29 100644 --- a/pkg/testing/bindings_mock.go +++ b/pkg/testing/bindings_mock.go @@ -16,7 +16,7 @@ type MockBinding struct { } // Init is a mock initialization method. -func (m *MockBinding) Init(metadata bindings.Metadata) error { +func (m *MockBinding) Init(ctx context.Context, metadata bindings.Metadata) error { return nil } @@ -65,7 +65,7 @@ type FailingBinding struct { } // Init is a mock initialization method. -func (m *FailingBinding) Init(metadata bindings.Metadata) error { +func (m *FailingBinding) Init(ctx context.Context, metadata bindings.Metadata) error { return nil } diff --git a/pkg/testing/lock_mock.go b/pkg/testing/lock_mock.go index f3af73e6862..d93d6b26f93 100644 --- a/pkg/testing/lock_mock.go +++ b/pkg/testing/lock_mock.go @@ -36,7 +36,7 @@ func (m *MockStore) EXPECT() *MockStoreMockRecorder { } // InitLockStore mocks base method. -func (m *MockStore) InitLockStore(metadata lock.Metadata) error { +func (m *MockStore) InitLockStore(ctx context.Context, metadata lock.Metadata) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "InitLockStore", metadata) ret0, _ := ret[0].(error) @@ -44,7 +44,7 @@ func (m *MockStore) InitLockStore(metadata lock.Metadata) error { } // InitLockStore indicates an expected call of InitLockStore. -func (mr *MockStoreMockRecorder) InitLockStore(metadata interface{}) *gomock.Call { +func (mr *MockStoreMockRecorder) InitLockStore(ctx context.Context, metadata interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitLockStore", reflect.TypeOf((*MockStore)(nil).InitLockStore), metadata) } diff --git a/pkg/testing/pubsub_mock.go b/pkg/testing/pubsub_mock.go index 6be5c82d9be..5b306e4416c 100644 --- a/pkg/testing/pubsub_mock.go +++ b/pkg/testing/pubsub_mock.go @@ -15,7 +15,7 @@ type MockPubSub struct { } // Init is a mock initialization method. -func (m *MockPubSub) Init(metadata pubsub.Metadata) error { +func (m *MockPubSub) Init(ctx context.Context, metadata pubsub.Metadata) error { args := m.Called(metadata) return args.Error(0) } @@ -67,7 +67,7 @@ func (f *FailingPubsub) GetComponentMetadata() map[string]string { return map[string]string{} } -func (f *FailingPubsub) Init(metadata pubsub.Metadata) error { +func (f *FailingPubsub) Init(ctx context.Context, metadata pubsub.Metadata) error { return nil } @@ -125,7 +125,7 @@ type subscription struct { } // Init is a mock initialization method. -func (m *InMemoryPubsub) Init(metadata pubsub.Metadata) error { +func (m *InMemoryPubsub) Init(ctx context.Context, metadata pubsub.Metadata) error { m.lock = &sync.Mutex{} args := m.Called(metadata) return args.Error(0) diff --git a/pkg/testing/secrets_mock.go b/pkg/testing/secrets_mock.go index fac670a8134..e80b870dec0 100644 --- a/pkg/testing/secrets_mock.go +++ b/pkg/testing/secrets_mock.go @@ -45,7 +45,7 @@ func (c FakeSecretStore) BulkGetSecret(ctx context.Context, req secretstores.Bul }, nil } -func (c FakeSecretStore) Init(metadata secretstores.Metadata) error { +func (c FakeSecretStore) Init(ctx context.Context, metadata secretstores.Metadata) error { return nil } @@ -88,7 +88,7 @@ func (c FailingSecretStore) BulkGetSecret(ctx context.Context, req secretstores. }, nil } -func (c FailingSecretStore) Init(metadata secretstores.Metadata) error { +func (c FailingSecretStore) Init(ctx context.Context, metadata secretstores.Metadata) error { return nil } diff --git a/pkg/testing/state_mock.go b/pkg/testing/state_mock.go index b84a077eb1b..1993f7d9750 100644 --- a/pkg/testing/state_mock.go +++ b/pkg/testing/state_mock.go @@ -98,7 +98,7 @@ func (_m *MockStateStore) BulkGet(ctx context.Context, req []state.GetRequest) ( } // Init provides a mock function with given fields: metadata -func (_m *MockStateStore) Init(metadata state.Metadata) error { +func (_m *MockStateStore) Init(ctx context.Context, metadata state.Metadata) error { ret := _m.Called(metadata) var r0 error @@ -202,7 +202,7 @@ func (f *FailingStatestore) BulkGet(ctx context.Context, req []state.GetRequest) return false, nil, nil } -func (f *FailingStatestore) Init(metadata state.Metadata) error { +func (f *FailingStatestore) Init(ctx context.Context, metadata state.Metadata) error { return nil } diff --git a/pkg/testing/store_mock.go b/pkg/testing/store_mock.go index 68b0383667e..2c68ea79842 100644 --- a/pkg/testing/store_mock.go +++ b/pkg/testing/store_mock.go @@ -52,7 +52,7 @@ func (_m *MockConfigurationStore) Get(ctx context.Context, req *configuration.Ge } // Init provides a mock function with given fields: metadata -func (_m *MockConfigurationStore) Init(metadata configuration.Metadata) error { +func (_m *MockConfigurationStore) Init(ctx context.Context, metadata configuration.Metadata) error { ret := _m.Called(metadata) var r0 error @@ -113,7 +113,7 @@ func (f *FailingConfigurationStore) Get(ctx context.Context, req *configuration. return &configuration.GetResponse{}, nil } -func (f *FailingConfigurationStore) Init(metadata configuration.Metadata) error { +func (f *FailingConfigurationStore) Init(ctx context.Context, metadata configuration.Metadata) error { return nil }