Skip to content

Commit

Permalink
PMM-12811 single agents change endpoint (#2777)
Browse files Browse the repository at this point in the history
* PMM-12811 fix a typo

* PMM-12811 fix tests

* PMM-12811 modify agents.proto

* PMM-12811 modify agents_server and tests

* PMM-12811 fix API tests

* PMM-12811 fix linter warning

* PMM-12811 increase container wait time

* PMM-12811 print docker logs on failure

* PMM-12811 increase the container wait time again

* PMM-12811 try exit-code param for container launch

* PMM-12811 check the container exit code

* PMM-12811 launch pmm w/o waiting

* PMM-12811 launch the container manually

* PMM-12811 simplify, remove redundant methods

* PMM-12811 rename exporter to agent in proto

* PMM-12811 document the change

* PMM-12811 fix API tests

* PMM-12811 fix platform_test.go

* PMM-12811 prefer a single enable boolean vs paired

* PMM-12811 make custom_labels map optional

* PMM-12811 fix Advisor params

* PMM-12811 get rid of remove_custom_labels field

* PMM-12811 remove a duplicate test

* PMM-12811 follow up on review

* PMM-12811 pass context to changeAgent

* PMM-12811 move tableCount to MysqldExporter

* PMM-12811 pass context around, fix tests

* PMM-12811 add an annotation about one param

* PMM-12811 fix Azure test
  • Loading branch information
ademidoff authored Feb 6, 2024
1 parent 0ba47f4 commit a40df07
Show file tree
Hide file tree
Showing 70 changed files with 15,840 additions and 23,952 deletions.
1 change: 1 addition & 0 deletions .github/workflows/managed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ jobs:
docker compose --profile pmm up -d
sleep 100s
docker logs pmm-server
- name: Restore Go build cache
if: ${{ fromJSON(env.DEVCONTAINER_CACHE_ENABLED) }}
continue-on-error: true
Expand Down
2 changes: 1 addition & 1 deletion admin/commands/inventory/add_agent_mysqld_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,6 @@ func (cmd *AddAgentMysqldExporterCommand) RunCmd() (commands.Result, error) {
}
return &addAgentMysqldExporterResult{
Agent: resp.Payload.MysqldExporter,
TableCount: resp.Payload.TableCount,
TableCount: resp.Payload.MysqldExporter.TableCount,
}, nil
}
122 changes: 62 additions & 60 deletions api-tests/inventory/agents_azure_database_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,23 @@ func TestAzureDatabaseExporter(t *testing.T) { //nolint:tparallel
}, getAgentRes)

// Test change API.
changeAzureDatabaseExporterOK, err := client.Default.AgentsService.ChangeAzureDatabaseExporter(&agents.ChangeAzureDatabaseExporterParams{
Body: agents.ChangeAzureDatabaseExporterBody{
AgentID: agentID,
Common: &agents.ChangeAzureDatabaseExporterParamsBodyCommon{
Disable: true,
RemoveCustomLabels: true,
changeAzureDatabaseExporterOK, err := client.Default.AgentsService.ChangeAgent(
&agents.ChangeAgentParams{
Body: agents.ChangeAgentBody{
AzureDatabaseExporter: &agents.ChangeAgentParamsBodyAzureDatabaseExporter{
AgentID: agentID,
Common: &agents.ChangeAgentParamsBodyAzureDatabaseExporterCommon{
Enable: pointer.ToBool(false),
CustomLabels: &agents.ChangeAgentParamsBodyAzureDatabaseExporterCommonCustomLabels{},
},
},
},
},
Context: pmmapitests.Context,
})
Context: pmmapitests.Context,
})
assert.NoError(t, err)
assert.Equal(t, &agents.ChangeAzureDatabaseExporterOK{
Payload: &agents.ChangeAzureDatabaseExporterOKBody{
AzureDatabaseExporter: &agents.ChangeAzureDatabaseExporterOKBodyAzureDatabaseExporter{
assert.Equal(t, &agents.ChangeAgentOK{
Payload: &agents.ChangeAgentOKBody{
AzureDatabaseExporter: &agents.ChangeAgentOKBodyAzureDatabaseExporter{
NodeID: nodeID,
AgentID: agentID,
PMMAgentID: pmmAgentID,
Expand All @@ -108,22 +111,27 @@ func TestAzureDatabaseExporter(t *testing.T) { //nolint:tparallel
},
}, changeAzureDatabaseExporterOK)

changeAzureDatabaseExporterOK, err = client.Default.AgentsService.ChangeAzureDatabaseExporter(&agents.ChangeAzureDatabaseExporterParams{
Body: agents.ChangeAzureDatabaseExporterBody{
AgentID: agentID,
Common: &agents.ChangeAzureDatabaseExporterParamsBodyCommon{
Enable: true,
CustomLabels: map[string]string{
"new_label": "azure_database_exporter",
changeAzureDatabaseExporterOK, err = client.Default.AgentsService.ChangeAgent(
&agents.ChangeAgentParams{
Body: agents.ChangeAgentBody{
AzureDatabaseExporter: &agents.ChangeAgentParamsBodyAzureDatabaseExporter{
AgentID: agentID,
Common: &agents.ChangeAgentParamsBodyAzureDatabaseExporterCommon{
Enable: pointer.ToBool(true),
CustomLabels: &agents.ChangeAgentParamsBodyAzureDatabaseExporterCommonCustomLabels{
Values: map[string]string{
"new_label": "azure_database_exporter",
},
},
},
},
},
},
Context: pmmapitests.Context,
})
Context: pmmapitests.Context,
})
assert.NoError(t, err)
assert.Equal(t, &agents.ChangeAzureDatabaseExporterOK{
Payload: &agents.ChangeAzureDatabaseExporterOKBody{
AzureDatabaseExporter: &agents.ChangeAzureDatabaseExporterOKBodyAzureDatabaseExporter{
assert.Equal(t, &agents.ChangeAgentOK{
Payload: &agents.ChangeAgentOKBody{
AzureDatabaseExporter: &agents.ChangeAgentOKBodyAzureDatabaseExporter{
NodeID: nodeID,
AgentID: agentID,
PMMAgentID: pmmAgentID,
Expand Down Expand Up @@ -159,7 +167,7 @@ func TestAzureDatabaseExporter(t *testing.T) { //nolint:tparallel
},
Context: pmmapitests.Context,
})
pmmapitests.AssertAPIErrorf(t, err, 400, codes.InvalidArgument, "invalid AddDatabaseExporterRequest.NodeId: value length must be at least 1 runes")
pmmapitests.AssertAPIErrorf(t, err, 400, codes.InvalidArgument, "invalid AddAzureDatabaseExporterParams.NodeId: value length must be at least 1 runes")
if !assert.Nil(t, res) {
pmmapitests.RemoveNodes(t, res.Payload.AzureDatabaseExporter.AgentID)
}
Expand Down Expand Up @@ -265,19 +273,22 @@ func TestAzureDatabaseExporter(t *testing.T) { //nolint:tparallel
}, getAgentRes)

// Test change API.
changeAzureDatabaseExporterOK, err := client.Default.AgentsService.ChangeAzureDatabaseExporter(&agents.ChangeAzureDatabaseExporterParams{
Body: agents.ChangeAzureDatabaseExporterBody{
AgentID: agentID,
Common: &agents.ChangeAzureDatabaseExporterParamsBodyCommon{
EnablePushMetrics: true,
changeAzureDatabaseExporterOK, err := client.Default.AgentsService.ChangeAgent(
&agents.ChangeAgentParams{
Body: agents.ChangeAgentBody{
AzureDatabaseExporter: &agents.ChangeAgentParamsBodyAzureDatabaseExporter{
AgentID: agentID,
Common: &agents.ChangeAgentParamsBodyAzureDatabaseExporterCommon{
EnablePushMetrics: pointer.ToBool(true),
},
},
},
},
Context: pmmapitests.Context,
})
Context: pmmapitests.Context,
})
assert.NoError(t, err)
assert.Equal(t, &agents.ChangeAzureDatabaseExporterOK{
Payload: &agents.ChangeAzureDatabaseExporterOKBody{
AzureDatabaseExporter: &agents.ChangeAzureDatabaseExporterOKBodyAzureDatabaseExporter{
assert.Equal(t, &agents.ChangeAgentOK{
Payload: &agents.ChangeAgentOKBody{
AzureDatabaseExporter: &agents.ChangeAgentOKBodyAzureDatabaseExporter{
NodeID: nodeID,
AgentID: agentID,
PMMAgentID: pmmAgentID,
Expand All @@ -291,19 +302,22 @@ func TestAzureDatabaseExporter(t *testing.T) { //nolint:tparallel
},
}, changeAzureDatabaseExporterOK)

changeAzureDatabaseExporterOK, err = client.Default.AgentsService.ChangeAzureDatabaseExporter(&agents.ChangeAzureDatabaseExporterParams{
Body: agents.ChangeAzureDatabaseExporterBody{
AgentID: agentID,
Common: &agents.ChangeAzureDatabaseExporterParamsBodyCommon{
DisablePushMetrics: true,
changeAzureDatabaseExporterOK, err = client.Default.AgentsService.ChangeAgent(
&agents.ChangeAgentParams{
Body: agents.ChangeAgentBody{
AzureDatabaseExporter: &agents.ChangeAgentParamsBodyAzureDatabaseExporter{
AgentID: agentID,
Common: &agents.ChangeAgentParamsBodyAzureDatabaseExporterCommon{
EnablePushMetrics: pointer.ToBool(false),
},
},
},
},
Context: pmmapitests.Context,
})
Context: pmmapitests.Context,
})
assert.NoError(t, err)
assert.Equal(t, &agents.ChangeAzureDatabaseExporterOK{
Payload: &agents.ChangeAzureDatabaseExporterOKBody{
AzureDatabaseExporter: &agents.ChangeAzureDatabaseExporterOKBodyAzureDatabaseExporter{
assert.Equal(t, &agents.ChangeAgentOK{
Payload: &agents.ChangeAgentOKBody{
AzureDatabaseExporter: &agents.ChangeAgentOKBodyAzureDatabaseExporter{
NodeID: nodeID,
AgentID: agentID,
PMMAgentID: pmmAgentID,
Expand All @@ -316,17 +330,5 @@ func TestAzureDatabaseExporter(t *testing.T) { //nolint:tparallel
},
},
}, changeAzureDatabaseExporterOK)
_, err = client.Default.AgentsService.ChangeAzureDatabaseExporter(&agents.ChangeAzureDatabaseExporterParams{
Body: agents.ChangeAzureDatabaseExporterBody{
AgentID: agentID,
Common: &agents.ChangeAzureDatabaseExporterParamsBodyCommon{
EnablePushMetrics: true,
DisablePushMetrics: true,
},
},
Context: pmmapitests.Context,
})

pmmapitests.AssertAPIErrorf(t, err, 400, codes.InvalidArgument, "expected one of param: enable_push_metrics or disable_push_metrics")
})
}
117 changes: 60 additions & 57 deletions api-tests/inventory/agents_external_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package inventory
import (
"testing"

"github.com/AlekSi/pointer"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -139,19 +140,22 @@ func TestExternalExporter(t *testing.T) {
}, getAgentRes.Payload)

// Test change API.
changeExternalExporterOK, err := client.Default.AgentsService.ChangeExternalExporter(&agents.ChangeExternalExporterParams{
Body: agents.ChangeExternalExporterBody{
AgentID: agentID,
Common: &agents.ChangeExternalExporterParamsBodyCommon{
Disable: true,
RemoveCustomLabels: true,
changeExternalExporterOK, err := client.Default.AgentsService.ChangeAgent(
&agents.ChangeAgentParams{
Body: agents.ChangeAgentBody{
ExternalExporter: &agents.ChangeAgentParamsBodyExternalExporter{
AgentID: agentID,
Common: &agents.ChangeAgentParamsBodyExternalExporterCommon{
Enable: pointer.ToBool(false),
CustomLabels: &agents.ChangeAgentParamsBodyExternalExporterCommonCustomLabels{},
},
},
},
},
Context: pmmapitests.Context,
})
Context: pmmapitests.Context,
})
assert.NoError(t, err)
assert.Equal(t, &agents.ChangeExternalExporterOKBody{
ExternalExporter: &agents.ChangeExternalExporterOKBodyExternalExporter{
assert.Equal(t, &agents.ChangeAgentOKBody{
ExternalExporter: &agents.ChangeAgentOKBodyExternalExporter{
AgentID: agentID,
ServiceID: serviceID,
RunsOnNodeID: genericNodeID,
Expand All @@ -164,21 +168,26 @@ func TestExternalExporter(t *testing.T) {
},
}, changeExternalExporterOK.Payload)

changeExternalExporterOK, err = client.Default.AgentsService.ChangeExternalExporter(&agents.ChangeExternalExporterParams{
Body: agents.ChangeExternalExporterBody{
AgentID: agentID,
Common: &agents.ChangeExternalExporterParamsBodyCommon{
Enable: true,
CustomLabels: map[string]string{
"new_label": "external_exporter",
changeExternalExporterOK, err = client.Default.AgentsService.ChangeAgent(
&agents.ChangeAgentParams{
Body: agents.ChangeAgentBody{
ExternalExporter: &agents.ChangeAgentParamsBodyExternalExporter{
AgentID: agentID,
Common: &agents.ChangeAgentParamsBodyExternalExporterCommon{
Enable: pointer.ToBool(true),
CustomLabels: &agents.ChangeAgentParamsBodyExternalExporterCommonCustomLabels{
Values: map[string]string{
"new_label": "external_exporter",
},
},
},
},
},
},
Context: pmmapitests.Context,
})
Context: pmmapitests.Context,
})
assert.NoError(t, err)
assert.Equal(t, &agents.ChangeExternalExporterOKBody{
ExternalExporter: &agents.ChangeExternalExporterOKBodyExternalExporter{
assert.Equal(t, &agents.ChangeAgentOKBody{
ExternalExporter: &agents.ChangeAgentOKBodyExternalExporter{
AgentID: agentID,
ServiceID: serviceID,
RunsOnNodeID: genericNodeID,
Expand Down Expand Up @@ -243,7 +252,7 @@ func TestExternalExporter(t *testing.T) {
},
Context: pmmapitests.Context,
})
pmmapitests.AssertAPIErrorf(t, err, 400, codes.InvalidArgument, "invalid AddAgentRequest.ListenPort: value must be inside range (0, 65536)")
pmmapitests.AssertAPIErrorf(t, err, 400, codes.InvalidArgument, "invalid AddExternalExporterParams.ListenPort: value must be inside range (0, 65536)")
if !assert.Nil(t, res) {
pmmapitests.RemoveNodes(t, res.Payload.ExternalExporter.AgentID)
}
Expand Down Expand Up @@ -276,7 +285,7 @@ func TestExternalExporter(t *testing.T) {
},
Context: pmmapitests.Context,
})
pmmapitests.AssertAPIErrorf(t, err, 400, codes.InvalidArgument, "invalid AddAgentRequest.RunsOnNodeId: value length must be at least 1 runes")
pmmapitests.AssertAPIErrorf(t, err, 400, codes.InvalidArgument, "invalid AddExternalExporterParams.RunsOnNodeId: value length must be at least 1 runes")
if !assert.Nil(t, res) {
pmmapitests.RemoveAgents(t, res.Payload.ExternalExporter.AgentID)
}
Expand Down Expand Up @@ -392,18 +401,21 @@ func TestExternalExporter(t *testing.T) {
}, getAgentRes.Payload)

// Test change API.
changeExternalExporterOK, err := client.Default.AgentsService.ChangeExternalExporter(&agents.ChangeExternalExporterParams{
Body: agents.ChangeExternalExporterBody{
AgentID: agentID,
Common: &agents.ChangeExternalExporterParamsBodyCommon{
DisablePushMetrics: true,
changeExternalExporterOK, err := client.Default.AgentsService.ChangeAgent(
&agents.ChangeAgentParams{
Body: agents.ChangeAgentBody{
ExternalExporter: &agents.ChangeAgentParamsBodyExternalExporter{
AgentID: agentID,
Common: &agents.ChangeAgentParamsBodyExternalExporterCommon{
EnablePushMetrics: pointer.ToBool(false),
},
},
},
},
Context: pmmapitests.Context,
})
Context: pmmapitests.Context,
})
assert.NoError(t, err)
assert.Equal(t, &agents.ChangeExternalExporterOKBody{
ExternalExporter: &agents.ChangeExternalExporterOKBodyExternalExporter{
assert.Equal(t, &agents.ChangeAgentOKBody{
ExternalExporter: &agents.ChangeAgentOKBodyExternalExporter{
AgentID: agentID,
ServiceID: serviceID,
RunsOnNodeID: genericNodeID,
Expand All @@ -417,18 +429,21 @@ func TestExternalExporter(t *testing.T) {
},
}, changeExternalExporterOK.Payload)

changeExternalExporterOK, err = client.Default.AgentsService.ChangeExternalExporter(&agents.ChangeExternalExporterParams{
Body: agents.ChangeExternalExporterBody{
AgentID: agentID,
Common: &agents.ChangeExternalExporterParamsBodyCommon{
EnablePushMetrics: true,
changeExternalExporterOK, err = client.Default.AgentsService.ChangeAgent(
&agents.ChangeAgentParams{
Body: agents.ChangeAgentBody{
ExternalExporter: &agents.ChangeAgentParamsBodyExternalExporter{
AgentID: agentID,
Common: &agents.ChangeAgentParamsBodyExternalExporterCommon{
EnablePushMetrics: pointer.ToBool(true),
},
},
},
},
Context: pmmapitests.Context,
})
Context: pmmapitests.Context,
})
assert.NoError(t, err)
assert.Equal(t, &agents.ChangeExternalExporterOKBody{
ExternalExporter: &agents.ChangeExternalExporterOKBodyExternalExporter{
assert.Equal(t, &agents.ChangeAgentOKBody{
ExternalExporter: &agents.ChangeAgentOKBodyExternalExporter{
AgentID: agentID,
ServiceID: serviceID,
RunsOnNodeID: genericNodeID,
Expand All @@ -441,17 +456,5 @@ func TestExternalExporter(t *testing.T) {
PushMetricsEnabled: true,
},
}, changeExternalExporterOK.Payload)

_, err = client.Default.AgentsService.ChangeExternalExporter(&agents.ChangeExternalExporterParams{
Body: agents.ChangeExternalExporterBody{
AgentID: agentID,
Common: &agents.ChangeExternalExporterParamsBodyCommon{
EnablePushMetrics: true,
DisablePushMetrics: true,
},
},
Context: pmmapitests.Context,
})
pmmapitests.AssertAPIErrorf(t, err, 400, codes.InvalidArgument, "expected one of param: enable_push_metrics or disable_push_metrics")
})
}
Loading

0 comments on commit a40df07

Please sign in to comment.