This repository has been archived by the owner on Oct 17, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Chao Wang
committed
Jun 23, 2017
1 parent
977ac1b
commit 2884ab9
Showing
3 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package cache | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/m3db/m3metrics/matcher" | ||
"github.com/m3db/m3x/clock" | ||
"github.com/m3db/m3x/instrument" | ||
) | ||
|
||
// Configuration is config used to create a matcher.Cache. | ||
type Configuration struct { | ||
Capacity int `yaml:"capacity"` | ||
FreshDuration time.Duration `yaml:"freshDuration"` | ||
StutterDuration time.Duration `yaml:"stutterDuration"` | ||
EvictionBatchSize int `yaml:"evictionBatchSize"` | ||
DeletionBatchSize int `yaml:"deletionBatchSize"` | ||
} | ||
|
||
// NewCache creates a matcher.Cache. | ||
func (cfg *Configuration) NewCache( | ||
clockOpts clock.Options, | ||
instrumentOpts instrument.Options, | ||
) matcher.Cache { | ||
opts := NewOptions(). | ||
SetClockOptions(clockOpts). | ||
SetInstrumentOptions(instrumentOpts) | ||
if cfg.Capacity != 0 { | ||
opts = opts.SetCapacity(cfg.Capacity) | ||
} | ||
if cfg.FreshDuration != 0 { | ||
opts = opts.SetFreshDuration(cfg.FreshDuration) | ||
} | ||
if cfg.StutterDuration != 0 { | ||
opts = opts.SetStutterDuration(cfg.StutterDuration) | ||
} | ||
if cfg.EvictionBatchSize != 0 { | ||
opts = opts.SetEvictionBatchSize(cfg.EvictionBatchSize) | ||
} | ||
if cfg.DeletionBatchSize != 0 { | ||
opts = opts.SetDeletionBatchSize(cfg.DeletionBatchSize) | ||
} | ||
|
||
return NewCache(opts) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright (c) 2017 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package matcher | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/m3db/m3cluster/client" | ||
"github.com/m3db/m3metrics/metric/id" | ||
"github.com/m3db/m3metrics/metric/id/m3" | ||
"github.com/m3db/m3metrics/rules" | ||
"github.com/m3db/m3x/clock" | ||
"github.com/m3db/m3x/instrument" | ||
) | ||
|
||
// Configuration is config used to create a matcher.Matcher. | ||
type Configuration struct { | ||
TagsFilter m3.TagsFilterConfiguration `yaml:"tagsFilter" validate:"nonzero"` | ||
InitWatchTimeout time.Duration `yaml:"initWatchTimeout"` | ||
RulesKVNamespace string `yaml:"rulesKVNamespace" validate:"nonzero"` | ||
NamespacesKey string `yaml:"namespacesKey" validate:"nonzero"` | ||
RuleSetKeyFmt string `yaml:"ruleSetKeyFmt" validate:"nonzero"` | ||
NamespaceTag string `yaml:"namespaceTag" validate:"nonzero"` | ||
DefaultNamespace string `yaml:"defaultNamespace" validate:"nonzero"` | ||
} | ||
|
||
// NewMatcher creates a Matcher. | ||
func (cfg *Configuration) NewMatcher( | ||
cache Cache, | ||
kvCluster client.Client, | ||
iter id.SortedTagIterator, | ||
clockOpts clock.Options, | ||
instrumentOpts instrument.Options, | ||
) (Matcher, error) { | ||
isRollupIDFn := func(name []byte, tags []byte) bool { | ||
return m3.IsRollupID(name, tags, iter) | ||
} | ||
// Configure ruleset options. | ||
tagsFilterOpts := cfg.TagsFilter.NewTagsFilterOptions(instrumentOpts) | ||
ruleSetOpts := rules.NewOptions(). | ||
SetTagsFilterOptions(tagsFilterOpts). | ||
SetNewRollupIDFn(m3.NewRollupID). | ||
SetIsRollupIDFn(isRollupIDFn) | ||
|
||
// Configure rules kv store. | ||
rulesStore, err := kvCluster.Store(cfg.RulesKVNamespace) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Configure ruleset key function. | ||
ruleSetKeyFn := func(namespace []byte) string { | ||
return fmt.Sprintf(cfg.RuleSetKeyFmt, namespace) | ||
} | ||
|
||
opts := NewOptions(). | ||
SetClockOptions(clockOpts). | ||
SetInstrumentOptions(instrumentOpts). | ||
SetRuleSetOptions(ruleSetOpts). | ||
SetKVStore(rulesStore). | ||
SetNamespacesKey(cfg.NamespacesKey). | ||
SetRuleSetKeyFn(ruleSetKeyFn). | ||
SetNamespaceTag([]byte(cfg.NamespaceTag)). | ||
SetDefaultNamespace([]byte(cfg.DefaultNamespace)) | ||
|
||
if cfg.InitWatchTimeout != 0 { | ||
opts = opts.SetInitWatchTimeout(cfg.InitWatchTimeout) | ||
} | ||
|
||
return NewMatcher(cache, opts) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters