2017-10-23 15:02:55 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								package provisioning
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import (
							 | 
						
					
						
							
								
									
										
										
										
											2017-11-23 18:29:06 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"context"
							 | 
						
					
						
							
								
									
										
										
										
											2022-06-03 15:24:24 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"fmt"
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-17 15:03:16 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"path/filepath"
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-25 15:06:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"sync"
							 | 
						
					
						
							
								
									
										
										
										
											2017-11-23 18:29:06 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2022-10-19 21:02:15 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"github.com/grafana/grafana/pkg/infra/db"
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-13 14:45:54 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"github.com/grafana/grafana/pkg/infra/log"
							 | 
						
					
						
							
								
									
										
										
										
											2023-08-03 21:19:01 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"github.com/grafana/grafana/pkg/registry"
							 | 
						
					
						
							
								
									
										
										
										
											2022-07-15 05:53:13 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"github.com/grafana/grafana/pkg/services/accesscontrol"
							 | 
						
					
						
							
								
									
										
										
										
											2022-07-25 22:19:07 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"github.com/grafana/grafana/pkg/services/correlations"
							 | 
						
					
						
							
								
									
										
										
										
											2022-02-16 21:15:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									dashboardservice "github.com/grafana/grafana/pkg/services/dashboards"
							 | 
						
					
						
							
								
									
										
										
										
											2022-02-25 23:56:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									datasourceservice "github.com/grafana/grafana/pkg/services/datasources"
							 | 
						
					
						
							
								
									
										
										
										
											2021-10-07 22:33:50 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"github.com/grafana/grafana/pkg/services/encryption"
							 | 
						
					
						
							
								
									
										
										
										
											2022-10-11 03:47:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"github.com/grafana/grafana/pkg/services/folder"
							 | 
						
					
						
							
								
									
										
										
										
											2024-03-23 03:37:10 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									alertingauthz "github.com/grafana/grafana/pkg/services/ngalert/accesscontrol"
							 | 
						
					
						
							
								
									
										
										
										
											2024-07-30 03:49:10 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models"
							 | 
						
					
						
							
								
									
										
										
										
											2024-02-15 22:45:10 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"github.com/grafana/grafana/pkg/services/ngalert/notifier"
							 | 
						
					
						
							
								
									
										
										
										
											2024-07-27 05:45:33 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"github.com/grafana/grafana/pkg/services/ngalert/notifier/legacy_storage"
							 | 
						
					
						
							
								
									
										
										
										
											2022-07-15 05:53:13 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"github.com/grafana/grafana/pkg/services/ngalert/provisioning"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									"github.com/grafana/grafana/pkg/services/ngalert/store"
							 | 
						
					
						
							
								
									
										
										
										
											2022-02-03 20:26:05 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"github.com/grafana/grafana/pkg/services/notifications"
							 | 
						
					
						
							
								
									
										
										
										
											2022-10-05 02:48:02 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"github.com/grafana/grafana/pkg/services/org"
							 | 
						
					
						
							
								
									
										
										
										
											2023-03-08 00:22:30 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginsettings"
							 | 
						
					
						
							
								
									
										
										
										
											2023-09-11 19:59:24 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginstore"
							 | 
						
					
						
							
								
									
										
										
										
											2022-08-02 00:17:42 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									prov_alerting "github.com/grafana/grafana/pkg/services/provisioning/alerting"
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-01 00:43:28 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"github.com/grafana/grafana/pkg/services/provisioning/dashboards"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									"github.com/grafana/grafana/pkg/services/provisioning/datasources"
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-22 23:49:13 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"github.com/grafana/grafana/pkg/services/provisioning/plugins"
							 | 
						
					
						
							
								
									
										
										
										
											2022-07-15 05:53:13 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"github.com/grafana/grafana/pkg/services/quota"
							 | 
						
					
						
							
								
									
										
										
										
											2022-06-27 23:11:08 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"github.com/grafana/grafana/pkg/services/searchV2"
							 | 
						
					
						
							
								
									
										
										
										
											2022-08-02 00:17:42 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"github.com/grafana/grafana/pkg/services/secrets"
							 | 
						
					
						
							
								
									
										
										
										
											2018-05-01 21:51:15 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"github.com/grafana/grafana/pkg/setting"
							 | 
						
					
						
							
								
									
										
										
										
											2017-10-23 15:02:55 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2022-07-15 05:53:13 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								func ProvideService(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									ac accesscontrol.AccessControl,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									cfg *setting.Cfg,
							 | 
						
					
						
							
								
									
										
										
										
											2022-10-15 03:33:06 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									sqlStore db.DB,
							 | 
						
					
						
							
								
									
										
										
										
											2023-09-11 19:59:24 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									pluginStore pluginstore.Store,
							 | 
						
					
						
							
								
									
										
										
										
											2022-07-15 05:53:13 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									encryptionService encryption.Internal,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									notificatonService *notifications.NotificationService,
							 | 
						
					
						
							
								
									
										
										
										
											2022-05-18 02:52:22 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									dashboardProvisioningService dashboardservice.DashboardProvisioningService,
							 | 
						
					
						
							
								
									
										
										
										
											2022-02-25 23:56:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									datasourceService datasourceservice.DataSourceService,
							 | 
						
					
						
							
								
									
										
										
										
											2022-07-25 22:19:07 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									correlationsService correlations.Service,
							 | 
						
					
						
							
								
									
										
										
										
											2022-05-18 02:52:22 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									dashboardService dashboardservice.DashboardService,
							 | 
						
					
						
							
								
									
										
										
										
											2022-10-11 03:47:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									folderService folder.Service,
							 | 
						
					
						
							
								
									
										
										
										
											2022-07-15 05:53:13 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									pluginSettings pluginsettings.Service,
							 | 
						
					
						
							
								
									
										
										
										
											2022-06-27 23:11:08 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									searchService searchV2.SearchService,
							 | 
						
					
						
							
								
									
										
										
										
											2022-07-16 00:06:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									quotaService quota.Service,
							 | 
						
					
						
							
								
									
										
										
										
											2022-08-02 00:17:42 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									secrectService secrets.Service,
							 | 
						
					
						
							
								
									
										
										
										
											2022-10-05 02:48:02 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									orgService org.Service,
							 | 
						
					
						
							
								
									
										
										
										
											2022-02-18 00:18:19 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								) (*ProvisioningServiceImpl, error) {
							 | 
						
					
						
							
								
									
										
										
										
											2023-08-03 21:19:01 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									s := &ProvisioningServiceImpl{
							 | 
						
					
						
							
								
									
										
										
										
											2022-05-18 02:52:22 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										Cfg:                          cfg,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										SQLStore:                     sqlStore,
							 | 
						
					
						
							
								
									
										
										
										
											2022-07-15 05:53:13 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										ac:                           ac,
							 | 
						
					
						
							
								
									
										
										
										
											2022-05-18 02:52:22 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										pluginStore:                  pluginStore,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										EncryptionService:            encryptionService,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										NotificationService:          notificatonService,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										newDashboardProvisioner:      dashboards.New,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										provisionDatasources:         datasources.Provision,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										provisionPlugins:             plugins.Provision,
							 | 
						
					
						
							
								
									
										
										
										
											2022-08-02 00:17:42 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										provisionAlerting:            prov_alerting.Provision,
							 | 
						
					
						
							
								
									
										
										
										
											2022-05-18 02:52:22 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										dashboardProvisioningService: dashboardProvisioningService,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										dashboardService:             dashboardService,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										datasourceService:            datasourceService,
							 | 
						
					
						
							
								
									
										
										
										
											2022-07-25 22:19:07 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										correlationsService:          correlationsService,
							 | 
						
					
						
							
								
									
										
										
										
											2022-05-18 02:52:22 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										pluginsSettings:              pluginSettings,
							 | 
						
					
						
							
								
									
										
										
										
											2022-06-27 23:11:08 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										searchService:                searchService,
							 | 
						
					
						
							
								
									
										
										
										
											2022-07-15 05:53:13 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										quotaService:                 quotaService,
							 | 
						
					
						
							
								
									
										
										
										
											2022-08-02 00:17:42 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										secretService:                secrectService,
							 | 
						
					
						
							
								
									
										
										
										
											2022-07-15 05:53:13 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										log:                          log.New("provisioning"),
							 | 
						
					
						
							
								
									
										
										
										
											2022-10-05 02:48:02 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										orgService:                   orgService,
							 | 
						
					
						
							
								
									
										
										
										
											2024-01-10 23:48:28 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										folderService:                folderService,
							 | 
						
					
						
							
								
									
										
										
										
											2021-08-25 21:11:22 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							
								
									
										
										
										
											2024-03-26 18:32:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									err := s.setDashboardProvisioner()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									if err != nil {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										return nil, fmt.Errorf("%v: %w", "Failed to create provisioner", err)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2023-08-03 21:19:01 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									return s, nil
							 | 
						
					
						
							
								
									
										
										
										
											2021-08-25 21:11:22 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2024-03-26 18:32:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								func (ps *ProvisioningServiceImpl) setDashboardProvisioner() error {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									dashboardPath := filepath.Join(ps.Cfg.ProvisioningPath, "dashboards")
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									dashProvisioner, err := ps.newDashboardProvisioner(context.Background(), dashboardPath, ps.dashboardProvisioningService, ps.orgService, ps.dashboardService, ps.folderService)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									if err != nil {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										return fmt.Errorf("%v: %w", "Failed to create provisioner", err)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									ps.dashboardProvisioner = dashProvisioner
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									return nil
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-25 21:14:24 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								type ProvisioningService interface {
							 | 
						
					
						
							
								
									
										
										
										
											2023-08-03 21:19:01 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									registry.BackgroundService
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									RunInitProvisioners(ctx context.Context) error
							 | 
						
					
						
							
								
									
										
										
										
											2021-10-18 23:06:19 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									ProvisionDatasources(ctx context.Context) error
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-03 01:08:59 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									ProvisionPlugins(ctx context.Context) error
							 | 
						
					
						
							
								
									
										
										
										
											2021-10-05 19:26:24 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									ProvisionDashboards(ctx context.Context) error
							 | 
						
					
						
							
								
									
										
										
										
											2022-08-02 00:17:42 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									ProvisionAlerting(ctx context.Context) error
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-25 21:14:24 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									GetDashboardProvisionerResolvedPath(name string) string
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-15 14:12:52 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									GetAllowUIUpdatesFromConfig(name string) bool
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-30 19:32:18 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-21 19:41:34 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								// Add a public constructor for overriding service to be able to instantiate OSS as fallback
							 | 
						
					
						
							
								
									
										
										
										
											2021-08-25 21:11:22 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								func NewProvisioningServiceImpl() *ProvisioningServiceImpl {
							 | 
						
					
						
							
								
									
										
										
										
											2022-07-15 05:53:13 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									logger := log.New("provisioning")
							 | 
						
					
						
							
								
									
										
										
										
											2023-08-03 21:19:01 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									return &ProvisioningServiceImpl{
							 | 
						
					
						
							
								
									
										
										
										
											2022-07-15 05:53:13 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										log:                     logger,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-21 19:41:34 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										newDashboardProvisioner: dashboards.New,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										provisionDatasources:    datasources.Provision,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										provisionPlugins:        plugins.Provision,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// Used for testing purposes
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-17 23:06:10 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								func newProvisioningServiceImpl(
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-25 21:14:24 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									newDashboardProvisioner dashboards.DashboardProvisionerFactory,
							 | 
						
					
						
							
								
									
										
										
										
											2024-06-03 21:19:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									provisionDatasources func(context.Context, string, datasources.BaseDataSourceService, datasources.CorrelationsStore, org.Service) error,
							 | 
						
					
						
							
								
									
										
										
										
											2023-09-11 19:59:24 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									provisionPlugins func(context.Context, string, pluginstore.Store, pluginsettings.Service, org.Service) error,
							 | 
						
					
						
							
								
									
										
										
										
											2024-08-23 17:48:42 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									searchService searchV2.SearchService,
							 | 
						
					
						
							
								
									
										
										
										
											2021-08-25 21:11:22 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								) *ProvisioningServiceImpl {
							 | 
						
					
						
							
								
									
										
										
										
											2023-08-03 21:19:01 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									return &ProvisioningServiceImpl{
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-25 15:06:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										log:                     log.New("provisioning"),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										newDashboardProvisioner: newDashboardProvisioner,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										provisionDatasources:    provisionDatasources,
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-22 23:49:13 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										provisionPlugins:        provisionPlugins,
							 | 
						
					
						
							
								
									
										
										
										
											2024-03-26 18:32:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										Cfg:                     setting.NewCfg(),
							 | 
						
					
						
							
								
									
										
										
										
											2024-08-23 17:48:42 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										searchService:           searchService,
							 | 
						
					
						
							
								
									
										
										
										
											2017-11-23 18:29:06 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-25 15:06:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2017-11-23 18:29:06 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-08-25 21:11:22 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								type ProvisioningServiceImpl struct {
							 | 
						
					
						
							
								
									
										
										
										
											2022-05-18 02:52:22 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									Cfg                          *setting.Cfg
							 | 
						
					
						
							
								
									
										
										
										
											2022-10-15 03:33:06 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									SQLStore                     db.DB
							 | 
						
					
						
							
								
									
										
										
										
											2022-10-05 02:48:02 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									orgService                   org.Service
							 | 
						
					
						
							
								
									
										
										
										
											2022-07-15 05:53:13 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									ac                           accesscontrol.AccessControl
							 | 
						
					
						
							
								
									
										
										
										
											2023-09-11 19:59:24 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									pluginStore                  pluginstore.Store
							 | 
						
					
						
							
								
									
										
										
										
											2022-05-18 02:52:22 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									EncryptionService            encryption.Internal
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									NotificationService          *notifications.NotificationService
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									log                          log.Logger
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									pollingCtxCancel             context.CancelFunc
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									newDashboardProvisioner      dashboards.DashboardProvisionerFactory
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									dashboardProvisioner         dashboards.DashboardProvisioner
							 | 
						
					
						
							
								
									
										
										
										
											2024-06-03 21:19:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									provisionDatasources         func(context.Context, string, datasources.BaseDataSourceService, datasources.CorrelationsStore, org.Service) error
							 | 
						
					
						
							
								
									
										
										
										
											2023-09-11 19:59:24 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									provisionPlugins             func(context.Context, string, pluginstore.Store, pluginsettings.Service, org.Service) error
							 | 
						
					
						
							
								
									
										
										
										
											2022-08-02 00:17:42 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									provisionAlerting            func(context.Context, prov_alerting.ProvisionerConfig) error
							 | 
						
					
						
							
								
									
										
										
										
											2022-05-18 02:52:22 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									mutex                        sync.Mutex
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									dashboardProvisioningService dashboardservice.DashboardProvisioningService
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									dashboardService             dashboardservice.DashboardService
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									datasourceService            datasourceservice.DataSourceService
							 | 
						
					
						
							
								
									
										
										
										
											2022-07-25 22:19:07 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									correlationsService          correlations.Service
							 | 
						
					
						
							
								
									
										
										
										
											2022-05-18 02:52:22 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									pluginsSettings              pluginsettings.Service
							 | 
						
					
						
							
								
									
										
										
										
											2022-06-27 23:11:08 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									searchService                searchV2.SearchService
							 | 
						
					
						
							
								
									
										
										
										
											2022-07-15 05:53:13 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									quotaService                 quota.Service
							 | 
						
					
						
							
								
									
										
										
										
											2022-08-02 00:17:42 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									secretService                secrets.Service
							 | 
						
					
						
							
								
									
										
										
										
											2024-01-10 23:48:28 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									folderService                folder.Service
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-25 15:06:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-10-18 23:06:19 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								func (ps *ProvisioningServiceImpl) RunInitProvisioners(ctx context.Context) error {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									err := ps.ProvisionDatasources(ctx)
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-25 15:06:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									if err != nil {
							 | 
						
					
						
							
								
									
										
										
										
											2023-09-28 15:00:36 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										ps.log.Error("Failed to provision data sources", "error", err)
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-25 15:06:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										return err
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-03 01:08:59 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									err = ps.ProvisionPlugins(ctx)
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-22 23:49:13 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									if err != nil {
							 | 
						
					
						
							
								
									
										
										
										
											2023-09-28 15:00:36 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										ps.log.Error("Failed to provision plugins", "error", err)
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-22 23:49:13 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										return err
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2022-08-02 00:17:42 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									err = ps.ProvisionAlerting(ctx)
							 | 
						
					
						
							
								
									
										
										
										
											2022-07-15 05:53:13 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									if err != nil {
							 | 
						
					
						
							
								
									
										
										
										
											2023-09-28 15:00:36 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										ps.log.Error("Failed to provision alerting", "error", err)
							 | 
						
					
						
							
								
									
										
										
										
											2022-07-15 05:53:13 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										return err
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-05-01 21:51:15 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									return nil
							 | 
						
					
						
							
								
									
										
										
										
											2017-11-23 18:29:06 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-08-25 21:11:22 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								func (ps *ProvisioningServiceImpl) Run(ctx context.Context) error {
							 | 
						
					
						
							
								
									
										
										
										
											2021-10-05 19:26:24 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									err := ps.ProvisionDashboards(ctx)
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-17 20:39:41 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									if err != nil {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										ps.log.Error("Failed to provision dashboard", "error", err)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							
								
									
										
										
										
											2022-06-27 23:11:08 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									if ps.dashboardProvisioner.HasDashboardSources() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										ps.searchService.TriggerReIndex()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-17 20:39:41 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-25 15:06:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									for {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										// Wait for unlock. This is tied to new dashboardProvisioner to be instantiated before we start polling.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										ps.mutex.Lock()
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-30 16:35:54 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										// Using background here because otherwise if root context was canceled the select later on would
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										// non-deterministically take one of the route possibly going into one polling loop before exiting.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										pollingContext, cancelFun := context.WithCancel(context.Background())
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-25 15:06:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										ps.pollingCtxCancel = cancelFun
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										ps.dashboardProvisioner.PollChanges(pollingContext)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										ps.mutex.Unlock()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										select {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										case <-pollingContext.Done():
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											// Polling was canceled.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											continue
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										case <-ctx.Done():
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-30 16:35:54 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											// Root server context was cancelled so cancel polling and leave.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											ps.cancelPolling()
							 | 
						
					
						
							
								
									
										
										
										
											2023-08-03 21:19:01 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											return ctx.Err()
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-25 15:06:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-10-18 23:06:19 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								func (ps *ProvisioningServiceImpl) ProvisionDatasources(ctx context.Context) error {
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-17 15:03:16 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									datasourcePath := filepath.Join(ps.Cfg.ProvisioningPath, "datasources")
							 | 
						
					
						
							
								
									
										
										
										
											2022-10-13 20:40:46 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									if err := ps.provisionDatasources(ctx, datasourcePath, ps.datasourceService, ps.correlationsService, ps.orgService); err != nil {
							 | 
						
					
						
							
								
									
										
										
										
											2022-06-03 15:24:24 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										err = fmt.Errorf("%v: %w", "Datasource provisioning error", err)
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-13 23:50:02 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										ps.log.Error("Failed to provision data sources", "error", err)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										return err
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									return nil
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-25 15:06:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-03 01:08:59 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								func (ps *ProvisioningServiceImpl) ProvisionPlugins(ctx context.Context) error {
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-17 15:03:16 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									appPath := filepath.Join(ps.Cfg.ProvisioningPath, "plugins")
							 | 
						
					
						
							
								
									
										
										
										
											2022-10-05 02:48:02 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									if err := ps.provisionPlugins(ctx, appPath, ps.pluginStore, ps.pluginsSettings, ps.orgService); err != nil {
							 | 
						
					
						
							
								
									
										
										
										
											2022-06-03 15:24:24 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										err = fmt.Errorf("%v: %w", "app provisioning error", err)
							 | 
						
					
						
							
								
									
										
										
										
											2021-12-13 23:50:02 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										ps.log.Error("Failed to provision plugins", "error", err)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										return err
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									return nil
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-22 23:49:13 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-10-05 19:26:24 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								func (ps *ProvisioningServiceImpl) ProvisionDashboards(ctx context.Context) error {
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-25 15:06:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									ps.mutex.Lock()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									defer ps.mutex.Unlock()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									ps.cancelPolling()
							 | 
						
					
						
							
								
									
										
										
										
											2024-03-26 18:32:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									ps.dashboardProvisioner.CleanUpOrphanedDashboards(ctx)
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-25 15:06:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2024-03-26 18:32:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									err := ps.dashboardProvisioner.Provision(ctx)
							 | 
						
					
						
							
								
									
										
										
										
											2020-09-11 15:19:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									if err != nil {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										// If we fail to provision with the new provisioner, the mutex will unlock and the polling will restart with the
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-25 15:06:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										// old provisioner as we did not switch them yet.
							 | 
						
					
						
							
								
									
										
										
										
											2022-06-03 15:24:24 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										return fmt.Errorf("%v: %w", "Failed to provision dashboards", err)
							 | 
						
					
						
							
								
									
										
										
										
											2017-11-23 18:29:06 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-25 15:06:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									return nil
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2018-05-01 21:51:15 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2022-08-02 00:17:42 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								func (ps *ProvisioningServiceImpl) ProvisionAlerting(ctx context.Context) error {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									alertingPath := filepath.Join(ps.Cfg.ProvisioningPath, "alerting")
							 | 
						
					
						
							
								
									
										
										
										
											2022-07-15 05:53:13 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									st := store.DBstore{
							 | 
						
					
						
							
								
									
										
										
										
											2022-07-16 02:13:30 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										Cfg:              ps.Cfg.UnifiedAlerting,
							 | 
						
					
						
							
								
									
										
										
										
											2022-07-15 05:53:13 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										SQLStore:         ps.SQLStore,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										Logger:           ps.log,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										FolderService:    nil, // we don't use it yet
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										DashboardService: ps.dashboardService,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									ruleService := provisioning.NewAlertRuleService(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										st,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										st,
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-31 16:09:20 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										ps.folderService,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										//ps.dashboardService,
							 | 
						
					
						
							
								
									
										
										
										
											2022-07-15 05:53:13 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										ps.quotaService,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										ps.SQLStore,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										int64(ps.Cfg.UnifiedAlerting.DefaultRuleEvaluationInterval.Seconds()),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										int64(ps.Cfg.UnifiedAlerting.BaseInterval.Seconds()),
							 | 
						
					
						
							
								
									
										
										
										
											2024-02-13 22:29:03 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										ps.Cfg.UnifiedAlerting.RulesPerRuleGroupLimit,
							 | 
						
					
						
							
								
									
										
										
										
											2024-03-23 03:37:10 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										ps.log,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										notifier.NewCachedNotificationSettingsValidationService(&st),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										alertingauthz.NewRuleService(ps.ac),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									)
							 | 
						
					
						
							
								
									
										
										
										
											2024-07-27 05:45:33 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									configStore := legacy_storage.NewAlertmanagerConfigStore(&st)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									receiverSvc := notifier.NewReceiverService(
							 | 
						
					
						
							
								
									
										
										
										
											2024-07-30 03:49:10 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										alertingauthz.NewReceiverAccess[*ngmodels.Receiver](ps.ac, true),
							 | 
						
					
						
							
								
									
										
										
										
											2024-07-27 05:45:33 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										configStore,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										st,
							 | 
						
					
						
							
								
									
										
										
										
											2024-08-26 22:47:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										st,
							 | 
						
					
						
							
								
									
										
										
										
											2024-07-27 05:45:33 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										ps.secretService,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										ps.SQLStore,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										ps.log,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									contactPointService := provisioning.NewContactPointService(configStore, ps.secretService,
							 | 
						
					
						
							
								
									
										
										
										
											2024-02-15 22:45:10 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										st, ps.SQLStore, receiverSvc, ps.log, &st)
							 | 
						
					
						
							
								
									
										
										
										
											2024-07-27 05:45:33 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									notificationPolicyService := provisioning.NewNotificationPolicyService(configStore,
							 | 
						
					
						
							
								
									
										
										
										
											2022-08-02 01:14:57 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										st, ps.SQLStore, ps.Cfg.UnifiedAlerting, ps.log)
							 | 
						
					
						
							
								
									
										
										
										
											2024-07-27 05:45:33 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									mutetimingsService := provisioning.NewMuteTimingService(configStore, st, &st, ps.log, &st)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									templateService := provisioning.NewTemplateService(configStore, st, &st, ps.log)
							 | 
						
					
						
							
								
									
										
										
										
											2022-08-02 00:17:42 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									cfg := prov_alerting.ProvisionerConfig{
							 | 
						
					
						
							
								
									
										
										
										
											2022-08-02 01:14:57 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										Path:                       alertingPath,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										RuleService:                *ruleService,
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-31 16:09:20 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										FolderService:              ps.folderService,
							 | 
						
					
						
							
								
									
										
										
										
											2022-08-02 01:14:57 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										DashboardProvService:       ps.dashboardProvisioningService,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										ContactPointService:        *contactPointService,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										NotificiationPolicyService: *notificationPolicyService,
							 | 
						
					
						
							
								
									
										
										
										
											2022-08-02 02:19:33 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										MuteTimingService:          *mutetimingsService,
							 | 
						
					
						
							
								
									
										
										
										
											2022-08-02 02:50:03 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										TemplateService:            *templateService,
							 | 
						
					
						
							
								
									
										
										
										
											2022-08-02 00:17:42 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									return ps.provisionAlerting(ctx, cfg)
							 | 
						
					
						
							
								
									
										
										
										
											2022-07-15 05:53:13 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-08-25 21:11:22 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								func (ps *ProvisioningServiceImpl) GetDashboardProvisionerResolvedPath(name string) string {
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-30 19:32:18 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									return ps.dashboardProvisioner.GetProvisionerResolvedPath(name)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-08-25 21:11:22 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								func (ps *ProvisioningServiceImpl) GetAllowUIUpdatesFromConfig(name string) bool {
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-15 14:12:52 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									return ps.dashboardProvisioner.GetAllowUIUpdatesFromConfig(name)
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-31 21:27:31 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-08-25 21:11:22 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								func (ps *ProvisioningServiceImpl) cancelPolling() {
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-25 15:06:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									if ps.pollingCtxCancel != nil {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										ps.log.Debug("Stop polling for dashboard changes")
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										ps.pollingCtxCancel()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									ps.pollingCtxCancel = nil
							 | 
						
					
						
							
								
									
										
										
										
											2017-10-23 15:02:55 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 |