Skip to content

Commit

Permalink
chore: Fix linter findings for revive:exported in `plugins/inputs/l…
Browse files Browse the repository at this point in the history
…*` (#16167)
  • Loading branch information
zak-pawel authored Nov 12, 2024
1 parent 54dcd2d commit 942d2b3
Show file tree
Hide file tree
Showing 31 changed files with 1,112 additions and 1,044 deletions.
19 changes: 19 additions & 0 deletions internal/env.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package internal

import "os"

// GetProcPath returns the path stored in HOST_PROC env variable, or /proc if HOST_PROC has not been set.
func GetProcPath() string {
if hostProc := os.Getenv("HOST_PROC"); hostProc != "" {
return hostProc
}
return "/proc"
}

// GetSysPath returns the path stored in HOST_SYS env variable, or /sys if HOST_SYS has not been set.
func GetSysPath() string {
if hostSys := os.Getenv("HOST_SYS"); hostSys != "" {
return hostSys
}
return "/sys"
}
22 changes: 3 additions & 19 deletions plugins/inputs/bond/bond.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,13 @@ import (
"strings"

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/internal"
"github.com/influxdata/telegraf/plugins/inputs"
)

//go:embed sample.conf
var sampleConfig string

const (
defaultHostProc = "/proc"
defaultHostSys = "/sys"
envProc = "HOST_PROC"
envSys = "HOST_SYS"
)

type Bond struct {
HostProc string `toml:"host_proc"`
HostSys string `toml:"host_sys"`
Expand Down Expand Up @@ -286,21 +280,11 @@ func (bond *Bond) gatherSlavePart(bondName, rawFile string, acc telegraf.Accumul
// if it is empty then try read from env variable
func (bond *Bond) loadPaths() {
if bond.HostProc == "" {
bond.HostProc = proc(envProc, defaultHostProc)
bond.HostProc = internal.GetProcPath()
}
if bond.HostSys == "" {
bond.HostSys = proc(envSys, defaultHostSys)
}
}

// proc can be used to read file paths from env
func proc(env, path string) string {
// try to read full file path
if p := os.Getenv(env); p != "" {
return p
bond.HostSys = internal.GetSysPath()
}
// return default path
return path
}

func (bond *Bond) listInterfaces() ([]string, error) {
Expand Down
58 changes: 55 additions & 3 deletions plugins/inputs/dpdk/mocks/conn.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugins/inputs/intel_baseband/sock_connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

mocks "github.com/influxdata/telegraf/plugins/inputs/intel_baseband/mock"
"github.com/influxdata/telegraf/plugins/inputs/intel_baseband/mocks"
)

func TestWriteCommandToSocket(t *testing.T) {
Expand Down
Loading

0 comments on commit 942d2b3

Please sign in to comment.