Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

Commit

Permalink
Merge pull request #140 from percona/revert-138-revert-137-release/2.15
Browse files Browse the repository at this point in the history
Revert "Revert "Changes from 2.15""
  • Loading branch information
BupycHuk authored Feb 15, 2021
2 parents f71f635 + 5d46f53 commit 3b922dd
Show file tree
Hide file tree
Showing 51 changed files with 2,310 additions and 81 deletions.
5 changes: 3 additions & 2 deletions Gopkg.lock

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

16 changes: 16 additions & 0 deletions commands/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,22 @@ func ParseCustomLabels(labels string) (map[string]string, error) {
return result, nil
}

// ParseDisableCollectors parses --disable-collectors flag value.
func ParseDisableCollectors(collectors string) []string {
var disableCollectors []string

if collectors != "" {
for _, v := range strings.Split(collectors, ",") {
disableCollector := strings.TrimSpace(v)
if disableCollector != "" {
disableCollectors = append(disableCollectors, disableCollector)
}
}
}

return disableCollectors
}

// ReadFile reads file from filepath if filepath is not empty.
func ReadFile(filepath string) (string, error) {
if filepath == "" {
Expand Down
15 changes: 11 additions & 4 deletions commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ type configCommand struct {
NodeType string
NodeName string

NodeModel string
Region string
Az string
MetricsMode string
NodeModel string
Region string
Az string
MetricsMode string
DisableCollectors string

Force bool
}
Expand Down Expand Up @@ -103,6 +104,11 @@ func (cmd *configCommand) args() (res []string, switchedToTLS bool) {
if cmd.MetricsMode != "" {
res = append(res, fmt.Sprintf("--metrics-mode=%s", cmd.MetricsMode))
}

if cmd.DisableCollectors != "" {
res = append(res, fmt.Sprintf("--disable-collectors=%s", cmd.DisableCollectors))
}

res = append(res, cmd.NodeAddress, cmd.NodeType, cmd.NodeName)
return //nolint:nakedret
}
Expand Down Expand Up @@ -155,4 +161,5 @@ func init() {
ConfigC.Flag("force", "Remove Node with that name with all dependent Services and Agents if one exist").BoolVar(&Config.Force)
ConfigC.Flag("metrics-mode", "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.").Default("auto").EnumVar(&Config.MetricsMode, "auto", "push", "pull")
ConfigC.Flag("disable-collectors", "Comma-separated list of collector names to exclude from exporter").StringVar(&Config.DisableCollectors)
}
25 changes: 25 additions & 0 deletions commands/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,29 @@ func TestConfigCommandArgs(t *testing.T) {
assert.Equal(t, expected, args)
assert.True(t, switchedToTLS)
})
t.Run("DisableCollectors", func(t *testing.T) {
cmd := &configCommand{
NodeAddress: "1.2.3.4",
NodeType: "generic",
NodeName: "node1",
DisableCollectors: "cpu,diskstats",
}
u, err := url.Parse("http://admin:[email protected]")
require.NoError(t, err)
GlobalFlags = &globalFlagsValues{
ServerURL: u,
}
args, switchedToTLS := cmd.args()
expected := []string{
"--server-address=127.0.0.1:443",
"--server-username=admin",
"--server-password=admin",
"--server-insecure-tls",
"setup",
"--disable-collectors=cpu,diskstats",
"1.2.3.4", "generic", "node1",
}
assert.Equal(t, expected, args)
assert.True(t, switchedToTLS)
})
}
10 changes: 9 additions & 1 deletion commands/inventory/add_agent_external_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
package inventory

import (
"fmt"
"strings"

"github.com/percona/pmm/api/inventorypb/json/client"
"github.com/percona/pmm/api/inventorypb/json/client/agents"

Expand Down Expand Up @@ -63,6 +66,11 @@ func (cmd *addAgentExternalExporterCommand) Run() (commands.Result, error) {
if err != nil {
return nil, err
}

if !strings.HasPrefix(cmd.MetricsPath, "/") {
cmd.MetricsPath = fmt.Sprintf("/%s", cmd.MetricsPath)
}

params := &agents.AddExternalExporterParams{
Body: agents.AddExternalExporterBody{
RunsOnNodeID: cmd.RunsOnNodeID,
Expand Down Expand Up @@ -98,7 +106,7 @@ func init() {
AddAgentExternalExporterC.Flag("service-id", "Service identifier").Required().StringVar(&AddAgentExternalExporter.ServiceID)
AddAgentExternalExporterC.Flag("username", "HTTP Basic auth username for scraping metrics").StringVar(&AddAgentExternalExporter.Username)
AddAgentExternalExporterC.Flag("password", "HTTP Basic auth password for scraping metrics").StringVar(&AddAgentExternalExporter.Password)
AddAgentExternalExporterC.Flag("scheme", "Scheme to generate URI to exporter metrics endpoints").StringVar(&AddAgentExternalExporter.Scheme)
AddAgentExternalExporterC.Flag("scheme", "Scheme to generate URI to exporter metrics endpoints (http, https)").StringVar(&AddAgentExternalExporter.Scheme)
AddAgentExternalExporterC.Flag("metrics-path", "Path under which metrics are exposed, used to generate URI").StringVar(&AddAgentExternalExporter.MetricsPath)
AddAgentExternalExporterC.Flag("listen-port", "Listen port for scraping metrics").Required().Int64Var(&AddAgentExternalExporter.ListenPort)
AddAgentExternalExporterC.Flag("custom-labels", "Custom user-assigned labels").StringVar(&AddAgentExternalExporter.CustomLabels)
Expand Down
4 changes: 4 additions & 0 deletions commands/inventory/add_agent_mongodb_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type addAgentMongodbExporterCommand struct {
TLSCertificateKeyFilePassword string
TLSCaFile string
PushMetrics bool
DisableCollectors string
}

func (cmd *addAgentMongodbExporterCommand) Run() (commands.Result, error) {
Expand Down Expand Up @@ -91,6 +92,7 @@ func (cmd *addAgentMongodbExporterCommand) Run() (commands.Result, error) {
TLSCertificateKeyFilePassword: cmd.TLSCertificateKeyFilePassword,
TLSCa: tlsCa,
PushMetrics: cmd.PushMetrics,
DisableCollectors: commands.ParseDisableCollectors(cmd.DisableCollectors),
},
Context: commands.Ctx,
}
Expand Down Expand Up @@ -124,4 +126,6 @@ func init() {
AddAgentMongodbExporterC.Flag("tls-ca-file", "Path to certificate authority file").StringVar(&AddAgentMongodbExporter.TLSCaFile)
AddAgentMongodbExporterC.Flag("push-metrics", "Enables push metrics model flow,"+
" it will be sent to the server by an agent").BoolVar(&AddAgentMongodbExporter.PushMetrics)
AddAgentMongodbExporterC.Flag("disable-collectors",
"Comma-separated list of collector names to exclude from exporter").StringVar(&AddAgentMongodbExporter.DisableCollectors)
}
4 changes: 4 additions & 0 deletions commands/inventory/add_agent_mysqld_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type addAgentMysqldExporterCommand struct {
TLSSkipVerify bool
TablestatsGroupTableLimit int32
PushMetrics bool
DisableCollectors string
}

func (cmd *addAgentMysqldExporterCommand) Run() (commands.Result, error) {
Expand All @@ -110,6 +111,7 @@ func (cmd *addAgentMysqldExporterCommand) Run() (commands.Result, error) {
TLSSkipVerify: cmd.TLSSkipVerify,
TablestatsGroupTableLimit: cmd.TablestatsGroupTableLimit,
PushMetrics: cmd.PushMetrics,
DisableCollectors: commands.ParseDisableCollectors(cmd.DisableCollectors),
},
Context: commands.Ctx,
}
Expand Down Expand Up @@ -145,4 +147,6 @@ func init() {
Int32Var(&AddAgentMysqldExporter.TablestatsGroupTableLimit)
AddAgentMysqldExporterC.Flag("push-metrics", "Enables push metrics model flow,"+
" it will be sent to the server by an agent").BoolVar(&AddAgentMysqldExporter.PushMetrics)
AddAgentMysqldExporterC.Flag("disable-collectors",
"Comma-separated list of collector names to exclude from exporter").StringVar(&AddAgentMysqldExporter.DisableCollectors)
}
16 changes: 10 additions & 6 deletions commands/inventory/add_agent_node_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ func (res *addAgentNodeExporterResult) String() string {
}

type addAgentNodeExporterCommand struct {
PMMAgentID string
CustomLabels string
PushMetrics bool
PMMAgentID string
CustomLabels string
PushMetrics bool
DisableCollectors string
}

func (cmd *addAgentNodeExporterCommand) Run() (commands.Result, error) {
Expand All @@ -56,9 +57,10 @@ func (cmd *addAgentNodeExporterCommand) Run() (commands.Result, error) {
}
params := &agents.AddNodeExporterParams{
Body: agents.AddNodeExporterBody{
PMMAgentID: cmd.PMMAgentID,
CustomLabels: customLabels,
PushMetrics: cmd.PushMetrics,
PMMAgentID: cmd.PMMAgentID,
CustomLabels: customLabels,
PushMetrics: cmd.PushMetrics,
DisableCollectors: commands.ParseDisableCollectors(cmd.DisableCollectors),
},
Context: commands.Ctx,
}
Expand All @@ -83,4 +85,6 @@ func init() {
AddAgentNodeExporterC.Flag("custom-labels", "Custom user-assigned labels").StringVar(&AddAgentNodeExporter.CustomLabels)
AddAgentNodeExporterC.Flag("push-metrics", "Enables push metrics model flow,"+
" it will be sent to the server by an agent").BoolVar(&AddAgentNodeExporter.PushMetrics)
AddAgentNodeExporterC.Flag("disable-collectors",
"Comma-separated list of collector names to exclude from exporter").StringVar(&AddAgentNodeExporter.DisableCollectors)
}
4 changes: 4 additions & 0 deletions commands/inventory/add_agent_postgres_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type addAgentPostgresExporterCommand struct {
TLS bool
TLSSkipVerify bool
PushMetrics bool
DisableCollectors string
}

func (cmd *addAgentPostgresExporterCommand) Run() (commands.Result, error) {
Expand All @@ -75,6 +76,7 @@ func (cmd *addAgentPostgresExporterCommand) Run() (commands.Result, error) {
TLS: cmd.TLS,
TLSSkipVerify: cmd.TLSSkipVerify,
PushMetrics: cmd.PushMetrics,
DisableCollectors: commands.ParseDisableCollectors(cmd.DisableCollectors),
},
Context: commands.Ctx,
}
Expand Down Expand Up @@ -105,4 +107,6 @@ func init() {
AddAgentPostgresExporterC.Flag("tls-skip-verify", "Skip TLS certificates validation").BoolVar(&AddAgentPostgresExporter.TLSSkipVerify)
AddAgentPostgresExporterC.Flag("push-metrics", "Enables push metrics model flow,"+
" it will be sent to the server by an agent").BoolVar(&AddAgentPostgresExporter.PushMetrics)
AddAgentPostgresExporterC.Flag("disable-collectors",
"Comma-separated list of collector names to exclude from exporter").StringVar(&AddAgentPostgresExporter.DisableCollectors)
}
4 changes: 4 additions & 0 deletions commands/inventory/add_agent_proxysql_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type addAgentProxysqlExporterCommand struct {
TLS bool
TLSSkipVerify bool
PushMetrics bool
DisableCollectors string
}

func (cmd *addAgentProxysqlExporterCommand) Run() (commands.Result, error) {
Expand All @@ -75,6 +76,7 @@ func (cmd *addAgentProxysqlExporterCommand) Run() (commands.Result, error) {
TLS: cmd.TLS,
TLSSkipVerify: cmd.TLSSkipVerify,
PushMetrics: cmd.PushMetrics,
DisableCollectors: commands.ParseDisableCollectors(cmd.DisableCollectors),
},
Context: commands.Ctx,
}
Expand Down Expand Up @@ -105,4 +107,6 @@ func init() {
AddAgentProxysqlExporterC.Flag("tls-skip-verify", "Skip TLS certificates validation").BoolVar(&AddAgentProxysqlExporter.TLSSkipVerify)
AddAgentProxysqlExporterC.Flag("push-metrics", "Enables push metrics model flow,"+
" it will be sent to the server by an agent").BoolVar(&AddAgentProxysqlExporter.PushMetrics)
AddAgentProxysqlExporterC.Flag("disable-collectors",
"Comma-separated list of collector names to exclude from exporter").StringVar(&AddAgentProxysqlExporter.DisableCollectors)
}
1 change: 1 addition & 0 deletions commands/inventory/list_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,5 @@ var (
func init() {
ListServicesC.Flag("node-id", "Filter by Node identifier").StringVar(&ListServices.filters.NodeID)
ListServicesC.Flag("service-type", "Filter by Service type").StringVar(&ListServices.ServiceType)
ListServicesC.Flag("external-group", "Filter by external group").StringVar(&ListServices.filters.ExternalGroup)
}
6 changes: 5 additions & 1 deletion commands/management/add_external.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ func (cmd *addExternalCommand) Run() (commands.Result, error) {
cmd.ServiceName = fmt.Sprintf("%s-%s", strings.TrimSuffix(cmd.ServiceName, defaultServiceNameSuffix), cmd.Group)
}

if !strings.HasPrefix(cmd.MetricsPath, "/") {
cmd.MetricsPath = fmt.Sprintf("/%s", cmd.MetricsPath)
}

params := &external.AddExternalParams{
Body: external.AddExternalBody{
RunsOnNodeID: cmd.RunsOnNodeID,
Expand Down Expand Up @@ -139,7 +143,7 @@ func init() {
AddExternalC.Flag("username", "External username").StringVar(&AddExternal.Username)
AddExternalC.Flag("password", "External password").StringVar(&AddExternal.Password)

AddExternalC.Flag("scheme", "Scheme to generate URI to exporter metrics endpoints").StringVar(&AddExternal.Scheme)
AddExternalC.Flag("scheme", "Scheme to generate URI to exporter metrics endpoints (http, https)").StringVar(&AddExternal.Scheme)
AddExternalC.Flag("metrics-path", "Path under which metrics are exposed, used to generate URI.").StringVar(&AddExternal.MetricsPath)
AddExternalC.Flag("listen-port", "Listen port of external exporter for scraping metrics.").Required().Uint16Var(&AddExternal.ListenPort)

Expand Down
7 changes: 6 additions & 1 deletion commands/management/add_external_serverless.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"net"
"net/url"
"strconv"
"strings"

"github.com/AlekSi/pointer"
"github.com/percona/pmm/api/managementpb/json/client"
Expand Down Expand Up @@ -88,6 +89,10 @@ func (cmd *addExternalServerlessCommand) Run() (commands.Result, error) {
serviceName = fmt.Sprintf("%s-external", address)
}

if !strings.HasPrefix(cmd.MetricsPath, "/") {
cmd.MetricsPath = fmt.Sprintf("/%s", cmd.MetricsPath)
}

params := &external.AddExternalParams{
Body: external.AddExternalBody{
AddNode: &external.AddExternalParamsBodyAddNode{
Expand Down Expand Up @@ -179,7 +184,7 @@ func init() {
AddExternalServerlessC.Flag("username", "External username").StringVar(&AddExternalServerless.Username)
AddExternalServerlessC.Flag("password", "External password").StringVar(&AddExternalServerless.Password)

AddExternalServerlessC.Flag("scheme", "Scheme to generate URL to exporter metrics endpoints").StringVar(&AddExternalServerless.Scheme)
AddExternalServerlessC.Flag("scheme", "Scheme to generate URL to exporter metrics endpoints (http, https)").StringVar(&AddExternalServerless.Scheme)
AddExternalServerlessC.Flag("url", "Full URL to exporter metrics endpoints").StringVar(&AddExternalServerless.URL)
AddExternalServerlessC.Flag("address", "External exporter address and port").StringVar(&AddExternalServerless.Address)
AddExternalServerlessC.Flag("host", "External exporters hostname or IP address").StringVar(&AddExternalServerless.Host)
Expand Down
27 changes: 15 additions & 12 deletions commands/management/add_mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,19 @@ func (res *addMongoDBResult) String() string {
}

type addMongoDBCommand struct {
Address string
Socket string
NodeID string
PMMAgentID string
ServiceName string
Username string
Password string
Environment string
Cluster string
ReplicationSet string
CustomLabels string
MetricsMode string
Address string
Socket string
NodeID string
PMMAgentID string
ServiceName string
Username string
Password string
Environment string
Cluster string
ReplicationSet string
CustomLabels string
MetricsMode string
DisableCollectors string

QuerySource string

Expand Down Expand Up @@ -146,6 +147,7 @@ func (cmd *addMongoDBCommand) Run() (commands.Result, error) {
TLSCertificateKeyFilePassword: cmd.TLSCertificateKeyFilePassword,
TLSCa: tlsCa,
MetricsMode: pointer.ToString(strings.ToUpper(cmd.MetricsMode)),
DisableCollectors: commands.ParseDisableCollectors(cmd.DisableCollectors),
},
Context: commands.Ctx,
}
Expand Down Expand Up @@ -198,6 +200,7 @@ func init() {
" pull - server scrape metrics from agent or auto - chosen by server.").
Default("auto").
EnumVar(&AddMongoDB.MetricsMode, metricsModes...)
AddMongoDBC.Flag("disable-collectors", "Comma-separated list of collector names to exclude from exporter").StringVar(&AddMongoDB.DisableCollectors)
addGlobalFlags(AddMongoDBC)
AddMongoDBC.Flag("socket", "Path to socket").StringVar(&AddMongoDB.Socket)
}
Loading

0 comments on commit 3b922dd

Please sign in to comment.