diff --git a/.gitignore b/.gitignore index 2d01020e57..ee601f2d71 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,4 @@ api-tests/pmm-api-tests-output.txt api-tests/pmm-api-tests-junit-report.xml packer.log +encryption.key \ No newline at end of file diff --git a/managed/models/agent_helpers.go b/managed/models/agent_helpers.go index f588fd4f17..76d64b020c 100644 --- a/managed/models/agent_helpers.go +++ b/managed/models/agent_helpers.go @@ -44,15 +44,12 @@ type MySQLOptionsParams interface { } // MySQLOptionsFromRequest creates MySQLOptions object from request. -func MySQLOptionsFromRequest(params MySQLOptionsParams) *MySQLOptions { - if params.GetTlsCa() != "" || params.GetTlsCert() != "" || params.GetTlsKey() != "" { - return &MySQLOptions{ - TLSCa: params.GetTlsCa(), - TLSCert: params.GetTlsCert(), - TLSKey: params.GetTlsKey(), - } +func MySQLOptionsFromRequest(params MySQLOptionsParams) MySQLOptions { + return MySQLOptions{ + TLSCa: params.GetTlsCa(), + TLSCert: params.GetTlsCert(), + TLSKey: params.GetTlsKey(), } - return &MySQLOptions{} } // PostgreSQLOptionsParams contains methods to create PostgreSQLOptions object. @@ -69,13 +66,11 @@ type PostgreSQLExtendedOptionsParams interface { } // PostgreSQLOptionsFromRequest creates PostgreSQLOptions object from request. -func PostgreSQLOptionsFromRequest(params PostgreSQLOptionsParams) *PostgreSQLOptions { - res := &PostgreSQLOptions{} - if params.GetTlsCa() != "" || params.GetTlsCert() != "" || params.GetTlsKey() != "" { - res.SSLCa = params.GetTlsCa() - res.SSLCert = params.GetTlsCert() - res.SSLKey = params.GetTlsKey() - } +func PostgreSQLOptionsFromRequest(params PostgreSQLOptionsParams) PostgreSQLOptions { + res := PostgreSQLOptions{} + res.SSLCa = params.GetTlsCa() + res.SSLCert = params.GetTlsCert() + res.SSLKey = params.GetTlsKey() // PostgreSQL exporter has these parameters but they are not needed for QAN agent. if extendedOptions, ok := params.(PostgreSQLExtendedOptionsParams); ok && extendedOptions != nil { @@ -103,20 +98,15 @@ type MongoDBExtendedOptionsParams interface { } // MongoDBOptionsFromRequest creates MongoDBOptionsParams object from request. -func MongoDBOptionsFromRequest(params MongoDBOptionsParams) *MongoDBOptions { - mdbOptions := &MongoDBOptions{} +func MongoDBOptionsFromRequest(params MongoDBOptionsParams) MongoDBOptions { + mdbOptions := MongoDBOptions{} - if params.GetTlsCertificateKey() != "" || params.GetTlsCertificateKeyFilePassword() != "" || params.GetTlsCa() != "" { - mdbOptions = &MongoDBOptions{} - mdbOptions.TLSCertificateKey = params.GetTlsCertificateKey() - mdbOptions.TLSCertificateKeyFilePassword = params.GetTlsCertificateKeyFilePassword() - mdbOptions.TLSCa = params.GetTlsCa() - } + mdbOptions.TLSCertificateKey = params.GetTlsCertificateKey() + mdbOptions.TLSCertificateKeyFilePassword = params.GetTlsCertificateKeyFilePassword() + mdbOptions.TLSCa = params.GetTlsCa() - if params.GetAuthenticationMechanism() != "" || params.GetAuthenticationDatabase() != "" { - mdbOptions.AuthenticationMechanism = params.GetAuthenticationMechanism() - mdbOptions.AuthenticationDatabase = params.GetAuthenticationDatabase() - } + mdbOptions.AuthenticationMechanism = params.GetAuthenticationMechanism() + mdbOptions.AuthenticationDatabase = params.GetAuthenticationDatabase() // MongoDB exporter has these parameters but they are not needed for QAN agent. if extendedOptions, ok := params.(MongoDBExtendedOptionsParams); ok { @@ -140,10 +130,10 @@ type AzureOptionsParams interface { } // AzureOptionsFromRequest creates AzureOptions object from request. -func AzureOptionsFromRequest(params AzureOptionsParams) *AzureOptions { +func AzureOptionsFromRequest(params AzureOptionsParams) AzureOptions { if params.GetAzureSubscriptionId() != "" || params.GetAzureClientId() != "" || params.GetAzureClientSecret() != "" || params.GetAzureTenantId() != "" || params.GetAzureResourceGroup() != "" { - return &AzureOptions{ + return AzureOptions{ SubscriptionID: params.GetAzureSubscriptionId(), ClientID: params.GetAzureClientId(), ClientSecret: params.GetAzureClientSecret(), @@ -151,7 +141,7 @@ func AzureOptionsFromRequest(params AzureOptionsParams) *AzureOptions { ResourceGroup: params.GetAzureResourceGroup(), } } - return nil + return AzureOptions{} } func checkUniqueAgentID(q *reform.Querier, id string) error { @@ -644,7 +634,7 @@ func CreateNodeExporter(q *reform.Querier, PMMAgentID: &pmmAgentID, NodeID: pmmAgent.RunsOnNodeID, AgentPassword: agentPassword, - ExporterOptions: &ExporterOptions{ + ExporterOptions: ExporterOptions{ ExposeExporter: exposeExporter, PushMetrics: pushMetrics, DisabledCollectors: disableCollectors, @@ -734,7 +724,7 @@ func CreateExternalExporter(q *reform.Querier, params *CreateExternalExporterPar Username: pointer.ToStringOrNil(params.Username), Password: pointer.ToStringOrNil(params.Password), ListenPort: pointer.ToUint16(uint16(params.ListenPort)), - ExporterOptions: &ExporterOptions{ + ExporterOptions: ExporterOptions{ PushMetrics: params.PushMetrics, MetricsPath: metricsPath, MetricsScheme: scheme, @@ -765,13 +755,13 @@ type CreateAgentParams struct { TLS bool TLSSkipVerify bool LogLevel string - ExporterOptions *ExporterOptions - QANOptions *QANOptions - AWSOptions *AWSOptions - AzureOptions *AzureOptions - MongoDBOptions *MongoDBOptions - MySQLOptions *MySQLOptions - PostgreSQLOptions *PostgreSQLOptions + ExporterOptions ExporterOptions + QANOptions QANOptions + AWSOptions AWSOptions + AzureOptions AzureOptions + MongoDBOptions MongoDBOptions + MySQLOptions MySQLOptions + PostgreSQLOptions PostgreSQLOptions } func compatibleNodeAndAgent(nodeType NodeType, agentType AgentType) bool { @@ -852,32 +842,6 @@ func compatibleServiceAndAgent(serviceType ServiceType, agentType AgentType) boo return false } -func prepareOptionsParams(params *CreateAgentParams) *CreateAgentParams { - if params.ExporterOptions == nil { - params.ExporterOptions = &ExporterOptions{} - } - if params.QANOptions == nil { - params.QANOptions = &QANOptions{} - } - if params.AWSOptions == nil { - params.AWSOptions = &AWSOptions{} - } - if params.AzureOptions == nil { - params.AzureOptions = &AzureOptions{} - } - if params.MongoDBOptions == nil { - params.MongoDBOptions = &MongoDBOptions{} - } - if params.MySQLOptions == nil { - params.MySQLOptions = &MySQLOptions{} - } - if params.PostgreSQLOptions == nil { - params.PostgreSQLOptions = &PostgreSQLOptions{} - } - - return params -} - // CreateAgent creates Agent with given type. func CreateAgent(q *reform.Querier, agentType AgentType, params *CreateAgentParams) (*Agent, error) { //nolint:unparam id := uuid.New().String() @@ -885,8 +849,6 @@ func CreateAgent(q *reform.Querier, agentType AgentType, params *CreateAgentPara return nil, err } - params = prepareOptionsParams(params) - pmmAgent, err := FindAgentByID(q, params.PMMAgentID) if err != nil { return nil, err diff --git a/managed/models/agent_helpers_test.go b/managed/models/agent_helpers_test.go index b4706fee0e..14e3e15683 100644 --- a/managed/models/agent_helpers_test.go +++ b/managed/models/agent_helpers_test.go @@ -104,7 +104,7 @@ func TestAgentHelpers(t *testing.T) { RunsOnNodeID: nil, NodeID: pointer.ToString("N2"), ListenPort: pointer.ToUint16(8200), - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ PushMetrics: true, }, }, @@ -125,14 +125,14 @@ func TestAgentHelpers(t *testing.T) { ListenPort: pointer.ToUint16(8200), TLS: true, TLSSkipVerify: true, - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ MetricsResolutions: &models.MetricsResolutions{ HR: 1 * time.Minute, MR: 5 * time.Minute, LR: 15 * time.Minute, }, }, - PostgreSQLOptions: &models.PostgreSQLOptions{ + PostgreSQLOptions: models.PostgreSQLOptions{ SSLCa: "ssl_ca", SSLCert: "ssl_cert", SSLKey: "ssl_key", @@ -147,7 +147,7 @@ func TestAgentHelpers(t *testing.T) { ListenPort: pointer.ToUint16(8200), TLS: true, TLSSkipVerify: true, - MongoDBOptions: &models.MongoDBOptions{ + MongoDBOptions: models.MongoDBOptions{ TLSCertificateKey: "tls_certificate_key", TLSCertificateKeyFilePassword: "tls_certificate_key_file_password", TLSCa: "tls_ca", @@ -166,7 +166,7 @@ func TestAgentHelpers(t *testing.T) { ListenPort: pointer.ToUint16(8200), TLS: true, TLSSkipVerify: true, - MongoDBOptions: &models.MongoDBOptions{ + MongoDBOptions: models.MongoDBOptions{ TLSCertificateKey: "tls_certificate_key", TLSCertificateKeyFilePassword: "tls_certificate_key_file_password", TLSCa: "tls_ca", @@ -178,15 +178,14 @@ func TestAgentHelpers(t *testing.T) { }, }, &models.Agent{ - AgentID: "A10", - AgentType: models.MongoDBExporterType, - PMMAgentID: pointer.ToString("A10"), - RunsOnNodeID: nil, - NodeID: pointer.ToString("N1"), - ListenPort: pointer.ToUint16(8200), - TLS: true, - TLSSkipVerify: true, - MongoDBOptions: nil, + AgentID: "A10", + AgentType: models.MongoDBExporterType, + PMMAgentID: pointer.ToString("A10"), + RunsOnNodeID: nil, + NodeID: pointer.ToString("N1"), + ListenPort: pointer.ToUint16(8200), + TLS: true, + TLSSkipVerify: true, }, } { require.NoError(t, q.Insert(str)) @@ -207,41 +206,27 @@ func TestAgentHelpers(t *testing.T) { require.NoError(t, err) expected := []*models.Agent{ { - CreatedAt: now, - UpdatedAt: now, - Status: models.AgentStatusUnknown, - AgentID: "A10", - AgentType: models.MongoDBExporterType, - PMMAgentID: pointer.ToString("A10"), - RunsOnNodeID: nil, - NodeID: pointer.ToString("N1"), - ListenPort: pointer.ToUint16(8200), - TLS: true, - TLSSkipVerify: true, - ExporterOptions: &models.ExporterOptions{}, - QANOptions: &models.QANOptions{}, - AWSOptions: &models.AWSOptions{}, - AzureOptions: &models.AzureOptions{}, - MongoDBOptions: &models.MongoDBOptions{}, - MySQLOptions: &models.MySQLOptions{}, - PostgreSQLOptions: &models.PostgreSQLOptions{}, + CreatedAt: now, + UpdatedAt: now, + Status: models.AgentStatusUnknown, + AgentID: "A10", + AgentType: models.MongoDBExporterType, + PMMAgentID: pointer.ToString("A10"), + RunsOnNodeID: nil, + NodeID: pointer.ToString("N1"), + ListenPort: pointer.ToUint16(8200), + TLS: true, + TLSSkipVerify: true, }, { - AgentID: "A3", - AgentType: models.NodeExporterType, - PMMAgentID: pointer.ToStringOrNil("A1"), - RunsOnNodeID: nil, - CreatedAt: now, - UpdatedAt: now, - NodeID: pointer.ToString("N1"), - Status: models.AgentStatusUnknown, - ExporterOptions: &models.ExporterOptions{}, - QANOptions: &models.QANOptions{}, - AWSOptions: &models.AWSOptions{}, - AzureOptions: &models.AzureOptions{}, - MongoDBOptions: &models.MongoDBOptions{}, - MySQLOptions: &models.MySQLOptions{}, - PostgreSQLOptions: &models.PostgreSQLOptions{}, + AgentID: "A3", + AgentType: models.NodeExporterType, + PMMAgentID: pointer.ToStringOrNil("A1"), + RunsOnNodeID: nil, + CreatedAt: now, + UpdatedAt: now, + NodeID: pointer.ToString("N1"), + Status: models.AgentStatusUnknown, }, { AgentID: "A7", @@ -254,40 +239,31 @@ func TestAgentHelpers(t *testing.T) { ListenPort: pointer.ToUint16OrNil(8200), TLS: true, TLSSkipVerify: true, - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ MetricsResolutions: &models.MetricsResolutions{ HR: 1 * time.Minute, MR: 5 * time.Minute, LR: 15 * time.Minute, }, }, - QANOptions: &models.QANOptions{}, - AWSOptions: &models.AWSOptions{}, - AzureOptions: &models.AzureOptions{}, - MongoDBOptions: &models.MongoDBOptions{}, - MySQLOptions: &models.MySQLOptions{}, - PostgreSQLOptions: &models.PostgreSQLOptions{ + PostgreSQLOptions: models.PostgreSQLOptions{ SSLCa: "ssl_ca", SSLCert: "ssl_cert", SSLKey: "ssl_key", }, }, { - AgentID: "A8", - AgentType: "mongodb_exporter", - NodeID: pointer.ToStringOrNil("N1"), - PMMAgentID: pointer.ToStringOrNil("A8"), - CreatedAt: now, - UpdatedAt: now, - Status: models.AgentStatusUnknown, - ListenPort: pointer.ToUint16OrNil(8200), - TLS: true, - TLSSkipVerify: true, - ExporterOptions: &models.ExporterOptions{}, - QANOptions: &models.QANOptions{}, - AWSOptions: &models.AWSOptions{}, - AzureOptions: &models.AzureOptions{}, - MongoDBOptions: &models.MongoDBOptions{ + AgentID: "A8", + AgentType: "mongodb_exporter", + NodeID: pointer.ToStringOrNil("N1"), + PMMAgentID: pointer.ToStringOrNil("A8"), + CreatedAt: now, + UpdatedAt: now, + Status: models.AgentStatusUnknown, + ListenPort: pointer.ToUint16OrNil(8200), + TLS: true, + TLSSkipVerify: true, + MongoDBOptions: models.MongoDBOptions{ TLSCertificateKey: "tls_certificate_key", TLSCertificateKeyFilePassword: "tls_certificate_key_file_password", TLSCa: "tls_ca", @@ -296,25 +272,19 @@ func TestAgentHelpers(t *testing.T) { StatsCollections: nil, CollectionsLimit: 0, // no limit }, - MySQLOptions: &models.MySQLOptions{}, - PostgreSQLOptions: &models.PostgreSQLOptions{}, }, { - AgentID: "A9", - AgentType: "mongodb_exporter", - NodeID: pointer.ToStringOrNil("N1"), - PMMAgentID: pointer.ToStringOrNil("A9"), - CreatedAt: now, - UpdatedAt: now, - Status: models.AgentStatusUnknown, - ListenPort: pointer.ToUint16OrNil(8200), - TLS: true, - TLSSkipVerify: true, - ExporterOptions: &models.ExporterOptions{}, - QANOptions: &models.QANOptions{}, - AWSOptions: &models.AWSOptions{}, - AzureOptions: &models.AzureOptions{}, - MongoDBOptions: &models.MongoDBOptions{ + AgentID: "A9", + AgentType: "mongodb_exporter", + NodeID: pointer.ToStringOrNil("N1"), + PMMAgentID: pointer.ToStringOrNil("A9"), + CreatedAt: now, + UpdatedAt: now, + Status: models.AgentStatusUnknown, + ListenPort: pointer.ToUint16OrNil(8200), + TLS: true, + TLSSkipVerify: true, + MongoDBOptions: models.MongoDBOptions{ TLSCertificateKey: "tls_certificate_key", TLSCertificateKeyFilePassword: "tls_certificate_key_file_password", TLSCa: "tls_ca", @@ -324,8 +294,6 @@ func TestAgentHelpers(t *testing.T) { CollectionsLimit: 79014, EnableAllCollectors: true, }, - MySQLOptions: &models.MySQLOptions{}, - PostgreSQLOptions: &models.PostgreSQLOptions{}, }, } assert.Equal(t, expected, agents) @@ -338,37 +306,23 @@ func TestAgentHelpers(t *testing.T) { agents, err := models.FindAgents(q, models.AgentFilters{PMMAgentID: "A1"}) require.NoError(t, err) expected := []*models.Agent{{ - AgentID: "A2", - AgentType: models.MySQLdExporterType, - PMMAgentID: pointer.ToStringOrNil("A1"), - ServiceID: pointer.ToString("S1"), - RunsOnNodeID: nil, - CreatedAt: now, - UpdatedAt: now, - Status: models.AgentStatusUnknown, - ExporterOptions: &models.ExporterOptions{}, - QANOptions: &models.QANOptions{}, - AWSOptions: &models.AWSOptions{}, - AzureOptions: &models.AzureOptions{}, - MongoDBOptions: &models.MongoDBOptions{}, - MySQLOptions: &models.MySQLOptions{}, - PostgreSQLOptions: &models.PostgreSQLOptions{}, + AgentID: "A2", + AgentType: models.MySQLdExporterType, + PMMAgentID: pointer.ToStringOrNil("A1"), + ServiceID: pointer.ToString("S1"), + RunsOnNodeID: nil, + CreatedAt: now, + UpdatedAt: now, + Status: models.AgentStatusUnknown, }, { - AgentID: "A3", - AgentType: models.NodeExporterType, - PMMAgentID: pointer.ToStringOrNil("A1"), - NodeID: pointer.ToString("N1"), - RunsOnNodeID: nil, - CreatedAt: now, - UpdatedAt: now, - Status: models.AgentStatusUnknown, - ExporterOptions: &models.ExporterOptions{}, - QANOptions: &models.QANOptions{}, - AWSOptions: &models.AWSOptions{}, - AzureOptions: &models.AzureOptions{}, - MongoDBOptions: &models.MongoDBOptions{}, - MySQLOptions: &models.MySQLOptions{}, - PostgreSQLOptions: &models.PostgreSQLOptions{}, + AgentID: "A3", + AgentType: models.NodeExporterType, + PMMAgentID: pointer.ToStringOrNil("A1"), + NodeID: pointer.ToString("N1"), + RunsOnNodeID: nil, + CreatedAt: now, + UpdatedAt: now, + Status: models.AgentStatusUnknown, }} assert.Equal(t, expected, agents) }) @@ -380,21 +334,14 @@ func TestAgentHelpers(t *testing.T) { agents, err := models.FindAgents(q, models.AgentFilters{PMMAgentID: "A1", AgentType: pointerToAgentType(models.MySQLdExporterType)}) require.NoError(t, err) expected := []*models.Agent{{ - AgentID: "A2", - AgentType: models.MySQLdExporterType, - PMMAgentID: pointer.ToStringOrNil("A1"), - ServiceID: pointer.ToString("S1"), - RunsOnNodeID: nil, - CreatedAt: now, - UpdatedAt: now, - Status: models.AgentStatusUnknown, - ExporterOptions: &models.ExporterOptions{}, - QANOptions: &models.QANOptions{}, - AWSOptions: &models.AWSOptions{}, - AzureOptions: &models.AzureOptions{}, - MongoDBOptions: &models.MongoDBOptions{}, - MySQLOptions: &models.MySQLOptions{}, - PostgreSQLOptions: &models.PostgreSQLOptions{}, + AgentID: "A2", + AgentType: models.MySQLdExporterType, + PMMAgentID: pointer.ToStringOrNil("A1"), + ServiceID: pointer.ToString("S1"), + RunsOnNodeID: nil, + CreatedAt: now, + UpdatedAt: now, + Status: models.AgentStatusUnknown, }} assert.Equal(t, expected, agents) }) @@ -406,42 +353,28 @@ func TestAgentHelpers(t *testing.T) { agents, err := models.FindAgents(q, models.AgentFilters{ServiceID: "S1"}) require.NoError(t, err) expected := []*models.Agent{{ - AgentID: "A2", - AgentType: models.MySQLdExporterType, - PMMAgentID: pointer.ToStringOrNil("A1"), - ServiceID: pointer.ToString("S1"), - RunsOnNodeID: nil, - CreatedAt: now, - UpdatedAt: now, - Status: models.AgentStatusUnknown, - ExporterOptions: &models.ExporterOptions{}, - QANOptions: &models.QANOptions{}, - AWSOptions: &models.AWSOptions{}, - AzureOptions: &models.AzureOptions{}, - MongoDBOptions: &models.MongoDBOptions{}, - MySQLOptions: &models.MySQLOptions{}, - PostgreSQLOptions: &models.PostgreSQLOptions{}, + AgentID: "A2", + AgentType: models.MySQLdExporterType, + PMMAgentID: pointer.ToStringOrNil("A1"), + ServiceID: pointer.ToString("S1"), + RunsOnNodeID: nil, + CreatedAt: now, + UpdatedAt: now, + Status: models.AgentStatusUnknown, }} assert.Equal(t, expected, agents) agents, err = models.FindAgents(q, models.AgentFilters{ServiceID: "S1", AgentType: pointerToAgentType(models.MySQLdExporterType)}) require.NoError(t, err) expected = []*models.Agent{{ - AgentID: "A2", - AgentType: models.MySQLdExporterType, - PMMAgentID: pointer.ToStringOrNil("A1"), - ServiceID: pointer.ToString("S1"), - RunsOnNodeID: nil, - CreatedAt: now, - UpdatedAt: now, - Status: models.AgentStatusUnknown, - ExporterOptions: &models.ExporterOptions{}, - QANOptions: &models.QANOptions{}, - AWSOptions: &models.AWSOptions{}, - AzureOptions: &models.AzureOptions{}, - MongoDBOptions: &models.MongoDBOptions{}, - MySQLOptions: &models.MySQLOptions{}, - PostgreSQLOptions: &models.PostgreSQLOptions{}, + AgentID: "A2", + AgentType: models.MySQLdExporterType, + PMMAgentID: pointer.ToStringOrNil("A1"), + ServiceID: pointer.ToString("S1"), + RunsOnNodeID: nil, + CreatedAt: now, + UpdatedAt: now, + Status: models.AgentStatusUnknown, }} assert.Equal(t, expected, agents) @@ -471,18 +404,11 @@ func TestAgentHelpers(t *testing.T) { tests.AssertGRPCError(t, status.New(codes.FailedPrecondition, `pmm-agent with ID A1 has agents.`), err) expected := &models.Agent{ - AgentID: "A1", - AgentType: models.PMMAgentType, - RunsOnNodeID: pointer.ToString("N1"), - CreatedAt: now, - UpdatedAt: now, - ExporterOptions: &models.ExporterOptions{}, - QANOptions: &models.QANOptions{}, - AWSOptions: &models.AWSOptions{}, - AzureOptions: &models.AzureOptions{}, - MongoDBOptions: &models.MongoDBOptions{}, - MySQLOptions: &models.MySQLOptions{}, - PostgreSQLOptions: &models.PostgreSQLOptions{}, + AgentID: "A1", + AgentType: models.PMMAgentType, + RunsOnNodeID: pointer.ToString("N1"), + CreatedAt: now, + UpdatedAt: now, } agent, err = models.RemoveAgent(q, "A1", models.RemoveCascade) assert.Equal(t, expected, agent) @@ -545,7 +471,7 @@ func TestAgentHelpers(t *testing.T) { RunsOnNodeID: pointer.ToString("N1"), ServiceID: pointer.ToString("S1"), ListenPort: pointer.ToUint16(9104), - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ MetricsPath: "/metrics", MetricsScheme: "http", }, diff --git a/managed/models/agent_model.go b/managed/models/agent_model.go index 5cc5b70ca8..a7c515f3b2 100644 --- a/managed/models/agent_model.go +++ b/managed/models/agent_model.go @@ -89,11 +89,21 @@ type ExporterOptions struct { } // Value implements database/sql/driver.Valuer interface. Should be defined on the value. -func (c *ExporterOptions) Value() (driver.Value, error) { return jsonValue(c) } +func (c ExporterOptions) Value() (driver.Value, error) { return jsonValue(c) } // Scan implements database/sql.Scanner interface. Should be defined on the pointer. func (c *ExporterOptions) Scan(src interface{}) error { return jsonScan(c, src) } +// IsEmpty returns true if all ExporterOptions fields are unset or have zero values, otherwise returns false. +func (c ExporterOptions) IsEmpty() bool { + return !c.ExposeExporter && + !c.PushMetrics && + len(c.DisabledCollectors) == 0 && + c.MetricsResolutions == nil && + c.MetricsPath == "" && + c.MetricsScheme == "" +} + // QANOptions represents structure for special QAN options. type QANOptions struct { MaxQueryLength int32 `json:"max_query_length"` @@ -103,11 +113,19 @@ type QANOptions struct { } // Value implements database/sql/driver.Valuer interface. Should be defined on the value. -func (c *QANOptions) Value() (driver.Value, error) { return jsonValue(c) } +func (c QANOptions) Value() (driver.Value, error) { return jsonValue(c) } // Scan implements database/sql.Scanner interface. Should be defined on the pointer. func (c *QANOptions) Scan(src interface{}) error { return jsonScan(c, src) } +// IsEmpty returns true if all QANOptions fields are unset or have zero values, otherwise returns false. +func (c QANOptions) IsEmpty() bool { + return c.MaxQueryLength == 0 && + c.MaxQueryLogSize == 0 && + !c.QueryExamplesDisabled && + !c.CommentsParsingDisabled +} + // AWSOptions represents structure for special AWS options. type AWSOptions struct { AWSAccessKey string `json:"aws_access_key"` @@ -117,11 +135,19 @@ type AWSOptions struct { } // Value implements database/sql/driver.Valuer interface. Should be defined on the value. -func (c *AWSOptions) Value() (driver.Value, error) { return jsonValue(c) } +func (c AWSOptions) Value() (driver.Value, error) { return jsonValue(c) } // Scan implements database/sql.Scanner interface. Should be defined on the pointer. func (c *AWSOptions) Scan(src interface{}) error { return jsonScan(c, src) } +// IsEmpty returns true if all AWSOptions fields are unset or have zero values, otherwise returns false. +func (c AWSOptions) IsEmpty() bool { + return c.AWSAccessKey == "" && + c.AWSSecretKey == "" && + !c.RDSBasicMetricsDisabled && + !c.RDSEnhancedMetricsDisabled +} + // AzureOptions represents structure for special Azure options. type AzureOptions struct { SubscriptionID string `json:"subscription_id"` @@ -132,11 +158,20 @@ type AzureOptions struct { } // Value implements database/sql/driver.Valuer interface. Should be defined on the value. -func (c *AzureOptions) Value() (driver.Value, error) { return jsonValue(c) } +func (c AzureOptions) Value() (driver.Value, error) { return jsonValue(c) } // Scan implements database/sql.Scanner interface. Should be defined on the pointer. func (c *AzureOptions) Scan(src interface{}) error { return jsonScan(c, src) } +// IsEmpty returns true if all AzureOptions fields are unset or have zero values, otherwise returns false. +func (c AzureOptions) IsEmpty() bool { + return c.SubscriptionID == "" && + c.ClientID == "" && + c.ClientSecret == "" && + c.TenantID == "" && + c.ResourceGroup == "" +} + // MongoDBOptions represents structure for special MongoDB options. type MongoDBOptions struct { TLSCertificateKey string `json:"tls_certificate_key"` @@ -150,11 +185,23 @@ type MongoDBOptions struct { } // Value implements database/sql/driver.Valuer interface. Should be defined on the value. -func (c *MongoDBOptions) Value() (driver.Value, error) { return jsonValue(c) } +func (c MongoDBOptions) Value() (driver.Value, error) { return jsonValue(c) } // Scan implements database/sql.Scanner interface. Should be defined on the pointer. func (c *MongoDBOptions) Scan(src interface{}) error { return jsonScan(c, src) } +// IsEmpty returns true if all MongoDBOptions fields are unset or have zero values, otherwise returns false. +func (c MongoDBOptions) IsEmpty() bool { + return c.TLSCertificateKey == "" && + c.TLSCertificateKeyFilePassword == "" && + c.TLSCa == "" && + c.AuthenticationMechanism == "" && + c.AuthenticationDatabase == "" && + len(c.StatsCollections) == 0 && + c.CollectionsLimit == 0 && + !c.EnableAllCollectors +} + // MySQLOptions represents structure for special MySQL options. type MySQLOptions struct { TLSCa string `json:"tls_ca"` @@ -172,11 +219,20 @@ type MySQLOptions struct { } // Value implements database/sql/driver.Valuer interface. Should be defined on the value. -func (c *MySQLOptions) Value() (driver.Value, error) { return jsonValue(c) } +func (c MySQLOptions) Value() (driver.Value, error) { return jsonValue(c) } // Scan implements database/sql.Scanner interface. Should be defined on the pointer. func (c *MySQLOptions) Scan(src interface{}) error { return jsonScan(c, src) } +// IsEmpty returns true if all MySQLOptions fields are unset or have zero values, otherwise returns false. +func (c MySQLOptions) IsEmpty() bool { + return c.TLSCa == "" && + c.TLSCert == "" && + c.TLSKey == "" && + c.TableCount == nil && + c.TableCountTablestatsGroupLimit == 0 +} + // PostgreSQLOptions represents structure for special PostgreSQL options. type PostgreSQLOptions struct { SSLCa string `json:"ssl_ca"` @@ -189,11 +245,22 @@ type PostgreSQLOptions struct { } // Value implements database/sql/driver.Valuer interface. Should be defined on the value. -func (c *PostgreSQLOptions) Value() (driver.Value, error) { return jsonValue(c) } +func (c PostgreSQLOptions) Value() (driver.Value, error) { return jsonValue(c) } // Scan implements database/sql.Scanner interface. Should be defined on the pointer. func (c *PostgreSQLOptions) Scan(src interface{}) error { return jsonScan(c, src) } +// IsEmpty returns true if all PostgreSQLOptions fields are unset or have zero values, otherwise returns false. +func (c PostgreSQLOptions) IsEmpty() bool { + return c.SSLCa == "" && + c.SSLCert == "" && + c.SSLKey == "" && + c.AutoDiscoveryLimit == nil && + c.DatabaseCount == 0 && + c.PGSMVersion == nil && + c.MaxExporterConnections == 0 +} + // PMMAgentWithPushMetricsSupport - version of pmmAgent, // that support vmagent and push metrics mode // will be released with PMM Agent v2.12. @@ -227,14 +294,14 @@ type Agent struct { LogLevel *string `reform:"log_level"` - ExporterOptions *ExporterOptions `reform:"exporter_options"` - QANOptions *QANOptions `reform:"qan_options"` + ExporterOptions ExporterOptions `reform:"exporter_options"` + QANOptions QANOptions `reform:"qan_options"` - AWSOptions *AWSOptions `reform:"aws_options"` - AzureOptions *AzureOptions `reform:"azure_options"` - MongoDBOptions *MongoDBOptions `reform:"mongo_options"` - MySQLOptions *MySQLOptions `reform:"mysql_options"` - PostgreSQLOptions *PostgreSQLOptions `reform:"postgresql_options"` + AWSOptions AWSOptions `reform:"aws_options"` + AzureOptions AzureOptions `reform:"azure_options"` + MongoDBOptions MongoDBOptions `reform:"mongo_options"` + MySQLOptions MySQLOptions `reform:"mysql_options"` + PostgreSQLOptions PostgreSQLOptions `reform:"postgresql_options"` } // BeforeInsert implements reform.BeforeInserter interface. diff --git a/managed/models/agent_model_reform.go b/managed/models/agent_model_reform.go index 2bce8110e1..e971c44c1a 100644 --- a/managed/models/agent_model_reform.go +++ b/managed/models/agent_model_reform.go @@ -99,13 +99,13 @@ var AgentTable = &agentTableType{ {Name: "TLS", Type: "bool", Column: "tls"}, {Name: "TLSSkipVerify", Type: "bool", Column: "tls_skip_verify"}, {Name: "LogLevel", Type: "*string", Column: "log_level"}, - {Name: "ExporterOptions", Type: "*ExporterOptions", Column: "exporter_options"}, - {Name: "QANOptions", Type: "*QANOptions", Column: "qan_options"}, - {Name: "AWSOptions", Type: "*AWSOptions", Column: "aws_options"}, - {Name: "AzureOptions", Type: "*AzureOptions", Column: "azure_options"}, - {Name: "MongoDBOptions", Type: "*MongoDBOptions", Column: "mongo_options"}, - {Name: "MySQLOptions", Type: "*MySQLOptions", Column: "mysql_options"}, - {Name: "PostgreSQLOptions", Type: "*PostgreSQLOptions", Column: "postgresql_options"}, + {Name: "ExporterOptions", Type: "ExporterOptions", Column: "exporter_options"}, + {Name: "QANOptions", Type: "QANOptions", Column: "qan_options"}, + {Name: "AWSOptions", Type: "AWSOptions", Column: "aws_options"}, + {Name: "AzureOptions", Type: "AzureOptions", Column: "azure_options"}, + {Name: "MongoDBOptions", Type: "MongoDBOptions", Column: "mongo_options"}, + {Name: "MySQLOptions", Type: "MySQLOptions", Column: "mysql_options"}, + {Name: "PostgreSQLOptions", Type: "PostgreSQLOptions", Column: "postgresql_options"}, }, PKFieldIndex: 0, }, diff --git a/managed/models/agent_model_test.go b/managed/models/agent_model_test.go index 1b7ab39dbc..d95e153b8a 100644 --- a/managed/models/agent_model_test.go +++ b/managed/models/agent_model_test.go @@ -50,11 +50,11 @@ func TestAgent(t *testing.T) { agent := &models.Agent{ Username: pointer.ToString("username"), Password: pointer.ToString("s3cur3 p@$$w0r4."), - ExporterOptions: &models.ExporterOptions{}, - QANOptions: &models.QANOptions{}, - MongoDBOptions: &models.MongoDBOptions{}, - MySQLOptions: &models.MySQLOptions{}, - PostgreSQLOptions: &models.PostgreSQLOptions{}, + ExporterOptions: models.ExporterOptions{}, + QANOptions: models.QANOptions{}, + MongoDBOptions: models.MongoDBOptions{}, + MySQLOptions: models.MySQLOptions{}, + PostgreSQLOptions: models.PostgreSQLOptions{}, } service := &models.Service{ Address: pointer.ToString("1.2.3.4"), @@ -87,9 +87,9 @@ func TestAgent(t *testing.T) { agent := &models.Agent{ Username: pointer.ToString("username"), Password: pointer.ToString("s3cur3 p@$$w0r4."), - ExporterOptions: &models.ExporterOptions{}, - QANOptions: &models.QANOptions{}, - MySQLOptions: &models.MySQLOptions{}, + ExporterOptions: models.ExporterOptions{}, + QANOptions: models.QANOptions{}, + MySQLOptions: models.MySQLOptions{}, } service := &models.Service{ Socket: pointer.ToString("/var/run/mysqld/mysqld.sock"), @@ -111,9 +111,9 @@ func TestAgent(t *testing.T) { agent := &models.Agent{ Username: pointer.ToString("username"), Password: pointer.ToString("s3cur3 p@$$w0r4."), - ExporterOptions: &models.ExporterOptions{}, - QANOptions: &models.QANOptions{}, - MongoDBOptions: &models.MongoDBOptions{}, + ExporterOptions: models.ExporterOptions{}, + QANOptions: models.QANOptions{}, + MongoDBOptions: models.MongoDBOptions{}, } service := &models.Service{ Socket: pointer.ToString("/var/run/mysqld/mysqld.sock"), @@ -150,10 +150,10 @@ func TestAgent(t *testing.T) { Username: pointer.ToString("username"), Password: pointer.ToString("s3cur3 p@$$w0r4."), TLS: true, - ExporterOptions: &models.ExporterOptions{}, - MongoDBOptions: &mongoDBOptions, - MySQLOptions: &mysqlOptions, - PostgreSQLOptions: &postgresqlOptions, + ExporterOptions: models.ExporterOptions{}, + MongoDBOptions: mongoDBOptions, + MySQLOptions: mysqlOptions, + PostgreSQLOptions: postgresqlOptions, } service := &models.Service{ Address: pointer.ToString("1.2.3.4"), @@ -213,11 +213,11 @@ func TestAgent(t *testing.T) { Password: pointer.ToString("s3cur3 p@$$w0r4."), TLS: true, TLSSkipVerify: true, - ExporterOptions: &models.ExporterOptions{}, - QANOptions: &models.QANOptions{}, - MongoDBOptions: &models.MongoDBOptions{}, - MySQLOptions: &models.MySQLOptions{}, - PostgreSQLOptions: &models.PostgreSQLOptions{}, + ExporterOptions: models.ExporterOptions{}, + QANOptions: models.QANOptions{}, + MongoDBOptions: models.MongoDBOptions{}, + MySQLOptions: models.MySQLOptions{}, + PostgreSQLOptions: models.PostgreSQLOptions{}, } service := &models.Service{ Address: pointer.ToString("1.2.3.4"), @@ -252,8 +252,8 @@ func TestPostgresAgentTLS(t *testing.T) { Username: pointer.ToString("username"), Password: pointer.ToString("s3cur3 p@$$w0r4."), AgentType: models.PostgresExporterType, - ExporterOptions: &models.ExporterOptions{}, - PostgreSQLOptions: &models.PostgreSQLOptions{}, + ExporterOptions: models.ExporterOptions{}, + PostgreSQLOptions: models.PostgreSQLOptions{}, } service := &models.Service{ Address: pointer.ToString("1.2.3.4"), @@ -279,7 +279,7 @@ func TestPostgresAgentTLS(t *testing.T) { t.Run(fmt.Sprintf("AutodiscoveryLimit set TLS:%v/TLSSkipVerify:%v", testCase.tls, testCase.tlsSkipVerify), func(t *testing.T) { agent.TLS = testCase.tls agent.TLSSkipVerify = testCase.tlsSkipVerify - agent.PostgreSQLOptions = &models.PostgreSQLOptions{AutoDiscoveryLimit: pointer.ToInt32(10)} + agent.PostgreSQLOptions = models.PostgreSQLOptions{AutoDiscoveryLimit: pointer.ToInt32(10)} assert.Equal(t, testCase.expected, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil, nil)) }) } @@ -292,8 +292,8 @@ func TestPostgresWithSocket(t *testing.T) { AgentType: models.PostgresExporterType, TLS: true, TLSSkipVerify: false, - ExporterOptions: &models.ExporterOptions{}, - PostgreSQLOptions: &models.PostgreSQLOptions{}, + ExporterOptions: models.ExporterOptions{}, + PostgreSQLOptions: models.PostgreSQLOptions{}, } service := &models.Service{ Socket: pointer.ToString("/var/run/postgres"), @@ -305,8 +305,8 @@ func TestPostgresWithSocket(t *testing.T) { t.Run("empty-user-password", func(t *testing.T) { agent := &models.Agent{ AgentType: models.PostgresExporterType, - ExporterOptions: &models.ExporterOptions{}, - PostgreSQLOptions: &models.PostgreSQLOptions{}, + ExporterOptions: models.ExporterOptions{}, + PostgreSQLOptions: models.PostgreSQLOptions{}, } service := &models.Service{ Socket: pointer.ToString("/var/run/postgres"), @@ -318,8 +318,8 @@ func TestPostgresWithSocket(t *testing.T) { t.Run("dir-with-symbols", func(t *testing.T) { agent := &models.Agent{ AgentType: models.PostgresExporterType, - ExporterOptions: &models.ExporterOptions{}, - PostgreSQLOptions: &models.PostgreSQLOptions{}, + ExporterOptions: models.ExporterOptions{}, + PostgreSQLOptions: models.PostgreSQLOptions{}, } service := &models.Service{ Socket: pointer.ToString(`/tmp/123\ A0m\%\$\@\8\,\+\-`), @@ -336,8 +336,8 @@ func TestMongoWithSocket(t *testing.T) { AgentType: models.MongoDBExporterType, TLS: true, TLSSkipVerify: false, - ExporterOptions: &models.ExporterOptions{}, - MongoDBOptions: &models.MongoDBOptions{}, + ExporterOptions: models.ExporterOptions{}, + MongoDBOptions: models.MongoDBOptions{}, } service := &models.Service{ Socket: pointer.ToString("/tmp/mongodb-27017.sock"), @@ -349,8 +349,8 @@ func TestMongoWithSocket(t *testing.T) { t.Run("empty-user-password", func(t *testing.T) { agent := &models.Agent{ AgentType: models.MongoDBExporterType, - ExporterOptions: &models.ExporterOptions{}, - MongoDBOptions: &models.MongoDBOptions{}, + ExporterOptions: models.ExporterOptions{}, + MongoDBOptions: models.MongoDBOptions{}, } service := &models.Service{ Socket: pointer.ToString("/tmp/mongodb-27017.sock"), @@ -362,8 +362,8 @@ func TestMongoWithSocket(t *testing.T) { t.Run("dir-with-symbols", func(t *testing.T) { agent := &models.Agent{ AgentType: models.MongoDBExporterType, - ExporterOptions: &models.ExporterOptions{}, - MongoDBOptions: &models.MongoDBOptions{}, + ExporterOptions: models.ExporterOptions{}, + MongoDBOptions: models.MongoDBOptions{}, } service := &models.Service{ Socket: pointer.ToString(`/tmp/123\ A0m\%\$\@\8\,\+\-/mongodb-27017.sock`), @@ -396,7 +396,7 @@ func TestIsMySQLTablestatsGroupEnabled(t *testing.T) { t.Run(fmt.Sprintf("Count:%s/Limit:%d", c, testCase.limit), func(t *testing.T) { agent := &models.Agent{ AgentType: models.MySQLdExporterType, - MySQLOptions: &models.MySQLOptions{ + MySQLOptions: models.MySQLOptions{ TableCount: testCase.count, TableCountTablestatsGroupLimit: testCase.limit, }, @@ -477,7 +477,7 @@ func TestExporterURL(t *testing.T) { ServiceID: pointer.ToString("external"), RunsOnNodeID: pointer.ToString("ExporterNodeID"), ListenPort: pointer.ToUint16(9121), - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ PushMetrics: true, MetricsPath: "/metrics", MetricsScheme: "http", @@ -492,7 +492,7 @@ func TestExporterURL(t *testing.T) { ListenPort: pointer.ToUint16(9121), Username: pointer.ToString("user"), Password: pointer.ToString("secret"), - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ PushMetrics: false, MetricsPath: "/metrics", MetricsScheme: "http", @@ -507,7 +507,7 @@ func TestExporterURL(t *testing.T) { ListenPort: pointer.ToUint16(9121), Username: pointer.ToString("user"), Password: pointer.ToString("secret"), - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ PushMetrics: false, MetricsPath: "/metrics", MetricsScheme: "http", @@ -522,7 +522,7 @@ func TestExporterURL(t *testing.T) { ListenPort: pointer.ToUint16(9121), Username: pointer.ToString("user"), Password: pointer.ToString("secret"), - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ PushMetrics: false, MetricsPath: "/metrics?format=prometheus&output=json", MetricsScheme: "http", @@ -537,7 +537,7 @@ func TestExporterURL(t *testing.T) { ListenPort: pointer.ToUint16(9121), Username: pointer.ToString("user"), Password: pointer.ToString("secret"), - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ PushMetrics: false, MetricsPath: "/", MetricsScheme: "http", diff --git a/managed/models/database.go b/managed/models/database.go index 7126979431..3185d42bab 100644 --- a/managed/models/database.go +++ b/managed/models/database.go @@ -1487,12 +1487,12 @@ func setupPMMServerAgents(q *reform.Querier, params SetupDBParams) error { TLSSkipVerify: params.SSLMode == DisableSSLMode || params.SSLMode == VerifyCaSSLMode, Username: params.Username, Password: params.Password, - QANOptions: &QANOptions{ + QANOptions: QANOptions{ CommentsParsingDisabled: true, }, } if ap.TLS { - ap.PostgreSQLOptions = &PostgreSQLOptions{} + ap.PostgreSQLOptions = PostgreSQLOptions{} for path, field := range map[string]*string{ params.SSLCAPath: &ap.PostgreSQLOptions.SSLCa, params.SSLCertPath: &ap.PostgreSQLOptions.SSLCert, diff --git a/managed/models/dsn_helpers_test.go b/managed/models/dsn_helpers_test.go index 4c8574618e..f7c49c4438 100644 --- a/managed/models/dsn_helpers_test.go +++ b/managed/models/dsn_helpers_test.go @@ -141,7 +141,7 @@ func TestFindDSNByServiceID(t *testing.T) { RunsOnNodeID: nil, ServiceID: pointer.ToString("S3"), TLS: true, - MySQLOptions: &models.MySQLOptions{ + MySQLOptions: models.MySQLOptions{ TLSCa: "content-of-tls-ca", TLSCert: "content-of-tls-cert", TLSKey: "content-of-tls-key", @@ -155,7 +155,7 @@ func TestFindDSNByServiceID(t *testing.T) { Username: pointer.ToString("pmm-user{{"), ServiceID: pointer.ToString("S4"), TLS: true, - MongoDBOptions: &models.MongoDBOptions{ + MongoDBOptions: models.MongoDBOptions{ TLSCertificateKey: "content-of-tls-certificate-key", TLSCertificateKeyFilePassword: "passwordoftls", TLSCa: "content-of-tls-ca", diff --git a/managed/models/encryption_helpers.go b/managed/models/encryption_helpers.go index e7929dc13d..275385d290 100644 --- a/managed/models/encryption_helpers.go +++ b/managed/models/encryption_helpers.go @@ -60,7 +60,7 @@ func agentEncryption(agent Agent, handler func(string) (string, error)) Agent { } var err error - if agent.AWSOptions != nil { + if !agent.AWSOptions.IsEmpty() { agent.AWSOptions.AWSAccessKey, err = handler(agent.AWSOptions.AWSAccessKey) if err != nil { logrus.Warning(err) @@ -72,7 +72,7 @@ func agentEncryption(agent Agent, handler func(string) (string, error)) Agent { } } - if agent.AzureOptions != nil { + if !agent.AzureOptions.IsEmpty() { agent.AzureOptions.ClientID, err = handler(agent.AzureOptions.ClientID) if err != nil { logrus.Warning(err) @@ -91,7 +91,7 @@ func agentEncryption(agent Agent, handler func(string) (string, error)) Agent { } } - if agent.MongoDBOptions != nil { + if !agent.MongoDBOptions.IsEmpty() { agent.MongoDBOptions.TLSCertificateKey, err = handler(agent.MongoDBOptions.TLSCertificateKey) if err != nil { logrus.Warning(err) @@ -102,7 +102,7 @@ func agentEncryption(agent Agent, handler func(string) (string, error)) Agent { } } - if agent.MySQLOptions != nil { + if !agent.MySQLOptions.IsEmpty() { agent.MySQLOptions.TLSCert, err = handler(agent.MySQLOptions.TLSCert) if err != nil { logrus.Warning(err) @@ -113,7 +113,7 @@ func agentEncryption(agent Agent, handler func(string) (string, error)) Agent { } } - if agent.PostgreSQLOptions != nil { + if !agent.PostgreSQLOptions.IsEmpty() { agent.PostgreSQLOptions.SSLCert, err = handler(agent.PostgreSQLOptions.SSLCert) if err != nil { logrus.Warning(err) diff --git a/managed/services/agents/agents.go b/managed/services/agents/agents.go index 90c898be57..6c387a60d9 100644 --- a/managed/services/agents/agents.go +++ b/managed/services/agents/agents.go @@ -101,33 +101,23 @@ func redactWords(agent *models.Agent) []string { if s := pointer.GetString(agent.AgentPassword); s != "" { words = append(words, s) } - if agent.AWSOptions != nil { - if s := agent.AWSOptions.AWSSecretKey; s != "" { - words = append(words, s) - } + if s := agent.AWSOptions.AWSSecretKey; s != "" { + words = append(words, s) } - if agent.AzureOptions != nil { - if s := agent.AzureOptions.ClientSecret; s != "" { - words = append(words, s) - } + if s := agent.AzureOptions.ClientSecret; s != "" { + words = append(words, s) } - if agent.MongoDBOptions != nil { - if s := agent.MongoDBOptions.TLSCertificateKey; s != "" { - words = append(words, s) - } - if s := agent.MongoDBOptions.TLSCertificateKeyFilePassword; s != "" { - words = append(words, s) - } + if s := agent.MongoDBOptions.TLSCertificateKey; s != "" { + words = append(words, s) } - if agent.MySQLOptions != nil { - if s := agent.MySQLOptions.TLSKey; s != "" { - words = append(words, s) - } + if s := agent.MongoDBOptions.TLSCertificateKeyFilePassword; s != "" { + words = append(words, s) } - if agent.PostgreSQLOptions != nil { - if s := agent.PostgreSQLOptions.SSLKey; s != "" { - words = append(words, s) - } + if s := agent.MySQLOptions.TLSKey; s != "" { + words = append(words, s) + } + if s := agent.PostgreSQLOptions.SSLKey; s != "" { + words = append(words, s) } return words diff --git a/managed/services/agents/agents_test.go b/managed/services/agents/agents_test.go index 846700ac39..782f9432c5 100644 --- a/managed/services/agents/agents_test.go +++ b/managed/services/agents/agents_test.go @@ -56,7 +56,7 @@ func TestGetExporterListenAddress(t *testing.T) { Address: "1.2.3.4", } exporter := &models.Agent{ - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ PushMetrics: true, }, } @@ -68,7 +68,7 @@ func TestGetExporterListenAddress(t *testing.T) { Address: "1.2.3.4", } exporter := &models.Agent{ - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ ExposeExporter: true, PushMetrics: true, }, @@ -81,7 +81,7 @@ func TestGetExporterListenAddress(t *testing.T) { Address: "1.2.3.4", } exporter := &models.Agent{ - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ ExposeExporter: true, PushMetrics: false, }, @@ -91,7 +91,7 @@ func TestGetExporterListenAddress(t *testing.T) { }) t.Run("exposes exporter address if node IP is unavailable in pull mode", func(t *testing.T) { exporter := &models.Agent{ - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ PushMetrics: false, }, } diff --git a/managed/services/agents/azure_database.go b/managed/services/agents/azure_database.go index 5b9e2634b4..158c290aad 100644 --- a/managed/services/agents/azure_database.go +++ b/managed/services/agents/azure_database.go @@ -79,7 +79,7 @@ func azureDatabaseExporterConfig(exporter *models.Agent, service *models.Service options := struct { models.AzureOptions ResourceTypes string - }{*exporter.AzureOptions, resourceTypes} + }{exporter.AzureOptions, resourceTypes} if err = t.Execute(&config, options); err != nil { return nil, err diff --git a/managed/services/agents/azure_database_test.go b/managed/services/agents/azure_database_test.go index fbea853761..b5a1406a14 100644 --- a/managed/services/agents/azure_database_test.go +++ b/managed/services/agents/azure_database_test.go @@ -59,7 +59,7 @@ func TestAzureExporterConfig(t *testing.T) { AgentType: models.AzureDatabaseExporterType, NodeID: &node1.NodeID, ServiceID: &service1.ServiceID, - AzureOptions: &models.AzureOptions{ + AzureOptions: models.AzureOptions{ ClientID: "azure_database_client_id", ClientSecret: "azure_database_client_secret", TenantID: "azure_database_tenant_id", diff --git a/managed/services/agents/handler.go b/managed/services/agents/handler.go index d9dcdacde6..1442c4833c 100644 --- a/managed/services/agents/handler.go +++ b/managed/services/agents/handler.go @@ -18,6 +18,7 @@ package agents import ( "context" "runtime/pprof" + "strings" "time" "github.com/AlekSi/pointer" @@ -191,6 +192,7 @@ func (h *Handler) stateChanged(ctx context.Context, req *agentv1.StateChangedReq errTX := h.db.InTransaction(func(tx *reform.TX) error { var agentIDs []string var err error + req.AgentId = strings.TrimPrefix(req.AgentId, "/agent_id/") PMMAgentID, agentIDs, err = h.r.roster.get(req.AgentId) if err != nil { return err diff --git a/managed/services/agents/mongodb_test.go b/managed/services/agents/mongodb_test.go index 786d5995ad..cf9fca0351 100644 --- a/managed/services/agents/mongodb_test.go +++ b/managed/services/agents/mongodb_test.go @@ -43,8 +43,8 @@ func TestMongodbExporterConfig225(t *testing.T) { Username: pointer.ToString("username"), Password: pointer.ToString("s3cur3 p@$$w0r4."), AgentPassword: pointer.ToString("agent-password"), - ExporterOptions: &models.ExporterOptions{}, - MongoDBOptions: &models.MongoDBOptions{}, + ExporterOptions: models.ExporterOptions{}, + MongoDBOptions: models.MongoDBOptions{}, } actual, err := mongodbExporterConfig(node, mongodb, exporter, redactSecrets, pmmAgentVersion) @@ -72,7 +72,7 @@ func TestMongodbExporterConfig225(t *testing.T) { require.Equal(t, expected, actual) t.Run("Having collstats limit", func(t *testing.T) { - exporter.MongoDBOptions = &models.MongoDBOptions{ + exporter.MongoDBOptions = models.MongoDBOptions{ StatsCollections: []string{"col1", "col2", "col3"}, CollectionsLimit: 79014, } @@ -105,8 +105,8 @@ func TestMongodbExporterConfig226(t *testing.T) { Username: pointer.ToString("username"), Password: pointer.ToString("s3cur3 p@$$w0r4."), AgentPassword: pointer.ToString("agent-password"), - ExporterOptions: &models.ExporterOptions{}, - MongoDBOptions: &models.MongoDBOptions{}, + ExporterOptions: models.ExporterOptions{}, + MongoDBOptions: models.MongoDBOptions{}, } actual, err := mongodbExporterConfig(node, mongodb, exporter, redactSecrets, pmmAgentVersion) expected := &agentv1.SetStateRequest_AgentProcess{ @@ -135,7 +135,7 @@ func TestMongodbExporterConfig226(t *testing.T) { require.Equal(t, expected, actual) t.Run("Having collstats limit", func(t *testing.T) { - exporter.MongoDBOptions = &models.MongoDBOptions{ + exporter.MongoDBOptions = models.MongoDBOptions{ StatsCollections: []string{"col1", "col2", "col3"}, CollectionsLimit: 79014, } @@ -156,7 +156,7 @@ func TestMongodbExporterConfig226(t *testing.T) { }) t.Run("Enabling all collectors with non zero limit", func(t *testing.T) { - exporter.MongoDBOptions = &models.MongoDBOptions{ + exporter.MongoDBOptions = models.MongoDBOptions{ StatsCollections: []string{"col1", "col2", "col3"}, CollectionsLimit: 79014, EnableAllCollectors: true, @@ -183,7 +183,7 @@ func TestMongodbExporterConfig226(t *testing.T) { }) t.Run("Enabling all collectors", func(t *testing.T) { - exporter.MongoDBOptions = &models.MongoDBOptions{ + exporter.MongoDBOptions = models.MongoDBOptions{ EnableAllCollectors: true, StatsCollections: []string{"db1.col1.one", "db2.col2", "db3"}, } @@ -211,7 +211,7 @@ func TestMongodbExporterConfig226(t *testing.T) { }) t.Run("collstats-limit=-1 -> automatically set the limit", func(t *testing.T) { - exporter.MongoDBOptions = &models.MongoDBOptions{ + exporter.MongoDBOptions = models.MongoDBOptions{ EnableAllCollectors: true, StatsCollections: []string{"db1.col1.one", "db2.col2", "db3"}, CollectionsLimit: -1, @@ -253,8 +253,8 @@ func TestMongodbExporterConfig2411(t *testing.T) { Username: pointer.ToString("username"), Password: pointer.ToString("s3cur3 p@$$w0r4."), AgentPassword: pointer.ToString("agent-password"), - ExporterOptions: &models.ExporterOptions{}, - MongoDBOptions: &models.MongoDBOptions{}, + ExporterOptions: models.ExporterOptions{}, + MongoDBOptions: models.MongoDBOptions{}, } actual, err := mongodbExporterConfig(node, mongodb, exporter, redactSecrets, pmmAgentVersion) expected := &agentv1.SetStateRequest_AgentProcess{ @@ -286,7 +286,7 @@ func TestMongodbExporterConfig2411(t *testing.T) { require.Equal(t, expected, actual) t.Run("Having collstats limit", func(t *testing.T) { - exporter.MongoDBOptions = &models.MongoDBOptions{ + exporter.MongoDBOptions = models.MongoDBOptions{ StatsCollections: []string{"col1", "col2", "col3"}, CollectionsLimit: 79014, } @@ -308,7 +308,7 @@ func TestMongodbExporterConfig2411(t *testing.T) { }) t.Run("Enabling all collectors with non zero limit", func(t *testing.T) { - exporter.MongoDBOptions = &models.MongoDBOptions{ + exporter.MongoDBOptions = models.MongoDBOptions{ StatsCollections: []string{"col1", "col2", "col3"}, CollectionsLimit: 79014, EnableAllCollectors: true, @@ -337,7 +337,7 @@ func TestMongodbExporterConfig2411(t *testing.T) { }) t.Run("Enabling all collectors", func(t *testing.T) { - exporter.MongoDBOptions = &models.MongoDBOptions{ + exporter.MongoDBOptions = models.MongoDBOptions{ EnableAllCollectors: true, StatsCollections: []string{"db1.col1.one", "db2.col2", "db3"}, } @@ -367,7 +367,7 @@ func TestMongodbExporterConfig2411(t *testing.T) { }) t.Run("collstats-limit=-1 -> automatically set the limit", func(t *testing.T) { - exporter.MongoDBOptions = &models.MongoDBOptions{ + exporter.MongoDBOptions = models.MongoDBOptions{ EnableAllCollectors: true, StatsCollections: []string{"db1.col1.one", "db2.col2", "db3"}, CollectionsLimit: -1, @@ -396,10 +396,10 @@ func TestMongodbExporterConfig2411(t *testing.T) { }) t.Run("Enable all collectors and disable some", func(t *testing.T) { - exporter.ExporterOptions = &models.ExporterOptions{ + exporter.ExporterOptions = models.ExporterOptions{ DisabledCollectors: []string{"dbstats", "topmetrics"}, } - exporter.MongoDBOptions = &models.MongoDBOptions{ + exporter.MongoDBOptions = models.MongoDBOptions{ EnableAllCollectors: true, StatsCollections: []string{"db1.col1.one", "db2.col2", "db3"}, } @@ -442,8 +442,8 @@ func TestMongodbExporterConfig2432(t *testing.T) { Username: pointer.ToString("username"), Password: pointer.ToString("s3cur3 p@$$w0r4."), AgentPassword: pointer.ToString("agent-password"), - ExporterOptions: &models.ExporterOptions{}, - MongoDBOptions: &models.MongoDBOptions{}, + ExporterOptions: models.ExporterOptions{}, + MongoDBOptions: models.MongoDBOptions{}, } actual, err := mongodbExporterConfig(node, mongodb, exporter, redactSecrets, pmmAgentVersion) expected := &agentv1.SetStateRequest_AgentProcess{ @@ -477,7 +477,7 @@ func TestMongodbExporterConfig2432(t *testing.T) { require.Equal(t, expected, actual) t.Run("Enabling all collectors", func(t *testing.T) { - exporter.MongoDBOptions = &models.MongoDBOptions{ + exporter.MongoDBOptions = models.MongoDBOptions{ EnableAllCollectors: true, StatsCollections: []string{"db1.col1.one", "db2.col2", "db3"}, } @@ -525,8 +525,8 @@ func TestMongodbExporterConfig(t *testing.T) { Username: pointer.ToString("username"), Password: pointer.ToString("s3cur3 p@$$w0r4."), AgentPassword: pointer.ToString("agent-password"), - ExporterOptions: &models.ExporterOptions{}, - MongoDBOptions: &models.MongoDBOptions{}, + ExporterOptions: models.ExporterOptions{}, + MongoDBOptions: models.MongoDBOptions{}, } actual, err := mongodbExporterConfig(node, mongodb, exporter, redactSecrets, pmmAgentVersion) expected := &agentv1.SetStateRequest_AgentProcess{ @@ -568,7 +568,7 @@ func TestMongodbExporterConfig(t *testing.T) { }) t.Run("SSLEnabled", func(t *testing.T) { exporter.TLS = true - exporter.MongoDBOptions = &models.MongoDBOptions{ + exporter.MongoDBOptions = models.MongoDBOptions{ TLSCertificateKey: "content-of-tls-certificate-key", TLSCertificateKeyFilePassword: "passwordoftls", TLSCa: "content-of-tls-ca", @@ -587,7 +587,7 @@ func TestMongodbExporterConfig(t *testing.T) { t.Run("AuthenticationDatabase", func(t *testing.T) { exporter.TLS = true - exporter.MongoDBOptions = &models.MongoDBOptions{ + exporter.MongoDBOptions = models.MongoDBOptions{ TLSCertificateKey: "content-of-tls-certificate-key", TLSCertificateKeyFilePassword: "passwordoftls", TLSCa: "content-of-tls-ca", @@ -613,7 +613,7 @@ func TestMongodbExporterConfig(t *testing.T) { }) t.Run("DisabledCollectors", func(t *testing.T) { - exporter.ExporterOptions = &models.ExporterOptions{ + exporter.ExporterOptions = models.ExporterOptions{ DisabledCollectors: []string{"topmetrics"}, } actual, err := mongodbExporterConfig(node, mongodb, exporter, exposeSecrets, pmmAgentVersion) @@ -649,8 +649,8 @@ func TestNewMongodbExporterConfig(t *testing.T) { AgentType: models.MongoDBExporterType, Username: pointer.ToString("username"), Password: pointer.ToString("s3cur3 p@$$w0r4."), - ExporterOptions: &models.ExporterOptions{}, - MongoDBOptions: &models.MongoDBOptions{}, + ExporterOptions: models.ExporterOptions{}, + MongoDBOptions: models.MongoDBOptions{}, } actual, err := mongodbExporterConfig(node, mongodb, exporter, redactSecrets, pmmAgentVersion) require.NoError(t, err) @@ -707,8 +707,8 @@ func TestMongodbExporterConfig228_WebConfigAuth(t *testing.T) { AgentType: models.MongoDBExporterType, Username: pointer.ToString("username"), Password: pointer.ToString("s3cur3 p@$$w0r4."), - ExporterOptions: &models.ExporterOptions{}, - MongoDBOptions: &models.MongoDBOptions{}, + ExporterOptions: models.ExporterOptions{}, + MongoDBOptions: models.MongoDBOptions{}, } expectedArgs := []string{ @@ -735,8 +735,8 @@ func TestMongodbExporterConfig228_WebConfigAuth(t *testing.T) { Username: exporter.Username, Password: exporter.Password, AgentPassword: pointer.ToString("agent-custom-password"), - ExporterOptions: &models.ExporterOptions{}, - MongoDBOptions: &models.MongoDBOptions{}, + ExporterOptions: models.ExporterOptions{}, + MongoDBOptions: models.MongoDBOptions{}, } actual, err := mongodbExporterConfig(node, mongodb, localExporter, redactSecrets, pmmAgentVersion) @@ -765,8 +765,8 @@ func TestMongodbExporterConfig228_WebConfigAuth(t *testing.T) { AgentType: exporter.AgentType, Username: exporter.Username, Password: exporter.Password, - ExporterOptions: &models.ExporterOptions{}, - MongoDBOptions: &models.MongoDBOptions{}, + ExporterOptions: models.ExporterOptions{}, + MongoDBOptions: models.MongoDBOptions{}, } actual, err := mongodbExporterConfig(node, mongodb, localExporter, redactSecrets, pmmAgentVersion) diff --git a/managed/services/agents/mysql_test.go b/managed/services/agents/mysql_test.go index 8bd6ca1f4e..d3ed5a3a7b 100644 --- a/managed/services/agents/mysql_test.go +++ b/managed/services/agents/mysql_test.go @@ -42,8 +42,8 @@ func TestMySQLdExporterConfig(t *testing.T) { Username: pointer.ToString("username"), Password: pointer.ToString("s3cur3 p@$$w0r4."), AgentPassword: pointer.ToString("agent-password"), - ExporterOptions: &models.ExporterOptions{}, - MySQLOptions: &models.MySQLOptions{}, + ExporterOptions: models.ExporterOptions{}, + MySQLOptions: models.MySQLOptions{}, } pmmAgentVersion := version.MustParse("2.21.0") @@ -117,7 +117,7 @@ func TestMySQLdExporterConfig(t *testing.T) { t.Run("SSLEnabled", func(t *testing.T) { exporter.TLS = true - exporter.MySQLOptions = &models.MySQLOptions{ + exporter.MySQLOptions = models.MySQLOptions{ TLSCa: "content-of-tls-ca", TLSCert: "content-of-tls-certificate-key", TLSKey: "content-of-tls-key", @@ -148,8 +148,8 @@ func TestMySQLdExporterConfigTablestatsGroupDisabled(t *testing.T) { Username: pointer.ToString("username"), Password: pointer.ToString("s3cur3 p@$$w0r4."), TLS: true, - ExporterOptions: &models.ExporterOptions{}, - MySQLOptions: &models.MySQLOptions{ + ExporterOptions: models.ExporterOptions{}, + MySQLOptions: models.MySQLOptions{ TableCountTablestatsGroupLimit: -1, TLSCa: "content-of-tls-ca", TLSCert: "content-of-tls-cert", @@ -252,10 +252,10 @@ func TestMySQLdExporterConfigDisabledCollectors(t *testing.T) { AgentType: models.MySQLdExporterType, Username: pointer.ToString("username"), Password: pointer.ToString("s3cur3 p@$$w0r4."), - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ DisabledCollectors: []string{"heartbeat", "info_schema.clientstats", "perf_schema.eventsstatements", "custom_query.hr"}, }, - MySQLOptions: &models.MySQLOptions{}, + MySQLOptions: models.MySQLOptions{}, } pmmAgentVersion := version.MustParse("2.24.0") diff --git a/managed/services/agents/node_test.go b/managed/services/agents/node_test.go index 8b70d371d3..d43445984f 100644 --- a/managed/services/agents/node_test.go +++ b/managed/services/agents/node_test.go @@ -36,7 +36,7 @@ func TestAuthWebConfig(t *testing.T) { exporter := &models.Agent{ AgentID: "agent-id", AgentType: models.NodeExporterType, - ExporterOptions: &models.ExporterOptions{}, + ExporterOptions: models.ExporterOptions{}, } agentVersion := version.MustParse("2.26.1") @@ -61,7 +61,7 @@ func TestAuthWebConfig(t *testing.T) { exporter := &models.Agent{ AgentID: "agent-id", AgentType: models.NodeExporterType, - ExporterOptions: &models.ExporterOptions{}, + ExporterOptions: models.ExporterOptions{}, } agentVersion := version.MustParse("2.28.0") @@ -87,7 +87,7 @@ func TestAuthWebConfig(t *testing.T) { exporter := &models.Agent{ AgentID: "agent-id", AgentType: models.NodeExporterType, - ExporterOptions: &models.ExporterOptions{}, + ExporterOptions: models.ExporterOptions{}, } agentVersion := version.MustParse("3.0.0") @@ -119,7 +119,7 @@ func TestNodeExporterConfig(t *testing.T) { exporter := &models.Agent{ AgentID: "agent-id", AgentType: models.NodeExporterType, - ExporterOptions: &models.ExporterOptions{}, + ExporterOptions: models.ExporterOptions{}, } agentVersion := version.MustParse("2.15.1") @@ -212,7 +212,7 @@ func TestNodeExporterConfig(t *testing.T) { exporter := &models.Agent{ AgentID: "agent-id", AgentType: models.NodeExporterType, - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ DisabledCollectors: []string{"cpu", "netstat", "netstat.fields", "vmstat", "meminfo"}, }, } @@ -299,7 +299,7 @@ func TestNodeExporterConfig(t *testing.T) { exporter := &models.Agent{ AgentID: "agent-id", AgentType: models.NodeExporterType, - ExporterOptions: &models.ExporterOptions{}, + ExporterOptions: models.ExporterOptions{}, } agentVersion := version.MustParse("2.15.1") diff --git a/managed/services/agents/postgresql_test.go b/managed/services/agents/postgresql_test.go index a1d115f127..b606bd8303 100644 --- a/managed/services/agents/postgresql_test.go +++ b/managed/services/agents/postgresql_test.go @@ -78,9 +78,9 @@ func (s *PostgresExporterConfigTestSuite) SetupTest() { } func (s *PostgresExporterConfigTestSuite) TestConfig() { - s.exporter.ExporterOptions = &models.ExporterOptions{} - s.exporter.AzureOptions = &models.AzureOptions{} - s.exporter.PostgreSQLOptions = &models.PostgreSQLOptions{} + s.exporter.ExporterOptions = models.ExporterOptions{} + s.exporter.AzureOptions = models.AzureOptions{} + s.exporter.PostgreSQLOptions = models.PostgreSQLOptions{} actual, err := postgresExporterConfig(s.node, s.postgresql, s.exporter, redactSecrets, s.pmmAgentVersion) s.NoError(err, "Failed to create exporter config") @@ -96,9 +96,9 @@ func (s *PostgresExporterConfigTestSuite) TestDatabaseName() { s.postgresql.DatabaseName = "db1" s.expected.Env[0] = "DATA_SOURCE_NAME=postgres://username:s3cur3%20p%40$$w0r4.@1.2.3.4:5432/db1?connect_timeout=1&sslmode=disable" - s.exporter.ExporterOptions = &models.ExporterOptions{} - s.exporter.AzureOptions = &models.AzureOptions{} - s.exporter.PostgreSQLOptions = &models.PostgreSQLOptions{} + s.exporter.ExporterOptions = models.ExporterOptions{} + s.exporter.AzureOptions = models.AzureOptions{} + s.exporter.PostgreSQLOptions = models.PostgreSQLOptions{} actual, err := postgresExporterConfig(s.node, s.postgresql, s.exporter, redactSecrets, s.pmmAgentVersion) s.NoError(err, "Failed to create exporter config") @@ -110,9 +110,9 @@ func (s *PostgresExporterConfigTestSuite) TestDatabaseName() { s.postgresql.DatabaseName = "" s.Require().PanicsWithValue("database name not set", func() { - s.exporter.ExporterOptions = &models.ExporterOptions{} - s.exporter.AzureOptions = &models.AzureOptions{} - s.exporter.PostgreSQLOptions = &models.PostgreSQLOptions{} + s.exporter.ExporterOptions = models.ExporterOptions{} + s.exporter.AzureOptions = models.AzureOptions{} + s.exporter.PostgreSQLOptions = models.PostgreSQLOptions{} _, err := postgresExporterConfig(s.node, s.postgresql, s.exporter, redactSecrets, s.pmmAgentVersion) s.NoError(err, "Failed to create exporter config") @@ -122,9 +122,9 @@ func (s *PostgresExporterConfigTestSuite) TestDatabaseName() { func (s *PostgresExporterConfigTestSuite) TestEmptyPassword() { s.exporter.Password = nil - s.exporter.ExporterOptions = &models.ExporterOptions{} - s.exporter.AzureOptions = &models.AzureOptions{} - s.exporter.PostgreSQLOptions = &models.PostgreSQLOptions{} + s.exporter.ExporterOptions = models.ExporterOptions{} + s.exporter.AzureOptions = models.AzureOptions{} + s.exporter.PostgreSQLOptions = models.PostgreSQLOptions{} actual, err := postgresExporterConfig(s.node, s.postgresql, s.exporter, exposeSecrets, s.pmmAgentVersion) s.NoError(err, "Failed to create exporter config") @@ -134,9 +134,9 @@ func (s *PostgresExporterConfigTestSuite) TestEmptyPassword() { func (s *PostgresExporterConfigTestSuite) TestEmptyUsername() { s.exporter.Username = nil - s.exporter.ExporterOptions = &models.ExporterOptions{} - s.exporter.AzureOptions = &models.AzureOptions{} - s.exporter.PostgreSQLOptions = &models.PostgreSQLOptions{} + s.exporter.ExporterOptions = models.ExporterOptions{} + s.exporter.AzureOptions = models.AzureOptions{} + s.exporter.PostgreSQLOptions = models.PostgreSQLOptions{} actual, err := postgresExporterConfig(s.node, s.postgresql, s.exporter, exposeSecrets, s.pmmAgentVersion) s.NoError(err, "Failed to create exporter config") @@ -147,9 +147,9 @@ func (s *PostgresExporterConfigTestSuite) TestEmptyUsername() { func (s *PostgresExporterConfigTestSuite) TestEmptyUsernameAndPassword() { s.exporter.Username = nil s.exporter.Password = nil - s.exporter.ExporterOptions = &models.ExporterOptions{} - s.exporter.AzureOptions = &models.AzureOptions{} - s.exporter.PostgreSQLOptions = &models.PostgreSQLOptions{} + s.exporter.ExporterOptions = models.ExporterOptions{} + s.exporter.AzureOptions = models.AzureOptions{} + s.exporter.PostgreSQLOptions = models.PostgreSQLOptions{} actual, err := postgresExporterConfig(s.node, s.postgresql, s.exporter, exposeSecrets, s.pmmAgentVersion) s.NoError(err, "Failed to create exporter config") @@ -163,9 +163,9 @@ func (s *PostgresExporterConfigTestSuite) TestSocket() { s.postgresql.Address = nil s.postgresql.Port = nil s.postgresql.Socket = pointer.ToString("/var/run/postgres") - s.exporter.ExporterOptions = &models.ExporterOptions{} - s.exporter.AzureOptions = &models.AzureOptions{} - s.exporter.PostgreSQLOptions = &models.PostgreSQLOptions{} + s.exporter.ExporterOptions = models.ExporterOptions{} + s.exporter.AzureOptions = models.AzureOptions{} + s.exporter.PostgreSQLOptions = models.PostgreSQLOptions{} actual, err := postgresExporterConfig(s.node, s.postgresql, s.exporter, exposeSecrets, s.pmmAgentVersion) s.NoError(err, "Failed to create exporter config") @@ -178,11 +178,11 @@ func (s *PostgresExporterConfigTestSuite) TestDisabledCollectors() { s.postgresql.Address = nil s.postgresql.Port = nil s.postgresql.Socket = pointer.ToString("/var/run/postgres") - s.exporter.ExporterOptions = &models.ExporterOptions{ + s.exporter.ExporterOptions = models.ExporterOptions{ DisabledCollectors: []string{"custom_query.hr", "custom_query.hr.directory", "locks"}, } - s.exporter.AzureOptions = &models.AzureOptions{} - s.exporter.PostgreSQLOptions = &models.PostgreSQLOptions{} + s.exporter.AzureOptions = models.AzureOptions{} + s.exporter.PostgreSQLOptions = models.PostgreSQLOptions{} actual, err := postgresExporterConfig(s.node, s.postgresql, s.exporter, exposeSecrets, s.pmmAgentVersion) s.NoError(err, "Failed to create exporter config") @@ -226,9 +226,9 @@ func TestAutoDiscovery(t *testing.T) { AgentType: models.PostgresExporterType, Username: pointer.ToString("username"), Password: pointer.ToString("s3cur3 p@$$w0r4."), - ExporterOptions: &models.ExporterOptions{}, - AzureOptions: &models.AzureOptions{}, - PostgreSQLOptions: &models.PostgreSQLOptions{}, + ExporterOptions: models.ExporterOptions{}, + AzureOptions: models.AzureOptions{}, + PostgreSQLOptions: models.PostgreSQLOptions{}, } expected := &agentv1.SetStateRequest_AgentProcess{ @@ -268,7 +268,7 @@ func TestAutoDiscovery(t *testing.T) { }) t.Run("Database count more than limit - disabled", func(t *testing.T) { - exporter.PostgreSQLOptions = &models.PostgreSQLOptions{ + exporter.PostgreSQLOptions = models.PostgreSQLOptions{ AutoDiscoveryLimit: pointer.ToInt32(5), DatabaseCount: 10, } @@ -279,7 +279,7 @@ func TestAutoDiscovery(t *testing.T) { }) t.Run("Database count equal to limit - enabled", func(t *testing.T) { - exporter.PostgreSQLOptions = &models.PostgreSQLOptions{ + exporter.PostgreSQLOptions = models.PostgreSQLOptions{ AutoDiscoveryLimit: pointer.ToInt32(5), DatabaseCount: 5, } @@ -290,7 +290,7 @@ func TestAutoDiscovery(t *testing.T) { }) t.Run("Database count less than limit - enabled", func(t *testing.T) { - exporter.PostgreSQLOptions = &models.PostgreSQLOptions{ + exporter.PostgreSQLOptions = models.PostgreSQLOptions{ AutoDiscoveryLimit: pointer.ToInt32(5), DatabaseCount: 3, } @@ -301,7 +301,7 @@ func TestAutoDiscovery(t *testing.T) { }) t.Run("Negative limit - disabled", func(t *testing.T) { - exporter.PostgreSQLOptions = &models.PostgreSQLOptions{ + exporter.PostgreSQLOptions = models.PostgreSQLOptions{ AutoDiscoveryLimit: pointer.ToInt32(-1), DatabaseCount: 3, } @@ -312,7 +312,7 @@ func TestAutoDiscovery(t *testing.T) { }) t.Run("Default - enabled", func(t *testing.T) { - exporter.PostgreSQLOptions = &models.PostgreSQLOptions{ + exporter.PostgreSQLOptions = models.PostgreSQLOptions{ AutoDiscoveryLimit: pointer.ToInt32(0), DatabaseCount: 3, } @@ -341,9 +341,9 @@ func TestMaxConnections(t *testing.T) { AgentType: models.PostgresExporterType, Username: pointer.ToString("username"), Password: pointer.ToString("s3cur3 p@$$w0r4."), - ExporterOptions: &models.ExporterOptions{}, - AzureOptions: &models.AzureOptions{}, - PostgreSQLOptions: &models.PostgreSQLOptions{ + ExporterOptions: models.ExporterOptions{}, + AzureOptions: models.AzureOptions{}, + PostgreSQLOptions: models.PostgreSQLOptions{ MaxExporterConnections: 10, }, } @@ -385,7 +385,7 @@ func TestMaxConnections(t *testing.T) { }) t.Run("Max exporter connections set to 0 - ignore", func(t *testing.T) { - exporter.PostgreSQLOptions = &models.PostgreSQLOptions{ + exporter.PostgreSQLOptions = models.PostgreSQLOptions{ MaxExporterConnections: 0, } res, err := postgresExporterConfig(node, postgresql, exporter, redactSecrets, pmmAgentVersion) @@ -394,7 +394,7 @@ func TestMaxConnections(t *testing.T) { }) t.Run("Max exporter connections set to 5 - apply", func(t *testing.T) { - exporter.PostgreSQLOptions = &models.PostgreSQLOptions{ + exporter.PostgreSQLOptions = models.PostgreSQLOptions{ MaxExporterConnections: 5, } res, err := postgresExporterConfig(node, postgresql, exporter, redactSecrets, pmmAgentVersion) @@ -416,15 +416,15 @@ func (s *PostgresExporterConfigTestSuite) TestAzureTimeout() { AgentType: models.PostgresExporterType, Username: pointer.ToString("username"), Password: pointer.ToString("s3cur3 p@$$w0r4."), - ExporterOptions: &models.ExporterOptions{}, - AzureOptions: &models.AzureOptions{ + ExporterOptions: models.ExporterOptions{}, + AzureOptions: models.AzureOptions{ SubscriptionID: "subscription_id", ClientID: "client_id", ClientSecret: "client_secret", TenantID: "tenant_id", ResourceGroup: "resource_group", }, - PostgreSQLOptions: &models.PostgreSQLOptions{}, + PostgreSQLOptions: models.PostgreSQLOptions{}, } actual, err := postgresExporterConfig(s.node, s.postgresql, s.exporter, redactSecrets, s.pmmAgentVersion) @@ -471,9 +471,9 @@ func (s *PostgresExporterConfigTestSuite) TestPrometheusWebConfig() { Username: pointer.ToString("username"), Password: pointer.ToString("s3cur3 p@$$w0r4."), TLS: true, - ExporterOptions: &models.ExporterOptions{}, - AzureOptions: &models.AzureOptions{}, - PostgreSQLOptions: &models.PostgreSQLOptions{}, + ExporterOptions: models.ExporterOptions{}, + AzureOptions: models.AzureOptions{}, + PostgreSQLOptions: models.PostgreSQLOptions{}, } actual, err := postgresExporterConfig(s.node, s.postgresql, s.exporter, redactSecrets, s.pmmAgentVersion) @@ -523,9 +523,9 @@ func (s *PostgresExporterConfigTestSuite) TestSSLSni() { Username: pointer.ToString("username"), Password: pointer.ToString("s3cur3 p@$$w0r4."), TLS: true, - ExporterOptions: &models.ExporterOptions{}, - AzureOptions: &models.AzureOptions{}, - PostgreSQLOptions: &models.PostgreSQLOptions{}, + ExporterOptions: models.ExporterOptions{}, + AzureOptions: models.AzureOptions{}, + PostgreSQLOptions: models.PostgreSQLOptions{}, } actual, err := postgresExporterConfig(s.node, s.postgresql, s.exporter, redactSecrets, s.pmmAgentVersion) diff --git a/managed/services/agents/proxysql_test.go b/managed/services/agents/proxysql_test.go index ba33c65943..4c4b161d83 100644 --- a/managed/services/agents/proxysql_test.go +++ b/managed/services/agents/proxysql_test.go @@ -44,7 +44,7 @@ func TestProxySQLExporterConfig(t *testing.T) { Username: pointer.ToString("username"), Password: pointer.ToString("s3cur3 p@$$w0r4."), AgentPassword: pointer.ToString("agent-password"), - ExporterOptions: &models.ExporterOptions{}, + ExporterOptions: models.ExporterOptions{}, } actual := proxysqlExporterConfig(node, proxysql, exporter, redactSecrets, pmmAgentVersion) expected := &agentv1.SetStateRequest_AgentProcess{ @@ -109,7 +109,7 @@ func TestProxySQLExporterConfig(t *testing.T) { AgentType: models.ProxySQLExporterType, Username: pointer.ToString("username"), Password: pointer.ToString("s3cur3 p@$$w0r4."), - ExporterOptions: &models.ExporterOptions{}, + ExporterOptions: models.ExporterOptions{}, } actual := proxysqlExporterConfig(node, proxysql, exporter, redactSecrets, pmmAgentVersion) expected := &agentv1.SetStateRequest_AgentProcess{ @@ -150,7 +150,7 @@ func TestProxySQLExporterConfig(t *testing.T) { AgentType: models.ProxySQLExporterType, Username: pointer.ToString("username"), Password: pointer.ToString("s3cur3 p@$$w0r4."), - ExporterOptions: &models.ExporterOptions{}, + ExporterOptions: models.ExporterOptions{}, } actual := proxysqlExporterConfig(node, proxysql, exporter, redactSecrets, pmmAgentVersion) expected := &agentv1.SetStateRequest_AgentProcess{ diff --git a/managed/services/agents/rds_test.go b/managed/services/agents/rds_test.go index 3cecdef1c6..428c3233ad 100644 --- a/managed/services/agents/rds_test.go +++ b/managed/services/agents/rds_test.go @@ -48,7 +48,7 @@ func TestRDSExporterConfig(t *testing.T) { AgentID: "agent1", AgentType: models.RDSExporterType, NodeID: &node1.NodeID, - AWSOptions: &models.AWSOptions{ + AWSOptions: models.AWSOptions{ AWSAccessKey: "access_key1", AWSSecretKey: "secret_key1", RDSBasicMetricsDisabled: true, @@ -72,7 +72,7 @@ func TestRDSExporterConfig(t *testing.T) { AgentID: "agent2", AgentType: models.RDSExporterType, NodeID: &node2.NodeID, - AWSOptions: &models.AWSOptions{ + AWSOptions: models.AWSOptions{ AWSAccessKey: "access_key2", AWSSecretKey: "secret_key2", }, diff --git a/managed/services/agents/registry.go b/managed/services/agents/registry.go index 3b63fc19dc..7d60c87883 100644 --- a/managed/services/agents/registry.go +++ b/managed/services/agents/registry.go @@ -323,7 +323,7 @@ func (r *Registry) addVMAgentToPMMAgent(q *reform.Querier, pmmAgentID, runsOnNod if _, err := models.CreateAgent(q, models.VMAgentType, &models.CreateAgentParams{ PMMAgentID: pmmAgentID, NodeID: runsOnNodeID, - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ PushMetrics: true, }, }); err != nil { diff --git a/managed/services/agents/roster_test.go b/managed/services/agents/roster_test.go index f7b8b5fcf4..7eda8a156b 100644 --- a/managed/services/agents/roster_test.go +++ b/managed/services/agents/roster_test.go @@ -57,7 +57,7 @@ func TestRoster(t *testing.T) { exporters[node] = &models.Agent{ AgentID: "agent1", AgentType: models.RDSExporterType, - AWSOptions: &models.AWSOptions{ + AWSOptions: models.AWSOptions{ AWSAccessKey: awsAccessKey, }, } @@ -97,7 +97,7 @@ func TestRoster(t *testing.T) { exporters[node] = &models.Agent{ AgentID: "agent1", AgentType: models.RDSExporterType, - AWSOptions: &models.AWSOptions{ + AWSOptions: models.AWSOptions{ AWSAccessKey: awsAccessKey, }, } diff --git a/managed/services/inventory/agents.go b/managed/services/inventory/agents.go index 9f6a39baaf..a2055ee503 100644 --- a/managed/services/inventory/agents.go +++ b/managed/services/inventory/agents.go @@ -275,7 +275,7 @@ func (as *AgentsService) AddMySQLdExporter(ctx context.Context, p *inventoryv1.A CustomLabels: p.CustomLabels, TLS: p.Tls, TLSSkipVerify: p.TlsSkipVerify, - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ PushMetrics: p.PushMetrics, DisabledCollectors: p.DisableCollectors, }, @@ -363,7 +363,7 @@ func (as *AgentsService) AddMongoDBExporter(ctx context.Context, p *inventoryv1. TLS: p.Tls, TLSSkipVerify: p.TlsSkipVerify, MongoDBOptions: models.MongoDBOptionsFromRequest(p), - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ PushMetrics: p.PushMetrics, DisabledCollectors: p.DisableCollectors, }, @@ -447,7 +447,7 @@ func (as *AgentsService) AddQANMySQLPerfSchemaAgent(ctx context.Context, p *inve CustomLabels: p.CustomLabels, TLS: p.Tls, TLSSkipVerify: p.TlsSkipVerify, - QANOptions: &models.QANOptions{ + QANOptions: models.QANOptions{ MaxQueryLength: p.MaxQueryLength, QueryExamplesDisabled: p.DisableQueryExamples, CommentsParsingDisabled: p.DisableCommentsParsing, @@ -533,7 +533,7 @@ func (as *AgentsService) AddQANMySQLSlowlogAgent(ctx context.Context, p *invento CustomLabels: p.CustomLabels, TLS: p.Tls, TLSSkipVerify: p.TlsSkipVerify, - QANOptions: &models.QANOptions{ + QANOptions: models.QANOptions{ MaxQueryLength: p.MaxQueryLength, QueryExamplesDisabled: p.DisableQueryExamples, CommentsParsingDisabled: p.DisableCommentsParsing, @@ -615,7 +615,7 @@ func (as *AgentsService) AddPostgresExporter(ctx context.Context, p *inventoryv1 CustomLabels: p.CustomLabels, TLS: p.Tls, TLSSkipVerify: p.TlsSkipVerify, - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ PushMetrics: p.PushMetrics, DisabledCollectors: p.DisableCollectors, }, @@ -700,7 +700,7 @@ func (as *AgentsService) AddQANMongoDBProfilerAgent(ctx context.Context, p *inve CustomLabels: p.CustomLabels, TLS: p.Tls, TLSSkipVerify: p.TlsSkipVerify, - QANOptions: &models.QANOptions{ + QANOptions: models.QANOptions{ MaxQueryLength: p.MaxQueryLength, // TODO QueryExamplesDisabled https://jira.percona.com/browse/PMM-4650 - done, but not included in params. }, @@ -782,7 +782,7 @@ func (as *AgentsService) AddProxySQLExporter(ctx context.Context, p *inventoryv1 CustomLabels: p.CustomLabels, TLS: p.Tls, TLSSkipVerify: p.TlsSkipVerify, - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ PushMetrics: p.PushMetrics, DisabledCollectors: p.DisableCollectors, }, @@ -865,7 +865,7 @@ func (as *AgentsService) AddQANPostgreSQLPgStatementsAgent(ctx context.Context, CustomLabels: p.CustomLabels, TLS: p.Tls, TLSSkipVerify: p.TlsSkipVerify, - QANOptions: &models.QANOptions{ + QANOptions: models.QANOptions{ MaxQueryLength: p.MaxQueryLength, CommentsParsingDisabled: p.DisableCommentsParsing, }, @@ -944,7 +944,7 @@ func (as *AgentsService) AddQANPostgreSQLPgStatMonitorAgent(ctx context.Context, CustomLabels: p.CustomLabels, TLS: p.Tls, TLSSkipVerify: p.TlsSkipVerify, - QANOptions: &models.QANOptions{ + QANOptions: models.QANOptions{ MaxQueryLength: p.MaxQueryLength, QueryExamplesDisabled: p.DisableQueryExamples, CommentsParsingDisabled: p.DisableCommentsParsing, @@ -1020,10 +1020,10 @@ func (as *AgentsService) AddRDSExporter(ctx context.Context, p *inventoryv1.AddR PMMAgentID: p.PmmAgentId, NodeID: p.NodeId, CustomLabels: p.CustomLabels, - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ PushMetrics: p.PushMetrics, }, - AWSOptions: &models.AWSOptions{ + AWSOptions: models.AWSOptions{ AWSAccessKey: p.AwsAccessKey, AWSSecretKey: p.AwsSecretKey, RDSBasicMetricsDisabled: p.DisableBasicMetrics, @@ -1173,7 +1173,7 @@ func (as *AgentsService) AddAzureDatabaseExporter(ctx context.Context, p *invent PMMAgentID: p.PmmAgentId, NodeID: p.NodeId, CustomLabels: p.CustomLabels, - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ PushMetrics: p.PushMetrics, }, AzureOptions: models.AzureOptionsFromRequest(p), diff --git a/managed/services/management/agent.go b/managed/services/management/agent.go index 85077bcc67..6e0e2540d0 100644 --- a/managed/services/management/agent.go +++ b/managed/services/management/agent.go @@ -146,30 +146,21 @@ func (s *ManagementService) agentToAPI(agent *models.Agent) (*managementv1.Unive Version: pointer.GetString(agent.Version), } - if agent.ExporterOptions != nil { - ua.DisabledCollectors = agent.ExporterOptions.DisabledCollectors - ua.MetricsPath = agent.ExporterOptions.MetricsPath - ua.MetricsScheme = agent.ExporterOptions.MetricsScheme - ua.PushMetrics = agent.ExporterOptions.PushMetrics - ua.ExposeExporter = agent.ExporterOptions.ExposeExporter - } - - if agent.QANOptions != nil { - ua.MaxQueryLength = agent.QANOptions.MaxQueryLength - ua.MaxQueryLogSize = agent.QANOptions.MaxQueryLogSize - ua.QueryExamplesDisabled = agent.QANOptions.QueryExamplesDisabled - ua.CommentsParsingDisabled = agent.QANOptions.CommentsParsingDisabled - } - - if agent.AWSOptions != nil { - ua.IsAwsSecretKeySet = agent.AWSOptions.AWSAccessKey != "" - ua.AwsAccessKey = agent.AWSOptions.AWSAccessKey - ua.RdsBasicMetricsDisabled = agent.AWSOptions.RDSBasicMetricsDisabled - ua.RdsEnhancedMetricsDisabled = agent.AWSOptions.RDSEnhancedMetricsDisabled - - } - - if agent.AzureOptions != nil { + // Exporter options + ua.DisabledCollectors = agent.ExporterOptions.DisabledCollectors + ua.MetricsPath = agent.ExporterOptions.MetricsPath + ua.MetricsScheme = agent.ExporterOptions.MetricsScheme + ua.PushMetrics = agent.ExporterOptions.PushMetrics + ua.ExposeExporter = agent.ExporterOptions.ExposeExporter + + // QAN options + ua.MaxQueryLength = agent.QANOptions.MaxQueryLength + ua.MaxQueryLogSize = agent.QANOptions.MaxQueryLogSize + ua.QueryExamplesDisabled = agent.QANOptions.QueryExamplesDisabled + ua.CommentsParsingDisabled = agent.QANOptions.CommentsParsingDisabled + + switch agent.AgentType { + case models.AzureDatabaseExporterType: ua.AzureOptions = &managementv1.UniversalAgent_AzureOptions{ ClientId: agent.AzureOptions.ClientID, IsClientSecretSet: agent.AzureOptions.ClientSecret != "", @@ -177,9 +168,7 @@ func (s *ManagementService) agentToAPI(agent *models.Agent) (*managementv1.Unive SubscriptionId: agent.AzureOptions.SubscriptionID, ResourceGroup: agent.AzureOptions.ResourceGroup, } - } - - if agent.MongoDBOptions != nil { + case models.MongoDBExporterType, models.QANMongoDBProfilerAgentType: ua.MongoDbOptions = &managementv1.UniversalAgent_MongoDBOptions{ AuthenticationMechanism: agent.MongoDBOptions.AuthenticationMechanism, AuthenticationDatabase: agent.MongoDBOptions.AuthenticationDatabase, @@ -189,23 +178,25 @@ func (s *ManagementService) agentToAPI(agent *models.Agent) (*managementv1.Unive IsTlsCertificateKeySet: agent.MongoDBOptions.TLSCertificateKey != "", IsTlsCertificateKeyFilePasswordSet: agent.MongoDBOptions.TLSCertificateKeyFilePassword != "", } - } - - if agent.MySQLOptions != nil { + case models.MySQLdExporterType, models.QANMySQLSlowlogAgentType, models.QANMySQLPerfSchemaAgentType: ua.MysqlOptions = &managementv1.UniversalAgent_MySQLOptions{ IsTlsKeySet: agent.MySQLOptions.TLSKey != "", } ua.TableCount = pointer.GetInt32(agent.MySQLOptions.TableCount) ua.TableCountTablestatsGroupLimit = agent.MySQLOptions.TableCountTablestatsGroupLimit - - } - - if agent.PostgreSQLOptions != nil { + case models.PostgresExporterType, models.QANPostgreSQLPgStatementsAgentType, models.QANPostgreSQLPgStatMonitorAgentType: ua.PostgresqlOptions = &managementv1.UniversalAgent_PostgreSQLOptions{ IsSslKeySet: agent.PostgreSQLOptions.SSLKey != "", AutoDiscoveryLimit: pointer.GetInt32(agent.PostgreSQLOptions.AutoDiscoveryLimit), MaxExporterConnections: agent.PostgreSQLOptions.MaxExporterConnections, } + case models.RDSExporterType: + ua.IsAwsSecretKeySet = agent.AWSOptions.AWSAccessKey != "" + ua.AwsAccessKey = agent.AWSOptions.AWSAccessKey + ua.RdsBasicMetricsDisabled = agent.AWSOptions.RDSBasicMetricsDisabled + ua.RdsEnhancedMetricsDisabled = agent.AWSOptions.RDSEnhancedMetricsDisabled + default: + // Do nothing. } return ua, nil diff --git a/managed/services/management/agent_test.go b/managed/services/management/agent_test.go index 40705bc901..97c6c36288 100644 --- a/managed/services/management/agent_test.go +++ b/managed/services/management/agent_test.go @@ -148,78 +148,36 @@ func TestAgentService(t *testing.T) { expected := []*agentv1.UniversalAgent{ { - AgentId: pgExporterID, - AgentType: "postgres_exporter", - PmmAgentId: models.PMMServerAgentID, - IsConnected: false, - CreatedAt: timestamppb.New(now), - UpdatedAt: timestamppb.New(now), - Username: "postgres", + AgentId: pgExporterID, + AgentType: "postgres_exporter", + PmmAgentId: models.PMMServerAgentID, + IsConnected: false, + CreatedAt: timestamppb.New(now), + UpdatedAt: timestamppb.New(now), + Username: "postgres", + PostgresqlOptions: &agentv1.UniversalAgent_PostgreSQLOptions{ + IsSslKeySet: false, + }, ServiceId: "00000000-0000-4000-8000-000000000002", Status: "AGENT_STATUS_UNKNOWN", Tls: true, CommentsParsingDisabled: true, - AzureOptions: &agentv1.UniversalAgent_AzureOptions{ - ClientId: "", - IsClientSecretSet: false, - ResourceGroup: "", - SubscriptionId: "", - TenantId: "", - }, - MongoDbOptions: &agentv1.UniversalAgent_MongoDBOptions{ - IsTlsCertificateKeySet: false, - IsTlsCertificateKeyFilePasswordSet: false, - AuthenticationMechanism: "", - AuthenticationDatabase: "", - StatsCollections: nil, - CollectionsLimit: 0, - EnableAllCollectors: false, - }, - MysqlOptions: &agentv1.UniversalAgent_MySQLOptions{ - IsTlsKeySet: false, - }, - PostgresqlOptions: &agentv1.UniversalAgent_PostgreSQLOptions{ - IsSslKeySet: false, - AutoDiscoveryLimit: 0, - MaxExporterConnections: 0, - }, }, { - AgentId: pgStatStatementID, - AgentType: "qan-postgresql-pgstatements-agent", - PmmAgentId: models.PMMServerAgentID, - IsConnected: false, - CreatedAt: timestamppb.New(now), - UpdatedAt: timestamppb.New(now), - Username: "postgres", + AgentId: pgStatStatementID, + AgentType: "qan-postgresql-pgstatements-agent", + PmmAgentId: models.PMMServerAgentID, + IsConnected: false, + CreatedAt: timestamppb.New(now), + UpdatedAt: timestamppb.New(now), + Username: "postgres", + PostgresqlOptions: &agentv1.UniversalAgent_PostgreSQLOptions{ + IsSslKeySet: false, + }, ServiceId: "00000000-0000-4000-8000-000000000002", Status: "AGENT_STATUS_UNKNOWN", Tls: true, CommentsParsingDisabled: true, - AzureOptions: &agentv1.UniversalAgent_AzureOptions{ - ClientId: "", - IsClientSecretSet: false, - ResourceGroup: "", - SubscriptionId: "", - TenantId: "", - }, - MongoDbOptions: &agentv1.UniversalAgent_MongoDBOptions{ - IsTlsCertificateKeySet: false, - IsTlsCertificateKeyFilePasswordSet: false, - AuthenticationMechanism: "", - AuthenticationDatabase: "", - StatsCollections: nil, - CollectionsLimit: 0, - EnableAllCollectors: false, - }, - MysqlOptions: &agentv1.UniversalAgent_MySQLOptions{ - IsTlsKeySet: false, - }, - PostgresqlOptions: &agentv1.UniversalAgent_PostgreSQLOptions{ - IsSslKeySet: false, - AutoDiscoveryLimit: 0, - MaxExporterConnections: 0, - }, }, { AgentId: models.PMMServerAgentID, @@ -228,30 +186,6 @@ func TestAgentService(t *testing.T) { IsConnected: true, CreatedAt: timestamppb.New(now), UpdatedAt: timestamppb.New(now), - AzureOptions: &agentv1.UniversalAgent_AzureOptions{ - ClientId: "", - IsClientSecretSet: false, - ResourceGroup: "", - SubscriptionId: "", - TenantId: "", - }, - MongoDbOptions: &agentv1.UniversalAgent_MongoDBOptions{ - IsTlsCertificateKeySet: false, - IsTlsCertificateKeyFilePasswordSet: false, - AuthenticationMechanism: "", - AuthenticationDatabase: "", - StatsCollections: nil, - CollectionsLimit: 0, - EnableAllCollectors: false, - }, - MysqlOptions: &agentv1.UniversalAgent_MySQLOptions{ - IsTlsKeySet: false, - }, - PostgresqlOptions: &agentv1.UniversalAgent_PostgreSQLOptions{ - IsSslKeySet: false, - AutoDiscoveryLimit: 0, - MaxExporterConnections: 0, - }, }, } @@ -303,30 +237,6 @@ func TestAgentService(t *testing.T) { UpdatedAt: timestamppb.New(now), ServiceId: "00000000-0000-4000-8000-000000000006", Status: "AGENT_STATUS_UNKNOWN", - AzureOptions: &agentv1.UniversalAgent_AzureOptions{ - ClientId: "", - IsClientSecretSet: false, - ResourceGroup: "", - SubscriptionId: "", - TenantId: "", - }, - MongoDbOptions: &agentv1.UniversalAgent_MongoDBOptions{ - IsTlsCertificateKeySet: false, - IsTlsCertificateKeyFilePasswordSet: false, - AuthenticationMechanism: "", - AuthenticationDatabase: "", - StatsCollections: nil, - CollectionsLimit: 0, - EnableAllCollectors: false, - }, - MysqlOptions: &agentv1.UniversalAgent_MySQLOptions{ - IsTlsKeySet: false, - }, - PostgresqlOptions: &agentv1.UniversalAgent_PostgreSQLOptions{ - IsSslKeySet: false, - AutoDiscoveryLimit: 0, - MaxExporterConnections: 0, - }, }, } assert.Equal(t, expected, response.Agents) @@ -369,38 +279,15 @@ func TestAgentService(t *testing.T) { expected := []*agentv1.UniversalAgent{ { - AgentId: azureExporter.AgentID, - AgentType: "azure_database_exporter", - PmmAgentId: "00000000-0000-4000-8000-000000000007", - IsConnected: false, - CreatedAt: timestamppb.New(now), - UpdatedAt: timestamppb.New(now), - ServiceId: "00000000-0000-4000-8000-000000000006", - Status: "AGENT_STATUS_UNKNOWN", - AzureOptions: &agentv1.UniversalAgent_AzureOptions{ - ClientId: "", - IsClientSecretSet: false, - ResourceGroup: "", - SubscriptionId: "", - TenantId: "", - }, - MongoDbOptions: &agentv1.UniversalAgent_MongoDBOptions{ - IsTlsCertificateKeySet: false, - IsTlsCertificateKeyFilePasswordSet: false, - AuthenticationMechanism: "", - AuthenticationDatabase: "", - StatsCollections: nil, - CollectionsLimit: 0, - EnableAllCollectors: false, - }, - MysqlOptions: &agentv1.UniversalAgent_MySQLOptions{ - IsTlsKeySet: false, - }, - PostgresqlOptions: &agentv1.UniversalAgent_PostgreSQLOptions{ - IsSslKeySet: false, - AutoDiscoveryLimit: 0, - MaxExporterConnections: 0, - }, + AgentId: azureExporter.AgentID, + AgentType: "azure_database_exporter", + PmmAgentId: "00000000-0000-4000-8000-000000000007", + IsConnected: false, + CreatedAt: timestamppb.New(now), + UpdatedAt: timestamppb.New(now), + ServiceId: "00000000-0000-4000-8000-000000000006", + Status: "AGENT_STATUS_UNKNOWN", + AzureOptions: &agentv1.UniversalAgent_AzureOptions{}, }, } assert.Equal(t, expected, response.Agents) diff --git a/managed/services/management/azure_database.go b/managed/services/management/azure_database.go index d98af5d1aa..f5d226ef9d 100644 --- a/managed/services/management/azure_database.go +++ b/managed/services/management/azure_database.go @@ -277,7 +277,7 @@ func (s *ManagementService) AddAzureDatabase(ctx context.Context, req *managemen Password: req.Password, TLS: req.Tls, TLSSkipVerify: req.TlsSkipVerify, - MySQLOptions: &models.MySQLOptions{ + MySQLOptions: models.MySQLOptions{ TableCountTablestatsGroupLimit: tablestatsGroupTableLimit, }, }) @@ -303,7 +303,7 @@ func (s *ManagementService) AddAzureDatabase(ctx context.Context, req *managemen Password: req.Password, TLS: req.Tls, TLSSkipVerify: req.TlsSkipVerify, - QANOptions: &models.QANOptions{ + QANOptions: models.QANOptions{ QueryExamplesDisabled: req.DisableQueryExamples, }, }) diff --git a/managed/services/management/mongodb.go b/managed/services/management/mongodb.go index 34b7e9d7ca..387c5432e0 100644 --- a/managed/services/management/mongodb.go +++ b/managed/services/management/mongodb.go @@ -72,7 +72,7 @@ func (s *ManagementService) addMongoDB(ctx context.Context, req *managementv1.Ad TLSSkipVerify: req.TlsSkipVerify, MongoDBOptions: models.MongoDBOptionsFromRequest(req), LogLevel: services.SpecifyLogLevel(req.LogLevel, inventoryv1.LogLevel_LOG_LEVEL_FATAL), - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ ExposeExporter: req.ExposeExporter, PushMetrics: isPushMode(req.MetricsMode), DisabledCollectors: req.DisableCollectors, @@ -106,7 +106,7 @@ func (s *ManagementService) addMongoDB(ctx context.Context, req *managementv1.Ad Password: req.Password, TLS: req.Tls, TLSSkipVerify: req.TlsSkipVerify, - QANOptions: &models.QANOptions{ + QANOptions: models.QANOptions{ MaxQueryLength: req.MaxQueryLength, // TODO QueryExamplesDisabled https://jira.percona.com/browse/PMM-7860 }, diff --git a/managed/services/management/mysql.go b/managed/services/management/mysql.go index 112de34e5a..160fe79ed3 100644 --- a/managed/services/management/mysql.go +++ b/managed/services/management/mysql.go @@ -98,7 +98,7 @@ func (s *ManagementService) addMySQL(ctx context.Context, req *managementv1.AddM TLS: req.Tls, TLSSkipVerify: req.TlsSkipVerify, MySQLOptions: mysqlOptions, - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ ExposeExporter: req.ExposeExporter, PushMetrics: isPushMode(req.MetricsMode), DisabledCollectors: req.DisableCollectors, @@ -134,7 +134,7 @@ func (s *ManagementService) addMySQL(ctx context.Context, req *managementv1.AddM Password: req.Password, TLS: req.Tls, TLSSkipVerify: req.TlsSkipVerify, - QANOptions: &models.QANOptions{ + QANOptions: models.QANOptions{ MaxQueryLength: req.MaxQueryLength, QueryExamplesDisabled: req.DisableQueryExamples, CommentsParsingDisabled: req.DisableCommentsParsing, @@ -162,7 +162,7 @@ func (s *ManagementService) addMySQL(ctx context.Context, req *managementv1.AddM TLS: req.Tls, TLSSkipVerify: req.TlsSkipVerify, MySQLOptions: models.MySQLOptionsFromRequest(req), - QANOptions: &models.QANOptions{ + QANOptions: models.QANOptions{ MaxQueryLength: req.MaxQueryLength, QueryExamplesDisabled: req.DisableQueryExamples, CommentsParsingDisabled: req.DisableCommentsParsing, diff --git a/managed/services/management/postgresql.go b/managed/services/management/postgresql.go index 63bb85171d..81af3b5008 100644 --- a/managed/services/management/postgresql.go +++ b/managed/services/management/postgresql.go @@ -72,7 +72,7 @@ func (s *ManagementService) addPostgreSQL(ctx context.Context, req *managementv1 AgentPassword: req.AgentPassword, TLS: req.Tls, TLSSkipVerify: req.TlsSkipVerify, - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ ExposeExporter: req.ExposeExporter, PushMetrics: isPushMode(req.MetricsMode), DisabledCollectors: req.DisableCollectors, @@ -113,7 +113,7 @@ func (s *ManagementService) addPostgreSQL(ctx context.Context, req *managementv1 ServiceID: service.ServiceID, Username: req.Username, Password: req.Password, - QANOptions: &models.QANOptions{ + QANOptions: models.QANOptions{ MaxQueryLength: req.MaxQueryLength, QueryExamplesDisabled: req.DisableQueryExamples, CommentsParsingDisabled: req.DisableCommentsParsing, @@ -142,7 +142,7 @@ func (s *ManagementService) addPostgreSQL(ctx context.Context, req *managementv1 Password: req.Password, TLS: req.Tls, TLSSkipVerify: req.TlsSkipVerify, - QANOptions: &models.QANOptions{ + QANOptions: models.QANOptions{ MaxQueryLength: req.MaxQueryLength, QueryExamplesDisabled: req.DisableQueryExamples, CommentsParsingDisabled: req.DisableCommentsParsing, diff --git a/managed/services/management/proxysql.go b/managed/services/management/proxysql.go index d1f5eb6bce..430cb6af2f 100644 --- a/managed/services/management/proxysql.go +++ b/managed/services/management/proxysql.go @@ -70,7 +70,7 @@ func (s *ManagementService) addProxySQL(ctx context.Context, req *managementv1.A AgentPassword: req.AgentPassword, TLS: req.Tls, TLSSkipVerify: req.TlsSkipVerify, - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ ExposeExporter: req.ExposeExporter, PushMetrics: isPushMode(req.MetricsMode), DisabledCollectors: req.DisableCollectors, diff --git a/managed/services/management/rds.go b/managed/services/management/rds.go index 6e3edfea89..ac4afa2b2d 100644 --- a/managed/services/management/rds.go +++ b/managed/services/management/rds.go @@ -276,13 +276,13 @@ func (s *ManagementService) addRDS(ctx context.Context, req *managementv1.AddRDS rdsExporter, err := models.CreateAgent(tx.Querier, models.RDSExporterType, &models.CreateAgentParams{ PMMAgentID: pmmAgentID, NodeID: node.NodeID, - AWSOptions: &models.AWSOptions{ + AWSOptions: models.AWSOptions{ AWSAccessKey: req.AwsAccessKey, AWSSecretKey: req.AwsSecretKey, RDSBasicMetricsDisabled: req.DisableBasicMetrics, RDSEnhancedMetricsDisabled: req.DisableEnhancedMetrics, }, - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ PushMetrics: isPushMode(metricsMode), }, }) @@ -326,10 +326,10 @@ func (s *ManagementService) addRDS(ctx context.Context, req *managementv1.AddRDS Password: req.Password, TLS: req.Tls, TLSSkipVerify: req.TlsSkipVerify, - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ PushMetrics: isPushMode(metricsMode), }, - MySQLOptions: &models.MySQLOptions{ + MySQLOptions: models.MySQLOptions{ TableCountTablestatsGroupLimit: tablestatsGroupTableLimit, }, }) @@ -360,7 +360,7 @@ func (s *ManagementService) addRDS(ctx context.Context, req *managementv1.AddRDS Password: req.Password, TLS: req.Tls, TLSSkipVerify: req.TlsSkipVerify, - QANOptions: &models.QANOptions{ + QANOptions: models.QANOptions{ QueryExamplesDisabled: req.DisableQueryExamples, CommentsParsingDisabled: req.DisableCommentsParsing, }, @@ -407,14 +407,14 @@ func (s *ManagementService) addRDS(ctx context.Context, req *managementv1.AddRDS Password: req.Password, TLS: req.Tls, TLSSkipVerify: req.TlsSkipVerify, - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ PushMetrics: isPushMode(metricsMode), }, - MySQLOptions: &models.MySQLOptions{ + MySQLOptions: models.MySQLOptions{ TableCountTablestatsGroupLimit: tablestatsGroupTableLimit, }, - PostgreSQLOptions: &models.PostgreSQLOptions{ + PostgreSQLOptions: models.PostgreSQLOptions{ AutoDiscoveryLimit: pointer.ToInt32(req.AutoDiscoveryLimit), MaxExporterConnections: req.MaxPostgresqlExporterConnections, }, @@ -446,7 +446,7 @@ func (s *ManagementService) addRDS(ctx context.Context, req *managementv1.AddRDS Password: req.Password, TLS: req.Tls, TLSSkipVerify: req.TlsSkipVerify, - QANOptions: &models.QANOptions{ + QANOptions: models.QANOptions{ QueryExamplesDisabled: req.DisableQueryExamples, CommentsParsingDisabled: req.DisableCommentsParsing, }, diff --git a/managed/services/victoriametrics/scrape_configs_test.go b/managed/services/victoriametrics/scrape_configs_test.go index e87462bd12..e7e13b79fd 100644 --- a/managed/services/victoriametrics/scrape_configs_test.go +++ b/managed/services/victoriametrics/scrape_configs_test.go @@ -51,7 +51,7 @@ func TestScrapeConfig(t *testing.T) { AgentType: models.NodeExporterType, CustomLabels: []byte(`{"_some_agent_label": "baz"}`), ListenPort: pointer.ToUint16(12345), - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ DisabledCollectors: []string{"cpu", "entropy"}, }, } @@ -188,7 +188,7 @@ func TestScrapeConfig(t *testing.T) { AgentType: models.NodeExporterType, CustomLabels: []byte(`{"_some_agent_label": "baz"}`), ListenPort: pointer.ToUint16(12345), - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ DisabledCollectors: []string{"cpu", "time"}, }, } @@ -261,8 +261,8 @@ func TestScrapeConfig(t *testing.T) { AgentType: models.MySQLdExporterType, CustomLabels: []byte(`{"_some_agent_label": "baz"}`), ListenPort: pointer.ToUint16(12345), - ExporterOptions: &models.ExporterOptions{}, - MySQLOptions: &models.MySQLOptions{}, + ExporterOptions: models.ExporterOptions{}, + MySQLOptions: models.MySQLOptions{}, } expected := []*config.ScrapeConfig{{ @@ -417,10 +417,10 @@ func TestScrapeConfig(t *testing.T) { AgentType: models.MySQLdExporterType, CustomLabels: []byte(`{"_some_agent_label": "baz"}`), ListenPort: pointer.ToUint16(12345), - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ DisabledCollectors: []string{"global_status", "info_schema.innodb_cmp", "info_schema.query_response_time", "perf_schema.eventsstatements", "heartbeat"}, }, - MySQLOptions: &models.MySQLOptions{}, + MySQLOptions: models.MySQLOptions{}, } expected := []*config.ScrapeConfig{{ @@ -567,8 +567,8 @@ func TestScrapeConfig(t *testing.T) { AgentID: "75bb30d3-ef4a-4147-97a8-621a996611dd", AgentType: models.MySQLdExporterType, ListenPort: pointer.ToUint16(12345), - ExporterOptions: &models.ExporterOptions{}, - MySQLOptions: &models.MySQLOptions{ + ExporterOptions: models.ExporterOptions{}, + MySQLOptions: models.MySQLOptions{ TableCount: pointer.ToInt32(100500), TableCountTablestatsGroupLimit: 1000, }, @@ -698,7 +698,7 @@ func TestScrapeConfig(t *testing.T) { agent := &models.Agent{ CustomLabels: []byte("{"), ListenPort: pointer.ToUint16(12345), - ExporterOptions: &models.ExporterOptions{}, + ExporterOptions: models.ExporterOptions{}, } _, err := scrapeConfigsForMySQLdExporter(&scrapeConfigParams{ @@ -731,8 +731,8 @@ func TestScrapeConfig(t *testing.T) { AgentType: models.MongoDBExporterType, CustomLabels: []byte(`{"_some_agent_label": "baz"}`), ListenPort: pointer.ToUint16(12345), - ExporterOptions: &models.ExporterOptions{}, - MongoDBOptions: &models.MongoDBOptions{EnableAllCollectors: true}, + ExporterOptions: models.ExporterOptions{}, + MongoDBOptions: models.MongoDBOptions{EnableAllCollectors: true}, } expected := []*config.ScrapeConfig{ @@ -831,8 +831,8 @@ func TestScrapeConfig(t *testing.T) { AgentType: models.MongoDBExporterType, CustomLabels: []byte(`{"_some_agent_label": "baz"}`), ListenPort: pointer.ToUint16(12345), - ExporterOptions: &models.ExporterOptions{}, - MongoDBOptions: &models.MongoDBOptions{}, + ExporterOptions: models.ExporterOptions{}, + MongoDBOptions: models.MongoDBOptions{}, } expected := []*config.ScrapeConfig{ @@ -921,7 +921,7 @@ func TestScrapeConfig(t *testing.T) { agent := &models.Agent{ CustomLabels: []byte("{"), ListenPort: pointer.ToUint16(12345), - ExporterOptions: &models.ExporterOptions{}, + ExporterOptions: models.ExporterOptions{}, } _, err := scrapeConfigsForMongoDBExporter(&scrapeConfigParams{ @@ -955,7 +955,7 @@ func TestScrapeConfig(t *testing.T) { AgentType: models.PostgresExporterType, CustomLabels: []byte(`{"_some_agent_label": "baz"}`), ListenPort: pointer.ToUint16(12345), - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ DisabledCollectors: []string{"standard.process", "custom_query.lr"}, }, } @@ -1073,7 +1073,7 @@ func TestScrapeConfig(t *testing.T) { agent := &models.Agent{ CustomLabels: []byte("{"), ListenPort: pointer.ToUint16(12345), - ExporterOptions: &models.ExporterOptions{}, + ExporterOptions: models.ExporterOptions{}, } _, err := scrapeConfigsForPostgresExporter(&scrapeConfigParams{ @@ -1294,7 +1294,7 @@ func TestScrapeConfig(t *testing.T) { AgentType: models.ExternalExporterType, CustomLabels: []byte(`{"_some_agent_label": "baz"}`), ListenPort: pointer.ToUint16(12345), - ExporterOptions: &models.ExporterOptions{}, + ExporterOptions: models.ExporterOptions{}, } expected := []*config.ScrapeConfig{{ @@ -1341,7 +1341,7 @@ func TestScrapeConfig(t *testing.T) { Username: pointer.ToString("username"), Password: pointer.ToString("password"), ListenPort: pointer.ToUint16(12345), - ExporterOptions: &models.ExporterOptions{ + ExporterOptions: models.ExporterOptions{ MetricsPath: "/some-metric-path", MetricsScheme: "https", }, @@ -1395,7 +1395,7 @@ func TestScrapeConfig(t *testing.T) { agent := &models.Agent{ CustomLabels: []byte("{"), ListenPort: pointer.ToUint16(12345), - ExporterOptions: &models.ExporterOptions{}, + ExporterOptions: models.ExporterOptions{}, } _, err := scrapeConfigsForMongoDBExporter(&scrapeConfigParams{ diff --git a/managed/services/victoriametrics/victoriametrics_test.go b/managed/services/victoriametrics/victoriametrics_test.go index 90633cc34e..198a8f6847 100644 --- a/managed/services/victoriametrics/victoriametrics_test.go +++ b/managed/services/victoriametrics/victoriametrics_test.go @@ -154,7 +154,7 @@ func TestVictoriaMetrics(t *testing.T) { ServiceID: pointer.ToString("acds89846-3cd2-47f8-a5f9-ac789513cde4"), CustomLabels: []byte(`{"_agent_label": "mongodb-baz"}`), ListenPort: pointer.ToUint16(12346), - MongoDBOptions: &models.MongoDBOptions{EnableAllCollectors: true}, + MongoDBOptions: models.MongoDBOptions{EnableAllCollectors: true}, }, &models.Agent{ @@ -229,8 +229,8 @@ func TestVictoriaMetrics(t *testing.T) { ServiceID: pointer.ToString("1eae647b-f1e2-4e15-bc58-dfdbc3c37cbf"), CustomLabels: []byte(`{"_agent_label": "mongodb-baz-push"}`), ListenPort: pointer.ToUint16(12346), - MongoDBOptions: &models.MongoDBOptions{EnableAllCollectors: true}, - ExporterOptions: &models.ExporterOptions{ + MongoDBOptions: models.MongoDBOptions{EnableAllCollectors: true}, + ExporterOptions: models.ExporterOptions{ PushMetrics: true, }, }, @@ -243,8 +243,8 @@ func TestVictoriaMetrics(t *testing.T) { ServiceID: pointer.ToString("1eae647b-f1e2-4e15-bc58-dfdbc3c37cbf"), CustomLabels: []byte(`{"_agent_label": "mongodb-baz-pull"}`), ListenPort: pointer.ToUint16(12346), - MongoDBOptions: &models.MongoDBOptions{EnableAllCollectors: true}, - ExporterOptions: &models.ExporterOptions{ + MongoDBOptions: models.MongoDBOptions{EnableAllCollectors: true}, + ExporterOptions: models.ExporterOptions{ PushMetrics: false, }, },