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

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Chao Wang committed Oct 13, 2017
1 parent dabe346 commit 3729762
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 115 deletions.
22 changes: 11 additions & 11 deletions matcher/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ import (

// Configuration is config used to create a Matcher.
type Configuration struct {
InitWatchTimeout time.Duration `yaml:"initWatchTimeout"`
RulesKVConfig kv.Configuration `yaml:"rulesKVConfig"`
NamespacesKey string `yaml:"namespacesKey" validate:"nonzero"`
RuleSetKeyFmt string `yaml:"ruleSetKeyFmt" validate:"nonzero"`
NamespaceTag string `yaml:"namespaceTag" validate:"nonzero"`
DefaultNamespace string `yaml:"defaultNamespace" validate:"nonzero"`
NameTagKey string `yaml:"nameTagKey" validate:"nonzero"`
MatchRangePast *time.Duration `yaml:"matchRangePast"`
SortedTagIteratorPool pool.ObjectPoolConfiguration `yaml:"sortedTagIteratorPool"`
Policy policy.Configuration `yaml:"policy"`
InitWatchTimeout time.Duration `yaml:"initWatchTimeout"`
RulesKVConfig kv.Configuration `yaml:"rulesKVConfig"`
NamespacesKey string `yaml:"namespacesKey" validate:"nonzero"`
RuleSetKeyFmt string `yaml:"ruleSetKeyFmt" validate:"nonzero"`
NamespaceTag string `yaml:"namespaceTag" validate:"nonzero"`
DefaultNamespace string `yaml:"defaultNamespace" validate:"nonzero"`
NameTagKey string `yaml:"nameTagKey" validate:"nonzero"`
MatchRangePast *time.Duration `yaml:"matchRangePast"`
SortedTagIteratorPool pool.ObjectPoolConfiguration `yaml:"sortedTagIteratorPool"`
AggregationTypes policy.AggregationTypesConfiguration `yaml:"aggregationTypes"`
}

// NewNamespaces creates a matcher.Namespaces.
Expand Down Expand Up @@ -118,7 +118,7 @@ func (cfg *Configuration) NewOptions(
SetTagsFilterOptions(tagsFilterOptions).
SetNewRollupIDFn(m3.NewRollupID).
SetIsRollupIDFn(isRollupIDFn).
SetPolicyOptions(cfg.Policy.NewOptions())
SetAggregationTypesOptions(cfg.AggregationTypes.NewOptions())

// Configure ruleset key function.
ruleSetKeyFn := func(namespace []byte) string {
Expand Down
2 changes: 1 addition & 1 deletion matcher/namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type Namespaces interface {
ForwardMatch(namespace, id []byte, fromNanos, toNanos int64) rules.MatchResult

// ReverseMatch reverse matches the matching policies for a given id in a given namespace
// between [fromNanos, toNanos), with aware of the metric type and aggregation type for the given id.
// between [fromNanos, toNanos), taking into account the metric type and aggregation type for the given id.
ReverseMatch(namespace, id []byte, fromNanos, toNanos int64, mt metric.Type, at policy.AggregationType) rules.MatchResult

// Close closes the namespaces.
Expand Down
5 changes: 3 additions & 2 deletions policy/aggregation_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,9 @@ func (id AggregationID) Contains(aggType AggregationType) bool {
if !aggType.IsValid() {
return false
}

return (id[int(aggType)/64] & (1 << (uint(aggType) % 64))) > 0
idx := int(aggType) >> 6
offset := uint(aggType) & 0x3F
return (id[idx] & (1 << offset)) > 0
}

// AggregationTypes returns the aggregation types defined by the id.
Expand Down
26 changes: 13 additions & 13 deletions policy/config.go → policy/aggregation_type_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,29 @@

package policy

// Configuration contains configuration.
type Configuration struct {
// AggregationTypesConfiguration contains configuration for aggregation types.
type AggregationTypesConfiguration struct {
// Default aggregation types for counter metrics.
CounterAggregationTypes *AggregationTypes `yaml:"counterAggregationTypes" validate:"nonzero"`
DefaultCounterAggregationTypes *AggregationTypes `yaml:"defaultCounterAggregationTypes"`

// Default aggregation types for timer metrics.
TimerAggregationTypes *AggregationTypes `yaml:"timerAggregationTypes" validate:"nonzero"`
DefaultTimerAggregationTypes *AggregationTypes `yaml:"defaultTimerAggregationTypes"`

// Default aggregation types for gauge metrics.
GaugeAggregationTypes *AggregationTypes `yaml:"gaugeAggregationTypes" validate:"nonzero"`
DefaultGaugeAggregationTypes *AggregationTypes `yaml:"defaultGaugeAggregationTypes"`
}

// NewOptions creates a new Option.
func (c Configuration) NewOptions() Options {
opts := NewOptions()
if c.CounterAggregationTypes != nil {
opts = opts.SetDefaultCounterAggregationTypes(*c.CounterAggregationTypes)
func (c AggregationTypesConfiguration) NewOptions() AggregationTypesOptions {
opts := NewAggregationTypesOptions()
if c.DefaultCounterAggregationTypes != nil {
opts = opts.SetDefaultCounterAggregationTypes(*c.DefaultCounterAggregationTypes)
}
if c.GaugeAggregationTypes != nil {
opts = opts.SetDefaultGaugeAggregationTypes(*c.GaugeAggregationTypes)
if c.DefaultGaugeAggregationTypes != nil {
opts = opts.SetDefaultGaugeAggregationTypes(*c.DefaultGaugeAggregationTypes)
}
if c.TimerAggregationTypes != nil {
opts = opts.SetDefaultTimerAggregationTypes(*c.TimerAggregationTypes)
if c.DefaultTimerAggregationTypes != nil {
opts = opts.SetDefaultTimerAggregationTypes(*c.DefaultTimerAggregationTypes)
}
return opts
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ import (
yaml "gopkg.in/yaml.v2"
)

func TestConfig(t *testing.T) {
func TestAggregationTypesConfiguration(t *testing.T) {
str := `
gaugeAggregationTypes: Max
timerAggregationTypes: P50,P99,P9999
defaultGaugeAggregationTypes: Max
defaultTimerAggregationTypes: P50,P99,P9999
`

var cfg Configuration
var cfg AggregationTypesConfiguration
require.NoError(t, yaml.Unmarshal([]byte(str), &cfg))
opts := cfg.NewOptions()
require.Equal(t, defaultDefaultCounterAggregationTypes, opts.DefaultCounterAggregationTypes())
Expand Down
54 changes: 38 additions & 16 deletions policy/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,33 @@

package policy

// Options provides a set of options for
type Options interface {
// SetDefaultCounterAggregationTypes sets the counter aggregation types.
SetDefaultCounterAggregationTypes(value AggregationTypes) Options
import (
"github.com/m3db/m3metrics/metric"
)

// AggregationTypesOptions provides a set of options for aggregation types.
type AggregationTypesOptions interface {
// SetDefaultCounterAggregationTypes sets the default aggregation types for counters.
SetDefaultCounterAggregationTypes(value AggregationTypes) AggregationTypesOptions

// DefaultCounterAggregationTypes returns the aggregation types for counters.
// DefaultCounterAggregationTypes returns the default aggregation types for counters.
DefaultCounterAggregationTypes() AggregationTypes

// SetDefaultTimerAggregationTypes sets the timer aggregation types.
SetDefaultTimerAggregationTypes(value AggregationTypes) Options
// SetDefaultTimerAggregationTypes sets the default aggregation types for timers.
SetDefaultTimerAggregationTypes(value AggregationTypes) AggregationTypesOptions

// DefaultTimerAggregationTypes returns the aggregation types for timers.
// DefaultTimerAggregationTypes returns the default aggregation types for timers.
DefaultTimerAggregationTypes() AggregationTypes

// SetDefaultGaugeAggregationTypes sets the gauge aggregation types.
SetDefaultGaugeAggregationTypes(value AggregationTypes) Options
// SetDefaultGaugeAggregationTypes sets the default aggregation types for gauges.
SetDefaultGaugeAggregationTypes(value AggregationTypes) AggregationTypesOptions

// DefaultGaugeAggregationTypes returns the aggregation types for gauges.
// DefaultGaugeAggregationTypes returns the default aggregation types for gauges.
DefaultGaugeAggregationTypes() AggregationTypes

// IsContainedInDefaultAggregationTypes checks if the given aggregation type is
// contained in the default aggregation types for the metric type.
IsContainedInDefaultAggregationTypes(at AggregationType, mt metric.Type) bool
}

var (
Expand Down Expand Up @@ -69,16 +77,16 @@ type options struct {
defaultGaugeAggregationTypes AggregationTypes
}

// NewOptions returns a default Options.
func NewOptions() Options {
// NewAggregationTypesOptions returns a default Options.
func NewAggregationTypesOptions() AggregationTypesOptions {
return &options{
defaultCounterAggregationTypes: defaultDefaultCounterAggregationTypes,
defaultGaugeAggregationTypes: defaultDefaultGaugeAggregationTypes,
defaultTimerAggregationTypes: defaultDefaultTimerAggregationTypes,
}
}

func (o *options) SetDefaultCounterAggregationTypes(aggTypes AggregationTypes) Options {
func (o *options) SetDefaultCounterAggregationTypes(aggTypes AggregationTypes) AggregationTypesOptions {
opts := *o
opts.defaultCounterAggregationTypes = aggTypes
return &opts
Expand All @@ -88,7 +96,7 @@ func (o *options) DefaultCounterAggregationTypes() AggregationTypes {
return o.defaultCounterAggregationTypes
}

func (o *options) SetDefaultTimerAggregationTypes(aggTypes AggregationTypes) Options {
func (o *options) SetDefaultTimerAggregationTypes(aggTypes AggregationTypes) AggregationTypesOptions {
opts := *o
opts.defaultTimerAggregationTypes = aggTypes
return &opts
Expand All @@ -98,7 +106,7 @@ func (o *options) DefaultTimerAggregationTypes() AggregationTypes {
return o.defaultTimerAggregationTypes
}

func (o *options) SetDefaultGaugeAggregationTypes(aggTypes AggregationTypes) Options {
func (o *options) SetDefaultGaugeAggregationTypes(aggTypes AggregationTypes) AggregationTypesOptions {
opts := *o
opts.defaultGaugeAggregationTypes = aggTypes
return &opts
Expand All @@ -107,3 +115,17 @@ func (o *options) SetDefaultGaugeAggregationTypes(aggTypes AggregationTypes) Opt
func (o *options) DefaultGaugeAggregationTypes() AggregationTypes {
return o.defaultGaugeAggregationTypes
}

func (o *options) IsContainedInDefaultAggregationTypes(at AggregationType, mt metric.Type) bool {
var aggTypes AggregationTypes
switch mt {
case metric.CounterType:
aggTypes = o.DefaultCounterAggregationTypes()
case metric.GaugeType:
aggTypes = o.DefaultGaugeAggregationTypes()
case metric.TimerType:
aggTypes = o.DefaultTimerAggregationTypes()
}

return aggTypes.Contains(at)
}
2 changes: 1 addition & 1 deletion policy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func NewPoliciesFromSchema(policies []*schema.Policy) ([]Policy, error) {
return res, nil
}

// IsDefaultPolicies checks if the policies is default.
// IsDefaultPolicies checks if the policies are the default policies.
func IsDefaultPolicies(ps []Policy) bool {
return len(ps) == 0
}
Expand Down
20 changes: 10 additions & 10 deletions rules/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,24 @@ type Options interface {
// IsRollupIDFn returns the function that determines whether an id is a rollup id.
IsRollupIDFn() id.MatchIDFn

// SetPolicyOptions sets the policy options.
SetPolicyOptions(v policy.Options) Options
// SetAggregationTypesOptions sets the aggregation types options.
SetAggregationTypesOptions(v policy.AggregationTypesOptions) Options

// PolicyOptions returns the policy options.
PolicyOptions() policy.Options
// PolicyOptions returns the aggregation types options.
AggregationTypesOptions() policy.AggregationTypesOptions
}

type options struct {
tagsFilterOpts filters.TagsFilterOptions
newRollupIDFn id.NewIDFn
isRollupIDFn id.MatchIDFn
pOpts policy.Options
aggOpts policy.AggregationTypesOptions
}

// NewOptions creates a new set of options.
func NewOptions() Options {
return &options{
pOpts: policy.NewOptions(),
aggOpts: policy.NewAggregationTypesOptions(),
}
}

Expand Down Expand Up @@ -97,12 +97,12 @@ func (o *options) IsRollupIDFn() id.MatchIDFn {
return o.isRollupIDFn
}

func (o *options) SetPolicyOptions(value policy.Options) Options {
func (o *options) SetAggregationTypesOptions(value policy.AggregationTypesOptions) Options {
opts := *o
opts.pOpts = value
opts.aggOpts = value
return &opts
}

func (o *options) PolicyOptions() policy.Options {
return o.pOpts
func (o *options) AggregationTypesOptions() policy.AggregationTypesOptions {
return o.aggOpts
}

0 comments on commit 3729762

Please sign in to comment.