From 80a553f0bb8e09322a2b394d83974188ee4bfd6b Mon Sep 17 00:00:00 2001 From: Arnob kumar saha Date: Wed, 31 Jan 2024 20:10:34 +0600 Subject: [PATCH] fix plural Signed-off-by: Arnob kumar saha --- pkg/monitor/alerts/db.go | 2 +- pkg/monitor/connection/db.go | 2 +- pkg/monitor/connection/helper.go | 32 ++++++++++++++++---------------- pkg/monitor/dashboard/db.go | 2 +- pkg/monitor/util.go | 30 +++++++++++++++++++++++++++++- 5 files changed, 48 insertions(+), 20 deletions(-) diff --git a/pkg/monitor/alerts/db.go b/pkg/monitor/alerts/db.go index f5fd45b60..4ab694d9c 100644 --- a/pkg/monitor/alerts/db.go +++ b/pkg/monitor/alerts/db.go @@ -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) } diff --git a/pkg/monitor/connection/db.go b/pkg/monitor/connection/db.go index 7190ef2d2..2b8d83c76 100644 --- a/pkg/monitor/connection/db.go +++ b/pkg/monitor/connection/db.go @@ -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 { diff --git a/pkg/monitor/connection/helper.go b/pkg/monitor/connection/helper.go index 21b39bd23..d801dd2a2 100644 --- a/pkg/monitor/connection/helper.go +++ b/pkg/monitor/connection/helper.go @@ -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, } diff --git a/pkg/monitor/dashboard/db.go b/pkg/monitor/dashboard/db.go index 8d950304d..247146187 100644 --- a/pkg/monitor/dashboard/db.go +++ b/pkg/monitor/dashboard/db.go @@ -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) diff --git a/pkg/monitor/util.go b/pkg/monitor/util.go index b1cb623ab..db7427218 100644 --- a/pkg/monitor/util.go +++ b/pkg/monitor/util.go @@ -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 { @@ -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 +}