| 
									
										
										
										
											2024-08-30 17:59:42 +08:00
										 |  |  | package setting | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"strings" | 
					
						
							| 
									
										
										
										
											2024-12-13 04:41:01 +08:00
										 |  |  | 	"time" | 
					
						
							| 
									
										
										
										
											2024-08-30 17:59:42 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/grafana/grafana/pkg/apiserver/rest" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // read storage configs from ini file. They look like:
 | 
					
						
							|  |  |  | // [unified_storage.<group>.<resource>]
 | 
					
						
							|  |  |  | // <field> = <value>
 | 
					
						
							|  |  |  | // e.g.
 | 
					
						
							|  |  |  | // [unified_storage.playlists.playlist.grafana.app]
 | 
					
						
							|  |  |  | // dualWriterMode = 2
 | 
					
						
							|  |  |  | func (cfg *Cfg) setUnifiedStorageConfig() { | 
					
						
							|  |  |  | 	storageConfig := make(map[string]UnifiedStorageConfig) | 
					
						
							|  |  |  | 	sections := cfg.Raw.Sections() | 
					
						
							|  |  |  | 	for _, section := range sections { | 
					
						
							|  |  |  | 		sectionName := section.Name() | 
					
						
							|  |  |  | 		if !strings.HasPrefix(sectionName, "unified_storage.") { | 
					
						
							|  |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		// the resource name is the part after the first dot
 | 
					
						
							|  |  |  | 		resourceName := strings.SplitAfterN(sectionName, ".", 2)[1] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// parse dualWriter modes from the section
 | 
					
						
							|  |  |  | 		dualWriterMode := section.Key("dualWriterMode").MustInt(0) | 
					
						
							| 
									
										
										
										
											2024-09-25 03:03:15 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// parse dualWriter periodic data syncer config
 | 
					
						
							|  |  |  | 		dualWriterPeriodicDataSyncJobEnabled := section.Key("dualWriterPeriodicDataSyncJobEnabled").MustBool(false) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-13 04:41:01 +08:00
										 |  |  | 		// parse dataSyncerRecordsLimit from resource section
 | 
					
						
							|  |  |  | 		dataSyncerRecordsLimit := section.Key("dataSyncerRecordsLimit").MustInt(1000) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// parse dataSyncerInterval from resource section
 | 
					
						
							|  |  |  | 		dataSyncerInterval := section.Key("dataSyncerInterval").MustDuration(time.Hour) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-25 03:03:15 +08:00
										 |  |  | 		storageConfig[resourceName] = UnifiedStorageConfig{ | 
					
						
							|  |  |  | 			DualWriterMode:                       rest.DualWriterMode(dualWriterMode), | 
					
						
							|  |  |  | 			DualWriterPeriodicDataSyncJobEnabled: dualWriterPeriodicDataSyncJobEnabled, | 
					
						
							| 
									
										
										
										
											2024-12-13 04:41:01 +08:00
										 |  |  | 			DataSyncerRecordsLimit:               dataSyncerRecordsLimit, | 
					
						
							|  |  |  | 			DataSyncerInterval:                   dataSyncerInterval, | 
					
						
							| 
									
										
										
										
											2024-09-25 03:03:15 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2024-08-30 17:59:42 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	cfg.UnifiedStorage = storageConfig | 
					
						
							| 
									
										
										
										
											2024-10-23 02:25:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-30 02:24:31 +08:00
										 |  |  | 	// Set indexer config for unified storaae
 | 
					
						
							|  |  |  | 	section := cfg.Raw.Section("unified_storage") | 
					
						
							|  |  |  | 	cfg.IndexPath = section.Key("index_path").String() | 
					
						
							|  |  |  | 	cfg.IndexWorkers = section.Key("index_workers").MustInt(10) | 
					
						
							|  |  |  | 	cfg.IndexMaxBatchSize = section.Key("index_max_batch_size").MustInt(100) | 
					
						
							| 
									
										
										
										
											2024-12-05 05:02:40 +08:00
										 |  |  | 	cfg.IndexFileThreshold = section.Key("index_file_threshold").MustInt(10) | 
					
						
							|  |  |  | 	cfg.IndexMinCount = section.Key("index_min_count").MustInt(1) | 
					
						
							| 
									
										
										
										
											2024-10-23 02:25:08 +08:00
										 |  |  | } |