From 431cb461f5aa1fe0a4d380fcb9b69c31b7f3d197 Mon Sep 17 00:00:00 2001 From: Alex Demidoff Date: Thu, 14 Mar 2024 15:46:58 +0000 Subject: [PATCH] PMM-12913 fix ManagementService being disabled --- managed/services/errors.go | 7 +++++-- managed/services/grafana/auth_server.go | 1 + managed/services/management/azure_database.go | 11 ++++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/managed/services/errors.go b/managed/services/errors.go index 5e752cd96c..4ac6eedd85 100644 --- a/managed/services/errors.go +++ b/managed/services/errors.go @@ -18,12 +18,15 @@ package services import "github.com/pkg/errors" var ( - // ErrAdvisorsDisabled means that advisors checks are disabled and can't be executed. + // ErrAdvisorsDisabled means that advisors checks are disabled and can't be called. ErrAdvisorsDisabled = errors.New("Advisor checks are disabled") // ErrLocationFolderPairAlreadyUsed returned when location-folder pair already in use and cannot be used for backup. ErrLocationFolderPairAlreadyUsed = errors.New("location-folder pair already used") - // ErrAlertingDisabled means Percona Alerting is disabled and its APIs can't be executed. + // ErrAlertingDisabled means Percona Alerting is disabled and its APIs can't be called. ErrAlertingDisabled = errors.New("Alerting is disabled") + + // ErrAzureDisabled means Azure Monitoring is disabled and its APIs can't be called. + ErrAzureDisabled = errors.New("Azure monitoring is disabled") ) diff --git a/managed/services/grafana/auth_server.go b/managed/services/grafana/auth_server.go index c81f956cc2..cbedf1f545 100644 --- a/managed/services/grafana/auth_server.go +++ b/managed/services/grafana/auth_server.go @@ -75,6 +75,7 @@ var rules = map[string]role{ "/v1/user": viewer, // must be available without authentication for health checking + "/v1/readyz": none, // TODO: remove once we have we merge it to v3 "/v1/server/readyz": none, "/v1/leaderHealthCheck": none, "/ping": none, // PMM 1.x variant diff --git a/managed/services/management/azure_database.go b/managed/services/management/azure_database.go index a1ad227c43..a2021dfd57 100644 --- a/managed/services/management/azure_database.go +++ b/managed/services/management/azure_database.go @@ -30,6 +30,7 @@ import ( azurev1beta1 "github.com/percona/pmm/api/management/v1/azure" "github.com/percona/pmm/managed/models" + "github.com/percona/pmm/managed/services" "github.com/percona/pmm/utils/logger" ) @@ -53,7 +54,7 @@ const ( ) // Enabled returns if service is enabled and can be used. -func (s *ManagementService) Enabled() bool { +func (s *ManagementService) isAzureEnabled() bool { settings, err := models.GetSettings(s.db) if err != nil { logrus.WithField("component", "management/azure_database").WithError(err).Error("can't get settings") @@ -133,6 +134,10 @@ func (s *ManagementService) DiscoverAzureDatabase( ctx context.Context, req *azurev1beta1.DiscoverAzureDatabaseRequest, ) (*azurev1beta1.DiscoverAzureDatabaseResponse, error) { + if !s.isAzureEnabled() { + return nil, services.ErrAzureDisabled + } + client, err := s.getAzureClient(req) if err != nil { return nil, err @@ -185,6 +190,10 @@ func (s *ManagementService) DiscoverAzureDatabase( // AddAzureDatabase add azure database to monitoring. func (s *ManagementService) AddAzureDatabase(ctx context.Context, req *azurev1beta1.AddAzureDatabaseRequest) (*azurev1beta1.AddAzureDatabaseResponse, error) { + if !s.isAzureEnabled() { + return nil, services.ErrAzureDisabled + } + l := logger.Get(ctx).WithField("component", "discover/azureDatabase") // tweak according to API docs if req.NodeName == "" {