diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 116f8b8..64612c8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,18 +11,16 @@ on: env: DEBIAN_FRONTEND: noninteractive jobs: -# TODO -# It's intended for code migration, so it's now a comment -# lint: -# strategy: -# matrix: -# os: [ubuntu-latest] -# runs-on: ${{ matrix.os }} -# steps: -# - uses: actions/checkout@v3 -# - uses: golangci/golangci-lint-action@v3 -# with: -# args: --timeout 2m + lint: + strategy: + matrix: + os: [ubuntu-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v3 + - uses: golangci/golangci-lint-action@v3 + with: + args: --timeout 2m test: strategy: matrix: diff --git a/go.mod b/go.mod index d52130b..5e07722 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/go-sql-driver/mysql v1.7.0 github.com/mackerelio/go-mackerel-plugin v0.1.4 github.com/stretchr/testify v1.8.1 + golang.org/x/text v0.3.7 ) require ( @@ -14,7 +15,6 @@ require ( github.com/mackerelio/golib v1.2.1 // indirect github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/text v0.3.7 // indirect gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/lib/mysql.go b/lib/mysql.go index f95b94d..a169c52 100644 --- a/lib/mysql.go +++ b/lib/mysql.go @@ -11,6 +11,9 @@ import ( "strconv" "strings" + "golang.org/x/text/cases" + "golang.org/x/text/language" + mp "github.com/mackerelio/go-mackerel-plugin" // MySQL Driver "github.com/go-sql-driver/mysql" @@ -47,12 +50,12 @@ func init() { } func (m *MySQLPlugin) defaultGraphdef() map[string]mp.Graphs { - labelPrefix := strings.Title(strings.Replace(m.MetricKeyPrefix(), "mysql", "MySQL", -1)) + labelPrefix := cases.Title(language.Und, cases.NoLower).String(strings.Replace(m.MetricKeyPrefix(), "mysql", "MySQL", -1)) capacityMetrics := []mp.Metrics{ {Name: "PercentageOfConnections", Label: "Percentage Of Connections", Diff: false, Stacked: false}, } - if m.DisableInnoDB != true { + if !m.DisableInnoDB { capacityMetrics = append(capacityMetrics, mp.Metrics{ Name: "PercentageOfBufferPool", Label: "Percentage Of Buffer Pool", Diff: false, Stacked: false, }) @@ -191,7 +194,7 @@ func (m *MySQLPlugin) fetchVersion(db *sql.DB) (version [3]int, err error) { version[2], _ = strconv.Atoi(xs[2]) } } - break + break //nolint } if version[0] == 0 { err = errors.New("failed to get mysql version") @@ -371,7 +374,7 @@ func (m *MySQLPlugin) convertInnodbStats(stat map[string]float64) { func (m *MySQLPlugin) calculateCapacity(stat map[string]float64) { stat["PercentageOfConnections"] = 100.0 * stat["Threads_connected"] / stat["max_connections"] - if m.DisableInnoDB != true { + if !m.DisableInnoDB { stat["PercentageOfBufferPool"] = 100.0 * stat["database_pages"] / stat["pool_size"] } } @@ -415,7 +418,7 @@ func (m *MySQLPlugin) FetchMetrics() (map[string]float64, error) { return nil, err } - if m.DisableInnoDB != true { + if !m.DisableInnoDB { m.convertInnodbStats(stat) if !m.isAuroraReader { err := m.fetchShowInnodbStatus(db, stat) @@ -475,7 +478,7 @@ func (m *MySQLPlugin) GraphDefinition() map[string]mp.Graphs { } func (m *MySQLPlugin) addGraphdefWithInnoDBMetrics(graphdef map[string]mp.Graphs) map[string]mp.Graphs { - labelPrefix := strings.Title(strings.Replace(m.MetricKeyPrefix(), "mysql", "MySQL", -1)) + labelPrefix := cases.Title(language.Und, cases.NoLower).String(strings.Replace(m.MetricKeyPrefix(), "mysql", "MySQL", -1)) graphdef["innodb_rows"] = mp.Graphs{ Label: labelPrefix + " innodb Rows", Unit: "float", @@ -666,8 +669,7 @@ func (m *MySQLPlugin) addGraphdefWithInnoDBMetrics(graphdef map[string]mp.Graphs } func (m *MySQLPlugin) addExtendedGraphdef(graphdef map[string]mp.Graphs) map[string]mp.Graphs { - //TODO - labelPrefix := strings.Title(strings.Replace(m.MetricKeyPrefix(), "mysql", "MySQL", -1)) + labelPrefix := cases.Title(language.Und, cases.NoLower).String(strings.Replace(m.MetricKeyPrefix(), "mysql", "MySQL", -1)) graphdef["query_cache"] = mp.Graphs{ Label: labelPrefix + " query Cache", Unit: "float",