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

Local file-based name resolver with SQLite + Update components-contrib to register Blob Storage v2 #7038

Merged
merged 12 commits into from
Nov 6, 2023
25 changes: 25 additions & 0 deletions cmd/daprd/components/nameresolution_sqlite.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//go:build allcomponents

/*
Copyright 2023 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package components

import (
"github.com/dapr/components-contrib/nameresolution/sqlite"
nrLoader "github.com/dapr/dapr/pkg/components/nameresolution"
)

func init() {
nrLoader.DefaultRegistry.RegisterComponent(sqlite.NewResolver, "sqlite")
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -453,3 +453,6 @@ replace github.com/microcosm-cc/bluemonday => github.com/microcosm-cc/bluemonday
//
// Then, run `make modtidy` in this repository.
// This ensures that go.mod and go.sum are up-to-date.

// TODO: REMOVE
replace github.com/dapr/components-contrib => github.com/italypaleale/dapr-components-contrib v1.10.2-0.20231013225904-b55509fe9b3a
ItalyPaleAle marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,6 @@ 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.12.0-rc.4.0.20231009175401-9f2cc5c158bb h1:A1A1A5IvxSTzKFlT/ZPVFpp9rOWqzd/yjzyNRxlbuHY=
github.com/dapr/components-contrib v1.12.0-rc.4.0.20231009175401-9f2cc5c158bb/go.mod h1:SWa5Za44IumX+GeTVZvHe9McfpC8ay7/KvGVKHDu97Q=
github.com/dapr/kit v0.12.1 h1:XT0CJQQaKRYSzIzZo15O1PAHGUrMGoAavdFRcNVZ+UE=
github.com/dapr/kit v0.12.1/go.mod h1:eNYjsudq3Ij0x8CLWsPturHor56sZRNu5tk2hUiJT80=
github.com/dave/jennifer v1.4.0/go.mod h1:fIb+770HOpJ2fmN9EPPKOqm1vMGhB+TwXKMZhrIygKg=
Expand Down Expand Up @@ -909,6 +907,8 @@ github.com/influxdata/influxdb-client-go/v2 v2.12.3/go.mod h1:IrrLUbCjjfkmRuaCiG
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
github.com/influxdata/line-protocol v0.0.0-20210922203350-b1ad95c89adf h1:7JTmneyiNEwVBOHSjoMxiWAqB992atOeepeFYegn5RU=
github.com/influxdata/line-protocol v0.0.0-20210922203350-b1ad95c89adf/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo=
github.com/italypaleale/dapr-components-contrib v1.10.2-0.20231013225904-b55509fe9b3a h1:yMjWjrRsBf8RK/oxHdZzCQFayYvVMoWSfyWWz+a5BP4=
github.com/italypaleale/dapr-components-contrib v1.10.2-0.20231013225904-b55509fe9b3a/go.mod h1:SWa5Za44IumX+GeTVZvHe9McfpC8ay7/KvGVKHDu97Q=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
Expand Down
2 changes: 1 addition & 1 deletion pkg/messaging/direct_messaging.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@
address = d.checkHTTPEndpoints(id)
} else {
request := nr.ResolveRequest{ID: id, Namespace: namespace, Port: d.grpcPort}
address, err = d.resolver.ResolveID(request)
address, err = d.resolver.ResolveID(context.TODO(), request)

Check warning on line 569 in pkg/messaging/direct_messaging.go

View check run for this annotation

Codecov / codecov/patch

pkg/messaging/direct_messaging.go#L569

Added line #L569 was not covered by tests
ItalyPaleAle marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return remoteApp{}, err
}
Expand Down
20 changes: 11 additions & 9 deletions pkg/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@
return fmt.Errorf("failed to setup tracing: %w", err)
}
// Register and initialize name resolution for service discovery.
err = a.initNameResolution()
err = a.initNameResolution(ctx)
if err != nil {
log.Errorf(err.Error())
}
Expand Down Expand Up @@ -1069,12 +1069,14 @@
}
}

func (a *DaprRuntime) initNameResolution() error {
var resolver nr.Resolver
var err error
resolverMetadata := nr.Metadata{}
func (a *DaprRuntime) initNameResolution(ctx context.Context) (err error) {
var (
resolver nr.Resolver
resolverMetadata nr.Metadata
resolverName string
resolverVersion string
)

var resolverName, resolverVersion string
if a.globalConfig.Spec.NameResolutionSpec != nil {
resolverName = a.globalConfig.Spec.NameResolutionSpec.Component
resolverVersion = a.globalConfig.Spec.NameResolutionSpec.Version
Expand All @@ -1087,7 +1089,7 @@
case modes.StandaloneMode:
resolverName = "mdns"
default:
fName := utils.ComponentLogName(resolverName, "nameResolution", resolverVersion)
fName := utils.ComponentLogName("nr", resolverName, resolverVersion)

Check warning on line 1092 in pkg/runtime/runtime.go

View check run for this annotation

Codecov / codecov/patch

pkg/runtime/runtime.go#L1092

Added line #L1092 was not covered by tests
return rterrors.NewInit(rterrors.InitComponentFailure, fName, fmt.Errorf("unable to determine name resolver for %s mode", string(a.runtimeConfig.mode)))
}
}
Expand All @@ -1096,7 +1098,7 @@
resolverVersion = components.FirstStableVersion
}

fName := utils.ComponentLogName(resolverName, "nameResolution", resolverVersion)
fName := utils.ComponentLogName("nr", resolverName, resolverVersion)
resolver, err = a.runtimeConfig.registry.NameResolutions().Create(resolverName, resolverVersion, fName)
resolverMetadata.Name = resolverName
if a.globalConfig.Spec.NameResolutionSpec != nil {
Expand All @@ -1115,7 +1117,7 @@
return rterrors.NewInit(rterrors.CreateComponentFailure, fName, err)
}

if err = resolver.Init(resolverMetadata); err != nil {
if err = resolver.Init(ctx, resolverMetadata); err != nil {
diag.DefaultMonitoring.ComponentInitFailed("nameResolution", "init", resolverName)
return rterrors.NewInit(rterrors.InitComponentFailure, fName, err)
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ func TestInitNameResolution(t *testing.T) {
initMockResolverForRuntime(rt, "anotherResolver", nil)

// act
err = rt.initNameResolution()
err = rt.initNameResolution(context.Background())

// assert
assert.Error(t, err)
Expand All @@ -921,7 +921,7 @@ func TestInitNameResolution(t *testing.T) {
initMockResolverForRuntime(rt, "someResolver", nil)

// act
err = rt.initNameResolution()
err = rt.initNameResolution(context.Background())

// assert
assert.NoError(t, err, "expected no error")
Expand All @@ -939,7 +939,7 @@ func TestInitNameResolution(t *testing.T) {
initMockResolverForRuntime(rt, "mdns", nil)

// act
err = rt.initNameResolution()
err = rt.initNameResolution(context.Background())

// assert
assert.NoError(t, err, "expected no error")
Expand All @@ -957,7 +957,7 @@ func TestInitNameResolution(t *testing.T) {
initMockResolverForRuntime(rt, "mdns", nil)

// act
err = rt.initNameResolution()
err = rt.initNameResolution(context.Background())

// assert
assert.NoError(t, err, "expected no error")
Expand All @@ -975,7 +975,7 @@ func TestInitNameResolution(t *testing.T) {
initMockResolverForRuntime(rt, "kubernetes", nil)

// act
err = rt.initNameResolution()
err = rt.initNameResolution(context.Background())

// assert
assert.NoError(t, err, "expected no error")
Expand All @@ -993,7 +993,7 @@ func TestInitNameResolution(t *testing.T) {
initMockResolverForRuntime(rt, "kubernetes", nil)

// act
err = rt.initNameResolution()
err = rt.initNameResolution(context.Background())

// assert
assert.NoError(t, err, "expected no error")
Expand Down
6 changes: 4 additions & 2 deletions pkg/testing/nameresolution_mock.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package testing

import (
"context"

mock "github.com/stretchr/testify/mock"

nr "github.com/dapr/components-contrib/nameresolution"
Expand All @@ -12,13 +14,13 @@ type MockResolver struct {
}

// Init is a mock initialization method.
func (m *MockResolver) Init(metadata nr.Metadata) error {
func (m *MockResolver) Init(_ context.Context, metadata nr.Metadata) error {
args := m.Called(metadata)
return args.Error(0)
}

// ResolveID is a mock resolve method.
func (m *MockResolver) ResolveID(req nr.ResolveRequest) (string, error) {
func (m *MockResolver) ResolveID(_ context.Context, req nr.ResolveRequest) (string, error) {
args := m.Called(req)
return args.String(0), args.Error(1)
}