Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interfaces: Update all component interfaces to implement io.Closer #3542

Merged
merged 15 commits into from
Sep 19, 2024
Merged
2 changes: 1 addition & 1 deletion .build-tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
)

require (
github.com/dapr/kit v0.13.1-0.20240402103809-0c7cfce53d9e // indirect
github.com/dapr/kit v0.13.1-0.20240909215017-3823663aa4bb // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions .build-tools/go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/dapr/kit v0.13.1-0.20240402103809-0c7cfce53d9e h1:mLvqfGuppb6uhsijmwTlF5sZVtGvig+Ua5ESKF17SxA=
github.com/dapr/kit v0.13.1-0.20240402103809-0c7cfce53d9e/go.mod h1:dons8V2bF6MPR2yFdxtTa86PfaE7EJtKAOkZ9hOavBQ=
github.com/dapr/kit v0.13.1-0.20240909215017-3823663aa4bb h1:ahLO7pMmX6HAuT6/RxYWBY4AN2fXQJcYlU1msY6Kt7U=
github.com/dapr/kit v0.13.1-0.20240909215017-3823663aa4bb/go.mod h1:Hz1W2LmWfA4UX/12MdA+brsf+np6f/1dJt6C6F63cjI=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/certification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ jobs:
set +e
gotestsum --jsonfile ${{ env.TEST_OUTPUT_FILE_PREFIX }}_certification.json \
--junitfile ${{ env.TEST_OUTPUT_FILE_PREFIX }}_certification.xml --format standard-quiet -- \
-coverprofile=cover.out -covermode=set -tags=certtests -timeout=30m -coverpkg=${{ matrix.source-pkg }}
-coverprofile=cover.out -covermode=set -tags=certtests,unit -timeout=30m -coverpkg=${{ matrix.source-pkg }}
status=$?
echo "Completed certification tests for ${{ matrix.component }} ... "
if test $status -ne 0; then
Expand Down
4 changes: 4 additions & 0 deletions bindings/alicloud/oss/oss.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,7 @@ func (s *AliCloudOSS) GetComponentMetadata() (metadataInfo metadata.MetadataMap)
metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType)
return
}

func (s *AliCloudOSS) Close() error {
return nil
}
8 changes: 8 additions & 0 deletions bindings/alicloud/sls/sls.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,11 @@ func (s *AliCloudSlsLogstorage) GetComponentMetadata() (metadataInfo metadata.Me
metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType)
return
}

func (s *AliCloudSlsLogstorage) Close() error {
if s.producer != nil {
return s.producer.Close(time.Second.Milliseconds() * 5)
}

return nil
}
4 changes: 4 additions & 0 deletions bindings/alicloud/tablestore/tablestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,7 @@ func (s *AliCloudTableStore) GetComponentMetadata() (metadataInfo contribMetadat
contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.BindingType)
return
}

func (s *AliCloudTableStore) Close() error {
return nil
}
4 changes: 4 additions & 0 deletions bindings/apns/apns.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,7 @@ func (a *APNS) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap)
contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.BindingType)
return
}

func (a *APNS) Close() error {
return nil
}
4 changes: 4 additions & 0 deletions bindings/aws/dynamodb/dynamodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,7 @@ func (d *DynamoDB) GetComponentMetadata() (metadataInfo metadata.MetadataMap) {
metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType)
return
}

func (d *DynamoDB) Close() error {
return nil
}
4 changes: 4 additions & 0 deletions bindings/aws/ses/ses.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,7 @@ func (a *AWSSES) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMa
contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.BindingType)
return
}

func (a *AWSSES) Close() error {
return nil
}
4 changes: 4 additions & 0 deletions bindings/aws/sns/sns.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,7 @@ func (a *AWSSNS) GetComponentMetadata() (metadataInfo metadata.MetadataMap) {
metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType)
return
}

func (a *AWSSNS) Close() error {
return nil
}
4 changes: 4 additions & 0 deletions bindings/azure/blobstorage/blobstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,7 @@ func (a *AzureBlobStorage) GetComponentMetadata() (metadataInfo contribMetadata.
contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.BindingType)
return
}

func (a *AzureBlobStorage) Close() error {
return nil
}
4 changes: 4 additions & 0 deletions bindings/azure/cosmosdb/cosmosdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,7 @@ func (c *CosmosDB) GetComponentMetadata() (metadataInfo contribMetadata.Metadata
contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.BindingType)
return
}

func (c *CosmosDB) Close() error {
return nil
}
13 changes: 10 additions & 3 deletions bindings/azure/cosmosdbgremlinapi/cosmosdbgremlinapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const (
// CosmosDBGremlinAPI allows performing state operations on collections.
type CosmosDBGremlinAPI struct {
metadata *cosmosDBGremlinAPICredentials
client *gremcos.Cosmos
client gremcos.Cosmos
logger logger.Logger
}

Expand Down Expand Up @@ -77,7 +77,7 @@ func (c *CosmosDBGremlinAPI) Init(_ context.Context, metadata bindings.Metadata)
return errors.New("CosmosDBGremlinAPI Error: failed to create the Cosmos Graph DB connector")
}

c.client = &client
c.client = client

return nil
}
Expand Down Expand Up @@ -116,7 +116,7 @@ func (c *CosmosDBGremlinAPI) Invoke(_ context.Context, req *bindings.InvokeReque
respStartTimeKey: startTime.Format(time.RFC3339Nano),
},
}
d, err := (*c.client).Execute(gq)
d, err := c.client.Execute(gq)
if err != nil {
return nil, errors.New("CosmosDBGremlinAPI Error:error excuting gremlin")
}
Expand All @@ -136,3 +136,10 @@ func (c *CosmosDBGremlinAPI) GetComponentMetadata() (metadataInfo metadata.Metad
metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType)
return
}

func (c *CosmosDBGremlinAPI) Close() error {
if c.client != nil {
return c.client.Stop()
}
return nil
}
4 changes: 4 additions & 0 deletions bindings/azure/signalr/signalr.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,3 +419,7 @@ func (s *SignalR) GetComponentMetadata() (metadataInfo metadata.MetadataMap) {
metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType)
return
}

func (s *SignalR) Close() error {
return nil
}
4 changes: 4 additions & 0 deletions bindings/dubbo/dubbo_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,7 @@ func (out *DubboOutputBinding) Operations() []bindings.OperationKind {
func (out *DubboOutputBinding) GetComponentMetadata() metadata.MetadataMap {
return metadata.MetadataMap{}
}

func (out *DubboOutputBinding) Close() error {
return nil
}
4 changes: 4 additions & 0 deletions bindings/graphql/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,7 @@ func (gql *GraphQL) GetComponentMetadata() (metadataInfo metadata.MetadataMap) {
metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType)
return
}

func (gql *GraphQL) Close() error {
return nil
}
4 changes: 4 additions & 0 deletions bindings/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,7 @@ func (h *HTTPSource) GetComponentMetadata() (metadataInfo metadata.MetadataMap)
metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType)
return
}

func (h *HTTPSource) Close() error {
return nil
}
7 changes: 7 additions & 0 deletions bindings/huawei/obs/obs.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,10 @@ func (o *HuaweiOBS) GetComponentMetadata() (metadataInfo metadata.MetadataMap) {
metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType)
return
}

func (o *HuaweiOBS) Close() error {
if o.service != nil {
o.service.Close()
}
return nil
}
5 changes: 5 additions & 0 deletions bindings/huawei/obs/obs_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type HuaweiOBSAPI interface {
GetObject(ctx context.Context, input *obs.GetObjectInput) (output *obs.GetObjectOutput, err error)
DeleteObject(ctx context.Context, input *obs.DeleteObjectInput) (output *obs.DeleteObjectOutput, err error)
ListObjects(ctx context.Context, input *obs.ListObjectsInput) (output *obs.ListObjectsOutput, err error)
Close()
}

// HuaweiOBSService is a service layer which wraps the actual OBS SDK client to provide the API functions
Expand Down Expand Up @@ -54,3 +55,7 @@ func (s *HuaweiOBSService) DeleteObject(ctx context.Context, input *obs.DeleteOb
func (s *HuaweiOBSService) ListObjects(ctx context.Context, input *obs.ListObjectsInput) (output *obs.ListObjectsOutput, err error) {
return s.client.ListObjects(input, obs.WithRequestContext(ctx))
}

func (s *HuaweiOBSService) Close() {
s.client.Close()
}
2 changes: 2 additions & 0 deletions bindings/huawei/obs/obs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ func (m *MockHuaweiOBSService) ListObjects(ctx context.Context, input *obs.ListO
return m.ListObjectsFn(ctx, input)
}

func (m *MockHuaweiOBSService) Close() {}

func TestParseMetadata(t *testing.T) {
obs := NewHuaweiOBS(logger.NewLogger("test")).(*HuaweiOBS)

Expand Down
4 changes: 4 additions & 0 deletions bindings/kitex/kitex_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,7 @@ func (out *kitexOutputBinding) Operations() []bindings.OperationKind {
func (out *kitexOutputBinding) GetComponentMetadata() (metadataInfo metadata.MetadataMap) {
return
}

func (out *kitexOutputBinding) Close() error {
return nil
}
4 changes: 4 additions & 0 deletions bindings/localstorage/localstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,7 @@ func (ls *LocalStorage) GetComponentMetadata() (metadataInfo metadata.MetadataMa
metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType)
return
}

func (ls *LocalStorage) Close() error {
return nil
}
2 changes: 2 additions & 0 deletions bindings/output_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package bindings
import (
"context"
"fmt"
"io"

"github.com/dapr/components-contrib/health"
"github.com/dapr/components-contrib/metadata"
Expand All @@ -28,6 +29,7 @@ type OutputBinding interface {
Init(ctx context.Context, metadata Metadata) error
Invoke(ctx context.Context, req *InvokeRequest) (*InvokeResponse, error)
Operations() []OperationKind
io.Closer
}

func PingOutBinding(ctx context.Context, outputBinding OutputBinding) error {
Expand Down
4 changes: 4 additions & 0 deletions bindings/postmark/postmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,7 @@ func (p *Postmark) GetComponentMetadata() (metadataInfo metadata.MetadataMap) {
metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType)
return
}

func (p *Postmark) Close() error {
return nil
}
4 changes: 4 additions & 0 deletions bindings/smtp/smtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,7 @@ func (s *Mailer) GetComponentMetadata() (metadataInfo metadata.MetadataMap) {
metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType)
return
}

func (s *Mailer) Close() error {
return nil
}
8 changes: 8 additions & 0 deletions bindings/twilio/sendgrid/sendgrid.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ func (sg *SendGrid) GetComponentMetadata() (metadataInfo metadata.MetadataMap) {
return
}

func (sg *SendGrid) Close() error {
return nil
}

// Function that unmarshals the Dynamic Template Data JSON String into a map[string]any.
func UnmarshalDynamicTemplateData(jsonString string, result *map[string]any) error {
err := json.Unmarshal([]byte(jsonString), &result)
Expand All @@ -279,3 +283,7 @@ func UnmarshalDynamicTemplateData(jsonString string, result *map[string]any) err
}
return nil
}

func Close() error {
return nil
}
4 changes: 4 additions & 0 deletions bindings/twilio/sms/sms.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,7 @@ func (t *SMS) GetComponentMetadata() (metadataInfo metadata.MetadataMap) {
metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType)
return
}

func (t *SMS) Close() error {
return nil
}
7 changes: 7 additions & 0 deletions bindings/zeebe/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,10 @@ func (z *ZeebeCommand) GetComponentMetadata() (metadataInfo metadata.MetadataMap
metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType)
return
}

func (z *ZeebeCommand) Close() error {
if z.client != nil {
return z.client.Close()
}
return nil
}
1 change: 0 additions & 1 deletion common/component/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ type ConfigurationSubscribeArgs struct {
RedisChannel string
IsAllKeysChannel bool
ID string
Stop chan struct{}
}

func ParseClientFromProperties(properties map[string]string, componentType metadata.ComponentType, ctx context.Context, logger *kitlogger.Logger) (RedisClient, *Settings, error) {
Expand Down
2 changes: 0 additions & 2 deletions common/component/redis/v8client.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ func (c v8Client) ConfigurationSubscribe(ctx context.Context, args *Configuratio
defer p.Close()
for {
select {
case <-args.Stop:
return
case <-ctx.Done():
return
case msg := <-p.Channel():
Expand Down
2 changes: 0 additions & 2 deletions common/component/redis/v9client.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ func (c v9Client) ConfigurationSubscribe(ctx context.Context, args *Configuratio
defer p.Close()
for {
select {
case <-args.Stop:
return
case <-ctx.Done():
return
case msg := <-p.Channel():
Expand Down
Loading
Loading