Skip to content

Commit

Permalink
PMM-13416 Fix enum flags in pmm-admin. (#3236)
Browse files Browse the repository at this point in the history
* PMM-13416 Fix enum flags in pmm-admin.

* PMM-13416 Fix tests.

* PMM-13416 pmm-agent metrics mode.

* PMM-13416 fix linters.

* PMM-13416 fix linters.

* PMM-7 fix log level value on Server side.

* PMM-13416 fix log level value on API.

* PMM-13416 Regenerate.

* PMM-13416 Fix license.

* PMM-13416 Fix license.

* PMM-13416 Fix linters.

* PMM-13416 Fix imports linter.
  • Loading branch information
BupycHuk authored Nov 8, 2024
1 parent c3a9e56 commit 14242e8
Show file tree
Hide file tree
Showing 55 changed files with 748 additions and 412 deletions.
2 changes: 1 addition & 1 deletion admin/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import (
"github.com/alecthomas/kong"
"github.com/sirupsen/logrus"

"github.com/percona/pmm/admin/cli/flags"
"github.com/percona/pmm/admin/commands"
"github.com/percona/pmm/admin/commands/inventory"
"github.com/percona/pmm/admin/commands/management"
"github.com/percona/pmm/admin/commands/pmm/client"
"github.com/percona/pmm/admin/commands/pmm/server"
"github.com/percona/pmm/admin/pkg/flags"
)

// GlobalFlagsGetter supports retrieving GlobalFlags.
Expand Down
4 changes: 2 additions & 2 deletions admin/cmd/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ import (

"github.com/percona/pmm/admin/agentlocal"
"github.com/percona/pmm/admin/cli"
"github.com/percona/pmm/admin/cli/flags"
"github.com/percona/pmm/admin/commands"
"github.com/percona/pmm/admin/commands/base"
"github.com/percona/pmm/admin/commands/management"
"github.com/percona/pmm/admin/logger"
"github.com/percona/pmm/admin/pkg/flags"
"github.com/percona/pmm/admin/pkg/logger"
"github.com/percona/pmm/utils/nodeinfo"
"github.com/percona/pmm/version"
)
Expand Down
2 changes: 1 addition & 1 deletion admin/commands/base/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/sirupsen/logrus"

"github.com/percona/pmm/admin/agentlocal"
"github.com/percona/pmm/admin/cli/flags"
"github.com/percona/pmm/admin/pkg/flags"
inventoryClient "github.com/percona/pmm/api/inventory/v1/json/client"
managementClient "github.com/percona/pmm/api/management/v1/json/client"
serverClient "github.com/percona/pmm/api/server/v1/json/client"
Expand Down
2 changes: 1 addition & 1 deletion admin/commands/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/percona/pmm/admin/logger"
"github.com/percona/pmm/admin/pkg/logger"
)

func init() {
Expand Down
21 changes: 11 additions & 10 deletions admin/commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

"github.com/sirupsen/logrus"

"github.com/percona/pmm/admin/cli/flags"
"github.com/percona/pmm/admin/pkg/flags"
)

type configResult struct {
Expand All @@ -43,20 +43,21 @@ func (res *configResult) String() string {
//
//nolint:lll
type ConfigCommand struct {
NodeAddress string `arg:"" default:"${nodeIp}" help:"Node address (autodetected default: ${nodeIp})"`
NodeType string `arg:"" enum:"generic,container" default:"${nodeTypeDefault}" help:"Node type, one of: generic, container (default: ${nodeTypeDefault})"`
NodeName string `arg:"" default:"${hostname}" help:"Node name (autodetected default: ${hostname})"`
NodeAddress string `arg:"" default:"${nodeIp}" help:"Node address (autodetected, default: ${default})"`
NodeType string `arg:"" enum:"generic,container" default:"${nodeTypeDefault}" help:"Node type. One of: [${enum}]. Default: ${default}"`
NodeName string `arg:"" default:"${hostname}" help:"Node name (autodetected, default: ${default})"`
NodeModel string `help:"Node model"`
Region string `help:"Node region"`
Az string `help:"Node availability zone"`
AgentPassword string `help:"Custom password for /metrics endpoint"`
Force bool `help:"Remove Node with that name with all dependent Services and Agents if one exist"`
MetricsMode string `enum:"${metricsModesEnum}" default:"auto" help:"Metrics flow mode for agents node-exporter, 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"`
CustomLabels string `placeholder:"KEY=VALUE,KEY=VALUE,..." help:"Custom user-assigned labels"`
BasePath string `name:"paths-base" help:"Base path where all binaries, tools and collectors of PMM client are located"`
LogLevel string `enum:"debug,info,warn,error,fatal" default:"warn" help:"Logging level"`
LogLinesCount uint `help:"Take and return N most recent log lines in logs.zip for each: server, every configured exporters and agents" default:"1024"`

flags.MetricsModeFlags
flags.LogLevelFatalFlags
}

func (cmd *ConfigCommand) args(globals *flags.GlobalFlags) ([]string, bool) {
Expand Down Expand Up @@ -92,8 +93,8 @@ func (cmd *ConfigCommand) args(globals *flags.GlobalFlags) ([]string, bool) {
res = append(res, "--server-insecure-tls")
}

if cmd.LogLevel != "" {
res = append(res, fmt.Sprintf("--log-level=%s", cmd.LogLevel))
if cmd.LogLevelFatalFlags.LogLevel != "" {
res = append(res, fmt.Sprintf("--log-level=%s", cmd.LogLevelFatalFlags.LogLevel))
}
if globals.EnableDebug {
res = append(res, "--debug")
Expand All @@ -120,8 +121,8 @@ func (cmd *ConfigCommand) args(globals *flags.GlobalFlags) ([]string, bool) {
res = append(res, "--force")
}

if cmd.MetricsMode != "" {
res = append(res, fmt.Sprintf("--metrics-mode=%s", cmd.MetricsMode))
if cmd.MetricsModeFlags.MetricsMode != "" {
res = append(res, fmt.Sprintf("--metrics-mode=%s", cmd.MetricsModeFlags.MetricsMode))
}

if len(cmd.DisableCollectors) != 0 {
Expand Down
6 changes: 4 additions & 2 deletions admin/commands/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/percona/pmm/admin/cli/flags"
"github.com/percona/pmm/admin/pkg/flags"
)

func TestConfigCommandArgs(t *testing.T) {
Expand Down Expand Up @@ -91,7 +91,9 @@ func TestConfigCommandArgs(t *testing.T) {
NodeAddress: "1.2.3.4",
NodeType: "generic",
NodeName: "node1",
LogLevel: "info",
LogLevelFatalFlags: flags.LogLevelFatalFlags{
LogLevel: "info",
},
}

u, err := url.Parse("http://admin:[email protected]")
Expand Down
6 changes: 4 additions & 2 deletions admin/commands/inventory/add_agent_mongodb_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package inventory

import (
"github.com/percona/pmm/admin/commands"
"github.com/percona/pmm/admin/pkg/flags"
"github.com/percona/pmm/api/inventory/v1/json/client"
agents "github.com/percona/pmm/api/inventory/v1/json/client/agents_service"
)
Expand Down Expand Up @@ -66,7 +67,8 @@ type AddAgentMongodbExporterCommand struct {
DisableCollectors []string `help:"Comma-separated list of collector names to exclude from exporter"`
StatsCollections []string `help:"Collections for collstats & indexstats"`
CollectionsLimit int32 `name:"max-collections-limit" placeholder:"number" help:"Disable collstats & indexstats if there are more than <n> collections"` //nolint:lll
LogLevel string `enum:"debug,info,warn,error,fatal" default:"warn" help:"Service logging level. One of: [debug, info, warn, error, fatal]"`

flags.LogLevelFatalFlags
}

// RunCmd executes the AddAgentMongodbExporterCommand and returns the result.
Expand Down Expand Up @@ -102,7 +104,7 @@ func (cmd *AddAgentMongodbExporterCommand) RunCmd() (commands.Result, error) {
DisableCollectors: commands.ParseDisableCollectors(cmd.DisableCollectors),
StatsCollections: commands.ParseDisableCollectors(cmd.StatsCollections),
CollectionsLimit: cmd.CollectionsLimit,
LogLevel: &cmd.LogLevel,
LogLevel: cmd.LogLevelFatalFlags.LogLevel.EnumValue(),
},
},
Context: commands.Ctx,
Expand Down
6 changes: 4 additions & 2 deletions admin/commands/inventory/add_agent_mysqld_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"strconv"

"github.com/percona/pmm/admin/commands"
"github.com/percona/pmm/admin/pkg/flags"
"github.com/percona/pmm/api/inventory/v1/json/client"
agents "github.com/percona/pmm/api/inventory/v1/json/client/agents_service"
)
Expand Down Expand Up @@ -98,7 +99,8 @@ type AddAgentMysqldExporterCommand struct {
PushMetrics bool `help:"Enables push metrics model flow, it will be sent to the server by an agent"`
ExposeExporter bool `help:"Expose the address of the exporter publicly on 0.0.0.0"`
DisableCollectors []string `help:"Comma-separated list of collector names to exclude from exporter"`
LogLevel string `enum:"debug,info,warn,error" default:"warn" help:"Service logging level. One of: [debug, info, warn, error]"`

flags.LogLevelNoFatalFlags
}

// RunCmd executes the AddAgentMysqldExporterCommand and returns the result.
Expand Down Expand Up @@ -145,7 +147,7 @@ func (cmd *AddAgentMysqldExporterCommand) RunCmd() (commands.Result, error) {
PushMetrics: cmd.PushMetrics,
ExposeExporter: cmd.ExposeExporter,
DisableCollectors: commands.ParseDisableCollectors(cmd.DisableCollectors),
LogLevel: &cmd.LogLevel,
LogLevel: cmd.LogLevelNoFatalFlags.LogLevel.EnumValue(),
},
},
Context: commands.Ctx,
Expand Down
6 changes: 4 additions & 2 deletions admin/commands/inventory/add_agent_node_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package inventory

import (
"github.com/percona/pmm/admin/commands"
"github.com/percona/pmm/admin/pkg/flags"
"github.com/percona/pmm/api/inventory/v1/json/client"
agents "github.com/percona/pmm/api/inventory/v1/json/client/agents_service"
)
Expand Down Expand Up @@ -48,7 +49,8 @@ type AddAgentNodeExporterCommand struct {
PushMetrics bool `help:"Enables push metrics model flow, it will be sent to the server by an agent"`
ExposeExporter bool `help:"Expose the address of the exporter publicly on 0.0.0.0"`
DisableCollectors []string `help:"Comma-separated list of collector names to exclude from exporter"`
LogLevel string `enum:"debug,info,warn,error" default:"warn" help:"Service logging level. One of: [debug, info, warn, error]"`

flags.LogLevelNoFatalFlags
}

// RunCmd runs the command for AddAgentNodeExporterCommand.
Expand All @@ -62,7 +64,7 @@ func (cmd *AddAgentNodeExporterCommand) RunCmd() (commands.Result, error) {
PushMetrics: cmd.PushMetrics,
ExposeExporter: cmd.ExposeExporter,
DisableCollectors: commands.ParseDisableCollectors(cmd.DisableCollectors),
LogLevel: &cmd.LogLevel,
LogLevel: cmd.LogLevelNoFatalFlags.LogLevel.EnumValue(),
},
},
Context: commands.Ctx,
Expand Down
6 changes: 4 additions & 2 deletions admin/commands/inventory/add_agent_postgres_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package inventory

import (
"github.com/percona/pmm/admin/commands"
"github.com/percona/pmm/admin/pkg/flags"
"github.com/percona/pmm/api/inventory/v1/json/client"
agents "github.com/percona/pmm/api/inventory/v1/json/client/agents_service"
)
Expand Down Expand Up @@ -64,8 +65,9 @@ type AddAgentPostgresExporterCommand struct {
TLSCAFile string `help:"TLS CA certificate file"`
TLSCertFile string `help:"TLS certificate file"`
TLSKeyFile string `help:"TLS certificate key file"`
LogLevel string `enum:"debug,info,warn,error" default:"warn" help:"Service logging level. One of: [debug, info, warn, error]"`
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)"`

flags.LogLevelNoFatalFlags
}

// RunCmd executes the AddAgentPostgresExporterCommand and returns the result.
Expand Down Expand Up @@ -113,7 +115,7 @@ func (cmd *AddAgentPostgresExporterCommand) RunCmd() (commands.Result, error) {
TLSCa: tlsCa,
TLSCert: tlsCert,
TLSKey: tlsKey,
LogLevel: &cmd.LogLevel,
LogLevel: cmd.LogLevelNoFatalFlags.LogLevel.EnumValue(),
},
},
Context: commands.Ctx,
Expand Down
6 changes: 4 additions & 2 deletions admin/commands/inventory/add_agent_proxysql_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package inventory

import (
"github.com/percona/pmm/admin/commands"
"github.com/percona/pmm/admin/pkg/flags"
"github.com/percona/pmm/api/inventory/v1/json/client"
agents "github.com/percona/pmm/api/inventory/v1/json/client/agents_service"
)
Expand Down Expand Up @@ -59,7 +60,8 @@ type AddAgentProxysqlExporterCommand struct {
PushMetrics bool `help:"Enables push metrics model flow, it will be sent to the server by an agent"`
ExposeExporter bool `help:"Expose the address of the exporter publicly on 0.0.0.0"`
DisableCollectors []string `help:"Comma-separated list of collector names to exclude from exporter"`
LogLevel string `enum:"debug,info,warn,error,fatal" default:"warn" help:"Service logging level. One of: [debug, info, warn, error, fatal]"`

flags.LogLevelFatalFlags
}

// RunCmd executes the AddAgentProxysqlExporterCommand and returns the result.
Expand All @@ -80,7 +82,7 @@ func (cmd *AddAgentProxysqlExporterCommand) RunCmd() (commands.Result, error) {
PushMetrics: cmd.PushMetrics,
ExposeExporter: cmd.ExposeExporter,
DisableCollectors: commands.ParseDisableCollectors(cmd.DisableCollectors),
LogLevel: &cmd.LogLevel,
LogLevel: cmd.LogLevelFatalFlags.LogLevel.EnumValue(),
},
},
Context: commands.Ctx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package inventory

import (
"github.com/percona/pmm/admin/commands"
"github.com/percona/pmm/admin/pkg/flags"
"github.com/percona/pmm/api/inventory/v1/json/client"
agents "github.com/percona/pmm/api/inventory/v1/json/client/agents_service"
)
Expand Down Expand Up @@ -62,7 +63,8 @@ type AddAgentQANMongoDBProfilerAgentCommand struct {
TLSCertificateKeyFilePassword string `help:"Password for certificate"`
TLSCaFile string `help:"Path to certificate authority file"`
AuthenticationMechanism string `help:"Authentication mechanism. Default is empty. Use MONGODB-X509 for ssl certificates"`
LogLevel string `enum:"debug,info,warn,error,fatal" default:"warn" help:"Service logging level. One of: [debug, info, warn, error, fatal]"`

flags.LogLevelFatalFlags
}

// RunCmd executes the AddAgentQANMongoDBProfilerAgentCommand and returns the result.
Expand Down Expand Up @@ -94,7 +96,7 @@ func (cmd *AddAgentQANMongoDBProfilerAgentCommand) RunCmd() (commands.Result, er
TLSCertificateKeyFilePassword: cmd.TLSCertificateKeyFilePassword,
TLSCa: tlsCa,
AuthenticationMechanism: cmd.AuthenticationMechanism,
LogLevel: &cmd.LogLevel,
LogLevel: cmd.LogLevelFatalFlags.LogLevel.EnumValue(),
},
},
Context: commands.Ctx,
Expand Down
15 changes: 6 additions & 9 deletions admin/commands/inventory/add_agent_qan_mysql_perfschema_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package inventory

import (
"github.com/percona/pmm/admin/commands"
"github.com/percona/pmm/admin/pkg/flags"
"github.com/percona/pmm/api/inventory/v1/json/client"
agents "github.com/percona/pmm/api/inventory/v1/json/client/agents_service"
)
Expand Down Expand Up @@ -60,15 +61,16 @@ type AddAgentQANMySQLPerfSchemaAgentCommand struct {
Password string `help:"MySQL password for scraping metrics"`
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]"`
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"`
TLS bool `help:"Use TLS to connect to the database"`
TLSSkipVerify bool `help:"Skip TLS certificates validation"`
TLSCAFile string `name:"tls-ca" help:"Path to certificate authority certificate file"`
TLSCertFile string `name:"tls-cert" help:"Path to client certificate file"`
TLSKeyFile string `name:"tls-key" help:"Path to client key file"`
LogLevel string `enum:"debug,info,warn,error,fatal" default:"warn" help:"Service logging level. One of: [debug, info, warn, error, fatal]"`

flags.CommentsParsingFlags
flags.LogLevelFatalFlags
}

// RunCmd runs the command for AddAgentQANMySQLPerfSchemaAgentCommand.
Expand Down Expand Up @@ -96,11 +98,6 @@ func (cmd *AddAgentQANMySQLPerfSchemaAgentCommand) RunCmd() (commands.Result, er
}
}

disableCommentsParsing := true
if cmd.CommentsParsing == "on" {
disableCommentsParsing = false
}

params := &agents.AddAgentParams{
Body: agents.AddAgentBody{
QANMysqlPerfschemaAgent: &agents.AddAgentParamsBodyQANMysqlPerfschemaAgent{
Expand All @@ -110,15 +107,15 @@ func (cmd *AddAgentQANMySQLPerfSchemaAgentCommand) RunCmd() (commands.Result, er
Password: cmd.Password,
CustomLabels: customLabels,
SkipConnectionCheck: cmd.SkipConnectionCheck,
DisableCommentsParsing: disableCommentsParsing,
DisableCommentsParsing: !cmd.CommentsParsingFlags.CommentsParsingEnabled(),
MaxQueryLength: cmd.MaxQueryLength,
DisableQueryExamples: cmd.DisableQueryExamples,
TLS: cmd.TLS,
TLSSkipVerify: cmd.TLSSkipVerify,
TLSCa: tlsCa,
TLSCert: tlsCert,
TLSKey: tlsKey,
LogLevel: &cmd.LogLevel,
LogLevel: cmd.LogLevelFatalFlags.LogLevel.EnumValue(),
},
},
Context: commands.Ctx,
Expand Down
Loading

0 comments on commit 14242e8

Please sign in to comment.