Skip to content

Commit

Permalink
Merge branch 'v3' into PMM-11231-pmm-updates-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
matejkubinec committed Jun 5, 2024
2 parents b96b1a9 + 8a59705 commit d1abfc5
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 94 deletions.
88 changes: 44 additions & 44 deletions cli-tests/package-lock.json

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

4 changes: 2 additions & 2 deletions cli-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"devDependencies": {
"@types/promise-retry": "^1.1.3",
"@types/shelljs": "^0.8.12",
"@typescript-eslint/eslint-plugin": "^7.11.0",
"@typescript-eslint/parser": "^7.11.0",
"@typescript-eslint/eslint-plugin": "^7.12.0",
"@typescript-eslint/parser": "^7.12.0",
"eslint": "8.56",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^18.0.0",
Expand Down
18 changes: 18 additions & 0 deletions managed/models/agent_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,24 @@ func FindPmmAgentIDToRunActionOrJob(pmmAgentID string, agents []*Agent) (string,
return "", status.Errorf(codes.FailedPrecondition, "Couldn't find pmm-agent-id to run action")
}

// ExtractPmmAgentVersionFromAgent extract PMM agent version from Agent by pmm-agent-id.
func ExtractPmmAgentVersionFromAgent(q *reform.Querier, agent *Agent) *version.Parsed {
pmmAgentID, err := ExtractPmmAgentID(agent)
if err != nil {
return nil
}
pmmAgent, err := FindAgentByID(q, pmmAgentID)
if err != nil {
return nil
}
version, err := version.Parse(pointer.GetString(pmmAgent.Version))
if err != nil {
return nil
}

return version
}

// ExtractPmmAgentID extract pmm-agent-id from Agent by type.
func ExtractPmmAgentID(agent *Agent) (string, error) {
switch agent.AgentType {
Expand Down
12 changes: 11 additions & 1 deletion managed/models/agent_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ const (
VMAgentType AgentType = "vmagent"
)

var v2_42 = version.MustParse("2.42.0-0")

// PMMServerAgentID is a special Agent ID representing pmm-agent on PMM Server.
const PMMServerAgentID = string("pmm-server") // no /agent_id/ prefix

Expand Down Expand Up @@ -313,7 +315,7 @@ type DSNParams struct {
}

// DSN returns a DSN string for accessing a given Service with this Agent (and an implicit driver).
func (s *Agent) DSN(service *Service, dsnParams DSNParams, tdp *DelimiterPair) string { //nolint:cyclop,maintidx
func (s *Agent) DSN(service *Service, dsnParams DSNParams, tdp *DelimiterPair, pmmAgentVersion *version.Parsed) string { //nolint:cyclop,maintidx
host := pointer.GetString(service.Address)
port := pointer.GetUint16(service.Port)
socket := pointer.GetString(service.Socket)
Expand All @@ -340,8 +342,12 @@ func (s *Agent) DSN(service *Service, dsnParams DSNParams, tdp *DelimiterPair) s
cfg.Params = make(map[string]string)
if s.TLS {
// It is mandatory to have "custom" as the first case.
// Except case for backward compatibility.
// Skip verify for "custom" is handled on pmm-agent side.
switch {
// Backward compatibility
case s.TLSSkipVerify && (pmmAgentVersion == nil || pmmAgentVersion.Less(v2_42)):
cfg.Params["tls"] = skipVerify
case len(s.Files()) != 0:
cfg.Params["tls"] = "custom"
case s.TLSSkipVerify:
Expand Down Expand Up @@ -371,8 +377,12 @@ func (s *Agent) DSN(service *Service, dsnParams DSNParams, tdp *DelimiterPair) s
cfg.Params = make(map[string]string)
if s.TLS {
// It is mandatory to have "custom" as the first case.
// Except case for backward compatibility.
// Skip verify for "custom" is handled on pmm-agent side.
switch {
// Backward compatibility
case pmmAgentVersion != nil && s.TLSSkipVerify && pmmAgentVersion.Less(v2_42):
cfg.Params["tls"] = skipVerify
case len(s.Files()) != 0:
cfg.Params["tls"] = "custom"
case s.TLSSkipVerify:
Expand Down
Loading

0 comments on commit d1abfc5

Please sign in to comment.