Skip to content

Commit

Permalink
Merge branch 'PMM-12913-migrate-api-endpoints-to-restful' of github.c…
Browse files Browse the repository at this point in the history
  • Loading branch information
ademidoff committed Mar 11, 2024
2 parents 581e273 + 1db0345 commit 559c7f3
Show file tree
Hide file tree
Showing 57 changed files with 2,449 additions and 2,091 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
interval: 45
timeout: 1200
ignored: "WhiteSource License Check, WhiteSource Security Check"
ignored: "license/snyk (Percona Github Org), security/snyk (Percona Github Org)"
ref: ${{ github.event.pull_request.head.sha || github.sha }}

workflow_success:
Expand Down
50 changes: 26 additions & 24 deletions admin/commands/management/add_postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,25 @@ type AddPostgreSQLCommand struct {
NodeID string `help:"Node ID (default is autodetected)"`
PMMAgentID string `help:"The pmm-agent identifier which runs this instance (default is autodetected)"`
// TODO add "auto"
QuerySource string `default:"pgstatmonitor" help:"Source of SQL queries, one of: pgstatements, pgstatmonitor, none (default: pgstatmonitor)"`
Environment string `help:"Environment name"`
Cluster string `help:"Cluster name"`
ReplicationSet string `help:"Replication set name"`
CustomLabels map[string]string `mapsep:"," help:"Custom user-assigned labels"`
SkipConnectionCheck bool `help:"Skip connection check"`
CommentsParsing string `enum:"on,off" default:"off" help:"Enable/disable parsing comments from queries. One of: [on, off]"`
TLS bool `help:"Use TLS to connect to the database"`
TLSCAFile string `name:"tls-ca-file" help:"TLS CA certificate file"`
TLSCertFile string `help:"TLS certificate file"`
TLSKeyFile string `help:"TLS certificate key file"`
TLSSkipVerify bool `help:"Skip TLS certificates validation"`
MaxQueryLength int32 `placeholder:"NUMBER" help:"Limit query length in QAN (default: server-defined; -1: no limit)"`
DisableQueryExamples bool `name:"disable-queryexamples" help:"Disable collection of query examples"`
MetricsMode string `enum:"${metricsModesEnum}" default:"auto" help:"Metrics flow mode, can be push - agent will push metrics, pull - server scrape metrics from agent or auto - chosen by server"`
DisableCollectors []string `help:"Comma-separated list of collector names to exclude from exporter"`
ExposeExporter bool `name:"expose-exporter" help:"Optionally expose the address of the exporter publicly on 0.0.0.0"`
AutoDiscoveryLimit int32 `default:"0" placeholder:"NUMBER" help:"Auto-discovery will be disabled if there are more than that number of databases (default: server-defined, -1: always disabled)"`
QuerySource string `default:"pgstatmonitor" help:"Source of SQL queries, one of: pgstatements, pgstatmonitor, none (default: pgstatmonitor)"`
Environment string `help:"Environment name"`
Cluster string `help:"Cluster name"`
ReplicationSet string `help:"Replication set name"`
CustomLabels map[string]string `mapsep:"," help:"Custom user-assigned labels"`
SkipConnectionCheck bool `help:"Skip connection check"`
CommentsParsing string `enum:"on,off" default:"off" help:"Enable/disable parsing comments from queries. One of: [on, off]"`
TLS bool `help:"Use TLS to connect to the database"`
TLSCAFile string `name:"tls-ca-file" help:"TLS CA certificate file"`
TLSCertFile string `help:"TLS certificate file"`
TLSKeyFile string `help:"TLS certificate key file"`
TLSSkipVerify bool `help:"Skip TLS certificates validation"`
MaxQueryLength int32 `placeholder:"NUMBER" help:"Limit query length in QAN (default: server-defined; -1: no limit)"`
DisableQueryExamples bool `name:"disable-queryexamples" help:"Disable collection of query examples"`
MetricsMode string `enum:"${metricsModesEnum}" default:"auto" help:"Metrics flow mode, can be push - agent will push metrics, pull - server scrape metrics from agent or auto - chosen by server"`
DisableCollectors []string `help:"Comma-separated list of collector names to exclude from exporter"`
ExposeExporter bool `name:"expose-exporter" help:"Optionally expose the address of the exporter publicly on 0.0.0.0"`
AutoDiscoveryLimit int32 `placeholder:"NUMBER" help:"Auto-discovery will be disabled if there are more than that number of databases (default: server-defined, -1: always disabled)"`
MaxExporterConnections int32 `placeholder:"NUMBER" help:"Maximum number of connections to PostgreSQL instance that exporter can use (default: server-defined)"`

AddCommonFlags
AddLogLevelNoFatalFlags
Expand Down Expand Up @@ -211,12 +212,13 @@ func (cmd *AddPostgreSQLCommand) RunCmd() (commands.Result, error) {
TLSKey: tlsKey,
TLSSkipVerify: cmd.TLSSkipVerify,

MaxQueryLength: cmd.MaxQueryLength,
DisableQueryExamples: cmd.DisableQueryExamples,
MetricsMode: pointer.ToString(strings.ToUpper(cmd.MetricsMode)),
DisableCollectors: commands.ParseDisableCollectors(cmd.DisableCollectors),
AutoDiscoveryLimit: cmd.AutoDiscoveryLimit,
LogLevel: &cmd.AddLogLevel,
MaxQueryLength: cmd.MaxQueryLength,
DisableQueryExamples: cmd.DisableQueryExamples,
MetricsMode: pointer.ToString(strings.ToUpper(cmd.MetricsMode)),
DisableCollectors: commands.ParseDisableCollectors(cmd.DisableCollectors),
AutoDiscoveryLimit: cmd.AutoDiscoveryLimit,
MaxExporterConnections: cmd.MaxExporterConnections,
LogLevel: &cmd.AddLogLevel,
},
Context: commands.Ctx,
}
Expand Down
38 changes: 20 additions & 18 deletions api-tests/inventory/agents_postgres_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func TestPostgresExporter(t *testing.T) {
CustomLabels: map[string]string{
"custom_label_postgres_exporter": "postgres_exporter",
},

SkipConnectionCheck: true,
SkipConnectionCheck: true,
MaxExporterConnections: 10,
},
})
agentID := PostgresExporter.PostgresExporter.AgentID
Expand All @@ -88,9 +88,10 @@ func TestPostgresExporter(t *testing.T) {
CustomLabels: map[string]string{
"custom_label_postgres_exporter": "postgres_exporter",
},
Status: &AgentStatusUnknown,
DisabledCollectors: make([]string, 0),
LogLevel: pointer.ToString("LOG_LEVEL_UNSPECIFIED"),
DisabledCollectors: make([]string, 0),
LogLevel: pointer.ToString("LOG_LEVEL_UNSPECIFIED"),
Status: &AgentStatusUnknown,
MaxExporterConnections: 10,
},
},
}, getAgentRes)
Expand All @@ -113,15 +114,16 @@ func TestPostgresExporter(t *testing.T) {
assert.Equal(t, &agents.ChangeAgentOK{
Payload: &agents.ChangeAgentOKBody{
PostgresExporter: &agents.ChangeAgentOKBodyPostgresExporter{
AgentID: agentID,
ServiceID: serviceID,
Username: "username",
PMMAgentID: pmmAgentID,
Disabled: true,
Status: &AgentStatusUnknown,
CustomLabels: map[string]string{},
DisabledCollectors: make([]string, 0),
LogLevel: pointer.ToString("LOG_LEVEL_UNSPECIFIED"),
AgentID: agentID,
ServiceID: serviceID,
Username: "username",
PMMAgentID: pmmAgentID,
Disabled: true,
Status: &AgentStatusUnknown,
CustomLabels: map[string]string{},
DisabledCollectors: make([]string, 0),
LogLevel: pointer.ToString("LOG_LEVEL_UNSPECIFIED"),
MaxExporterConnections: 10,
},
},
}, changePostgresExporterOK)
Expand Down Expand Up @@ -155,9 +157,10 @@ func TestPostgresExporter(t *testing.T) {
CustomLabels: map[string]string{
"new_label": "postgres_exporter",
},
Status: &AgentStatusUnknown,
DisabledCollectors: make([]string, 0),
LogLevel: pointer.ToString("LOG_LEVEL_UNSPECIFIED"),
Status: &AgentStatusUnknown,
DisabledCollectors: make([]string, 0),
LogLevel: pointer.ToString("LOG_LEVEL_UNSPECIFIED"),
MaxExporterConnections: 10,
},
},
}, changePostgresExporterOK)
Expand Down Expand Up @@ -322,7 +325,6 @@ func TestPostgresExporter(t *testing.T) {
CustomLabels: map[string]string{
"custom_label_postgres_exporter": "postgres_exporter",
},

SkipConnectionCheck: true,
PushMetrics: true,
},
Expand Down
82 changes: 43 additions & 39 deletions api-tests/management/postgresql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ func TestAddPostgreSQL(t *testing.T) {
Port: 5432,
Username: "username",

SkipConnectionCheck: true,
DisableCollectors: []string{"custom_query.ml", "custom_query.mr.directory"},
AutoDiscoveryLimit: 0,
SkipConnectionCheck: true,
DisableCollectors: []string{"custom_query.ml", "custom_query.mr.directory"},
AutoDiscoveryLimit: 0,
MaxExporterConnections: 0,
},
}
addPostgreSQLOK, err := client.Default.ManagementService.AddPostgreSQL(params)
Expand Down Expand Up @@ -98,16 +99,17 @@ func TestAddPostgreSQL(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, []*agents.ListAgentsOKBodyPostgresExporterItems0{
{
AgentID: listAgents.Payload.PostgresExporter[0].AgentID,
ServiceID: serviceID,
PMMAgentID: pmmAgentID,
Username: "username",
DisabledCollectors: []string{"custom_query.ml", "custom_query.mr.directory"},
PushMetricsEnabled: true,
Status: &AgentStatusUnknown,
AutoDiscoveryLimit: 10,
CustomLabels: make(map[string]string),
LogLevel: pointer.ToString("LOG_LEVEL_UNSPECIFIED"),
AgentID: listAgents.Payload.PostgresExporter[0].AgentID,
ServiceID: serviceID,
PMMAgentID: pmmAgentID,
Username: "username",
DisabledCollectors: []string{"custom_query.ml", "custom_query.mr.directory"},
PushMetricsEnabled: true,
Status: &AgentStatusUnknown,
AutoDiscoveryLimit: 0,
CustomLabels: make(map[string]string),
LogLevel: pointer.ToString("LOG_LEVEL_UNSPECIFIED"),
MaxExporterConnections: 0,
},
}, listAgents.Payload.PostgresExporter)
defer removeAllAgentsInList(t, listAgents)
Expand Down Expand Up @@ -138,8 +140,9 @@ func TestAddPostgreSQL(t *testing.T) {
QANPostgresqlPgstatmonitorAgent: true,
DisableQueryExamples: true,

SkipConnectionCheck: true,
AutoDiscoveryLimit: 15,
SkipConnectionCheck: true,
AutoDiscoveryLimit: 15,
MaxExporterConnections: 10,
},
}
addPostgreSQLOK, err := client.Default.ManagementService.AddPostgreSQL(params)
Expand Down Expand Up @@ -185,16 +188,17 @@ func TestAddPostgreSQL(t *testing.T) {
require.Len(t, listAgents.Payload.QANPostgresqlPgstatmonitorAgent, 1)
assert.Equal(t, []*agents.ListAgentsOKBodyPostgresExporterItems0{
{
AgentID: listAgents.Payload.PostgresExporter[0].AgentID,
ServiceID: serviceID,
PMMAgentID: pmmAgentID,
Username: "username",
PushMetricsEnabled: true,
Status: &AgentStatusUnknown,
AutoDiscoveryLimit: 15,
CustomLabels: make(map[string]string),
DisabledCollectors: make([]string, 0),
LogLevel: pointer.ToString("LOG_LEVEL_UNSPECIFIED"),
AgentID: listAgents.Payload.PostgresExporter[0].AgentID,
ServiceID: serviceID,
PMMAgentID: pmmAgentID,
Username: "username",
PushMetricsEnabled: true,
Status: &AgentStatusUnknown,
AutoDiscoveryLimit: 15,
CustomLabels: make(map[string]string),
DisabledCollectors: make([]string, 0),
LogLevel: pointer.ToString("LOG_LEVEL_UNSPECIFIED"),
MaxExporterConnections: 10,
},
}, listAgents.Payload.PostgresExporter)

Expand Down Expand Up @@ -676,7 +680,7 @@ func TestAddPostgreSQL(t *testing.T) {
Username: "username",
PushMetricsEnabled: true,
Status: &AgentStatusUnknown,
AutoDiscoveryLimit: 10,
AutoDiscoveryLimit: 0,
CustomLabels: make(map[string]string),
DisabledCollectors: make([]string, 0),
LogLevel: pointer.ToString(agents.ListAgentsOKBodyPostgresExporterItems0LogLevelLOGLEVELUNSPECIFIED),
Expand Down Expand Up @@ -753,7 +757,7 @@ func TestAddPostgreSQL(t *testing.T) {
PMMAgentID: pmmAgentID,
Username: "username",
Status: &AgentStatusUnknown,
AutoDiscoveryLimit: 10,
AutoDiscoveryLimit: 0,
CustomLabels: make(map[string]string),
DisabledCollectors: make([]string, 0),
LogLevel: pointer.ToString(agents.ListAgentsOKBodyPostgresExporterItems0LogLevelLOGLEVELUNSPECIFIED),
Expand Down Expand Up @@ -825,16 +829,17 @@ func TestAddPostgreSQL(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, []*agents.ListAgentsOKBodyPostgresExporterItems0{
{
AgentID: listAgents.Payload.PostgresExporter[0].AgentID,
ServiceID: serviceID,
PMMAgentID: pmmAgentID,
Username: "username",
PushMetricsEnabled: true,
Status: &AgentStatusUnknown,
AutoDiscoveryLimit: 10,
CustomLabels: make(map[string]string),
DisabledCollectors: make([]string, 0),
LogLevel: pointer.ToString(agents.ListAgentsOKBodyPostgresExporterItems0LogLevelLOGLEVELUNSPECIFIED),
AgentID: listAgents.Payload.PostgresExporter[0].AgentID,
ServiceID: serviceID,
PMMAgentID: pmmAgentID,
Username: "username",
PushMetricsEnabled: true,
Status: &AgentStatusUnknown,
AutoDiscoveryLimit: 0,
CustomLabels: make(map[string]string),
DisabledCollectors: make([]string, 0),
LogLevel: pointer.ToString(agents.ListAgentsOKBodyPostgresExporterItems0LogLevelLOGLEVELUNSPECIFIED),
MaxExporterConnections: 0,
},
}, listAgents.Payload.PostgresExporter)
defer removeAllAgentsInList(t, listAgents)
Expand All @@ -861,8 +866,7 @@ func TestRemovePostgreSQL(t *testing.T) {
Password: "password",
QANPostgresqlPgstatementsAgent: withAgents,
QANPostgresqlPgstatmonitorAgent: withAgents,

SkipConnectionCheck: true,
SkipConnectionCheck: true,
},
}
addPostgreSQLOK, err := client.Default.ManagementService.AddPostgreSQL(params)
Expand Down
Loading

0 comments on commit 559c7f3

Please sign in to comment.