Skip to content

Commit

Permalink
PMM-5086-12634 Fix migrations, helpers test.
Browse files Browse the repository at this point in the history
  • Loading branch information
JiriCtvrtka committed Dec 3, 2024
1 parent d011239 commit 7c0fb2a
Show file tree
Hide file tree
Showing 2 changed files with 168 additions and 110 deletions.
272 changes: 165 additions & 107 deletions managed/models/agent_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,18 @@ func TestAgentHelpers(t *testing.T) {
PMMAgentID: pointer.ToString("A4"),
RunsOnNodeID: nil,
NodeID: pointer.ToString("N2"),
ListenPort: pointer.ToUint16(8200),
ExporterOptions: &models.ExporterOptions{
PushMetrics: true,
},
ListenPort: pointer.ToUint16(8200),
},
&models.Agent{
AgentID: "A6",
AgentType: models.MySQLdExporterType,
PMMAgentID: pointer.ToString("A4"),
RunsOnNodeID: nil,
NodeID: pointer.ToString("N2"),
ExporterOptions: &models.ExporterOptions{
PushMetrics: false,
},
ListenPort: pointer.ToUint16(8200),
ListenPort: pointer.ToUint16(8200),
},
&models.Agent{
AgentID: "A7",
Expand All @@ -129,7 +126,6 @@ func TestAgentHelpers(t *testing.T) {
TLS: true,
TLSSkipVerify: true,
ExporterOptions: &models.ExporterOptions{
PushMetrics: false,
MetricsResolutions: &models.MetricsResolutions{
HR: 1 * time.Minute,
MR: 5 * time.Minute,
Expand All @@ -151,9 +147,6 @@ func TestAgentHelpers(t *testing.T) {
ListenPort: pointer.ToUint16(8200),
TLS: true,
TLSSkipVerify: true,
ExporterOptions: &models.ExporterOptions{
PushMetrics: false,
},
MongoDBOptions: &models.MongoDBOptions{
TLSCertificateKey: "tls_certificate_key",
TLSCertificateKeyFilePassword: "tls_certificate_key_file_password",
Expand All @@ -165,15 +158,14 @@ func TestAgentHelpers(t *testing.T) {
},
},
&models.Agent{
AgentID: "A9",
AgentType: models.MongoDBExporterType,
PMMAgentID: pointer.ToString("A9"),
RunsOnNodeID: nil,
NodeID: pointer.ToString("N1"),
ListenPort: pointer.ToUint16(8200),
TLS: true,
TLSSkipVerify: true,
ExporterOptions: &models.ExporterOptions{},
AgentID: "A9",
AgentType: models.MongoDBExporterType,
PMMAgentID: pointer.ToString("A9"),
RunsOnNodeID: nil,
NodeID: pointer.ToString("N1"),
ListenPort: pointer.ToUint16(8200),
TLS: true,
TLSSkipVerify: true,
MongoDBOptions: &models.MongoDBOptions{
TLSCertificateKey: "tls_certificate_key",
TLSCertificateKeyFilePassword: "tls_certificate_key_file_password",
Expand All @@ -186,16 +178,15 @@ func TestAgentHelpers(t *testing.T) {
},
},
&models.Agent{
AgentID: "A10",
AgentType: models.MongoDBExporterType,
PMMAgentID: pointer.ToString("A10"),
RunsOnNodeID: nil,
NodeID: pointer.ToString("N1"),
ListenPort: pointer.ToUint16(8200),
TLS: true,
TLSSkipVerify: true,
ExporterOptions: &models.ExporterOptions{},
MongoDBOptions: nil, // this test is specific for nil MongoDBOptions
AgentID: "A10",
AgentType: models.MongoDBExporterType,
PMMAgentID: pointer.ToString("A10"),
RunsOnNodeID: nil,
NodeID: pointer.ToString("N1"),
ListenPort: pointer.ToUint16(8200),
TLS: true,
TLSSkipVerify: true,
MongoDBOptions: nil,
},
} {
require.NoError(t, q.Insert(str))
Expand All @@ -216,29 +207,41 @@ func TestAgentHelpers(t *testing.T) {
require.NoError(t, err)
expected := []*models.Agent{
{
CreatedAt: now,
UpdatedAt: now,
Status: models.AgentStatusUnknown,
AgentID: "A10",
AgentType: models.MongoDBExporterType,
PMMAgentID: pointer.ToString("A10"),
RunsOnNodeID: nil,
NodeID: pointer.ToString("N1"),
ListenPort: pointer.ToUint16(8200),
TLS: true,
TLSSkipVerify: true,
ExporterOptions: &models.ExporterOptions{},
MongoDBOptions: nil, // this test is specific for nil MongoDBOptions
CreatedAt: now,
UpdatedAt: now,
Status: models.AgentStatusUnknown,
AgentID: "A10",
AgentType: models.MongoDBExporterType,
PMMAgentID: pointer.ToString("A10"),
RunsOnNodeID: nil,
NodeID: pointer.ToString("N1"),
ListenPort: pointer.ToUint16(8200),
TLS: true,
TLSSkipVerify: true,
ExporterOptions: &models.ExporterOptions{},
QANOptions: &models.QANOptions{},
AWSOptions: &models.AWSOptions{},
AzureOptions: &models.AzureOptions{},
MongoDBOptions: &models.MongoDBOptions{},
MySQLOptions: &models.MySQLOptions{},
PostgreSQLOptions: &models.PostgreSQLOptions{},
},
{
AgentID: "A3",
AgentType: models.NodeExporterType,
PMMAgentID: pointer.ToStringOrNil("A1"),
RunsOnNodeID: nil,
CreatedAt: now,
UpdatedAt: now,
NodeID: pointer.ToString("N1"),
Status: models.AgentStatusUnknown,
AgentID: "A3",
AgentType: models.NodeExporterType,
PMMAgentID: pointer.ToStringOrNil("A1"),
RunsOnNodeID: nil,
CreatedAt: now,
UpdatedAt: now,
NodeID: pointer.ToString("N1"),
Status: models.AgentStatusUnknown,
ExporterOptions: &models.ExporterOptions{},
QANOptions: &models.QANOptions{},
AWSOptions: &models.AWSOptions{},
AzureOptions: &models.AzureOptions{},
MongoDBOptions: &models.MongoDBOptions{},
MySQLOptions: &models.MySQLOptions{},
PostgreSQLOptions: &models.PostgreSQLOptions{},
},
{
AgentID: "A7",
Expand All @@ -258,26 +261,32 @@ func TestAgentHelpers(t *testing.T) {
LR: 15 * time.Minute,
},
},
QANOptions: &models.QANOptions{},
AWSOptions: &models.AWSOptions{},
AzureOptions: &models.AzureOptions{},
MongoDBOptions: &models.MongoDBOptions{},
MySQLOptions: &models.MySQLOptions{},
PostgreSQLOptions: &models.PostgreSQLOptions{
SSLCa: "ssl_ca",
SSLCert: "ssl_cert",
SSLKey: "ssl_key",
},
},
{
AgentID: "A8",
AgentType: "mongodb_exporter",
NodeID: pointer.ToStringOrNil("N1"),
PMMAgentID: pointer.ToStringOrNil("A8"),
CreatedAt: now,
UpdatedAt: now,
Status: models.AgentStatusUnknown,
ListenPort: pointer.ToUint16OrNil(8200),
TLS: true,
TLSSkipVerify: true,
ExporterOptions: &models.ExporterOptions{
ExposeExporter: false,
},
AgentID: "A8",
AgentType: "mongodb_exporter",
NodeID: pointer.ToStringOrNil("N1"),
PMMAgentID: pointer.ToStringOrNil("A8"),
CreatedAt: now,
UpdatedAt: now,
Status: models.AgentStatusUnknown,
ListenPort: pointer.ToUint16OrNil(8200),
TLS: true,
TLSSkipVerify: true,
ExporterOptions: &models.ExporterOptions{},
QANOptions: &models.QANOptions{},
AWSOptions: &models.AWSOptions{},
AzureOptions: &models.AzureOptions{},
MongoDBOptions: &models.MongoDBOptions{
TLSCertificateKey: "tls_certificate_key",
TLSCertificateKeyFilePassword: "tls_certificate_key_file_password",
Expand All @@ -287,6 +296,8 @@ func TestAgentHelpers(t *testing.T) {
StatsCollections: nil,
CollectionsLimit: 0, // no limit
},
MySQLOptions: &models.MySQLOptions{},
PostgreSQLOptions: &models.PostgreSQLOptions{},
},
{
AgentID: "A9",
Expand All @@ -300,6 +311,9 @@ func TestAgentHelpers(t *testing.T) {
TLS: true,
TLSSkipVerify: true,
ExporterOptions: &models.ExporterOptions{},
QANOptions: &models.QANOptions{},
AWSOptions: &models.AWSOptions{},
AzureOptions: &models.AzureOptions{},
MongoDBOptions: &models.MongoDBOptions{
TLSCertificateKey: "tls_certificate_key",
TLSCertificateKeyFilePassword: "tls_certificate_key_file_password",
Expand All @@ -310,6 +324,8 @@ func TestAgentHelpers(t *testing.T) {
CollectionsLimit: 79014,
EnableAllCollectors: true,
},
MySQLOptions: &models.MySQLOptions{},
PostgreSQLOptions: &models.PostgreSQLOptions{},
},
}
assert.Equal(t, expected, agents)
Expand All @@ -322,23 +338,37 @@ func TestAgentHelpers(t *testing.T) {
agents, err := models.FindAgents(q, models.AgentFilters{PMMAgentID: "A1"})
require.NoError(t, err)
expected := []*models.Agent{{
AgentID: "A2",
AgentType: models.MySQLdExporterType,
PMMAgentID: pointer.ToStringOrNil("A1"),
ServiceID: pointer.ToString("S1"),
RunsOnNodeID: nil,
CreatedAt: now,
UpdatedAt: now,
Status: models.AgentStatusUnknown,
AgentID: "A2",
AgentType: models.MySQLdExporterType,
PMMAgentID: pointer.ToStringOrNil("A1"),
ServiceID: pointer.ToString("S1"),
RunsOnNodeID: nil,
CreatedAt: now,
UpdatedAt: now,
Status: models.AgentStatusUnknown,
ExporterOptions: &models.ExporterOptions{},
QANOptions: &models.QANOptions{},
AWSOptions: &models.AWSOptions{},
AzureOptions: &models.AzureOptions{},
MongoDBOptions: &models.MongoDBOptions{},
MySQLOptions: &models.MySQLOptions{},
PostgreSQLOptions: &models.PostgreSQLOptions{},
}, {
AgentID: "A3",
AgentType: models.NodeExporterType,
PMMAgentID: pointer.ToStringOrNil("A1"),
NodeID: pointer.ToString("N1"),
RunsOnNodeID: nil,
CreatedAt: now,
UpdatedAt: now,
Status: models.AgentStatusUnknown,
AgentID: "A3",
AgentType: models.NodeExporterType,
PMMAgentID: pointer.ToStringOrNil("A1"),
NodeID: pointer.ToString("N1"),
RunsOnNodeID: nil,
CreatedAt: now,
UpdatedAt: now,
Status: models.AgentStatusUnknown,
ExporterOptions: &models.ExporterOptions{},
QANOptions: &models.QANOptions{},
AWSOptions: &models.AWSOptions{},
AzureOptions: &models.AzureOptions{},
MongoDBOptions: &models.MongoDBOptions{},
MySQLOptions: &models.MySQLOptions{},
PostgreSQLOptions: &models.PostgreSQLOptions{},
}}
assert.Equal(t, expected, agents)
})
Expand All @@ -350,14 +380,21 @@ func TestAgentHelpers(t *testing.T) {
agents, err := models.FindAgents(q, models.AgentFilters{PMMAgentID: "A1", AgentType: pointerToAgentType(models.MySQLdExporterType)})
require.NoError(t, err)
expected := []*models.Agent{{
AgentID: "A2",
AgentType: models.MySQLdExporterType,
PMMAgentID: pointer.ToStringOrNil("A1"),
ServiceID: pointer.ToString("S1"),
RunsOnNodeID: nil,
CreatedAt: now,
UpdatedAt: now,
Status: models.AgentStatusUnknown,
AgentID: "A2",
AgentType: models.MySQLdExporterType,
PMMAgentID: pointer.ToStringOrNil("A1"),
ServiceID: pointer.ToString("S1"),
RunsOnNodeID: nil,
CreatedAt: now,
UpdatedAt: now,
Status: models.AgentStatusUnknown,
ExporterOptions: &models.ExporterOptions{},
QANOptions: &models.QANOptions{},
AWSOptions: &models.AWSOptions{},
AzureOptions: &models.AzureOptions{},
MongoDBOptions: &models.MongoDBOptions{},
MySQLOptions: &models.MySQLOptions{},
PostgreSQLOptions: &models.PostgreSQLOptions{},
}}
assert.Equal(t, expected, agents)
})
Expand All @@ -369,28 +406,42 @@ func TestAgentHelpers(t *testing.T) {
agents, err := models.FindAgents(q, models.AgentFilters{ServiceID: "S1"})
require.NoError(t, err)
expected := []*models.Agent{{
AgentID: "A2",
AgentType: models.MySQLdExporterType,
PMMAgentID: pointer.ToStringOrNil("A1"),
ServiceID: pointer.ToString("S1"),
RunsOnNodeID: nil,
CreatedAt: now,
UpdatedAt: now,
Status: models.AgentStatusUnknown,
AgentID: "A2",
AgentType: models.MySQLdExporterType,
PMMAgentID: pointer.ToStringOrNil("A1"),
ServiceID: pointer.ToString("S1"),
RunsOnNodeID: nil,
CreatedAt: now,
UpdatedAt: now,
Status: models.AgentStatusUnknown,
ExporterOptions: &models.ExporterOptions{},
QANOptions: &models.QANOptions{},
AWSOptions: &models.AWSOptions{},
AzureOptions: &models.AzureOptions{},
MongoDBOptions: &models.MongoDBOptions{},
MySQLOptions: &models.MySQLOptions{},
PostgreSQLOptions: &models.PostgreSQLOptions{},
}}
assert.Equal(t, expected, agents)

agents, err = models.FindAgents(q, models.AgentFilters{ServiceID: "S1", AgentType: pointerToAgentType(models.MySQLdExporterType)})
require.NoError(t, err)
expected = []*models.Agent{{
AgentID: "A2",
AgentType: models.MySQLdExporterType,
PMMAgentID: pointer.ToStringOrNil("A1"),
ServiceID: pointer.ToString("S1"),
RunsOnNodeID: nil,
CreatedAt: now,
UpdatedAt: now,
Status: models.AgentStatusUnknown,
AgentID: "A2",
AgentType: models.MySQLdExporterType,
PMMAgentID: pointer.ToStringOrNil("A1"),
ServiceID: pointer.ToString("S1"),
RunsOnNodeID: nil,
CreatedAt: now,
UpdatedAt: now,
Status: models.AgentStatusUnknown,
ExporterOptions: &models.ExporterOptions{},
QANOptions: &models.QANOptions{},
AWSOptions: &models.AWSOptions{},
AzureOptions: &models.AzureOptions{},
MongoDBOptions: &models.MongoDBOptions{},
MySQLOptions: &models.MySQLOptions{},
PostgreSQLOptions: &models.PostgreSQLOptions{},
}}
assert.Equal(t, expected, agents)

Expand Down Expand Up @@ -420,11 +471,18 @@ func TestAgentHelpers(t *testing.T) {
tests.AssertGRPCError(t, status.New(codes.FailedPrecondition, `pmm-agent with ID A1 has agents.`), err)

expected := &models.Agent{
AgentID: "A1",
AgentType: models.PMMAgentType,
RunsOnNodeID: pointer.ToString("N1"),
CreatedAt: now,
UpdatedAt: now,
AgentID: "A1",
AgentType: models.PMMAgentType,
RunsOnNodeID: pointer.ToString("N1"),
CreatedAt: now,
UpdatedAt: now,
ExporterOptions: &models.ExporterOptions{},
QANOptions: &models.QANOptions{},
AWSOptions: &models.AWSOptions{},
AzureOptions: &models.AzureOptions{},
MongoDBOptions: &models.MongoDBOptions{},
MySQLOptions: &models.MySQLOptions{},
PostgreSQLOptions: &models.PostgreSQLOptions{},
}
agent, err = models.RemoveAgent(q, "A1", models.RemoveCascade)
assert.Equal(t, expected, agent)
Expand Down
Loading

0 comments on commit 7c0fb2a

Please sign in to comment.