Skip to content

Commit

Permalink
fix plural
Browse files Browse the repository at this point in the history
Signed-off-by: Arnob kumar saha <[email protected]>
  • Loading branch information
ArnobKumarSaha committed Jan 31, 2024
1 parent dea7aaf commit 80a553f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pkg/monitor/alerts/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func Run(f cmdutil.Factory, args []string, prom monitor.PromSvc) {
_ = fmt.Errorf("failed to get current namespace")
}

opts, err := newDBOpts(f, dbName, namespace, monitor.ConvertedResource(resource))
opts, err := newDBOpts(f, dbName, namespace, monitor.ConvertedResourceToPlural(resource))
if err != nil {
log.Fatalln(err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/monitor/connection/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func Run(f cmdutil.Factory, args []string, prom monitor.PromSvc) {
log.Fatal("Enter database and specific database name as argument")
}

database := monitor.ConvertedResource(args[0])
database := monitor.ConvertedResourceToSingular(args[0])
databaseName := args[1]
namespace, _, err := f.ToRawKubeConfigLoader().Namespace()
if err != nil {
Expand Down
32 changes: 16 additions & 16 deletions pkg/monitor/connection/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,57 +46,57 @@ func getDBMetrics(database, name string, queries map[string]*metrics) map[string
label := "service"
labelValue := fmt.Sprintf("%s-stats", name)
switch database {
case api.ResourcePluralMongoDB:
case api.ResourceSingularElasticsearch:
queries[database] = &metrics{
metric: "mongodb_up",
metric: "elasticsearch_clusterinfo_up",
label: label,
labelValue: labelValue,
}
case api.ResourcePluralPostgres:
case api.ResourceSingularKafka:
queries[database] = &metrics{
metric: "pg_up",
metric: "kafka_controller_kafkacontroller_activebrokercount",
label: label,
labelValue: labelValue,
}
case api.ResourcePluralMySQL:
case api.ResourceSingularMariaDB:
queries[database] = &metrics{
metric: "mysql_up",
label: label,
labelValue: labelValue,
}
case api.ResourcePluralRedis:
case api.ResourceSingularMongoDB:
queries[database] = &metrics{
metric: "redis_up",
metric: "mongodb_up",
label: label,
labelValue: labelValue,
}
case api.ResourcePluralMariaDB:
case api.ResourceSingularMySQL:
queries[database] = &metrics{
metric: "mysql_up",
label: label,
labelValue: labelValue,
}
case api.ResourcePluralProxySQL:
case api.ResourceSingularPerconaXtraDB:
queries[database] = &metrics{
metric: "proxysql_uptime_seconds_total",
metric: "mysql_up",
label: label,
labelValue: labelValue,
}
case api.ResourcePluralElasticsearch:
case api.ResourceSingularPostgres:
queries[database] = &metrics{
metric: "elasticsearch_clusterinfo_up",
metric: "pg_up",
label: label,
labelValue: labelValue,
}
case api.ResourcePluralPerconaXtraDB:
case api.ResourceSingularProxySQL:
queries[database] = &metrics{
metric: "mysql_up",
metric: "proxysql_uptime_seconds_total",
label: label,
labelValue: labelValue,
}
case api.ResourcePluralKafka:
case api.ResourceSingularRedis:
queries[database] = &metrics{
metric: "kafka_controller_kafkacontroller_activebrokercount",
metric: "redis_up",
label: label,
labelValue: labelValue,
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/monitor/dashboard/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func Run(f cmdutil.Factory, args []string, branch string, prom monitor.PromSvc)
log.Fatal("Enter database and grafana dashboard name as argument")
}

database := monitor.ConvertedResource(args[0])
database := monitor.ConvertedResourceToSingular(args[0])
dashboard := args[1]

url := getURL(branch, database, dashboard)
Expand Down
30 changes: 29 additions & 1 deletion pkg/monitor/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
api "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"
)

func ConvertedResource(resource string) string {
func ConvertedResourceToPlural(resource string) string {
// standardizing the resource name
res := strings.ToLower(resource)
switch res {
Expand All @@ -50,3 +50,31 @@ func ConvertedResource(resource string) string {
}
return res
}

func ConvertedResourceToSingular(resource string) string {
// standardizing the resource name
res := strings.ToLower(resource)
switch res {
case api.ResourceCodeElasticsearch, api.ResourcePluralElasticsearch, api.ResourceSingularElasticsearch:
res = api.ResourceSingularElasticsearch
case api.ResourceCodeKafka, api.ResourcePluralKafka, api.ResourceSingularKafka:
res = api.ResourceSingularKafka
case api.ResourceCodeMariaDB, api.ResourcePluralMariaDB, api.ResourceSingularMariaDB:
res = api.ResourceSingularMariaDB
case api.ResourceCodeMongoDB, api.ResourcePluralMongoDB, api.ResourceSingularMongoDB:
res = api.ResourceSingularMongoDB
case api.ResourceCodeMySQL, api.ResourcePluralMySQL, api.ResourceSingularMySQL:
res = api.ResourceSingularMySQL
case api.ResourceCodePerconaXtraDB, api.ResourcePluralPerconaXtraDB, api.ResourceSingularPerconaXtraDB:
res = api.ResourceSingularPerconaXtraDB
case api.ResourceCodePostgres, api.ResourcePluralPostgres, api.ResourceSingularPostgres:
res = api.ResourceSingularPostgres
case api.ResourceCodeProxySQL, api.ResourcePluralProxySQL, api.ResourceSingularProxySQL:
res = api.ResourceSingularProxySQL
case api.ResourceCodeRedis, api.ResourcePluralRedis, api.ResourceSingularRedis:
res = api.ResourceSingularRedis
default:
log.Fatalf("%s is not a valid resource type \n", resource)
}
return res
}

0 comments on commit 80a553f

Please sign in to comment.