Skip to content
This repository has been archived by the owner on Oct 17, 2018. It is now read-only.

Commit

Permalink
Add match mode to config
Browse files Browse the repository at this point in the history
  • Loading branch information
Chao Wang committed Jun 26, 2017
1 parent 54d3c25 commit 7229a72
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
19 changes: 18 additions & 1 deletion matcher/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type Configuration struct {
DefaultNamespace string `yaml:"defaultNamespace" validate:"nonzero"`
NameTagKey string `yaml:"nameTagKey" validate:"nonzero"`
SortedTagIteratorPool pool.ObjectPoolConfiguration `yaml:"sortedTagIteratorPool"`
MatchMode string `yaml:"matchMode"`
}

// NewNamespaces creates a matcher.Namespaces.
Expand Down Expand Up @@ -82,6 +83,11 @@ func (cfg *Configuration) NewOptions(
clockOpts clock.Options,
instrumentOpts instrument.Options,
) (Options, error) {
mode, err := parseMatchMode(cfg.MatchMode)
if err != nil {
return nil, err
}

// Configure rules kv store.
rulesStore, err := kvCluster.Store(cfg.RulesKVNamespace)
if err != nil {
Expand Down Expand Up @@ -128,11 +134,22 @@ func (cfg *Configuration) NewOptions(
SetNamespacesKey(cfg.NamespacesKey).
SetRuleSetKeyFn(ruleSetKeyFn).
SetNamespaceTag([]byte(cfg.NamespaceTag)).
SetDefaultNamespace([]byte(cfg.DefaultNamespace))
SetDefaultNamespace([]byte(cfg.DefaultNamespace)).
SetMatchMode(mode)

if cfg.InitWatchTimeout != 0 {
opts = opts.SetInitWatchTimeout(cfg.InitWatchTimeout)
}

return opts, nil
}

func parseMatchMode(value string) (rules.MatchMode, error) {
mode := rules.MatchMode(value)
switch mode {
case rules.ForwardMatch, rules.ReverseMatch:
return mode, nil
default:
return mode, fmt.Errorf("unknown match mode: %s", value)
}
}
3 changes: 3 additions & 0 deletions matcher/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/golang/mock/gomock"
"github.com/m3db/m3cluster/client"
"github.com/m3db/m3cluster/kv/mem"
"github.com/m3db/m3metrics/rules"
"github.com/m3db/m3x/clock"
"github.com/m3db/m3x/instrument"

Expand All @@ -41,6 +42,7 @@ func TestConfigurationNewNamespaces(t *testing.T) {
NamespaceTag: "NamespaceTag",
DefaultNamespace: "DefaultNamespace",
NameTagKey: "NameTagKey",
MatchMode: "forward",
}

ctrl := gomock.NewController(t)
Expand All @@ -57,4 +59,5 @@ func TestConfigurationNewNamespaces(t *testing.T) {
require.Equal(t, cfg.NamespacesKey, opts.NamespacesKey())
require.Equal(t, []byte(cfg.NamespaceTag), opts.NamespaceTag())
require.Equal(t, []byte(cfg.DefaultNamespace), opts.DefaultNamespace())
require.Equal(t, rules.ForwardMatch, opts.MatchMode())
}
6 changes: 3 additions & 3 deletions rules/ruleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ var (
)

// MatchMode determines how match is performed.
type MatchMode int
type MatchMode string

// List of supported match modes.
const (
// When performing matches in ForwardMatch mode, the matcher matches the given id against
// both the mapping rules and rollup rules to find out the applicable mapping policies
// and rollup policies.
ForwardMatch MatchMode = iota
ForwardMatch MatchMode = "forward"

// When performing matches in ReverseMatch mode, the matcher find the applicable mapping
// policies for the given id.
ReverseMatch
ReverseMatch MatchMode = "reverse"
)

// Matcher matches metrics against rules to determine applicable policies.
Expand Down

0 comments on commit 7229a72

Please sign in to comment.