github.com/m3db/m3@v1.5.0/src/metrics/policy/drop_policy.go (about) 1 // Copyright (c) 2018 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 policy 22 23 // DropPolicy is a metrics dropping policy. 24 type DropPolicy uint 25 26 // NB(r): The enum values are an exact match with protobuf values so they can 27 // be casted to each other. 28 const ( 29 // DropNone specifies not to drop any of the matched metrics. 30 DropNone DropPolicy = iota 31 // DropMust specifies to always drop matched metrics, irregardless of 32 // other rules. Metrics are not dropped from the rollup rules. 33 DropMust 34 // DropIfOnlyMatch specifies to drop matched metrics, but only if no 35 // other rules match. Metrics are not dropped from the rollup rules. 36 DropIfOnlyMatch 37 38 // DefaultDropPolicy is to drop none. 39 DefaultDropPolicy = DropNone 40 ) 41 42 var validDropPolicies = []DropPolicy{ 43 DropNone, 44 DropMust, 45 DropIfOnlyMatch, 46 } 47 48 // IsDefault returns whether the drop policy is the default drop none policy. 49 func (p DropPolicy) IsDefault() bool { 50 return p == DefaultDropPolicy 51 } 52 53 func (p DropPolicy) String() string { 54 switch p { 55 case DropNone: 56 return "drop_none" 57 case DropMust: 58 return "drop_must" 59 case DropIfOnlyMatch: 60 return "drop_if_only_match" 61 } 62 return DropNone.String() 63 } 64 65 // IsValid returns whether a drop policy value is a known valid value. 66 func (p DropPolicy) IsValid() bool { 67 for _, policy := range validDropPolicies { 68 if policy == p { 69 return true 70 } 71 } 72 return false 73 } 74 75 // ValidDropPolicies returns a copy of all the valid drop policies. 76 func ValidDropPolicies() []DropPolicy { 77 return append([]DropPolicy(nil), validDropPolicies...) 78 }