Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ jobs:
- run: 'make check-deps'
- run:
name: "Install golangci-lint"
command: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.5.0
command: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.7.2
- run:
name: "golangci-lint/Linux"
# There are only 4 vCPUs available for this executor, so use only 4 instead of the default number
Expand All @@ -129,7 +129,7 @@ jobs:
- check-changed-files-or-halt
- run:
name: "Install golangci-lint"
command: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.5.0
command: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.7.2
- run:
name: "golangci-lint/macOS"
# There are only 4 vCPUs available for this executor, so use only 4 instead of the default number
Expand All @@ -143,7 +143,7 @@ jobs:
- check-changed-files-or-halt
- run:
name: "Install golangci-lint"
command: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.5.0
command: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.7.2
- run:
name: "golangci-lint/Windows"
# There are only 4 vCPUs available for this executor, so use only 4 instead of the default number
Expand Down
13 changes: 11 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ version: "2"

linters:
# Default set of linters.
# The value can be: `standard`, `all`, `none`, or `fast`.
# The value can be:
# - `standard`: https://golangci-lint.run/docs/linters/#enabled-by-default
# - `all`: enables all linters by default.
# - `none`: disables all linters by default.
# - `fast`: enables only linters considered as "fast" (`golangci-lint help linters --json | jq '[ .[] | select(.fast==true) ] | map(.name)'`).
# Default: standard
default: none

# Enable specific linter.
# https://golangci-lint.run/usage/linters/#enabled-by-default
enable:
- asasalint
- asciicheck
Expand Down Expand Up @@ -45,6 +48,7 @@ linters:
- unused
- usetesting

# All available settings of specific linters.
settings:
depguard:
# Rules to apply.
Expand Down Expand Up @@ -405,6 +409,7 @@ linters:
staticcheck:
# SAxxxx checks in https://staticcheck.dev/docs/configuration/options/#checks
# Example (to disable some checks): [ "all", "-SA1000", "-SA1001"]
# Run `GL_DEBUG=staticcheck golangci-lint run --enable=staticcheck` to see all available checks and enabled by config checks.
# Default: ["all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022"]
checks:
- all
Expand Down Expand Up @@ -517,6 +522,10 @@ linters:
- path: migrations/.*\.go$
text: don't use MixedCaps in package name

# revive:var-naming: Exclude check for package names that conflict with standard library package names (e.g., "net", "json", "http", "os")
- path: (.*)\.go$
text: conflict with Go standard library package names

# revive:exported
- path: (.+)\.go$
text: exported method .*\.(Init |SampleConfig |Gather |Start |Stop |GetState |SetState |SetParser |SetParserFunc |SetTranslator |Probe |Add |Push |Reset |Serialize |SerializeBatch |Get |Set |List |GetResolver |Apply |SetSerializer )should have comment or be unexported
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ vet:
.PHONY: lint-install
lint-install:
@echo "Installing golangci-lint"
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.5.0
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.7.2

@echo "Installing markdownlint"
npm install -g markdownlint-cli
Expand Down
8 changes: 6 additions & 2 deletions plugins/common/snmp/translator_netsnmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ func (n *netsnmpTranslator) snmpTranslateCall(oid string) (mibName string, oidNu
oidText = oidText[i+2:]
}

var b strings.Builder
for scanner.Scan() {
line := scanner.Text()

Expand All @@ -247,18 +248,21 @@ func (n *netsnmpTranslator) snmpTranslateCall(oid string) (mibName string, oidNu
if i := strings.Index(obj, "("); i != -1 {
obj = obj[i+1:]
if j := strings.Index(obj, ")"); j != -1 {
oidNum += "." + obj[:j]
b.WriteString(".")
b.WriteString(obj[:j])
} else {
return "", "", "", "", fmt.Errorf("getting OID number from: %s", obj)
}

} else {
oidNum += "." + obj
b.WriteString(".")
b.WriteString(obj)
}
}
break
}
}
oidNum = b.String()

return mibName, oidNum, oidText, conversion, nil
}
Expand Down
75 changes: 52 additions & 23 deletions plugins/inputs/gnmi/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,20 +268,25 @@ func (pi *pathInfo) relative(path *pathInfo, withNamespace bool) string {
}

segments := path.segments[len(pi.segments):len(path.segments)]
var r string
var b strings.Builder
if withNamespace && segments[0].namespace != "" {
r = segments[0].namespace + ":" + segments[0].id
b.WriteString(segments[0].namespace)
b.WriteString(":")
b.WriteString(segments[0].id)
} else {
r = segments[0].id
b.WriteString(segments[0].id)
}
for _, s := range segments[1:] {
b.WriteString("/")
if withNamespace && s.namespace != "" {
r += "/" + s.namespace + ":" + s.id
b.WriteString(s.namespace)
b.WriteString(":")
b.WriteString(s.id)
} else {
r += "/" + s.id
b.WriteString(s.id)
}
}
return r
return b.String()
}

func (pi *pathInfo) keepCommonPart(path *pathInfo) {
Expand Down Expand Up @@ -310,18 +315,22 @@ func (pi *pathInfo) dir() string {
return ""
}

var dir string
var b strings.Builder
if pi.origin != "" {
dir = pi.origin + ":"
b.WriteString(pi.origin)
b.WriteString(":")
}
for _, s := range pi.segments[:len(pi.segments)-1] {
b.WriteString("/")
if s.namespace != "" {
dir += "/" + s.namespace + ":" + s.id
b.WriteString(s.namespace)
b.WriteString(":")
b.WriteString(s.id)
} else {
dir += "/" + s.id
b.WriteString(s.id)
}
}
return dir
return b.String()
}

func (pi *pathInfo) base() string {
Expand All @@ -341,31 +350,37 @@ func (pi *pathInfo) path() (origin, path string) {
return pi.origin, "/"
}

var b strings.Builder
for _, s := range pi.segments {
path += "/" + s.id
b.WriteString("/")
b.WriteString(s.id)
}

return pi.origin, path
return pi.origin, b.String()
}

func (pi *pathInfo) fullPath() string {
var path string
var b strings.Builder
if pi.origin != "" {
path = pi.origin + ":"
b.WriteString(pi.origin)
b.WriteString(":")
}
if len(pi.segments) == 0 {
return path
return b.String()
}

for _, s := range pi.segments {
b.WriteString("/")
if s.namespace != "" {
path += "/" + s.namespace + ":" + s.id
b.WriteString(s.namespace)
b.WriteString(":")
b.WriteString(s.id)
} else {
path += "/" + s.id
b.WriteString(s.id)
}
}

return path
return b.String()
}

func (pi *pathInfo) String() string {
Expand All @@ -374,10 +389,13 @@ func (pi *pathInfo) String() string {
}

origin, path := pi.path()
var b strings.Builder
if origin != "" {
return origin + ":" + path
b.WriteString(origin)
b.WriteString(":")
}
return path
b.WriteString(path)
return b.String()
}

func (pi *pathInfo) tags(pathPrefix bool) map[string]string {
Expand All @@ -387,15 +405,26 @@ func (pi *pathInfo) tags(pathPrefix bool) map[string]string {
if pathPrefix && s.name != "" {
prefix = s.name + "_"
}
// precompute constant path prefix for this keySegment
pathPrefixStr := s.path + "/"

for k, v := range s.kv {
key := strings.ReplaceAll(prefix+k, "-", "_")
// build the key (prefix + k) and sanitize in one builder
var kb strings.Builder
kb.WriteString(prefix)
kb.WriteString(k)
key := strings.ReplaceAll(kb.String(), "-", "_")

// Use short-form of key if possible
if _, exists := tags[key]; !exists {
tags[key] = v
continue
}
tags[s.path+"/"+key] = v
// build full path/key only when needed
var fb strings.Builder
fb.WriteString(pathPrefixStr)
fb.WriteString(key)
tags[fb.String()] = v
}
}

Expand Down
10 changes: 6 additions & 4 deletions plugins/inputs/intel_rdt/intel_rdt.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,20 +355,22 @@ func shutDownPqos(pqos *exec.Cmd) error {

func createArgCores(cores []string) string {
allGroupsArg := "--mon-core="
var b strings.Builder
for _, coreGroup := range cores {
argGroup := createArgsForGroups(strings.Split(coreGroup, ","))
allGroupsArg = allGroupsArg + argGroup
b.WriteString(argGroup)
}
return allGroupsArg
return allGroupsArg + b.String()
}

func createArgProcess(processPIDs map[string]string) string {
allPIDsArg := "--mon-pid="
var b strings.Builder
for _, PIDs := range processPIDs {
argPIDs := createArgsForGroups(strings.Split(PIDs, ","))
allPIDsArg = allPIDsArg + argPIDs
b.WriteString(argPIDs)
}
return allPIDsArg
return allPIDsArg + b.String()
}

func createArgsForGroups(coresOrPIDs []string) string {
Expand Down
13 changes: 8 additions & 5 deletions plugins/inputs/modbus/modbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/url"
"path/filepath"
"strconv"
"strings"
"time"

mb "github.com/grid-x/modbus"
Expand Down Expand Up @@ -118,13 +119,15 @@ func (m *Modbus) SampleConfig() string {
&m.configurationPerMetric,
}

totalConfig := sampleConfigStart
var b strings.Builder
b.WriteString(sampleConfigStart)
for _, c := range configs {
totalConfig += c.sampleConfigPart() + "\n"
b.WriteString(c.sampleConfigPart())
b.WriteString("\n")
}
totalConfig += "\n"
totalConfig += sampleConfigEnd
return totalConfig
b.WriteString("\n")
b.WriteString(sampleConfigEnd)
return b.String()
}

func (m *Modbus) Init() error {
Expand Down
14 changes: 7 additions & 7 deletions plugins/inputs/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -1374,8 +1374,6 @@ func (m *Mysql) gatherInnoDBMetrics(db *sql.DB, servtag string, acc telegraf.Acc
// gatherPerfSummaryPerAccountPerEvent can be used to fetch enabled metrics from
// performance_schema.events_statements_summary_by_account_by_event_name
func (m *Mysql) gatherPerfSummaryPerAccountPerEvent(db *sql.DB, servtag string, acc telegraf.Accumulator) error {
sqlQuery := perfSummaryPerAccountPerEvent

var rows *sql.Rows
var err error

Expand Down Expand Up @@ -1412,17 +1410,19 @@ func (m *Mysql) gatherPerfSummaryPerAccountPerEvent(db *sql.DB, servtag string,
var events []interface{}
// if we have perf_summary_events set - select only listed events (adding filter criteria for rows)
if len(m.PerfSummaryEvents) > 0 {
sqlQuery += " WHERE EVENT_NAME IN ("
var sqlQueryBuilder strings.Builder
sqlQueryBuilder.WriteString(perfSummaryPerAccountPerEvent)
sqlQueryBuilder.WriteString(" WHERE EVENT_NAME IN (")
for i, eventName := range m.PerfSummaryEvents {
if i > 0 {
sqlQuery += ", "
sqlQueryBuilder.WriteString(", ")
}
sqlQuery += "?"
sqlQueryBuilder.WriteString("?")
events = append(events, eventName)
}
sqlQuery += ")"
sqlQueryBuilder.WriteString(")")

rows, err = db.Query(sqlQuery, events...)
rows, err = db.Query(sqlQueryBuilder.String(), events...)
} else {
// otherwise no filter, hence, select all rows
rows, err = db.Query(perfSummaryPerAccountPerEvent)
Expand Down
17 changes: 9 additions & 8 deletions plugins/inputs/opcua_listener/opcua_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package opcua_listener
import (
"context"
"fmt"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -230,12 +231,12 @@ func TestSubscribeClientIntegration(t *testing.T) {
}

case <-ctx.Done():
msg := ""
var sb strings.Builder
for _, tag := range tagsRemaining {
msg += tag + ", "
sb.WriteString(tag)
sb.WriteString(", ")
}

t.Errorf("Tags %s are remaining without a received value", msg)
t.Errorf("Tags %s are remaining without a received value", sb.String())
return
}
}
Expand Down Expand Up @@ -371,12 +372,12 @@ func TestSubscribeClientIntegrationAdditionalFields(t *testing.T) {
}

case <-ctx.Done():
msg := ""
var sb strings.Builder
for _, tag := range tagsRemaining {
msg += tag + ", "
sb.WriteString(tag)
sb.WriteString(", ")
}

t.Errorf("Tags %s are remaining without a received value", msg)
t.Errorf("Tags %s are remaining without a received value", sb.String())
return
}
}
Expand Down
Loading
Loading