Skip to content

Commit

Permalink
PMM-13399 include nomad into pmm client (#3257)
Browse files Browse the repository at this point in the history
* PMM-13399 include nomad into pmm-client.

* PMM-13399 include nomad into pmm-client.

* PMM-13399 include nomad into pmm-client.

* PMM-13399 install tree.

* PMM-13399 install deps.

* PMM-13399 install deps.

* PMM-13399 trying to fix build.

* PMM-13399 copy binary.

* PMM-13399 copy nomad binary.

* PMM-13399 add nomad to pmm-agent config.

* PMM-13399 add nomad to pmm-agent config.

* PMM-13399 add nomad data dir to pmm-agent config.

* PMM-13399 add nomad data dir to tests and flags.

* PMM-13399 Fix tests.

* PMM-13399 Apply suggestions from code review

Co-authored-by: Alex Demidoff <[email protected]>

* PMM-13399 Address review comments.

---------

Co-authored-by: Alex Demidoff <[email protected]>
  • Loading branch information
BupycHuk and ademidoff authored Nov 8, 2024
1 parent 98bde60 commit 45b18f5
Show file tree
Hide file tree
Showing 17 changed files with 194 additions and 116 deletions.
5 changes: 4 additions & 1 deletion agent/agents/supervisor/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,6 @@ func (s *Supervisor) processParams(agentID string, agentProcess *agentv1.SetStat
case type_TEST_SLEEP:
processParams.Path = "sleep"
case inventoryv1.AgentType_AGENT_TYPE_VM_AGENT:
// add template params for vmagent.
templateParams["server_insecure"] = cfg.Server.InsecureTLS
templateParams["server_url"] = fmt.Sprintf("https://%s", cfg.Server.Address)
if cfg.Server.WithoutTLS {
Expand All @@ -696,6 +695,10 @@ func (s *Supervisor) processParams(agentID string, agentProcess *agentv1.SetStat
templateParams["server_username"] = cfg.Server.Username
templateParams["tmp_dir"] = cfg.Paths.TempDir
processParams.Path = cfg.Paths.VMAgent
case inventoryv1.AgentType_AGENT_TYPE_NOMAD_AGENT:
templateParams["server_host"] = cfg.Server.URL().Host
templateParams["nomad_data_dir"] = cfg.Paths.NomadDataDir
processParams.Path = cfg.Paths.Nomad
default:
return nil, errors.Errorf("unhandled agent type %[1]s (%[1]d).", agentProcess.Type) //nolint:revive
}
Expand Down
57 changes: 35 additions & 22 deletions agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
const (
pathBaseDefault = "/usr/local/percona/pmm"
agentTmpPath = "tmp" // temporary directory to keep exporters' config files, relative to pathBase
agentDataPath = "data"
agentPrefix = "/agent_id/"
)

Expand Down Expand Up @@ -101,8 +102,10 @@ type Paths struct {
AzureExporter string `yaml:"azure_exporter"`

VMAgent string `yaml:"vmagent"`
Nomad string `yaml:"nomad"`

TempDir string `yaml:"tempdir"`
TempDir string `yaml:"tempdir"`
NomadDataDir string `yaml:"nomad_data_dir"`

PTSummary string `yaml:"pt_summary"`
PTPGSummary string `yaml:"pt_pg_summary"`
Expand Down Expand Up @@ -230,6 +233,7 @@ func get(args []string, cfg *Config, l *logrus.Entry) (string, error) { //nolint
&cfg.Paths.PTPGSummary: "tools/pt-pg-summary",
&cfg.Paths.PTMongoDBSummary: "tools/pt-mongodb-summary",
&cfg.Paths.PTMySQLSummary: "tools/pt-mysql-summary",
&cfg.Paths.Nomad: "tools/nomad",
} {
if *sp == "" {
*sp = v
Expand All @@ -255,38 +259,43 @@ func get(args []string, cfg *Config, l *logrus.Entry) (string, error) { //nolint
l.Infof("Temporary directory is not configured and will be set to %s", cfg.Paths.TempDir)
}

if cfg.Paths.NomadDataDir == "" {
cfg.Paths.NomadDataDir = filepath.Join(cfg.Paths.PathsBase, agentDataPath, "nomad")
l.Infof("Nomad data directory will default to %s", cfg.Paths.NomadDataDir)
}

if !filepath.IsAbs(cfg.Paths.TempDir) {
cfg.Paths.TempDir = filepath.Join(cfg.Paths.PathsBase, cfg.Paths.TempDir)
l.Debugf("Temporary directory is configured as %s", cfg.Paths.TempDir)
}

if !filepath.IsAbs(cfg.Paths.PTSummary) {
cfg.Paths.PTSummary = filepath.Join(cfg.Paths.PathsBase, cfg.Paths.PTSummary)
}
if !filepath.IsAbs(cfg.Paths.PTPGSummary) {
cfg.Paths.PTPGSummary = filepath.Join(cfg.Paths.PathsBase, cfg.Paths.PTPGSummary)
}
if !filepath.IsAbs(cfg.Paths.PTMongoDBSummary) {
cfg.Paths.PTMongoDBSummary = filepath.Join(cfg.Paths.PathsBase, cfg.Paths.PTMongoDBSummary)
}
if !filepath.IsAbs(cfg.Paths.PTMySQLSummary) {
cfg.Paths.PTMySQLSummary = filepath.Join(cfg.Paths.PathsBase, cfg.Paths.PTMySQLSummary)
for n, sp := range map[string]*string{
"Percona Toolkit pt-summary": &cfg.Paths.PTSummary,
"Percona Toolkit pt-pg-summary": &cfg.Paths.PTPGSummary,
"Percona Toolkit pt-mongodb-summary": &cfg.Paths.PTMongoDBSummary,
"Percona Toolkit pt-mysql-summary": &cfg.Paths.PTMySQLSummary,
"Nomad binary": &cfg.Paths.Nomad,
} {
if !filepath.IsAbs(*sp) {
*sp = filepath.Join(cfg.Paths.PathsBase, *sp)
l.Infof("Using %s as a path to %s", *sp, n)
}
}

for _, sp := range []*string{
&cfg.Paths.NodeExporter,
&cfg.Paths.MySQLdExporter,
&cfg.Paths.MongoDBExporter,
&cfg.Paths.PostgresExporter,
&cfg.Paths.ProxySQLExporter,
&cfg.Paths.RDSExporter,
&cfg.Paths.AzureExporter,
&cfg.Paths.VMAgent,
for n, sp := range map[string]*string{
"node_exporter": &cfg.Paths.NodeExporter,
"mysqld_exporter": &cfg.Paths.MySQLdExporter,
"mongodb_exporter": &cfg.Paths.MongoDBExporter,
"postgres_exporter": &cfg.Paths.PostgresExporter,
"proxysql_exporter": &cfg.Paths.ProxySQLExporter,
"rds_exporter": &cfg.Paths.RDSExporter,
"azure_exporter": &cfg.Paths.AzureExporter,
"vmagent": &cfg.Paths.VMAgent,
} {
if cfg.Paths.ExportersBase != "" && !filepath.IsAbs(*sp) {
*sp = filepath.Join(cfg.Paths.ExportersBase, *sp)
}
l.Infof("Using %s", *sp)
l.Infof("Using %s as a path to %s", *sp, n)
}

if cfg.Server.Address != "" {
Expand Down Expand Up @@ -395,6 +404,10 @@ func Application(cfg *Config) (*kingpin.Application, *string) {
Envar("PMM_AGENT_PATHS_PT_MONGODB_SUMMARY").StringVar(&cfg.Paths.PTMongoDBSummary)
app.Flag("paths-pt-mysql-summary", "Path to pt my sql summary to use [PMM_AGENT_PATHS_PT_MYSQL_SUMMARY]").
Envar("PMM_AGENT_PATHS_PT_MYSQL_SUMMARY").StringVar(&cfg.Paths.PTMySQLSummary)
app.Flag("paths-nomad", "Path to nomad binary. Can be overridden using [PMM_AGENT_PATHS_NOMAD]").
Envar("PMM_AGENT_PATHS_NOMAD").StringVar(&cfg.Paths.Nomad)
app.Flag("paths-nomad-data-dir", "Nomad data directory [PMM_AGENT_PATHS_NOMAD_DATA_DIR]").
Envar("PMM_AGENT_PATHS_NOMAD_DATA_DIR").StringVar(&cfg.Paths.NomadDataDir)
app.Flag("paths-tempdir", "Temporary directory for exporters [PMM_AGENT_PATHS_TEMPDIR]").
Envar("PMM_AGENT_PATHS_TEMPDIR").StringVar(&cfg.Paths.TempDir)
// no flag for SlowLogFilePrefix - it is only for development and testing
Expand Down
14 changes: 14 additions & 0 deletions agent/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,12 @@ func TestGet(t *testing.T) {
AzureExporter: "/usr/local/percona/pmm/exporters/azure_exporter",
VMAgent: "/usr/local/percona/pmm/exporters/vmagent",
TempDir: "/usr/local/percona/pmm/tmp",
NomadDataDir: "/usr/local/percona/pmm/data/nomad",
PTSummary: "/usr/local/percona/pmm/tools/pt-summary",
PTPGSummary: "/usr/local/percona/pmm/tools/pt-pg-summary",
PTMySQLSummary: "/usr/local/percona/pmm/tools/pt-mysql-summary",
PTMongoDBSummary: "/usr/local/percona/pmm/tools/pt-mongodb-summary",
Nomad: "/usr/local/percona/pmm/tools/nomad",
},
WindowConnectedTime: defaultWindowPeriod,
Ports: Ports{
Expand Down Expand Up @@ -176,10 +178,12 @@ func TestGet(t *testing.T) {
AzureExporter: "/usr/local/percona/pmm/exporters/azure_exporter",
VMAgent: "/usr/local/percona/pmm/exporters/vmagent",
TempDir: "/usr/local/percona/pmm/tmp",
NomadDataDir: "/usr/local/percona/pmm/data/nomad",
PTSummary: "/usr/local/percona/pmm/tools/pt-summary",
PTPGSummary: "/usr/local/percona/pmm/tools/pt-pg-summary",
PTMongoDBSummary: "/usr/local/percona/pmm/tools/pt-mongodb-summary",
PTMySQLSummary: "/usr/local/percona/pmm/tools/pt-mysql-summary",
Nomad: "/usr/local/percona/pmm/tools/nomad",
},
WindowConnectedTime: defaultWindowPeriod,
Ports: Ports{
Expand Down Expand Up @@ -235,10 +239,12 @@ func TestGet(t *testing.T) {
AzureExporter: "/usr/local/percona/pmm/exporters/azure_exporter",
VMAgent: "/usr/local/percona/pmm/exporters/vmagent",
TempDir: "/foo/bar/tmp",
NomadDataDir: "/usr/local/percona/pmm/data/nomad",
PTSummary: "/usr/local/percona/pmm/tools/pt-summary",
PTPGSummary: "/usr/local/percona/pmm/tools/pt-pg-summary",
PTMySQLSummary: "/usr/local/percona/pmm/tools/pt-mysql-summary",
PTMongoDBSummary: "/usr/local/percona/pmm/tools/pt-mongodb-summary",
Nomad: "/usr/local/percona/pmm/tools/nomad",
},
WindowConnectedTime: defaultWindowPeriod,
Ports: Ports{
Expand Down Expand Up @@ -302,10 +308,12 @@ func TestGet(t *testing.T) {
AzureExporter: "/base/azure_exporter", // default value
VMAgent: "/base/vmagent", // default value
TempDir: "/usr/local/percona/pmm/tmp",
NomadDataDir: "/usr/local/percona/pmm/data/nomad",
PTSummary: "/usr/local/percona/pmm/tools/pt-summary",
PTPGSummary: "/usr/local/percona/pmm/tools/pt-pg-summary",
PTMongoDBSummary: "/usr/local/percona/pmm/tools/pt-mongodb-summary",
PTMySQLSummary: "/usr/local/percona/pmm/tools/pt-mysql-summary",
Nomad: "/usr/local/percona/pmm/tools/nomad",
},
WindowConnectedTime: defaultWindowPeriod,
Ports: Ports{
Expand Down Expand Up @@ -367,10 +375,12 @@ func TestGet(t *testing.T) {
AzureExporter: "/base/exporters/azure_exporter", // default value
VMAgent: "/base/exporters/vmagent", // default value
TempDir: "/base/tmp",
NomadDataDir: "/base/data/nomad",
PTSummary: "/base/tools/pt-summary",
PTPGSummary: "/base/tools/pt-pg-summary",
PTMongoDBSummary: "/base/tools/pt-mongodb-summary",
PTMySQLSummary: "/base/tools/pt-mysql-summary",
Nomad: "/base/tools/nomad",
},
WindowConnectedTime: defaultWindowPeriod,
Ports: Ports{
Expand Down Expand Up @@ -430,10 +440,12 @@ func TestGet(t *testing.T) {
AzureExporter: "/foo/exporters/azure_exporter", // default value
VMAgent: "/foo/exporters/vmagent", // default value
TempDir: "/foo/tmp",
NomadDataDir: "/base/data/nomad",
PTSummary: "/base/tools/pt-summary",
PTPGSummary: "/base/tools/pt-pg-summary",
PTMongoDBSummary: "/base/tools/pt-mongodb-summary",
PTMySQLSummary: "/base/tools/pt-mysql-summary",
Nomad: "/base/tools/nomad",
},
WindowConnectedTime: defaultWindowPeriod,
Ports: Ports{
Expand Down Expand Up @@ -478,10 +490,12 @@ func TestGet(t *testing.T) {
AzureExporter: "/usr/local/percona/pmm/exporters/azure_exporter",
VMAgent: "/usr/local/percona/pmm/exporters/vmagent",
TempDir: "/usr/local/percona/pmm/tmp",
NomadDataDir: "/usr/local/percona/pmm/data/nomad",
PTSummary: "/usr/local/percona/pmm/tools/pt-summary",
PTPGSummary: "/usr/local/percona/pmm/tools/pt-pg-summary",
PTMongoDBSummary: "/usr/local/percona/pmm/tools/pt-mongodb-summary",
PTMySQLSummary: "/usr/local/percona/pmm/tools/pt-mysql-summary",
Nomad: "/usr/local/percona/pmm/tools/nomad",
},
WindowConnectedTime: defaultWindowPeriod,
Ports: Ports{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions api/agentlocal/v1/json/v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@
"AGENT_TYPE_QAN_POSTGRESQL_PGSTATMONITOR_AGENT",
"AGENT_TYPE_EXTERNAL_EXPORTER",
"AGENT_TYPE_RDS_EXPORTER",
"AGENT_TYPE_AZURE_DATABASE_EXPORTER"
"AGENT_TYPE_AZURE_DATABASE_EXPORTER",
"AGENT_TYPE_NOMAD_AGENT"
],
"x-order": 1
},
Expand Down Expand Up @@ -370,7 +371,8 @@
"AGENT_TYPE_QAN_POSTGRESQL_PGSTATMONITOR_AGENT",
"AGENT_TYPE_EXTERNAL_EXPORTER",
"AGENT_TYPE_RDS_EXPORTER",
"AGENT_TYPE_AZURE_DATABASE_EXPORTER"
"AGENT_TYPE_AZURE_DATABASE_EXPORTER",
"AGENT_TYPE_NOMAD_AGENT"
],
"x-order": 1
},
Expand Down
Loading

0 comments on commit 45b18f5

Please sign in to comment.