Skip to content

Commit

Permalink
chore: Fix linter findings for revive:exported in `plugins/inputs/p…
Browse files Browse the repository at this point in the history
  • Loading branch information
zak-pawel authored Dec 17, 2024
1 parent 3b87986 commit e2b5a99
Show file tree
Hide file tree
Showing 38 changed files with 777 additions and 852 deletions.
18 changes: 9 additions & 9 deletions plugins/inputs/p4runtime/p4runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func createEntityCounterEntry(
}
}

func NewTestP4RuntimeClient(
func newTestP4RuntimeClient(
p4RuntimeClient *fakeP4RuntimeClient,
addr string,
t *testing.T,
Expand Down Expand Up @@ -102,7 +102,7 @@ func TestErrorGetP4Info(t *testing.T) {
listener, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(t, err)

plugin := NewTestP4RuntimeClient(p4RtClient, listener.Addr().String(), t)
plugin := newTestP4RuntimeClient(p4RtClient, listener.Addr().String(), t)

var acc testutil.Accumulator
require.Error(t, plugin.Gather(&acc))
Expand Down Expand Up @@ -245,7 +245,7 @@ func TestOneCounterRead(t *testing.T) {
listener, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(t, err)

plugin := NewTestP4RuntimeClient(p4RtClient, listener.Addr().String(), t)
plugin := newTestP4RuntimeClient(p4RtClient, listener.Addr().String(), t)

var acc testutil.Accumulator
require.NoError(t, plugin.Gather(&acc))
Expand Down Expand Up @@ -333,7 +333,7 @@ func TestMultipleEntitiesSingleCounterRead(t *testing.T) {
listener, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(t, err)

plugin := NewTestP4RuntimeClient(p4RtClient, listener.Addr().String(), t)
plugin := newTestP4RuntimeClient(p4RtClient, listener.Addr().String(), t)

var acc testutil.Accumulator
require.NoError(t, plugin.Gather(&acc))
Expand Down Expand Up @@ -425,7 +425,7 @@ func TestSingleEntitiesMultipleCounterRead(t *testing.T) {
listener, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(t, err)

plugin := NewTestP4RuntimeClient(p4RtClient, listener.Addr().String(), t)
plugin := newTestP4RuntimeClient(p4RtClient, listener.Addr().String(), t)

var acc testutil.Accumulator
require.NoError(t, plugin.Gather(&acc))
Expand Down Expand Up @@ -457,7 +457,7 @@ func TestNoCountersAvailable(t *testing.T) {
listener, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(t, err)

plugin := NewTestP4RuntimeClient(p4RtClient, listener.Addr().String(), t)
plugin := newTestP4RuntimeClient(p4RtClient, listener.Addr().String(), t)

var acc testutil.Accumulator
require.NoError(t, plugin.Gather(&acc))
Expand All @@ -484,7 +484,7 @@ func TestFilterCounters(t *testing.T) {
listener, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(t, err)

plugin := NewTestP4RuntimeClient(p4RtClient, listener.Addr().String(), t)
plugin := newTestP4RuntimeClient(p4RtClient, listener.Addr().String(), t)

plugin.CounterNamesInclude = []string{"oof"}

Expand Down Expand Up @@ -534,7 +534,7 @@ func TestFailReadCounterEntryFromEntry(t *testing.T) {
listener, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(t, err)

plugin := NewTestP4RuntimeClient(p4RtClient, listener.Addr().String(), t)
plugin := newTestP4RuntimeClient(p4RtClient, listener.Addr().String(), t)

var acc testutil.Accumulator
require.NoError(t, plugin.Gather(&acc))
Expand Down Expand Up @@ -577,7 +577,7 @@ func TestFailReadAllEntries(t *testing.T) {
listener, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(t, err)

plugin := NewTestP4RuntimeClient(p4RtClient, listener.Addr().String(), t)
plugin := newTestP4RuntimeClient(p4RtClient, listener.Addr().String(), t)

var acc testutil.Accumulator
require.NoError(t, plugin.Gather(&acc))
Expand Down
72 changes: 36 additions & 36 deletions plugins/inputs/passenger/passenger.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,8 @@ import (
//go:embed sample.conf
var sampleConfig string

type passenger struct {
Command string
}

func (p *passenger) parseCommand() (string, []string) {
var arguments []string
if !strings.Contains(p.Command, " ") {
return p.Command, arguments
}

arguments = strings.Split(p.Command, " ")
if len(arguments) == 1 {
return arguments[0], arguments[1:]
}

return arguments[0], arguments[1:]
type Passenger struct {
Command string `toml:"command"`
}

type info struct {
Expand Down Expand Up @@ -91,6 +77,39 @@ type process struct {
ProcessGroupID string `xml:"process_group_id"`
}

func (*Passenger) SampleConfig() string {
return sampleConfig
}

func (p *Passenger) Gather(acc telegraf.Accumulator) error {
if p.Command == "" {
p.Command = "passenger-status -v --show=xml"
}

cmd, args := p.parseCommand()
out, err := exec.Command(cmd, args...).Output()

if err != nil {
return err
}

return importMetric(out, acc)
}

func (p *Passenger) parseCommand() (string, []string) {
var arguments []string
if !strings.Contains(p.Command, " ") {
return p.Command, arguments
}

arguments = strings.Split(p.Command, " ")
if len(arguments) == 1 {
return arguments[0], arguments[1:]
}

return arguments[0], arguments[1:]
}

func (p *process) getUptime() int64 {
if p.Uptime == "" {
return 0
Expand Down Expand Up @@ -131,25 +150,6 @@ func (p *process) getUptime() int64 {
return uptime
}

func (*passenger) SampleConfig() string {
return sampleConfig
}

func (p *passenger) Gather(acc telegraf.Accumulator) error {
if p.Command == "" {
p.Command = "passenger-status -v --show=xml"
}

cmd, args := p.parseCommand()
out, err := exec.Command(cmd, args...).Output()

if err != nil {
return err
}

return importMetric(out, acc)
}

func importMetric(stat []byte, acc telegraf.Accumulator) error {
var p info

Expand Down Expand Up @@ -231,6 +231,6 @@ func importMetric(stat []byte, acc telegraf.Accumulator) error {

func init() {
inputs.Add("passenger", func() telegraf.Input {
return &passenger{}
return &Passenger{}
})
}
8 changes: 4 additions & 4 deletions plugins/inputs/passenger/passenger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func teardown(tempFilePath string) {
}

func Test_Invalid_Passenger_Status_Cli(t *testing.T) {
r := &passenger{
r := &Passenger{
Command: "an-invalid-command passenger-status",
}

Expand All @@ -55,7 +55,7 @@ func Test_Invalid_Xml(t *testing.T) {
require.NoError(t, err)
defer teardown(tempFilePath)

r := &passenger{
r := &Passenger{
Command: tempFilePath,
}

Expand All @@ -72,7 +72,7 @@ func Test_Default_Config_Load_Default_Command(t *testing.T) {
require.NoError(t, err)
defer teardown(tempFilePath)

r := &passenger{}
r := &Passenger{}

var acc testutil.Accumulator

Expand All @@ -87,7 +87,7 @@ func TestPassengerGenerateMetric(t *testing.T) {
defer teardown(tempFilePath)

// Now we tested again above server, with our authentication data
r := &passenger{
r := &Passenger{
Command: tempFilePath,
}

Expand Down
Loading

0 comments on commit e2b5a99

Please sign in to comment.