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

PMM-5086 Refactor agent model (DRAFT) #745

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions data/bindata.go

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

18 changes: 5 additions & 13 deletions models/agent_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,14 +540,10 @@ type CreateAgentParams struct {
CustomLabels map[string]string
TLS bool
TLSSkipVerify bool
MongoDBOptions *MongoDBOptions
TableCountTablestatsGroupLimit int32
QueryExamplesDisabled bool
MaxQueryLogSize int64
AWSAccessKey string
AWSSecretKey string
RDSBasicMetricsDisabled bool
RDSEnhancedMetricsDisabled bool
MongoDBOptions *MongoDBOptions
QANOptions *QANOptions
AWSOptions *AWSOptions
AzureOptions *AzureOptions
PushMetrics bool
DisableCollectors []string
Expand Down Expand Up @@ -596,12 +592,8 @@ func CreateAgent(q *reform.Querier, agentType AgentType, params *CreateAgentPara
TLSSkipVerify: params.TLSSkipVerify,
MongoDBOptions: params.MongoDBOptions,
TableCountTablestatsGroupLimit: params.TableCountTablestatsGroupLimit,
QueryExamplesDisabled: params.QueryExamplesDisabled,
MaxQueryLogSize: params.MaxQueryLogSize,
AWSAccessKey: pointer.ToStringOrNil(params.AWSAccessKey),
AWSSecretKey: pointer.ToStringOrNil(params.AWSSecretKey),
RDSBasicMetricsDisabled: params.RDSBasicMetricsDisabled,
RDSEnhancedMetricsDisabled: params.RDSEnhancedMetricsDisabled,
QANOptions: params.QANOptions,
AWSOptions: params.AWSOptions,
AzureOptions: params.AzureOptions,
PushMetrics: params.PushMetrics,
DisabledCollectors: params.DisableCollectors,
Expand Down
46 changes: 33 additions & 13 deletions models/agent_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,32 @@ 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) }

// AWSOptions represents structure for special AWS options.
type AWSOptions struct {
RDSBasicMetricsDisabled bool `reform:"rds_basic_metrics_disabled"`
RDSEnhancedMetricsDisabled bool `reform:"rds_enhanced_metrics_disabled"`
AWSAccessKey *string `reform:"aws_access_key"`
AWSSecretKey *string `reform:"aws_secret_key"`
}

// Value implements database/sql/driver.Valuer interface. Should be defined on the value.
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) }

// QANOptions represents structure for special Query Analytics options.
type QANOptions struct {
QueryExamplesDisabled bool `reform:"query_examples_disabled"`
MaxQueryLogSize int64 `reform:"max_query_log_size"`
}

// Value implements database/sql/driver.Valuer interface. Should be defined on the value.
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) }

// PMMAgentWithPushMetricsSupport - version of pmmAgent,
// that support vmagent and push metrics mode
// will be released with PMM Agent v2.12.
Expand Down Expand Up @@ -121,11 +147,6 @@ type Agent struct {
TLS bool `reform:"tls"`
TLSSkipVerify bool `reform:"tls_skip_verify"`

AWSAccessKey *string `reform:"aws_access_key"`
AWSSecretKey *string `reform:"aws_secret_key"`

AzureOptions *AzureOptions `reform:"azure_options"`

// TableCount stores last known table count. NULL if unknown.
TableCount *int32 `reform:"table_count"`

Expand All @@ -135,17 +156,16 @@ type Agent struct {
// See IsMySQLTablestatsGroupEnabled method.
TableCountTablestatsGroupLimit int32 `reform:"table_count_tablestats_group_limit"`

QueryExamplesDisabled bool `reform:"query_examples_disabled"`
MaxQueryLogSize int64 `reform:"max_query_log_size"`
MetricsPath *string `reform:"metrics_path"`
MetricsScheme *string `reform:"metrics_scheme"`
MetricsPath *string `reform:"metrics_path"`
MetricsScheme *string `reform:"metrics_scheme"`

RDSBasicMetricsDisabled bool `reform:"rds_basic_metrics_disabled"`
RDSEnhancedMetricsDisabled bool `reform:"rds_enhanced_metrics_disabled"`
PushMetrics bool `reform:"push_metrics"`
DisabledCollectors pq.StringArray `reform:"disabled_collectors"`
PushMetrics bool `reform:"push_metrics"`
DisabledCollectors pq.StringArray `reform:"disabled_collectors"`

QANOptions *QANOptions `reform:"qan_options"`
MongoDBOptions *MongoDBOptions `reform:"mongo_db_tls_options"`
AzureOptions *AzureOptions `reform:"azure_options"`
AWSOptions *AWSOptions `reform:"aws_options"`
}

// BeforeInsert implements reform.BeforeInserter interface.
Expand Down
66 changes: 23 additions & 43 deletions models/agent_model_reform.go

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

25 changes: 25 additions & 0 deletions models/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,31 @@ var databaseSchema = [][]string{
34: {
`ALTER TABLE kubernetes_clusters ADD COLUMN haproxy JSONB`,
},
35: {
`ALTER TABLE agents ALTER COLUMN azure_options TYPE JSONB USING azure_options::jsonb`,
`ALTER TABLE agents ADD COLUMN aws_options JSONB`,
`ALTER TABLE agents ADD COLUMN qan_options JSONB`,

`UPDATE agents SET aws_options=jsonb_build_object(
'aws_access_key', aws_access_key,
'aws_secret_key', aws_secret_key,
'rds_basic_metrics_disabled', rds_basic_metrics_disabled,
'rds_enhanced_metrics_disabled', rds_enhanced_metrics_disabled
)
WHERE aws_access_key != NULL OR aws_secret_key != NULL OR rds_basic_metrics_disabled OR rds_enhanced_metrics_disabled`,

`UPDATE agents SET aws_options=jsonb_build_object(
'query_examples_disabled', query_examples_disabled,
'max_query_log_size', max_query_log_size
)`,
`ALTER TABLE agents
DROP COLUMN aws_access_key,
DROP COLUMN aws_secret_key,
DROP COLUMN rds_basic_metrics_disabled,
DROP COLUMN rds_enhanced_metrics_disabled,
DROP COLUMN query_examples_disabled,
DROP COLUMN max_query_log_size`,
},
}

// ^^^ Avoid default values in schema definition. ^^^
Expand Down
3 changes: 1 addition & 2 deletions services/checks/mock_agents_registry_test.go

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

56 changes: 0 additions & 56 deletions services/inventory/mock_agents_registry_test.go

This file was deleted.

15 changes: 0 additions & 15 deletions services/inventory/mock_prometheus_service_test.go

This file was deleted.

Loading