Skip to content

Commit

Permalink
PMM-11770: Use PMM public address as Grafana domain (#2370)
Browse files Browse the repository at this point in the history
* use public address without SSO

* use IP as default host address

* fix supervisord test

* add check for url scheme

* fix lint

* fix linter

* remove check and use only domain for Grafana

* revert check

* add default config to test

* add retry for domains

* use fmt

* drop default host address

* use template conditions

* set redirect uri

---------

Co-authored-by: Alex Tymchuk <[email protected]>
Co-authored-by: Artem Gavrilov <[email protected]>
  • Loading branch information
3 people committed Aug 31, 2023
1 parent b1bbad4 commit 6189f18
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion managed/services/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ func (s *Server) validateChangeSettingsRequest(ctx context.Context, req *serverp
if req.PmmPublicAddress != "" && req.RemovePmmPublicAddress {
return status.Error(codes.InvalidArgument, "Both pmm_public_address and remove_pmm_public_address are present.")
}

if req.SshKey != "" {
if err := s.validateSSHKey(ctx, req.SshKey); err != nil {
return err
Expand Down Expand Up @@ -797,7 +798,7 @@ func (s *Server) TestEmailAlertingSettings(
return &serverpb.TestEmailAlertingSettingsResponse{}, nil
}

// UpdateConfigurations updates supervisor config and requests configuration update for VictoriaMetrics components.
// UpdateConfigurations updates supervisor config and requests configuration update for PMM components.
func (s *Server) UpdateConfigurations(ctx context.Context) error {
settings, err := models.GetSettings(s.db)
if err != nil {
Expand Down
17 changes: 16 additions & 1 deletion managed/services/supervisord/supervisord.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,19 @@ func (s *Service) marshalConfig(tmpl *template.Template, settings *models.Settin

s.addPostgresParams(templateParams)

templateParams["PMMServerHost"] = ""
if settings.PMMPublicAddress != "" {
publicURL, err := url.Parse(settings.PMMPublicAddress)
if err != nil {
return nil, errors.Wrap(err, "failed to parse PMM public address.")
}
if publicURL.Host == "" {
if publicURL, err = url.Parse(fmt.Sprintf("https://%s", settings.PMMPublicAddress)); err != nil {
return nil, errors.Wrap(err, "failed to parse PMM public address.")
}
}
templateParams["PMMServerHost"] = publicURL.Host
}
if ssoDetails != nil {
u, err := url.Parse(ssoDetails.IssuerURL)
if err != nil {
Expand Down Expand Up @@ -782,8 +795,10 @@ command =
/usr/sbin/grafana server
--homepath=/usr/share/grafana
--config=/etc/grafana/grafana.ini
{{- if .PMMServerHost}}
cfg:default.server.domain="{{ .PMMServerHost }}"
{{- end}}
{{- if .PerconaSSODetails}}
cfg:default.server.domain="{{ .PMMServerAddress }}"
cfg:default.auth.generic_oauth.enabled=true
cfg:default.auth.generic_oauth.name="Percona Account"
cfg:default.auth.generic_oauth.client_id="{{ .PerconaSSODetails.GrafanaClientID }}"
Expand Down

0 comments on commit 6189f18

Please sign in to comment.