From 20e683fdec87da446531bd21aed47e814e7e2e96 Mon Sep 17 00:00:00 2001 From: Nir Gilboa Date: Mon, 13 Apr 2020 17:16:55 +0300 Subject: [PATCH] Rename metric to replication_group_member_info, avoid unnecessary iteration, remove duplicate comment Signed-off-by: Nir Gilboa --- .../perf_schema_replication_group_members.go | 16 +++++----------- ...perf_schema_replication_group_members_test.go | 1 - 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/collector/perf_schema_replication_group_members.go b/collector/perf_schema_replication_group_members.go index 148cdfcb..6e49ff68 100644 --- a/collector/perf_schema_replication_group_members.go +++ b/collector/perf_schema_replication_group_members.go @@ -66,17 +66,19 @@ func (ScrapePerfReplicationGroupMembers) Scrape(ctx context.Context, db *sql.DB, return err } + var labelNames = make([]string, len(columnNames)) var values = make([]string, len(columnNames)) - for i := range columnNames { + for i, columnName := range columnNames { + labelNames[i] = strings.ToLower(columnName) values[i] = string(*scanArgs[i].(*sql.RawBytes)) } var performanceSchemaReplicationGroupMembersMemberDesc = prometheus.NewDesc( - prometheus.BuildFQName(namespace, performanceSchema, "replication_group_member"), + prometheus.BuildFQName(namespace, performanceSchema, "replication_group_member_info"), "Information about the replication group member: "+ "channel_name, member_id, member_host, member_port, member_state. "+ "(member_role and member_version where available)", - toLowerCase(columnNames), nil, + labelNames, nil, ) ch <- prometheus.MustNewConstMetric(performanceSchemaReplicationGroupMembersMemberDesc, @@ -86,13 +88,5 @@ func (ScrapePerfReplicationGroupMembers) Scrape(ctx context.Context, db *sql.DB, } -func toLowerCase(original []string) []string { - lowerCase := make([]string, len(original)) - for i, v := range original { - lowerCase[i] = strings.ToLower(v) - } - return lowerCase -} - // check interface var _ Scraper = ScrapePerfReplicationGroupMembers{} diff --git a/collector/perf_schema_replication_group_members_test.go b/collector/perf_schema_replication_group_members_test.go index fc11f9f6..cf2b841b 100644 --- a/collector/perf_schema_replication_group_members_test.go +++ b/collector/perf_schema_replication_group_members_test.go @@ -70,7 +70,6 @@ func TestScrapePerfReplicationGroupMembers(t *testing.T) { } }) - // Ensure all SQL queries were executed. // Ensure all SQL queries were executed. if err := mock.ExpectationsWereMet(); err != nil { t.Errorf("there were unfulfilled exceptions: %s", err)