Skip to content

Commit

Permalink
PMM-5003 Add nice type helpers for AgentType. (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekSi authored Feb 25, 2020
1 parent 5f89b0a commit 4e602e1
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 0 deletions.
24 changes: 24 additions & 0 deletions api/inventorypb/agents_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package inventorypb

import (
"strings"
"testing"

"github.com/stretchr/testify/assert"

"github.com/percona/pmm/api/inventorypb/types"
)

// This test ensures that the AgentTypeNames map that holds the human readable agent type
// names is up to date with the types defined in AgentType_name by the proto definition
// by calling the AgentTypeName function using the values from protobuf and it expects the
// result is a non-empty string, meaning that the AgentTypeNames list matches the proto
// definitions
func TestAgentTypes(t *testing.T) {
for _, val := range AgentType_name {
if strings.HasSuffix(val, "INVALID") {
continue
}
assert.NotEmpty(t, types.AgentTypeName(val))
}
}
24 changes: 24 additions & 0 deletions api/inventorypb/nodes_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package inventorypb

import (
"strings"
"testing"

"github.com/stretchr/testify/assert"

"github.com/percona/pmm/api/inventorypb/types"
)

// This test ensures that the NodetypeNames map that holds the human readable agent type
// names is up to date with the types defined in Nodetype_name by the proto definition
// by calling the NodetypeName function using the values from protobuf and it expects the
// result is a non-empty string, meaning that the NodetypeNames list matches the proto
// definitions
func TestNodeTypes(t *testing.T) {
for _, val := range NodeType_name {
if strings.HasSuffix(val, "INVALID") {
continue
}
assert.NotEmpty(t, types.NodeTypeName(val))
}
}
24 changes: 24 additions & 0 deletions api/inventorypb/services_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package inventorypb

import (
"strings"
"testing"

"github.com/stretchr/testify/assert"

"github.com/percona/pmm/api/inventorypb/types"
)

// This test ensures that the ServiceTypeNames map that holds the human readable agent type
// names is up to date with the types defined in ServiceType_name by the proto definition
// by calling the ServiceTypeName function using the values from protobuf and it expects the
// result is a non-empty string, meaning that the ServiceTypeNames list matches the proto
// definitions
func TestServiceTypes(t *testing.T) {
for _, val := range ServiceType_name {
if strings.HasSuffix(val, "INVALID") {
continue
}
assert.NotEmpty(t, types.ServiceTypeName(val))
}
}
45 changes: 45 additions & 0 deletions api/inventorypb/types/agent_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package types

import "fmt"

// this list should be in sync with inventorypb/agents.pb.go
const (
AgentTypePMMAgent = "PMM_AGENT"
AgentTypeNodeExporter = "NODE_EXPORTER"
AgentTypeMySQLdExporter = "MYSQLD_EXPORTER"
AgentTypeMongoDBExporter = "MONGODB_EXPORTER"
AgentTypePostgresExporter = "POSTGRES_EXPORTER"
AgentTypeProxySQLExporter = "PROXYSQL_EXPORTER"
AgentTypeQANMySQLPerfSchemaAgent = "QAN_MYSQL_PERFSCHEMA_AGENT"
AgentTypeQANMySQLSlowlogAgent = "QAN_MYSQL_SLOWLOG_AGENT"
AgentTypeQANMongoDBProfilerAgent = "QAN_MONGODB_PROFILER_AGENT"
AgentTypeQANPostgreSQLPgStatementsAgent = "QAN_POSTGRESQL_PGSTATEMENTS_AGENT"
AgentTypeRDSExporter = "RDS_EXPORTER"
)

// agentTypeNames is the human readable list of agent names to be used in reports and
// commands like list or status
var agentTypeNames = map[string]string{
// no invalid
AgentTypePMMAgent: "pmm_agent",
AgentTypeNodeExporter: "node_exporter",
AgentTypeMySQLdExporter: "mysqld_exporter",
AgentTypeMongoDBExporter: "mongodb_exporter",
AgentTypePostgresExporter: "postgres_exporter",
AgentTypeProxySQLExporter: "proxysql_exporter",
AgentTypeQANMySQLPerfSchemaAgent: "mysql_perfschema_agent",
AgentTypeQANMySQLSlowlogAgent: "mysql_slowlog_agent",
AgentTypeQANMongoDBProfilerAgent: "mongodb_profiler_agent",
AgentTypeQANPostgreSQLPgStatementsAgent: "postgresql_pgstatements_agent",
AgentTypeRDSExporter: "rds_exporter",
}

// AgentTypeName returns human friendly agent type to be used in reports
func AgentTypeName(t string) string {
res := agentTypeNames[t]
if res == "" {
panic(fmt.Sprintf("no nice string for Agent Type %s", t))
}

return res
}
28 changes: 28 additions & 0 deletions api/inventorypb/types/node_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package types

import "fmt"

// this list should be in sync with inventorypb/nodes.pb.go
const (
NodeTypeGenericNode = "GENERIC_NODE"
NodeTypeContainerNode = "CONTAINER_NODE"
NodeTypeRemoteNode = "REMOTE_NODE"
NodeTypeRemoteRDSNode = "REMOTE_RDS_NODE"
)

var nodeTypeNames = map[string]string{
NodeTypeGenericNode: "generic-node",
NodeTypeContainerNode: "container-node",
NodeTypeRemoteNode: "remote-node",
NodeTypeRemoteRDSNode: "remote-rds-node",
}

// NodeTypeName returns human friendly agent type to be used in reports
func NodeTypeName(t string) string {
res := nodeTypeNames[t]
if res == "" {
panic(fmt.Sprintf("no nice string for Node Type %s", t))
}

return res
}
28 changes: 28 additions & 0 deletions api/inventorypb/types/service_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package types

import "fmt"

// this list should be in sync with inventorypb/services.pb.go
const (
ServiceTypeMySQLService = "MYSQL_SERVICE"
ServiceTypeMongoDBService = "MONGODB_SERVICE"
ServiceTypePostgreSQLService = "POSTGRESQL_SERVICE"
ServiceTypeProxySQLService = "PROXYSQL_SERVICE"
)

var serviceTypeNames = map[string]string{
ServiceTypeMySQLService: "mysql-service",
ServiceTypeMongoDBService: "mongodb-service",
ServiceTypePostgreSQLService: "postgresql-service",
ServiceTypeProxySQLService: "proxysql-service",
}

// ServiceTypeName returns human friendly agent type to be used in reports
func ServiceTypeName(t string) string {
res := serviceTypeNames[t]
if res == "" {
panic(fmt.Sprintf("no nice string for Service Type %s", t))
}

return res
}

0 comments on commit 4e602e1

Please sign in to comment.