github.com/siglens/siglens@v0.0.0-20240328180423-f7ce9ae441ed/pkg/config/config_test.go (about) 1 /* 2 Copyright 2023. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package config 18 19 import ( 20 "flag" 21 "fmt" 22 "testing" 23 24 "github.com/siglens/siglens/pkg/config/common" 25 "github.com/stretchr/testify/assert" 26 ) 27 28 func Test_ExtractConfigData(t *testing.T) { 29 flag.Parse() 30 cases := []struct { 31 input []byte 32 expected common.Configuration 33 }{ 34 { // case 1 - For correct input parameters and values 35 []byte(` 36 ingestListenIP: "0.0.0.0" 37 queryListenIP: "0.0.0.0" 38 ingestPort: 9090 39 eventTypeKeywords: ["utm_content"] 40 baseLogDir: "./pkg/ingestor/httpserver/" 41 queryNode: true 42 ingestNode: true 43 seedNode: true 44 segreaderNode: true 45 metareaderNode: true 46 DataPath: "data/" 47 s3: 48 enabled: true 49 bucketName: "test-1" 50 bucketPrefix: "" 51 regionName: "us-east-1" 52 retentionHours: 90 53 TimeStampKey: "timestamp" 54 maxSegFileSize: 10 55 licensekeyPath: "./" 56 esVersion: "6.8.20" 57 maxVirtualTables: 10_000 58 logFileRotationSizeMB: 100 59 compressLogFile: false 60 dataDiskThresholdPercent: 85 61 memoryThresholdPercent: 80 62 partitionCountConsistentHasher: 271 63 replicationFactorConsistentHasher: 40 64 loadConsistentHasher: 1.2 65 s3IngestQueueName: "" 66 s3IngestQueueRegion: "" 67 s3IngestBufferSize: 1000 68 maxParallelS3IngestBuffers: 10 69 queryHostname: "abc:123" 70 PQSEnabled: bad string 71 analyticsEnabled: false 72 agileAggsEnabled: false 73 safeMode: true 74 log: 75 logPrefix: "./pkg/ingestor/httpserver/" 76 `), 77 78 common.Configuration{ 79 IngestListenIP: "0.0.0.0", 80 QueryListenIP: "0.0.0.0", 81 IngestPort: 9090, 82 IngestUrl: "http://localhost:9090", 83 QueryPort: 5122, 84 EventTypeKeywords: []string{"utm_content"}, 85 QueryNode: "true", 86 IngestNode: "true", 87 SegFlushIntervalSecs: 5, 88 DataPath: "data/", 89 S3: common.S3Config{Enabled: true, BucketName: "test-1", BucketPrefix: "", RegionName: "us-east-1"}, 90 RetentionHours: 90, 91 TimeStampKey: "timestamp", 92 MaxSegFileSize: 10, 93 LicenseKeyPath: "./", 94 ESVersion: "6.8.20", 95 DataDiskThresholdPercent: 85, 96 MemoryThresholdPercent: 80, 97 S3IngestQueueName: "", 98 S3IngestQueueRegion: "", 99 S3IngestBufferSize: 1000, 100 MaxParallelS3IngestBuffers: 10, 101 QueryHostname: "abc:123", 102 PQSEnabled: "false", 103 PQSEnabledConverted: false, 104 AnalyticsEnabled: "false", 105 AnalyticsEnabledConverted: false, 106 AgileAggsEnabled: "false", 107 AgileAggsEnabledConverted: false, 108 SafeServerStart: true, 109 Log: common.LogConfig{LogPrefix: "./pkg/ingestor/httpserver/", LogFileRotationSizeMB: 100, CompressLogFile: false}, 110 }, 111 }, 112 { // case 2 - For wrong input type, show error message 113 []byte(` 114 ingestListenIP: "0.0.0.0" 115 queryListenIP: "0.0.0.0" 116 ingestPort: 9090 117 queryPort: 9000 118 eventTypeKeywords: ["utm_content"] 119 queryNode: true 120 ingestNode: true 121 seedNode: true 122 segreaderNode: true 123 metareaderNode: true 124 segFlushIntervalSecs: 1200 125 DataPath: "data/" 126 retentionHours: 123 127 TimeStampKey: "timestamp" 128 maxSegFileSize: 12345 129 licensekeyPath: "./" 130 esVersion: "6.8.20" 131 dataDiskThresholdPercent: 85 132 memoryThresholdPercent: 80 133 partitionCountConsistentHasher: 271 134 replicationFactorConsistentHasher: 40 135 loadConsistentHasher: 1.2 136 S3IngestQueueName: "" 137 S3IngestQueueRegion: "" 138 S3IngestBufferSize: 1000 139 MaxParallelS3IngestBuffers: 10 140 PQSEnabled: F 141 analyticsEnabled: bad string 142 AgileAggsEnabled: bad string 143 log: 144 logPrefix: "./pkg/ingestor/httpserver/" 145 logFileRotationSizeMB: 1000 146 compressLogFile: true 147 `), 148 149 common.Configuration{ 150 IngestListenIP: "0.0.0.0", 151 QueryListenIP: "0.0.0.0", 152 IngestPort: 9090, 153 QueryPort: 9000, 154 IngestUrl: "http://localhost:9090", 155 EventTypeKeywords: []string{"utm_content"}, 156 QueryNode: "true", 157 IngestNode: "true", 158 SegFlushIntervalSecs: 1200, 159 DataPath: "data/", 160 S3: common.S3Config{Enabled: false, BucketName: "", BucketPrefix: "", RegionName: ""}, 161 RetentionHours: 123, 162 TimeStampKey: "timestamp", 163 MaxSegFileSize: 12345, 164 LicenseKeyPath: "./", 165 ESVersion: "6.8.20", 166 DataDiskThresholdPercent: 85, 167 MemoryThresholdPercent: 80, 168 S3IngestQueueName: "", 169 S3IngestQueueRegion: "", 170 S3IngestBufferSize: 1000, 171 MaxParallelS3IngestBuffers: 10, 172 QueryHostname: "", 173 PQSEnabled: "false", 174 PQSEnabledConverted: false, 175 AnalyticsEnabled: "true", 176 AnalyticsEnabledConverted: true, 177 AgileAggsEnabled: "true", 178 AgileAggsEnabledConverted: true, 179 SafeServerStart: false, 180 Log: common.LogConfig{LogPrefix: "./pkg/ingestor/httpserver/", LogFileRotationSizeMB: 1000, CompressLogFile: true}, 181 }, 182 }, 183 { // case 3 - Error out on bad yaml 184 []byte(` 185 invalid input, we should error out 186 `), 187 188 common.Configuration{ 189 IngestListenIP: "0.0.0.0", 190 QueryListenIP: "0.0.0.0", 191 IngestPort: 8081, 192 QueryPort: 0, 193 IngestUrl: "http://localhost:8081", 194 EventTypeKeywords: []string{"eventType"}, 195 QueryNode: "true", 196 IngestNode: "true", 197 SegFlushIntervalSecs: 30, 198 DataPath: "data/", 199 S3: common.S3Config{Enabled: false, BucketName: "", BucketPrefix: "", RegionName: ""}, 200 RetentionHours: 90, 201 TimeStampKey: "timestamp", 202 MaxSegFileSize: 1_073_741_824, 203 LicenseKeyPath: "./", 204 ESVersion: "6.8.20", 205 DataDiskThresholdPercent: 85, 206 MemoryThresholdPercent: 80, 207 S3IngestQueueName: "", 208 S3IngestQueueRegion: "", 209 210 S3IngestBufferSize: 1000, 211 MaxParallelS3IngestBuffers: 10, 212 QueryHostname: "", 213 AnalyticsEnabled: "true", 214 AnalyticsEnabledConverted: true, 215 AgileAggsEnabled: "true", 216 AgileAggsEnabledConverted: true, 217 Log: common.LogConfig{LogPrefix: "", LogFileRotationSizeMB: 100, CompressLogFile: false}, 218 }, 219 }, 220 { // case 4 - For no input, pick defaults 221 []byte(` 222 a: b 223 `), 224 common.Configuration{ 225 IngestListenIP: "0.0.0.0", 226 QueryListenIP: "0.0.0.0", 227 IngestPort: 8081, 228 QueryPort: 5122, 229 IngestUrl: "http://localhost:8081", 230 EventTypeKeywords: []string{"eventType"}, 231 QueryNode: "true", 232 IngestNode: "true", 233 SegFlushIntervalSecs: 5, 234 DataPath: "data/", 235 S3: common.S3Config{Enabled: false, BucketName: "", BucketPrefix: "", RegionName: ""}, 236 RetentionHours: 90 * 24, 237 TimeStampKey: "timestamp", 238 MaxSegFileSize: 1_073_741_824, 239 LicenseKeyPath: "./", 240 ESVersion: "6.8.20", 241 DataDiskThresholdPercent: 85, 242 MemoryThresholdPercent: 80, 243 S3IngestQueueName: "", 244 S3IngestQueueRegion: "", 245 S3IngestBufferSize: 1000, 246 MaxParallelS3IngestBuffers: 10, 247 QueryHostname: "", 248 PQSEnabled: "false", 249 PQSEnabledConverted: false, 250 SafeServerStart: false, 251 AnalyticsEnabled: "true", 252 AnalyticsEnabledConverted: true, 253 AgileAggsEnabled: "true", 254 AgileAggsEnabledConverted: true, 255 Log: common.LogConfig{LogPrefix: "", LogFileRotationSizeMB: 100, CompressLogFile: false}, 256 }, 257 }, 258 } 259 for i, test := range cases { 260 actualConfig, err := ExtractConfigData(test.input) 261 if i == 2 { 262 assert.Error(t, err) 263 continue 264 } 265 266 assert.NoError(t, err, fmt.Sprintf("Comparison failed, test=%v", i+1)) 267 assert.EqualValues(t, test.expected, actualConfig, fmt.Sprintf("Comparison failed, test=%v", i+1)) 268 } 269 }