Skip to content

Commit

Permalink
PMM-12078 don't run pmm-agent on passive nodes.
Browse files Browse the repository at this point in the history
  • Loading branch information
BupycHuk committed Jul 18, 2023
1 parent 7acd78e commit d709b76
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 123 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def setup():
def main():
install_packages()
install_go()
# make_init()
make_init()

# do basic setup
# TODO: fix the setup and revert
Expand Down
14 changes: 0 additions & 14 deletions agent/agents/process/process_logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,6 @@ func TestProcessLogger(t *testing.T) {
0,
0,
},
{
"redact keywords with special symbols",
3,
[]string{
"text\nsecond ",
"line\nthird r.o,w line\n",
"fourth ",
"line\nlast r.o,w\n",
},
[]string{"r.o,w"},
[]string{"third *** line", "fourth line", "last ***"},
0,
0,
},
}
for _, tt := range tests {
t.Run(tt.testName, func(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion managed/cmd/pmm-managed-init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func main() {
pmmConfigParams := make(map[string]any)
pmmConfigParams["DisableInternalDB"], _ = strconv.ParseBool(os.Getenv("PERCONA_TEST_PMM_DISABLE_BUILTIN_POSTGRES"))
pmmConfigParams["DisableInternalClickhouse"], _ = strconv.ParseBool(os.Getenv("PERCONA_TEST_PMM_DISABLE_BUILTIN_CLICKHOUSE"))
pmmConfigParams["PassivePMM"], _ = strconv.ParseBool(os.Getenv("PERCONA_TEST_HA_PASSIVE"))
if err := supervisord.SavePMMConfig(pmmConfigParams); err != nil {
logrus.Errorf("PMM Server configuration error: %s.", err)
os.Exit(1)
Expand Down
14 changes: 9 additions & 5 deletions managed/cmd/pmm-managed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ func runGRPCServer(ctx context.Context, deps *gRPCServerDeps) {
l.Debug("RPC response latency histogram enabled.")
grpcMetrics.EnableHandlingTimeHistogram()
}

serverpb.RegisterServerServer(gRPCServer, deps.server)
agentpb.RegisterAgentServer(gRPCServer, agentgrpc.NewAgentServer(deps.handler))

Expand Down Expand Up @@ -747,10 +746,6 @@ func main() { //nolint:cyclop,maintidx
Envar("PERCONA_TEST_GRAFANA_GOSSIP_PORT").
Default("9762").
Int()
// haGrafanaPort := kingpin.Flag("ha-grafana-port", "HA grafana port").
// Envar("PERCONA_TEST_HA_GRAFANA_PORT").
// Default("9760").
// Int()

supervisordConfigDirF := kingpin.Flag("supervisord-config-dir", "Supervisord configuration directory").Required().String()

Expand Down Expand Up @@ -932,6 +927,15 @@ func main() { //nolint:cyclop,maintidx
},
gRPCMessageMaxSize)

ha.AddLeaderService(highavailability.NewStandardService("pmm-agent-runner", func(ctx context.Context) error {
return supervisord.StartSupervisedService("pmm-agent")
}, func() {
err := supervisord.StopSupervisedService("pmm-agent")
if err != nil {
l.Warnf("couldn't stop pmm-agent: %q", err)
}
}))

platformAddress, err := envvars.GetPlatformAddress()
if err != nil {
l.Fatal(err)
Expand Down
2 changes: 2 additions & 0 deletions managed/models/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package models

// HAParams defines parameters related to High Availability.
type HAParams struct {
GrafanaGossipPort int
Enabled bool
Expand All @@ -26,6 +27,7 @@ type HAParams struct {
GossipPort int
}

// Params defines parameters for supervisor.
type Params struct {
HAParams *HAParams
VMParams *VictoriaMetricsParams
Expand Down
4 changes: 2 additions & 2 deletions managed/services/agents/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var (
)

type pmmAgentInfo interface {
Channel() communicationChannel
Channel() *channel.Channel
ID() string
StateChangeChan() chan struct{}
KickChan() chan struct{}
Expand All @@ -78,7 +78,7 @@ type localPMMAgentInfo struct {
kickChan chan struct{}
}

func (p *localPMMAgentInfo) Channel() communicationChannel { //nolint:ireturn
func (p *localPMMAgentInfo) Channel() *channel.Channel { //nolint:ireturn
return p.channel
}

Expand Down
4 changes: 1 addition & 3 deletions managed/services/supervisord/pmm_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,12 @@ stdout_logfile = /srv/logs/pmm-managed.log
stdout_logfile_maxbytes = 50MB
stdout_logfile_backups = 2
redirect_stderr = true
{{- if not .PassivePMM }}
[program:pmm-agent]
priority = 15
command = /usr/sbin/pmm-agent --config-file=/usr/local/percona/pmm2/config/pmm-agent.yaml
autorestart = true
autostart = true
autostart = false
startretries = 1000
startsecs = 1
stopsignal = TERM
Expand All @@ -194,7 +193,6 @@ stdout_logfile = /srv/logs/pmm-agent.log
stdout_logfile_maxbytes = 50MB
stdout_logfile_backups = 2
redirect_stderr = true
{{- end }}
[program:pmm-update-perform]
command = /usr/sbin/pmm-update -perform -playbook=/usr/share/pmm-update/ansible/playbook/tasks/update.yml
Expand Down
9 changes: 2 additions & 7 deletions managed/services/supervisord/pmm_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,14 @@ func TestSavePMMConfig(t *testing.T) {
}{
{
description: "disable internal postgresql db",
params: map[string]any{"DisableInternalDB": true, "DisableSupervisor": false, "DisableInternalClickhouse": false, "PassivePMM": false},
params: map[string]any{"DisableInternalDB": true, "DisableSupervisor": false, "DisableInternalClickhouse": false},
file: "pmm-db_disabled",
},
{
description: "enable internal postgresql db",
params: map[string]any{"DisableInternalDB": false, "DisableSupervisor": false, "DisableInternalClickhouse": false, "PassivePMM": false},
params: map[string]any{"DisableInternalDB": false, "DisableSupervisor": false, "DisableInternalClickhouse": false},
file: "pmm-db_enabled",
},
{
description: "passive pmm",
params: map[string]any{"DisableInternalDB": true, "DisableSupervisor": false, "DisableInternalClickhouse": false, "PassivePMM": true},
file: "pmm-passive",
},
}
for _, test := range tests {
test := test
Expand Down
12 changes: 12 additions & 0 deletions managed/services/supervisord/supervisord.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,18 @@ func (s *Service) RestartSupervisedService(serviceName string) error {
return err
}

// StartSupervisedService starts given service.
func (s *Service) StartSupervisedService(serviceName string) error {
_, err := s.supervisorctl("start", serviceName)
return err
}

// StopSupervisedService stops given service.
func (s *Service) StopSupervisedService(serviceName string) error {
_, err := s.supervisorctl("stop", serviceName)
return err
}

//nolint:lll
var templates = template.Must(template.New("").Option("missingkey=error").Parse(`
{{define "dbaas-controller"}}
Expand Down
2 changes: 1 addition & 1 deletion managed/testdata/pg/queries/grafana.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
CREATE DATABASE "grafana";
CREATE USER "grafana" WITH PASSWORD 'grafana';
GRANT ALL PRIVILEGES ON DATABASE "grafana" TO "grafana"
GRANT ALL PRIVILEGES ON DATABASE "grafana" TO "grafana";
89 changes: 0 additions & 89 deletions managed/testdata/supervisord.d/pmm-passive.ini

This file was deleted.

0 comments on commit d709b76

Please sign in to comment.