github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/integration/resources/options.go (about) 1 // Copyright (c) 2022 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 resources 22 23 import ( 24 "errors" 25 "fmt" 26 ) 27 28 // ClusterOptions contains options for spinning up a new M3 cluster 29 // composed of in-process components. 30 type ClusterOptions struct { 31 // EtcdEndpoints if provided, will be used directly instead of spinning up a dedicated etcd node for the cluster. 32 // By default, NewClusterFromSpecification will spin up and manage an etcd node itself. 33 EtcdEndpoints []string 34 // DBNode contains cluster options for spinning up dbnodes. 35 DBNode *DBNodeClusterOptions 36 // Aggregator is the optional cluster options for spinning up aggregators. 37 // If Aggregator is nil, the cluster contains only m3coordinator and dbnodes. 38 Aggregator *AggregatorClusterOptions 39 // Coordinator is the options for spinning up the coordinator 40 Coordinator CoordinatorClusterOptions 41 } 42 43 // Validate validates the ClusterOptions. 44 func (opts *ClusterOptions) Validate() error { 45 if err := opts.DBNode.Validate(); err != nil { 46 return fmt.Errorf("invalid dbnode cluster options: %w", err) 47 } 48 49 if opts.Aggregator != nil { 50 if err := opts.Aggregator.Validate(); err != nil { 51 return fmt.Errorf("invalid aggregator cluster options: %w", err) 52 } 53 } 54 55 return nil 56 } 57 58 // DBNodeClusterOptions contains the cluster options for spinning up 59 // dbnodes. 60 type DBNodeClusterOptions struct { 61 // RF is the replication factor to use for the cluster. 62 RF int32 63 // NumShards is the number of shards to use for each RF. 64 NumShards int32 65 // NumInstances is the number of dbnode instances per RF. 66 NumInstances int32 67 // NumIsolationGroups is the number of isolation groups to split 68 // nodes into. 69 NumIsolationGroups int32 70 } 71 72 // NewDBNodeClusterOptions creates DBNodeClusteOptions with sane defaults. 73 // DBNode config must still be provided. 74 func NewDBNodeClusterOptions() *DBNodeClusterOptions { 75 return &DBNodeClusterOptions{ 76 RF: 1, 77 NumShards: 4, 78 NumInstances: 1, 79 NumIsolationGroups: 1, 80 } 81 } 82 83 // Validate validates the DBNodeClusterOptions. 84 func (d *DBNodeClusterOptions) Validate() error { 85 if d.RF < 1 { 86 return errors.New("rf must be at least 1") 87 } 88 89 if d.NumShards < 1 { 90 return errors.New("numShards must be at least 1") 91 } 92 93 if d.NumInstances < 1 { 94 return errors.New("numInstances must be at least 1") 95 } 96 97 if d.NumIsolationGroups < 1 { 98 return errors.New("numIsolationGroups must be at least 1") 99 } 100 101 if d.RF > d.NumIsolationGroups { 102 return errors.New("rf must be less than or equal to numIsolationGroups") 103 } 104 105 return nil 106 } 107 108 // AggregatorClusterOptions contains the cluster options for spinning up 109 // aggregators. 110 type AggregatorClusterOptions struct { 111 // RF is the replication factor to use for aggregators. 112 // It should be 1 for non-replicated mode and 2 for leader-follower mode. 113 RF int32 114 // NumShards is the number of shards to use for each RF. 115 NumShards int32 116 // NumInstances is the number of aggregator instances in total. 117 NumInstances int32 118 // NumIsolationGroups is the number of isolation groups to split 119 // aggregators into. 120 NumIsolationGroups int32 121 } 122 123 // NewAggregatorClusterOptions creates AggregatorClusterOptions with sane defaults. 124 // Aggregator config must still be provided. 125 func NewAggregatorClusterOptions() *AggregatorClusterOptions { 126 return &AggregatorClusterOptions{ 127 RF: 1, 128 NumShards: 4, 129 NumInstances: 1, 130 NumIsolationGroups: 1, 131 } 132 } 133 134 // Validate validates the AggregatorClusterOptions. 135 func (a *AggregatorClusterOptions) Validate() error { 136 if a.RF < 1 { 137 return errors.New("rf must be at least 1") 138 } 139 140 if a.RF > 2 { 141 return errors.New("rf must be at most 2") 142 } 143 144 if a.NumShards < 1 { 145 return errors.New("numShards must be at least 1") 146 } 147 148 if a.NumInstances < 1 { 149 return errors.New("numInstances must be at least 1") 150 } 151 152 if a.NumIsolationGroups < 1 { 153 return errors.New("numIsolationGroups must be at least 1") 154 } 155 156 if a.RF > a.NumIsolationGroups { 157 return errors.New("rf must be less than or equal to numIsolationGroups") 158 } 159 160 return nil 161 } 162 163 // CoordinatorClusterOptions contains the cluster options for spinning up 164 // the coordinator. 165 type CoordinatorClusterOptions struct { 166 // GeneratePortsi ndicates whether to update the coordinator config to use open ports. 167 GeneratePorts bool 168 } 169 170 // M3msgTopicOptions represents a set of options for an m3msg topic. 171 type M3msgTopicOptions struct { 172 // Zone is the zone of the m3msg topic. 173 Zone string 174 // Env is the environment of the m3msg topic. 175 Env string 176 // TopicName is the topic name of the m3msg topic name. 177 TopicName string 178 } 179 180 // PlacementRequestOptions represents a set of options for placement-related requests. 181 type PlacementRequestOptions struct { 182 // Service is the type of service for the placement request. 183 Service ServiceType 184 // Env is the environment of the placement. 185 Env string 186 // Zone is the zone of the placement. 187 Zone string 188 } 189 190 // ServiceType represents the type of an m3 service. 191 type ServiceType int 192 193 const ( 194 // ServiceTypeUnknown is an unknown service type. 195 ServiceTypeUnknown ServiceType = iota 196 // ServiceTypeM3DB represents M3DB service. 197 ServiceTypeM3DB 198 // ServiceTypeM3Aggregator represents M3aggregator service. 199 ServiceTypeM3Aggregator 200 // ServiceTypeM3Coordinator represents M3coordinator service. 201 ServiceTypeM3Coordinator 202 )