Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PMM-12422 restrict agent interface #2534

Merged
merged 23 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
da5cae9
register node exporters with expose address disabled
idoqo Oct 3, 2023
ba25682
include expose-exporter-address flag for all services
idoqo Oct 9, 2023
88a26b8
update inventory api
idoqo Oct 10, 2023
b04918c
Merge branch 'main' into PMM-12422-restrict-agent-interface
idoqo Oct 10, 2023
edeb3a7
fix tests
idoqo Oct 10, 2023
88687d4
try to fix linter
idoqo Oct 11, 2023
16d5830
Merge branch 'main' into PMM-12422-restrict-agent-interface
idoqo Oct 11, 2023
af13e64
Merge branch 'main' into PMM-12422-restrict-agent-interface
idoqo Oct 18, 2023
1e4a70a
include expose mode in agent list api
idoqo Oct 18, 2023
39d4581
rename to expose exporter
idoqo Oct 20, 2023
9be613f
include expose exporter commands for inventory
idoqo Oct 23, 2023
ad03e6a
fix add tests
idoqo Oct 23, 2023
4c710a4
fix database tests
idoqo Oct 23, 2023
d9ecb98
Merge branch 'main' into PMM-12422-restrict-agent-interface
idoqo Oct 23, 2023
125d2f3
Merge branch 'main' into PMM-12422-restrict-agent-interface
idoqo Oct 25, 2023
5801c48
Merge branch 'main' into PMM-12422-restrict-agent-interface
idoqo Oct 25, 2023
4ebcbc5
Merge branch 'main' into PMM-12422-restrict-agent-interface
idoqo Oct 30, 2023
9c21488
Merge branch 'main' into PMM-12422-restrict-agent-interface
idoqo Nov 2, 2023
6cc2064
update documentation of flag
idoqo Nov 2, 2023
b424f74
Merge branch 'main' into PMM-12422-restrict-agent-interface
idoqo Nov 6, 2023
c9b0573
Merge branch 'main' into PMM-12422-restrict-agent-interface
idoqo Nov 13, 2023
3142745
Merge branch 'main' into PMM-12422-restrict-agent-interface
idoqo Nov 20, 2023
612be35
fix address in test
idoqo Nov 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions admin/commands/management/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,21 @@ type AddCommand struct {
ProxySQL AddProxySQLCommand `cmd:"" name:"proxysql" help:"Add ProxySQL to monitoring"`
}

// globalAddServiceParams holds common parameters that are passed as flags to the `add` command.
type globalAddServiceParams struct {
serviceName string
socket string
host string
port uint16
exposeExporterAddress bool
}

// AddCommonFlags is used by Kong for CLI flags and commands.
type AddCommonFlags struct {
AddServiceNameFlag string `name:"service-name" placeholder:"NAME" help:"Service name (overrides positional argument)"`
AddHostFlag string `name:"host" placeholder:"HOST" help:"Service hostname or IP address (overrides positional argument)"`
AddPortFlag uint16 `name:"port" placeholder:"PORT" help:"Service port number (overrides positional argument)"`
AddServiceNameFlag string `name:"service-name" placeholder:"NAME" help:"Service name (overrides positional argument)"`
AddHostFlag string `name:"host" placeholder:"HOST" help:"Service hostname or IP address (overrides positional argument)"`
AddPortFlag uint16 `name:"port" placeholder:"PORT" help:"Service port number (overrides positional argument)"`
AddExposeExporterAddressFlag bool `name:"expose-exporter-address" placeholder:"EXPOSE-EXPORTER" help:"Expose the address of the exporter publicly on 0.0.0.0"`
idoqo marked this conversation as resolved.
Show resolved Hide resolved
}

// AddLogLevelFatalFlags contains log level flag with "fatal" option.
Expand All @@ -60,7 +70,7 @@ type connectionGetter interface {
// - addPostgreSQLCommand
// - addMongoDBCommand
// Returns service name, socket, host, port, error.
func processGlobalAddFlagsWithSocket(cmd connectionGetter, opts AddCommonFlags) (string, string, string, uint16, error) {
func processGlobalAddFlagsWithSocket(cmd connectionGetter, opts AddCommonFlags) (globalAddServiceParams, error) {
serviceName := cmd.GetServiceName()
if opts.AddServiceNameFlag != "" {
serviceName = opts.AddServiceNameFlag
Expand All @@ -74,18 +84,19 @@ func processGlobalAddFlagsWithSocket(cmd connectionGetter, opts AddCommonFlags)

var portI int
var host string
var exposeExporterAddress bool
var err error

if address != "" {
var portS string
host, portS, err = net.SplitHostPort(address)
if err != nil {
return "", "", "", 0, err
return globalAddServiceParams{}, err
}

portI, err = strconv.Atoi(portS)
if err != nil {
return "", "", "", 0, err
return globalAddServiceParams{}, err
}
}

Expand All @@ -97,5 +108,14 @@ func processGlobalAddFlagsWithSocket(cmd connectionGetter, opts AddCommonFlags)
portI = int(opts.AddPortFlag)
}

return serviceName, socket, host, uint16(portI), nil
if opts.AddExposeExporterAddressFlag {
exposeExporterAddress = opts.AddExposeExporterAddressFlag
}
idoqo marked this conversation as resolved.
Show resolved Hide resolved
return globalAddServiceParams{
serviceName: serviceName,
socket: socket,
host: host,
port: uint16(portI),
exposeExporterAddress: exposeExporterAddress,
}, nil
}
27 changes: 14 additions & 13 deletions admin/commands/management/add_mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (cmd *AddMongoDBCommand) RunCmd() (commands.Result, error) {
}
}

serviceName, socket, host, port, err := processGlobalAddFlagsWithSocket(cmd, cmd.AddCommonFlags)
globalFlags, err := processGlobalAddFlagsWithSocket(cmd, cmd.AddCommonFlags)
if err != nil {
return nil, err
}
Expand All @@ -154,18 +154,19 @@ func (cmd *AddMongoDBCommand) RunCmd() (commands.Result, error) {

params := &mongodb.AddMongoDBParams{
Body: mongodb.AddMongoDBBody{
NodeID: cmd.NodeID,
ServiceName: serviceName,
Address: host,
Port: int64(port),
Socket: socket,
PMMAgentID: cmd.PMMAgentID,
Environment: cmd.Environment,
Cluster: cmd.Cluster,
ReplicationSet: cmd.ReplicationSet,
Username: cmd.Username,
Password: cmd.Password,
AgentPassword: cmd.AgentPassword,
NodeID: cmd.NodeID,
ServiceName: globalFlags.serviceName,
Address: globalFlags.host,
Port: int64(globalFlags.port),
Socket: globalFlags.socket,
ExposeExporterAddress: globalFlags.exposeExporterAddress,
PMMAgentID: cmd.PMMAgentID,
Environment: cmd.Environment,
Cluster: cmd.Cluster,
ReplicationSet: cmd.ReplicationSet,
Username: cmd.Username,
Password: cmd.Password,
AgentPassword: cmd.AgentPassword,

QANMongodbProfiler: cmd.QuerySource == MongodbQuerySourceProfiler,

Expand Down
29 changes: 15 additions & 14 deletions admin/commands/management/add_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (cmd *AddMySQLCommand) RunCmd() (commands.Result, error) {
}
}

serviceName, socket, host, port, err := processGlobalAddFlagsWithSocket(cmd, cmd.AddCommonFlags)
globalFlags, err := processGlobalAddFlagsWithSocket(cmd, cmd.AddCommonFlags)
if err != nil {
return nil, err
}
Expand All @@ -204,19 +204,20 @@ func (cmd *AddMySQLCommand) RunCmd() (commands.Result, error) {

params := &mysql.AddMySQLParams{
Body: mysql.AddMySQLBody{
NodeID: cmd.NodeID,
ServiceName: serviceName,
Address: host,
Socket: socket,
Port: int64(port),
PMMAgentID: cmd.PMMAgentID,
Environment: cmd.Environment,
Cluster: cmd.Cluster,
ReplicationSet: cmd.ReplicationSet,
Username: cmd.Username,
Password: cmd.Password,
AgentPassword: cmd.AgentPassword,
CustomLabels: customLabels,
NodeID: cmd.NodeID,
ServiceName: globalFlags.serviceName,
Address: globalFlags.host,
Socket: globalFlags.socket,
Port: int64(globalFlags.port),
ExposeExporterAddress: globalFlags.exposeExporterAddress,
PMMAgentID: cmd.PMMAgentID,
Environment: cmd.Environment,
Cluster: cmd.Cluster,
ReplicationSet: cmd.ReplicationSet,
Username: cmd.Username,
Password: cmd.Password,
AgentPassword: cmd.AgentPassword,
CustomLabels: customLabels,

QANMysqlSlowlog: cmd.QuerySource == MysqlQuerySourceSlowLog,
QANMysqlPerfschema: cmd.QuerySource == MysqlQuerySourcePerfSchema,
Expand Down
14 changes: 7 additions & 7 deletions admin/commands/management/add_postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (cmd *AddPostgreSQLCommand) RunCmd() (commands.Result, error) {
}
}

serviceName, socket, host, port, err := processGlobalAddFlagsWithSocket(cmd, cmd.AddCommonFlags)
globalFlags, err := processGlobalAddFlagsWithSocket(cmd, cmd.AddCommonFlags)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -171,16 +171,16 @@ func (cmd *AddPostgreSQLCommand) RunCmd() (commands.Result, error) {

params := &postgresql.AddPostgreSQLParams{
Body: postgresql.AddPostgreSQLBody{
NodeID: cmd.NodeID,
ServiceName: serviceName,

Address: host,
Port: int64(port),
NodeID: cmd.NodeID,
ServiceName: globalFlags.serviceName,
Address: globalFlags.host,
Socket: globalFlags.socket,
Port: int64(globalFlags.port),
ExposeExporterAddress: globalFlags.exposeExporterAddress,
Username: cmd.Username,
Password: cmd.Password,
Database: cmd.Database,
AgentPassword: cmd.AgentPassword,
Socket: socket,
SkipConnectionCheck: cmd.SkipConnectionCheck,
DisableCommentsParsing: disableCommentsParsing,

Expand Down
27 changes: 14 additions & 13 deletions admin/commands/management/add_proxysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (cmd *AddProxySQLCommand) RunCmd() (commands.Result, error) {
}
}

serviceName, socket, host, port, err := processGlobalAddFlagsWithSocket(cmd, cmd.AddCommonFlags)
globalFlags, err := processGlobalAddFlagsWithSocket(cmd, cmd.AddCommonFlags)
if err != nil {
return nil, err
}
Expand All @@ -127,18 +127,19 @@ func (cmd *AddProxySQLCommand) RunCmd() (commands.Result, error) {

params := &proxysql.AddProxySQLParams{
Body: proxysql.AddProxySQLBody{
NodeID: cmd.NodeID,
ServiceName: serviceName,
Address: host,
Port: int64(port),
Socket: socket,
PMMAgentID: cmd.PMMAgentID,
Environment: cmd.Environment,
Cluster: cmd.Cluster,
ReplicationSet: cmd.ReplicationSet,
Username: cmd.Username,
Password: cmd.Password,
AgentPassword: cmd.AgentPassword,
NodeID: cmd.NodeID,
ServiceName: globalFlags.serviceName,
Address: globalFlags.host,
Socket: globalFlags.socket,
Port: int64(globalFlags.port),
ExposeExporterAddress: globalFlags.exposeExporterAddress,
PMMAgentID: cmd.PMMAgentID,
Environment: cmd.Environment,
Cluster: cmd.Cluster,
ReplicationSet: cmd.ReplicationSet,
Username: cmd.Username,
Password: cmd.Password,
AgentPassword: cmd.AgentPassword,

CustomLabels: customLabels,
SkipConnectionCheck: cmd.SkipConnectionCheck,
Expand Down
10 changes: 5 additions & 5 deletions admin/commands/management/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ func TestManagementGlobalFlags(t *testing.T) {
},
}

serviceName, socket, address, port, err := processGlobalAddFlagsWithSocket(cmd, cmd.AddCommonFlags)
globalFlags, err := processGlobalAddFlagsWithSocket(cmd, cmd.AddCommonFlags)
idoqo marked this conversation as resolved.
Show resolved Hide resolved

assert.NoError(t, err)
assert.Equal(t, serviceName, test.wantServiceName)
assert.Equal(t, address, test.wantHost)
assert.Equal(t, int(port), int(test.wantPort))
assert.Equal(t, socket, test.wantSocket)
assert.Equal(t, globalFlags.serviceName, test.wantServiceName)
assert.Equal(t, globalFlags.host, test.wantHost)
assert.Equal(t, int(globalFlags.port), int(test.wantPort))
assert.Equal(t, globalFlags.socket, test.wantSocket)
})
}
}
7 changes: 4 additions & 3 deletions agent/commands/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,10 @@ func serverRegister(cfgSetup *config.Setup) (agentID, token string, _ error) { /
CustomLabels: customLabels,
AgentPassword: cfgSetup.AgentPassword,

Reregister: cfgSetup.Force,
MetricsMode: pointer.ToString(strings.ToUpper(cfgSetup.MetricsMode)),
DisableCollectors: disableCollectors,
Reregister: cfgSetup.Force,
MetricsMode: pointer.ToString(strings.ToUpper(cfgSetup.MetricsMode)),
DisableCollectors: disableCollectors,
ExposeExporterAddress: cfgSetup.ExposeExporterAddress,
},
Context: context.Background(),
})
Expand Down
7 changes: 5 additions & 2 deletions agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ type Setup struct {
CustomLabels string
AgentPassword string

Force bool
SkipRegistration bool
Force bool
SkipRegistration bool
ExposeExporterAddress bool
}

// Config represents pmm-agent's configuration.
Expand Down Expand Up @@ -479,6 +480,8 @@ func Application(cfg *Config) (*kingpin.Application, *string) {
Envar("PMM_AGENT_SETUP_CUSTOM_LABELS").StringVar(&cfg.Setup.CustomLabels)
setupCmd.Flag("agent-password", "Custom password for /metrics endpoint [PMM_AGENT_SETUP_NODE_PASSWORD]").
Envar("PMM_AGENT_SETUP_NODE_PASSWORD").StringVar(&cfg.Setup.AgentPassword)
setupCmd.Flag("expose-exporter-address", "Expose the address of the agents node-exporter publicly on 0.0.0.0").
Envar("PMM_AGENT_EXPOSE_EXPORTER_ADDRESS").BoolVar(&cfg.Setup.ExposeExporterAddress)

return app, configFileF
}
Expand Down
Loading