Skip to content

Commit

Permalink
PMM-12155 refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
BupycHuk committed Oct 10, 2024
1 parent 1f70720 commit 31cbcff
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
2 changes: 1 addition & 1 deletion agent/client/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type ServerRequest struct {
}

// AgentResponse represents agent's response.
// It is similar to agentpb.AgentMessage except it can contain only responses,
// It is similar to agentv1.AgentMessage except it can contain only responses,
// and the payload is already unwrapped (XXX instead of AgentMessage_XXX).
type AgentResponse struct {
ID uint32
Expand Down
9 changes: 1 addition & 8 deletions managed/services/agents/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,9 @@ func nodeExporterConfig(node *models.Node, exporter *models.Agent, agentVersion
Args: args,
}

if err := ensureAuthParams(exporter, params, agentVersion, v2_27_99, isNewTLSConfigSupported(exporter)); err != nil {
if err := ensureAuthParams(exporter, params, agentVersion, v2_27_99, agentVersion.IsFeatureSupported(version.NodeExporterNewTLSConfigVersion)); err != nil {
return nil, err
}

return params, nil
}

func isNewTLSConfigSupported(exporter *models.Agent) bool {
if agentVersion, err := version.Parse(pointer.GetString(exporter.Version)); err == nil {
return !agentVersion.Less(v1_5_0)
}
return false
}
8 changes: 3 additions & 5 deletions managed/services/agents/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package agents
import (
"testing"

"github.com/AlekSi/pointer"
"github.com/stretchr/testify/require"

agentv1 "github.com/percona/pmm/api/agent/v1"
Expand Down Expand Up @@ -79,21 +78,20 @@ func TestAuthWebConfig(t *testing.T) {
require.Contains(t, actual.Args, "--web.config={{ .TextFiles.webConfigPlaceholder }}")
})

t.Run("exporter v1.5.0", func(t *testing.T) {
t.Run("v3.0.0", func(t *testing.T) {
t.Parallel()

node := &models.Node{}
exporter := &models.Agent{
AgentID: "agent-id",
AgentType: models.NodeExporterType,
Version: pointer.ToString("1.5.0"),
}
agentVersion := version.MustParse("2.28.0")
agentVersion := version.MustParse("3.0.0")

actual, err := nodeExporterConfig(node, exporter, agentVersion)
require.NoError(t, err, "Unable to build node exporter config")

expected := &agentpb.SetStateRequest_AgentProcess{
expected := &agentv1.SetStateRequest_AgentProcess{
Env: []string(nil),
TextFiles: map[string]string{
"webConfigPlaceholder": "basic_auth_users:\n pmm: agent-id\n",
Expand Down
32 changes: 32 additions & 0 deletions version/features.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (C) 2023 Percona LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

package version

// versions list.
var (
V3_0_0 = MustParse("3.0.0")
)

type FeatureVersion *Parsed

// features list.
var (
NodeExporterNewTLSConfigVersion FeatureVersion = V3_0_0
)

func (p *Parsed) IsFeatureSupported(f FeatureVersion) bool {
return !p.Less(f)
}

0 comments on commit 31cbcff

Please sign in to comment.