github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/metrics/rules/options.go (about)

     1  // Copyright (c) 2017 Uber Technologies, Inc.
     2  //
     3  // Permission is hereby granted, free of charge, to any person obtaining a copy
     4  // of this software and associated documentation files (the "Software"), to deal
     5  // in the Software without restriction, including without limitation the rights
     6  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     7  // copies of the Software, and to permit persons to whom the Software is
     8  // furnished to do so, subject to the following conditions:
     9  //
    10  // The above copyright notice and this permission notice shall be included in
    11  // all copies or substantial portions of the Software.
    12  //
    13  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    14  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    15  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    16  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    17  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    18  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    19  // THE SOFTWARE.
    20  
    21  package rules
    22  
    23  import (
    24  	"github.com/m3db/m3/src/metrics/filters"
    25  	"github.com/m3db/m3/src/metrics/metric/id"
    26  )
    27  
    28  // Options provide a set of options for rule matching.
    29  type Options interface {
    30  	// SetTagsFilterOptions sets the tags filter options.
    31  	SetTagsFilterOptions(value filters.TagsFilterOptions) Options
    32  
    33  	// TagsFilterOptions returns the tags filter options.
    34  	TagsFilterOptions() filters.TagsFilterOptions
    35  
    36  	// SetNewRollupIDFn sets the new rollup id function.
    37  	SetNewRollupIDFn(value id.NewIDFn) Options
    38  
    39  	// NewRollupIDFn returns the new rollup id function.
    40  	NewRollupIDFn() id.NewIDFn
    41  
    42  	// SetIsRollupIDFn sets the function that determines whether an id is a rollup id.
    43  	SetIsRollupIDFn(value id.MatchIDFn) Options
    44  
    45  	// IsRollupIDFn returns the function that determines whether an id is a rollup id.
    46  	IsRollupIDFn() id.MatchIDFn
    47  }
    48  
    49  type options struct {
    50  	tagsFilterOpts filters.TagsFilterOptions
    51  	newRollupIDFn  id.NewIDFn
    52  	isRollupIDFn   id.MatchIDFn
    53  }
    54  
    55  // NewOptions creates a new set of options.
    56  func NewOptions() Options {
    57  	return &options{}
    58  }
    59  
    60  func (o *options) SetTagsFilterOptions(value filters.TagsFilterOptions) Options {
    61  	opts := *o
    62  	opts.tagsFilterOpts = value
    63  	return &opts
    64  }
    65  
    66  func (o *options) TagsFilterOptions() filters.TagsFilterOptions {
    67  	return o.tagsFilterOpts
    68  }
    69  
    70  func (o *options) SetNewRollupIDFn(value id.NewIDFn) Options {
    71  	opts := *o
    72  	opts.newRollupIDFn = value
    73  	return &opts
    74  }
    75  
    76  func (o *options) NewRollupIDFn() id.NewIDFn {
    77  	return o.newRollupIDFn
    78  }
    79  
    80  func (o *options) SetIsRollupIDFn(value id.MatchIDFn) Options {
    81  	opts := *o
    82  	opts.isRollupIDFn = value
    83  	return &opts
    84  }
    85  
    86  func (o *options) IsRollupIDFn() id.MatchIDFn {
    87  	return o.isRollupIDFn
    88  }