Skip to content

Commit

Permalink
PMM-5086-12634 CreateAgent options preparation.
Browse files Browse the repository at this point in the history
  • Loading branch information
JiriCtvrtka committed Dec 4, 2024
1 parent 1a661a8 commit ca3d1bf
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions managed/models/agent_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func MySQLOptionsFromRequest(params MySQLOptionsParams) *MySQLOptions {
TLSKey: params.GetTlsKey(),
}
}
return &MySQLOptions{}
return nil
}

// PostgreSQLOptionsParams contains methods to create PostgreSQLOptions object.
Expand Down Expand Up @@ -858,19 +858,47 @@ 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()
if err := checkUniqueAgentID(q, id); err != nil {
return nil, err
}

params = prepareOptionsParams(params)

pmmAgent, err := FindAgentByID(q, params.PMMAgentID)
if err != nil {
return nil, err
}
// check version for agent, if it exists.
if params.ExporterOptions != nil && params.ExporterOptions.PushMetrics {
if params.ExporterOptions.PushMetrics {
// special case for vmAgent, it always supports push metrics.
if agentType != VMAgentType && !IsPushMetricsSupported(pmmAgent.Version) {
return nil, status.Errorf(codes.FailedPrecondition, "cannot use push_metrics_enabled with pmm_agent version=%q,"+
Expand Down

0 comments on commit ca3d1bf

Please sign in to comment.