Skip to content

Commit 23ec83d

Browse files
authored
Merge pull request #5 from mackerelio/fix-lint
use golangci-lint
2 parents 22155b0 + 42c4c27 commit 23ec83d

3 files changed

Lines changed: 21 additions & 21 deletions

File tree

.github/workflows/test.yml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,16 @@ on:
1111
env:
1212
DEBIAN_FRONTEND: noninteractive
1313
jobs:
14-
# TODO
15-
# It's intended for code migration, so it's now a comment
16-
# lint:
17-
# strategy:
18-
# matrix:
19-
# os: [ubuntu-latest]
20-
# runs-on: ${{ matrix.os }}
21-
# steps:
22-
# - uses: actions/checkout@v3
23-
# - uses: golangci/golangci-lint-action@v3
24-
# with:
25-
# args: --timeout 2m
14+
lint:
15+
strategy:
16+
matrix:
17+
os: [ubuntu-latest]
18+
runs-on: ${{ matrix.os }}
19+
steps:
20+
- uses: actions/checkout@v3
21+
- uses: golangci/golangci-lint-action@v3
22+
with:
23+
args: --timeout 2m
2624
test:
2725
strategy:
2826
matrix:

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
github.com/go-sql-driver/mysql v1.7.0
77
github.com/mackerelio/go-mackerel-plugin v0.1.4
88
github.com/stretchr/testify v1.8.1
9+
golang.org/x/text v0.3.7
910
)
1011

1112
require (
@@ -14,7 +15,6 @@ require (
1415
github.com/mackerelio/golib v1.2.1 // indirect
1516
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
1617
github.com/pmezard/go-difflib v1.0.0 // indirect
17-
golang.org/x/text v0.3.7 // indirect
1818
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
1919
gopkg.in/yaml.v3 v3.0.1 // indirect
2020
)

lib/mysql.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import (
1111
"strconv"
1212
"strings"
1313

14+
"golang.org/x/text/cases"
15+
"golang.org/x/text/language"
16+
1417
mp "github.com/mackerelio/go-mackerel-plugin"
1518
// MySQL Driver
1619
"github.com/go-sql-driver/mysql"
@@ -47,12 +50,12 @@ func init() {
4750
}
4851

4952
func (m *MySQLPlugin) defaultGraphdef() map[string]mp.Graphs {
50-
labelPrefix := strings.Title(strings.Replace(m.MetricKeyPrefix(), "mysql", "MySQL", -1))
53+
labelPrefix := cases.Title(language.Und, cases.NoLower).String(strings.Replace(m.MetricKeyPrefix(), "mysql", "MySQL", -1))
5154

5255
capacityMetrics := []mp.Metrics{
5356
{Name: "PercentageOfConnections", Label: "Percentage Of Connections", Diff: false, Stacked: false},
5457
}
55-
if m.DisableInnoDB != true {
58+
if !m.DisableInnoDB {
5659
capacityMetrics = append(capacityMetrics, mp.Metrics{
5760
Name: "PercentageOfBufferPool", Label: "Percentage Of Buffer Pool", Diff: false, Stacked: false,
5861
})
@@ -191,7 +194,7 @@ func (m *MySQLPlugin) fetchVersion(db *sql.DB) (version [3]int, err error) {
191194
version[2], _ = strconv.Atoi(xs[2])
192195
}
193196
}
194-
break
197+
break //nolint
195198
}
196199
if version[0] == 0 {
197200
err = errors.New("failed to get mysql version")
@@ -371,7 +374,7 @@ func (m *MySQLPlugin) convertInnodbStats(stat map[string]float64) {
371374

372375
func (m *MySQLPlugin) calculateCapacity(stat map[string]float64) {
373376
stat["PercentageOfConnections"] = 100.0 * stat["Threads_connected"] / stat["max_connections"]
374-
if m.DisableInnoDB != true {
377+
if !m.DisableInnoDB {
375378
stat["PercentageOfBufferPool"] = 100.0 * stat["database_pages"] / stat["pool_size"]
376379
}
377380
}
@@ -415,7 +418,7 @@ func (m *MySQLPlugin) FetchMetrics() (map[string]float64, error) {
415418
return nil, err
416419
}
417420

418-
if m.DisableInnoDB != true {
421+
if !m.DisableInnoDB {
419422
m.convertInnodbStats(stat)
420423
if !m.isAuroraReader {
421424
err := m.fetchShowInnodbStatus(db, stat)
@@ -475,7 +478,7 @@ func (m *MySQLPlugin) GraphDefinition() map[string]mp.Graphs {
475478
}
476479

477480
func (m *MySQLPlugin) addGraphdefWithInnoDBMetrics(graphdef map[string]mp.Graphs) map[string]mp.Graphs {
478-
labelPrefix := strings.Title(strings.Replace(m.MetricKeyPrefix(), "mysql", "MySQL", -1))
481+
labelPrefix := cases.Title(language.Und, cases.NoLower).String(strings.Replace(m.MetricKeyPrefix(), "mysql", "MySQL", -1))
479482
graphdef["innodb_rows"] = mp.Graphs{
480483
Label: labelPrefix + " innodb Rows",
481484
Unit: "float",
@@ -666,8 +669,7 @@ func (m *MySQLPlugin) addGraphdefWithInnoDBMetrics(graphdef map[string]mp.Graphs
666669
}
667670

668671
func (m *MySQLPlugin) addExtendedGraphdef(graphdef map[string]mp.Graphs) map[string]mp.Graphs {
669-
//TODO
670-
labelPrefix := strings.Title(strings.Replace(m.MetricKeyPrefix(), "mysql", "MySQL", -1))
672+
labelPrefix := cases.Title(language.Und, cases.NoLower).String(strings.Replace(m.MetricKeyPrefix(), "mysql", "MySQL", -1))
671673
graphdef["query_cache"] = mp.Graphs{
672674
Label: labelPrefix + " query Cache",
673675
Unit: "float",

0 commit comments

Comments
 (0)