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