Skip to content

Commit

Permalink
PMM-12913 fix ManagementService being disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
ademidoff committed Mar 14, 2024
1 parent 5468b44 commit 431cb46
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
7 changes: 5 additions & 2 deletions managed/services/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
1 change: 1 addition & 0 deletions managed/services/grafana/auth_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion managed/services/management/azure_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 == "" {
Expand Down

0 comments on commit 431cb46

Please sign in to comment.