Skip to content

Commit

Permalink
chore: Update go to v1.23.0 (#15766)
Browse files Browse the repository at this point in the history
Co-authored-by: Pawel Zak <pawel.zak.pawel@gmail.com>
  • Loading branch information
srebhan and zak-pawel authored Aug 30, 2024
1 parent 9e3e220 commit b2967cb
Show file tree
Hide file tree
Showing 52 changed files with 376 additions and 306 deletions.
21 changes: 14 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ executors:
working_directory: '/go/src/github.com/influxdata/telegraf'
resource_class: large
docker:
- image: 'quay.io/influxdb/telegraf-ci:1.22.6'
- image: 'quay.io/influxdb/telegraf-ci:1.23.0'
environment:
GOFLAGS: -p=4
mac:
Expand Down Expand Up @@ -106,21 +106,26 @@ jobs:
- run: 'make check-deps'
- run:
name: "Install golangci-lint"
command: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1
command: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.3
- run:
name: "golangci-lint/Linux"
command: GOGC=80 GOMEMLIMIT=6656MiB /go/bin/golangci-lint run --verbose
# There are only 4 vCPUs available for this executor, so use only 4 instead of the default number
# (the OS may report the number of CPUs on the host instead of the number of CPUs available to the guest).
command: GOGC=80 GOMEMLIMIT=6144MiB /go/bin/golangci-lint run --verbose --timeout=30m --concurrency 4
no_output_timeout: 30m
lint-macos:
executor: telegraf-ci
steps:
- checkout
- check-changed-files-or-halt
- run:
name: "Install golangci-lint"
command: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1
command: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.3
- run:
name: "golangci-lint/macOS"
command: GOGC=80 GOMEMLIMIT=6656MiB GOOS=darwin /go/bin/golangci-lint run --verbose --timeout=30m
# There are only 4 vCPUs available for this executor, so use only 4 instead of the default number
# (the OS may report the number of CPUs on the host instead of the number of CPUs available to the guest).
command: GOGC=80 GOMEMLIMIT=6144MiB GOOS=darwin /go/bin/golangci-lint run --verbose --timeout=30m --concurrency 4
no_output_timeout: 30m
lint-windows:
executor: telegraf-ci
Expand All @@ -129,10 +134,12 @@ jobs:
- check-changed-files-or-halt
- run:
name: "Install golangci-lint"
command: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1
command: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.3
- run:
name: "golangci-lint/Windows"
command: GOGC=80 GOMEMLIMIT=6656MiB GOOS=windows /go/bin/golangci-lint run --verbose --timeout=30m
# There are only 4 vCPUs available for this executor, so use only 4 instead of the default number
# (the OS may report the number of CPUs on the host instead of the number of CPUs available to the guest).
command: GOGC=80 GOMEMLIMIT=6144MiB GOOS=windows /go/bin/golangci-lint run --verbose --timeout=30m --concurrency 4
no_output_timeout: 30m
test-go-linux:
executor: telegraf-ci
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/readme-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
steps:
- uses: actions/setup-go@v5
with:
go-version: '1.22.6'
go-version: '1.23.0'
- uses: actions/checkout@v4
with:
fetch-depth: 0
Expand Down
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ linters:
- errcheck
- errname
- errorlint
- exportloopref
- gocheckcompilerdirectives
- gocritic
- goprintffuncname
Expand Down
6 changes: 3 additions & 3 deletions 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/cmd/golangci-lint@v1.59.1
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.3

@echo "Installing markdownlint"
npm install -g markdownlint-cli
Expand Down Expand Up @@ -257,8 +257,8 @@ plugins/parsers/influx/machine.go: plugins/parsers/influx/machine.go.rl

.PHONY: ci
ci:
docker build -t quay.io/influxdb/telegraf-ci:1.22.6 - < scripts/ci.docker
docker push quay.io/influxdb/telegraf-ci:1.22.6
docker build -t quay.io/influxdb/telegraf-ci:1.23.0 - < scripts/ci.docker
docker push quay.io/influxdb/telegraf-ci:1.23.0

.PHONY: install
install: $(buildbin)
Expand Down
2 changes: 1 addition & 1 deletion cmd/telegraf/telegraf.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ func (t *Telegraf) runAgent(ctx context.Context, reloadConfig bool) error {
log.Printf("I! Found %d secrets...", c.NumberSecrets)
msg := fmt.Sprintf("Insufficient lockable memory %dkb when %dkb is required.", available, required)
msg += " Please increase the limit for Telegraf in your Operating System!"
log.Printf("W! " + color.RedString(msg))
log.Print("W! " + color.RedString(msg))
}
}
ag := agent.NewAgent(c)
Expand Down
6 changes: 3 additions & 3 deletions cmd/telegraf/telegraf_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import (
func getLockedMemoryLimit() uint64 {
handle := windows.CurrentProcess()

var min, max uintptr
var low, high uintptr
var flag uint32
windows.GetProcessWorkingSetSizeEx(handle, &min, &max, &flag)
windows.GetProcessWorkingSetSizeEx(handle, &low, &high, &flag)

return uint64(max)
return uint64(high)
}

func (t *Telegraf) Run() error {
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1585,7 +1585,7 @@ func (c *Config) setLocalMissingTomlFieldTracker(counter map[string]int) {
// All other elements are subtables of their respective plugin and
// should just be hit once anyway. Therefore, we mark them with a
// high number to handle them correctly later.
pt := reflect.PtrTo(t)
pt := reflect.PointerTo(t)
root := pt.Implements(reflect.TypeOf((*telegraf.Input)(nil)).Elem())
root = root || pt.Implements(reflect.TypeOf((*telegraf.ServiceInput)(nil)).Elem())
root = root || pt.Implements(reflect.TypeOf((*telegraf.Output)(nil)).Elem())
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/influxdata/telegraf

go 1.22.0
go 1.23.0

require (
cloud.google.com/go/bigquery v1.62.0
Expand Down
5 changes: 1 addition & 4 deletions internal/globpath/globpath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ func TestFindNestedTextFile(t *testing.T) {
}

func TestMatch_ErrPermission(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Skipping Unix only test")
}

tests := []struct {
input string
expected []string
Expand All @@ -106,6 +102,7 @@ func TestMatch_ErrPermission(t *testing.T) {
}

func TestWindowsSeparator(t *testing.T) {
//nolint:staticcheck // Silence linter for now as we plan to reenable tests for Windows later
if runtime.GOOS != "windows" {
t.Skip("Skipping Windows only test")
}
Expand Down
10 changes: 5 additions & 5 deletions internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ func SnakeCase(in string) string {

// RandomSleep will sleep for a random amount of time up to max.
// If the shutdown channel is closed, it will return before it has finished sleeping.
func RandomSleep(max time.Duration, shutdown chan struct{}) {
sleepDuration := RandomDuration(max)
func RandomSleep(limit time.Duration, shutdown chan struct{}) {
sleepDuration := RandomDuration(limit)
if sleepDuration == 0 {
return
}
Expand All @@ -140,12 +140,12 @@ func RandomSleep(max time.Duration, shutdown chan struct{}) {
}

// RandomDuration returns a random duration between 0 and max.
func RandomDuration(max time.Duration) time.Duration {
if max == 0 {
func RandomDuration(limit time.Duration) time.Duration {
if limit == 0 {
return 0
}

return time.Duration(rand.Int63n(max.Nanoseconds())) //nolint:gosec // G404: not security critical
return time.Duration(rand.Int63n(limit.Nanoseconds())) //nolint:gosec // G404: not security critical
}

// SleepContext sleeps until the context is closed or the duration is reached.
Expand Down
2 changes: 1 addition & 1 deletion internal/internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func TestCompressWithGzipErrorPropagationCopy(t *testing.T) {

rc := CompressWithGzip(r)
n, err := io.Copy(io.Discard, rc)
require.Greater(t, n, int64(0))
require.Positive(t, n)
require.ErrorIs(t, err, expected)
require.NoError(t, rc.Close())
}
Expand Down
6 changes: 3 additions & 3 deletions plugins/common/kafka/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (

func TestBackoffFunc(t *testing.T) {
b := 250 * time.Millisecond
max := 1100 * time.Millisecond
limit := 1100 * time.Millisecond

f := makeBackoffFunc(b, max)
f := makeBackoffFunc(b, limit)
require.Equal(t, b, f(0, 0))
require.Equal(t, b*2, f(1, 0))
require.Equal(t, b*4, f(2, 0))
require.Equal(t, max, f(3, 0)) // would be 2000 but that's greater than max
require.Equal(t, limit, f(3, 0)) // would be 2000 but that's greater than max

f = makeBackoffFunc(b, 0) // max = 0 means no max
require.Equal(t, b*8, f(3, 0)) // with no max, it's 2000
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/activemq/activemq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func TestURLs(t *testing.T) {
require.NoError(t, err)
default:
w.WriteHeader(http.StatusNotFound)
t.Fatalf("unexpected path: " + r.URL.Path)
t.Fatalf("unexpected path: %s", r.URL.Path)
}
})

Expand Down
1 change: 1 addition & 0 deletions plugins/inputs/beanstalkd/beanstalkd.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ func (b *Beanstalkd) gatherTubeStats(connection *textproto.Conn, tube string, ac
}

func runQuery(connection *textproto.Conn, cmd string, result interface{}) error {
//nolint:govet // Keep dynamic command as the passed string is constant
requestID, err := connection.Cmd(cmd)
if err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,21 +314,18 @@ func (cms *CloudWatchMetricStreams) composeMetrics(data Data) {

// Rename Statistics to match the CloudWatch API if in API Compatability mode
if cms.APICompatability {
max, ok := fields["max"]
if ok {
fields["maximum"] = max
if v, ok := fields["max"]; ok {
fields["maximum"] = v
delete(fields, "max")
}

min, ok := fields["min"]
if ok {
fields["minimum"] = min
if v, ok := fields["min"]; ok {
fields["minimum"] = v
delete(fields, "min")
}

count, ok := fields["count"]
if ok {
fields["samplecount"] = count
if v, ok := fields["count"]; ok {
fields["samplecount"] = v
delete(fields, "count")
}
}
Expand Down
6 changes: 3 additions & 3 deletions plugins/inputs/conntrack/conntrack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ func TestConfigsUsed(t *testing.T) {
dfltFiles = []string{cntFname, maxFname}

count := 1234321
max := 9999999
limit := 9999999
require.NoError(t, os.WriteFile(cntFile.Name(), []byte(strconv.Itoa(count)), 0640))
require.NoError(t, os.WriteFile(maxFile.Name(), []byte(strconv.Itoa(max)), 0640))
require.NoError(t, os.WriteFile(maxFile.Name(), []byte(strconv.Itoa(limit)), 0640))
c := &Conntrack{}
require.NoError(t, c.Init())
acc := &testutil.Accumulator{}
Expand All @@ -94,7 +94,7 @@ func TestConfigsUsed(t *testing.T) {
acc.AssertContainsFields(t, inputName,
map[string]interface{}{
fix(cntFname): float64(count),
fix(maxFname): float64(max),
fix(maxFname): float64(limit),
})
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/directory_monitor/directory_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (monitor *DirectoryMonitor) read(filePath string) {

// Handle a file read error. We don't halt execution but do document, log, and move the problematic file.
if err != nil {
monitor.Log.Errorf("Error while reading file: '" + filePath + "'. " + err.Error())
monitor.Log.Errorf("Error while reading file: %q: %v", filePath, err)
monitor.filesDropped.Incr(1)
monitor.filesDroppedDir.Incr(1)
if monitor.ErrorDirectory != "" {
Expand Down Expand Up @@ -343,7 +343,7 @@ func (monitor *DirectoryMonitor) moveFile(srcPath string, dstBaseDir string) {
dstPath := filepath.Join(dstBaseDir, basePath)
err := os.MkdirAll(filepath.Dir(dstPath), 0750)
if err != nil {
monitor.Log.Errorf("Error creating directory hierarchy for " + srcPath + ". Error: " + err.Error())
monitor.Log.Errorf("Error creating directory hierarchy for %q: %v", srcPath, err)
}

inputFile, err := os.Open(srcPath)
Expand Down
1 change: 1 addition & 0 deletions plugins/inputs/exec/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ func TestTruncate(t *testing.T) {
}

func TestRemoveCarriageReturns(t *testing.T) {
//nolint:staticcheck // Silence linter for now as we plan to reenable tests for Windows later
if runtime.GOOS == "windows" {
// Test that all carriage returns are removed
for _, test := range crTests {
Expand Down
1 change: 1 addition & 0 deletions plugins/inputs/filecount/filecount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ func getTestdataDir() string {
var chunks []string
var testDirectory string

//nolint:staticcheck // Silence linter for now as we plan to reenable tests for Windows later
if runtime.GOOS == "windows" {
chunks = strings.Split(dir, "\\")
testDirectory = strings.Join(chunks[:], "\\") + "\\testdata"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func startMultipleItemGCSServer(t *testing.T) *httptest.Server {
require.NoError(t, err)
} else {
w.WriteHeader(http.StatusNotFound)
t.Fatalf("unexpected path: " + r.URL.Path)
t.Fatalf("unexpected path: %s", r.URL.Path)
}

default:
Expand Down Expand Up @@ -399,7 +399,7 @@ func serveJSONText(w http.ResponseWriter, jsonText []byte) {

func failPath(path string, t *testing.T, w http.ResponseWriter) {
w.WriteHeader(http.StatusNotFound)
t.Fatalf("unexpected path: " + path)
t.Fatalf("unexpected path: %s", path)
}

func parseJSONFromFile(t *testing.T, jsonFilePath string) map[string]interface{} {
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/http_response/http_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ func (h *HTTPResponse) httpGather(cl client) (map[string]interface{}, map[string

// Set result in case of a body read error
func (h *HTTPResponse) setBodyReadError(errorMsg string, bodyBytes []byte, fields map[string]interface{}, tags map[string]string) {
h.Log.Debugf(errorMsg)
h.Log.Debug(errorMsg)
setResult("body_read_error", fields, tags)
fields["content_length"] = len(bodyBytes)
if h.ResponseStringMatch != "" {
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/intel_pmu/intel_pmu.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,11 @@ func readMaxFD(reader fileInfoProvider) (uint64, error) {
if err != nil {
return 0, fmt.Errorf("cannot open file %q: %w", fileMaxPath, err)
}
max, err := strconv.ParseUint(strings.Trim(string(buf), "\n "), 10, 64)
limit, err := strconv.ParseUint(strings.Trim(string(buf), "\n "), 10, 64)
if err != nil {
return 0, fmt.Errorf("cannot parse file content of %q: %w", fileMaxPath, err)
}
return max, nil
return limit, nil
}

func checkFiles(paths []string, fileInfo fileInfoProvider) error {
Expand Down
Loading

0 comments on commit b2967cb

Please sign in to comment.