Skip to content

Commit

Permalink
Remove unused config (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
yun-wang authored and jswarren4 committed Dec 3, 2018
1 parent dd1db35 commit 275ce1c
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 26 deletions.
12 changes: 5 additions & 7 deletions rules/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ type channelCloser func()

type v3Engine struct {
baseEngine
configV3 clientv3.Config
keyProc v3KeyProcessor
workChannel chan v3RuleWork
kvWrapper WrapKV
Expand All @@ -71,20 +70,20 @@ func NewV3Engine(configV3 clientv3.Config, logger *zap.Logger, options ...Engine
if err != nil {
logger.Fatal("Failed to connect to etcd", zap.Error(err))
}
return NewV3EngineWithClient(cl, configV3, logger, options...)
return NewV3EngineWithClient(cl, logger, options...)
}

// NewV3EngineWithClient creates a new V3Engine instance with the provided etcd v3 client instance.
func NewV3EngineWithClient(cl *clientv3.Client, configV3 clientv3.Config, logger *zap.Logger, options ...EngineOption) V3Engine {
eng := newV3Engine(configV3, logger, cl, options...)
func NewV3EngineWithClient(cl *clientv3.Client, logger *zap.Logger, options ...EngineOption) V3Engine {
eng := newV3Engine(logger, cl, options...)
return &eng
}

func newV3Engine(configV3 clientv3.Config, logger *zap.Logger, cl *clientv3.Client, options ...EngineOption) v3Engine {
func newV3Engine(logger *zap.Logger, cl *clientv3.Client, options ...EngineOption) v3Engine {
opts := makeEngineOptions(options...)
ruleMgr := newRuleManager(opts.constraints, opts.enhancedRuleFilter)
channel := make(chan v3RuleWork)
keyProc := newV3KeyProcessor(channel, &configV3, &ruleMgr)
keyProc := newV3KeyProcessor(channel, &ruleMgr)
eng := v3Engine{
baseEngine: baseEngine{
cCloser: func() {
Expand All @@ -96,7 +95,6 @@ func newV3Engine(configV3 clientv3.Config, logger *zap.Logger, cl *clientv3.Clie
ruleLockTTLs: map[int]int{},
ruleMgr: ruleMgr,
},
configV3: configV3,
keyProc: keyProc,
workChannel: channel,
kvWrapper: defaultWrapKV,
Expand Down
3 changes: 1 addition & 2 deletions rules/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,10 @@ func TestV3EngineConstructor(t *testing.T) {
}

func TestV3CallbackWrapper(t *testing.T) {
cfg, c := initV3Etcd()
_, c := initV3Etcd()
defer c.Close()
task := V3RuleTask{
Attr: &mapAttributes{values: map[string]string{"a": "b"}},
Conf: &cfg,
Logger: getTestLogger(),
}
cbw := v3CallbackWrapper{
Expand Down
16 changes: 5 additions & 11 deletions rules/key_processor.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package rules

import (
"github.com/coreos/etcd/clientv3"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -38,7 +37,6 @@ type v3KeyProcessor struct {
baseKeyProcessor
callbacks map[int]V3RuleTaskCallback
channel chan v3RuleWork
config *clientv3.Config
}

func (v3kp *v3KeyProcessor) setCallback(index int, callback interface{}) {
Expand All @@ -48,26 +46,23 @@ func (v3kp *v3KeyProcessor) setCallback(index int, callback interface{}) {
func (v3kp *v3KeyProcessor) dispatchWork(index int, rule staticRule, logger *zap.Logger, keyPattern string, metadata map[string]string) {
context, cancelFunc := v3kp.contextProviders[index]()
task := V3RuleTask{
Attr: rule.getAttributes(),
// This line is different
Conf: v3kp.config,
Attr: rule.getAttributes(),
Logger: logger,
Context: context,
cancel: cancelFunc,
Metadata: metadata,
}
work := v3RuleWork{
rule: rule,
ruleIndex: index,
ruleTask: task,
// This line is different
rule: rule,
ruleIndex: index,
ruleTask: task,
ruleTaskCallback: v3kp.callbacks[index],
lockKey: FormatWithAttributes(keyPattern, rule.getAttributes()),
}
v3kp.channel <- work
}

func newV3KeyProcessor(channel chan v3RuleWork, config *clientv3.Config, rm *ruleManager) v3KeyProcessor {
func newV3KeyProcessor(channel chan v3RuleWork, rm *ruleManager) v3KeyProcessor {
kp := v3KeyProcessor{
baseKeyProcessor: baseKeyProcessor{
contextProviders: map[int]ContextProvider{},
Expand All @@ -76,7 +71,6 @@ func newV3KeyProcessor(channel chan v3RuleWork, config *clientv3.Config, rm *rul
},
callbacks: map[int]V3RuleTaskCallback{},
channel: channel,
config: config,
}
return kp
}
Expand Down
2 changes: 0 additions & 2 deletions rules/key_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package rules
import (
"testing"

"github.com/coreos/etcd/clientv3"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -51,7 +50,6 @@ func TestV3KeyProcessor(t *testing.T) {
},
callbacks: callbacks,
channel: channel,
config: &clientv3.Config{},
}
logger := getTestLogger()
go kp.processKey("/test/key", &value, api, logger, map[string]string{})
Expand Down
2 changes: 0 additions & 2 deletions rules/task.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package rules

import (
"github.com/coreos/etcd/clientv3"
"go.uber.org/zap"
"golang.org/x/net/context"
)
Expand All @@ -19,7 +18,6 @@ type Attributes interface {
// for use by rule callbacks.
type V3RuleTask struct {
Attr Attributes
Conf *clientv3.Config
Logger *zap.Logger
Context context.Context
cancel context.CancelFunc
Expand Down
3 changes: 1 addition & 2 deletions rules/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestWorkerSingleRun(t *testing.T) {
}
cl, err := clientv3.New(conf)
assert.NoError(t, err)
e := newV3Engine(conf, getTestLogger(), cl, EngineLockTimeout(300))
e := newV3Engine(getTestLogger(), cl, EngineLockTimeout(300))
channel := e.workChannel
lockChannel := make(chan bool)
locker := testLocker{
Expand All @@ -36,7 +36,6 @@ func TestWorkerSingleRun(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
task := V3RuleTask{
Attr: &attr,
Conf: &clientv3.Config{},
Logger: getTestLogger(),
Metadata: map[string]string{},
Context: ctx,
Expand Down

0 comments on commit 275ce1c

Please sign in to comment.