github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/metrics/rules/view/mapping.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 view 22 23 import ( 24 "github.com/m3db/m3/src/metrics/aggregation" 25 "github.com/m3db/m3/src/metrics/policy" 26 "github.com/m3db/m3/src/query/models" 27 ) 28 29 // MappingRule is a mapping rule model at a given point in time. 30 type MappingRule struct { 31 ID string `json:"id,omitempty"` 32 Name string `json:"name" validate:"required"` 33 Tombstoned bool `json:"tombstoned"` 34 CutoverMillis int64 `json:"cutoverMillis,omitempty"` 35 Filter string `json:"filter" validate:"required"` 36 AggregationID aggregation.ID `json:"aggregation"` 37 StoragePolicies policy.StoragePolicies `json:"storagePolicies"` 38 DropPolicy policy.DropPolicy `json:"dropPolicy"` 39 Tags []models.Tag `json:"tags"` 40 LastUpdatedBy string `json:"lastUpdatedBy"` 41 LastUpdatedAtMillis int64 `json:"lastUpdatedAtMillis"` 42 } 43 44 // Equal determines whether two mapping rules are equal. 45 func (m *MappingRule) Equal(other *MappingRule) bool { 46 if m == nil && other == nil { 47 return true 48 } 49 if m == nil || other == nil { 50 return false 51 } 52 if len(m.Tags) != len(other.Tags) { 53 return false 54 } 55 56 for i := 0; i < len(m.Tags); i++ { 57 if !m.Tags[i].Equal(other.Tags[i]) { 58 return false 59 } 60 } 61 62 return m.ID == other.ID && 63 m.Name == other.Name && 64 m.Filter == other.Filter && 65 m.AggregationID.Equal(other.AggregationID) && 66 m.StoragePolicies.Equal(other.StoragePolicies) && 67 m.DropPolicy == other.DropPolicy 68 } 69 70 // MappingRules belonging to a ruleset indexed by uuid. 71 // Each value contains the entire snapshot history of the rule. 72 type MappingRules map[string][]MappingRule 73 74 // MappingRulesByNameAsc sorts mapping rules by name in ascending order. 75 type MappingRulesByNameAsc []MappingRule 76 77 func (a MappingRulesByNameAsc) Len() int { return len(a) } 78 func (a MappingRulesByNameAsc) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 79 func (a MappingRulesByNameAsc) Less(i, j int) bool { return a[i].Name < a[j].Name } 80 81 // MappingRuleSnapshots contains a list of mapping rule snapshots. 82 type MappingRuleSnapshots struct { 83 MappingRules []MappingRule `json:"mappingRules"` 84 }