From ca3d1bf9a1f340d6690435657ec02297f6063fe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20=C4=8Ctvrtka?= Date: Wed, 4 Dec 2024 10:43:09 +0100 Subject: [PATCH] PMM-5086-12634 CreateAgent options preparation. --- managed/models/agent_helpers.go | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/managed/models/agent_helpers.go b/managed/models/agent_helpers.go index 07230f0f17..30fc3da44a 100644 --- a/managed/models/agent_helpers.go +++ b/managed/models/agent_helpers.go @@ -52,7 +52,7 @@ func MySQLOptionsFromRequest(params MySQLOptionsParams) *MySQLOptions { TLSKey: params.GetTlsKey(), } } - return &MySQLOptions{} + return nil } // PostgreSQLOptionsParams contains methods to create PostgreSQLOptions object. @@ -858,6 +858,32 @@ 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() @@ -865,12 +891,14 @@ 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 } // 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,"+