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

logs for backend manager and backends #389

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build-index/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// 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
// 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,
Expand Down Expand Up @@ -136,7 +136,7 @@ func Run(flags *Flags, opts ...Option) {
log.Fatalf("Error creating simple store: %s", err)
}

backends, err := backend.NewManager(config.Backends, config.Auth, stats)
backends, err := backend.NewManager(config.BackendManager, config.Backends, config.Auth, stats)
if err != nil {
log.Fatalf("Error creating backend manager: %s", err)
}
Expand Down
1 change: 1 addition & 0 deletions build-index/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
type Config struct {
ZapLogging zap.Config `yaml:"zap"`
Metrics metrics.Config `yaml:"metrics"`
BackendManager backend.ManagerConfig `yaml:"backend_manager"`
Backends []backend.Config `yaml:"backends"`
Auth backend.AuthConfig `yaml:"auth"`
TagServer tagserver.Config `yaml:"tagserver"`
Expand Down
7 changes: 4 additions & 3 deletions lib/backend/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// 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
// 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,
Expand All @@ -17,15 +17,16 @@ import (
"fmt"
"io"

"github.com/uber/kraken/core"
"github.com/uber-go/tally"
"github.com/uber/kraken/core"
"go.uber.org/zap"
)

var _factories = make(map[string]ClientFactory)

// ClientFactory creates backend client given name.
type ClientFactory interface {
Create(config interface{}, masterAuthConfig AuthConfig, stats tally.Scope) (Client, error)
Create(config interface{}, masterAuthConfig AuthConfig, stats tally.Scope, logger *zap.SugaredLogger) (Client, error)
}

// Register registers new Factory with corresponding backend client name.
Expand Down
8 changes: 5 additions & 3 deletions lib/backend/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// 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
// 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,
Expand All @@ -13,11 +13,13 @@
// limitations under the License.
package backend

import "github.com/uber-go/tally"
import (
"github.com/uber-go/tally"
)

// ManagerFixture returns a Manager with no clients for testing purposes.
func ManagerFixture() *Manager {
m, err := NewManager(nil, AuthConfig{}, tally.NoopScope)
m, err := NewManager(ManagerConfig{}, nil, AuthConfig{}, tally.NoopScope)
if err != nil {
panic(err)
}
Expand Down
3 changes: 2 additions & 1 deletion lib/backend/gcsbackend/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"google.golang.org/api/iterator"
"google.golang.org/api/option"
"gopkg.in/yaml.v2"
"go.uber.org/zap"
)

const _gcs = "gcs"
Expand All @@ -42,7 +43,7 @@ func init() {
type factory struct{}

func (f *factory) Create(
confRaw interface{}, masterAuthConfig backend.AuthConfig, stats tally.Scope) (backend.Client, error) {
confRaw interface{}, masterAuthConfig backend.AuthConfig, stats tally.Scope, _ *zap.SugaredLogger) (backend.Client, error) {

confBytes, err := yaml.Marshal(confRaw)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion lib/backend/gcsbackend/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
)

type clientMocks struct {
Expand Down Expand Up @@ -85,7 +86,7 @@ func TestClientFactory(t *testing.T) {
userAuth := UserAuthConfig{"test-user": auth}
masterAuth := backend.AuthConfig{_gcs: userAuth}
f := factory{}
_, err := f.Create(config, masterAuth, tally.NoopScope)
_, err := f.Create(config, masterAuth, tally.NoopScope, zap.NewNop().Sugar())
fmt.Println(err.Error())
require.True(strings.Contains(err.Error(), "invalid gcs credentials"))
}
Expand Down
5 changes: 3 additions & 2 deletions lib/backend/hdfsbackend/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// 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
// 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,
Expand All @@ -30,6 +30,7 @@ import (
"github.com/uber/kraken/utils/log"

"github.com/satori/go.uuid"
"go.uber.org/zap"
"gopkg.in/yaml.v2"
)

Expand All @@ -42,7 +43,7 @@ func init() {
type factory struct{}

func (f *factory) Create(
confRaw interface{}, masterAuthConfig backend.AuthConfig, stats tally.Scope) (backend.Client, error) {
confRaw interface{}, masterAuthConfig backend.AuthConfig, stats tally.Scope, _ *zap.SugaredLogger) (backend.Client, error) {

confBytes, err := yaml.Marshal(confRaw)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion lib/backend/hdfsbackend/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
)

type clientMocks struct {
Expand Down Expand Up @@ -64,7 +65,7 @@ func TestClientFactory(t *testing.T) {
testing: true,
}
f := factory{}
_, err := f.Create(config, nil, tally.NoopScope)
_, err := f.Create(config, nil, tally.NoopScope, zap.NewNop().Sugar())
require.NoError(err)
}

Expand Down
5 changes: 3 additions & 2 deletions lib/backend/httpbackend/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// 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
// 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,
Expand All @@ -27,6 +27,7 @@ import (
"github.com/uber/kraken/utils/httputil"

"gopkg.in/yaml.v2"
"go.uber.org/zap"
)

const _http = "http"
Expand All @@ -38,7 +39,7 @@ func init() {
type factory struct{}

func (f *factory) Create(
confRaw interface{}, masterAuthConfig backend.AuthConfig, stats tally.Scope) (backend.Client, error) {
confRaw interface{}, masterAuthConfig backend.AuthConfig, stats tally.Scope, _ *zap.SugaredLogger) (backend.Client, error) {

confBytes, err := yaml.Marshal(confRaw)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion lib/backend/httpbackend/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ import (

"github.com/go-chi/chi"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
)

func TestClientFactory(t *testing.T) {
require := require.New(t)

config := Config{}
f := factory{}
_, err := f.Create(config, nil, tally.NoopScope)
_, err := f.Create(config, nil, tally.NoopScope, zap.NewNop().Sugar())
require.NoError(err)
}

Expand Down
15 changes: 13 additions & 2 deletions lib/backend/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,19 @@ type Manager struct {
backends []*backend
}

// ManagerConfig is config for backend manager.
type ManagerConfig struct {
Log log.Config `yaml:"log"`
}

// NewManager creates a new backend Manager.
func NewManager(configs []Config, auth AuthConfig, stats tally.Scope) (*Manager, error) {
func NewManager(managerConfig ManagerConfig, configs []Config, auth AuthConfig, stats tally.Scope) (*Manager, error) {
logger, err := log.New(managerConfig.Log, nil)
if err != nil {
return nil, fmt.Errorf("log: %s", err)
}
slogger := logger.Sugar()

var backends []*backend
for _, config := range configs {
config = config.applyDefaults()
Expand All @@ -71,7 +82,7 @@ func NewManager(configs []Config, auth AuthConfig, stats tally.Scope) (*Manager,
if err != nil {
return nil, fmt.Errorf("get backend client factory: %s", err)
}
c, err = factory.Create(backendConfig, auth, stats)
c, err = factory.Create(backendConfig, auth, stats, slogger)
if err != nil {
return nil, fmt.Errorf("create backend client: %s", err)
}
Expand Down
28 changes: 15 additions & 13 deletions lib/backend/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestManagerNamespaceOrdering(t *testing.T) {
var configs []Config
require.NoError(yaml.Unmarshal([]byte(configStr), &configs))

m, err := NewManager(configs, AuthConfig{}, tally.NoopScope)
m, err := NewManager(ManagerConfig{}, configs, AuthConfig{}, tally.NoopScope)
require.NoError(err)

for ns, expected := range map[string]string{
Expand All @@ -128,18 +128,20 @@ func TestManagerNamespaceOrdering(t *testing.T) {
func TestManagerBandwidth(t *testing.T) {
require := require.New(t)

m, err := NewManager([]Config{{
Namespace: ".*",
Bandwidth: bandwidth.Config{
EgressBitsPerSec: 10,
IngressBitsPerSec: 50,
TokenSize: 1,
Enable: true,
},
Backend: map[string]interface{}{
"testfs": testfs.Config{Addr: "test-addr", NamePath: namepath.Identity},
},
}}, AuthConfig{}, tally.NoopScope)
m, err := NewManager(
ManagerConfig{},
[]Config{{
Namespace: ".*",
Bandwidth: bandwidth.Config{
EgressBitsPerSec: 10,
IngressBitsPerSec: 50,
TokenSize: 1,
Enable: true,
},
Backend: map[string]interface{}{
"testfs": testfs.Config{Addr: "test-addr", NamePath: namepath.Identity},
},
}}, AuthConfig{}, tally.NoopScope)
require.NoError(err)

checkBandwidth := func(egress, ingress int64) {
Expand Down
3 changes: 2 additions & 1 deletion lib/backend/registrybackend/blobclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/uber/kraken/utils/httputil"
"github.com/uber/kraken/utils/log"
yaml "gopkg.in/yaml.v2"
"go.uber.org/zap"
)

const _registryblob = "registry_blob"
Expand All @@ -39,7 +40,7 @@ func init() {
type blobClientFactory struct{}

func (f *blobClientFactory) Create(
confRaw interface{}, masterAuthConfig backend.AuthConfig, stats tally.Scope) (backend.Client, error) {
confRaw interface{}, masterAuthConfig backend.AuthConfig, stats tally.Scope, _ *zap.SugaredLogger) (backend.Client, error) {

confBytes, err := yaml.Marshal(confRaw)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion lib/backend/registrybackend/blobclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ import (
"github.com/uber/kraken/utils/memsize"
"github.com/uber/kraken/utils/randutil"
"github.com/uber/kraken/utils/testutil"
"go.uber.org/zap"
)

func TestClientFactory(t *testing.T) {
require := require.New(t)

config := Config{}
f := blobClientFactory{}
_, err := f.Create(config, nil, tally.NoopScope)
_, err := f.Create(config, nil, tally.NoopScope, zap.NewNop().Sugar())
require.NoError(err)
}

Expand Down
5 changes: 3 additions & 2 deletions lib/backend/registrybackend/tagclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// 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
// 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,
Expand All @@ -28,6 +28,7 @@ import (
"github.com/uber/kraken/lib/backend/registrybackend/security"
"github.com/uber/kraken/utils/dockerutil"
"github.com/uber/kraken/utils/httputil"
"go.uber.org/zap"
yaml "gopkg.in/yaml.v2"
)

Expand All @@ -40,7 +41,7 @@ func init() {
type tagClientFactory struct{}

func (f *tagClientFactory) Create(
confRaw interface{}, masterAuthConfig backend.AuthConfig, stats tally.Scope) (backend.Client, error) {
confRaw interface{}, masterAuthConfig backend.AuthConfig, stats tally.Scope, _ *zap.SugaredLogger) (backend.Client, error) {

confBytes, err := yaml.Marshal(confRaw)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion lib/backend/s3backend/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/service/s3/s3manager"
"gopkg.in/yaml.v2"
"go.uber.org/zap"
)

const _s3 = "s3"
Expand All @@ -45,7 +46,7 @@ func init() {
type factory struct{}

func (f *factory) Create(
confRaw interface{}, masterAuthConfig backend.AuthConfig, stats tally.Scope) (backend.Client, error) {
confRaw interface{}, masterAuthConfig backend.AuthConfig, stats tally.Scope, _ *zap.SugaredLogger) (backend.Client, error) {

confBytes, err := yaml.Marshal(confRaw)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion lib/backend/s3backend/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/aws/aws-sdk-go/service/s3/s3manager"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
)

type clientMocks struct {
Expand Down Expand Up @@ -82,7 +83,7 @@ func TestClientFactory(t *testing.T) {
userAuth := UserAuthConfig{"test-user": auth}
masterAuth := backend.AuthConfig{_s3: userAuth}
f := factory{}
_, err := f.Create(config, masterAuth, tally.NoopScope)
_, err := f.Create(config, masterAuth, tally.NoopScope, zap.NewNop().Sugar())
require.NoError(err)
}

Expand Down
5 changes: 3 additions & 2 deletions lib/backend/shadowbackend/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// 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
// 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,
Expand All @@ -27,6 +27,7 @@ import (
"github.com/uber/kraken/lib/backend/sqlbackend"
"github.com/uber/kraken/lib/backend/testfs"
"github.com/uber/kraken/utils/log"
"go.uber.org/zap"
"gopkg.in/yaml.v2"
)

Expand All @@ -43,7 +44,7 @@ func (f *factory) Name() string {
}

func (f *factory) Create(
confRaw interface{}, masterAuthConfig backend.AuthConfig, stats tally.Scope) (backend.Client, error) {
confRaw interface{}, masterAuthConfig backend.AuthConfig, stats tally.Scope, _ *zap.SugaredLogger) (backend.Client, error) {

confBytes, err := yaml.Marshal(confRaw)
if err != nil {
Expand Down
Loading
Loading