Skip to content

Commit

Permalink
chore: Fix linter findings for revive:exported in plugins/inputs/m*
Browse files Browse the repository at this point in the history
  • Loading branch information
zak-pawel committed Nov 14, 2024
1 parent fe4246f commit b91a07c
Show file tree
Hide file tree
Showing 44 changed files with 923 additions and 1,014 deletions.
34 changes: 17 additions & 17 deletions plugins/inputs/mailchimp/chimp_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (
var mailchimpDatacenter = regexp.MustCompile("[a-z]+[0-9]+$")

type chimpAPI struct {
Transport http.RoundTripper
transport http.RoundTripper
debug bool

sync.Mutex
Expand All @@ -32,30 +32,30 @@ type chimpAPI struct {
}

type reportsParams struct {
Count string
Offset string
SinceSendTime string
BeforeSendTime string
count string
offset string
sinceSendTime string
beforeSendTime string
}

func (p *reportsParams) String() string {
v := url.Values{}
if p.Count != "" {
v.Set("count", p.Count)
if p.count != "" {
v.Set("count", p.count)
}
if p.Offset != "" {
v.Set("offset", p.Offset)
if p.offset != "" {
v.Set("offset", p.offset)
}
if p.BeforeSendTime != "" {
v.Set("before_send_time", p.BeforeSendTime)
if p.beforeSendTime != "" {
v.Set("before_send_time", p.beforeSendTime)
}
if p.SinceSendTime != "" {
v.Set("since_send_time", p.SinceSendTime)
if p.sinceSendTime != "" {
v.Set("since_send_time", p.sinceSendTime)
}
return v.Encode()
}

func NewChimpAPI(apiKey string, log telegraf.Logger) *chimpAPI {
func newChimpAPI(apiKey string, log telegraf.Logger) *chimpAPI {
u := &url.URL{}
u.Scheme = "https"
u.Host = mailchimpDatacenter.FindString(apiKey) + ".api.mailchimp.com"
Expand Down Expand Up @@ -86,7 +86,7 @@ func chimpErrorCheck(body []byte) error {
return nil
}

func (a *chimpAPI) GetReports(params reportsParams) (reportsResponse, error) {
func (a *chimpAPI) getReports(params reportsParams) (reportsResponse, error) {
a.Lock()
defer a.Unlock()
a.url.Path = reportsEndpoint
Expand All @@ -105,7 +105,7 @@ func (a *chimpAPI) GetReports(params reportsParams) (reportsResponse, error) {
return response, nil
}

func (a *chimpAPI) GetReport(campaignID string) (report, error) {
func (a *chimpAPI) getReport(campaignID string) (report, error) {
a.Lock()
defer a.Unlock()
a.url.Path = fmt.Sprintf(reportsEndpointCampaign, campaignID)
Expand All @@ -126,7 +126,7 @@ func (a *chimpAPI) GetReport(campaignID string) (report, error) {

func (a *chimpAPI) runChimp(params reportsParams) ([]byte, error) {
client := &http.Client{
Transport: a.Transport,
Transport: a.transport,
Timeout: 4 * time.Second,
}

Expand Down
19 changes: 9 additions & 10 deletions plugins/inputs/mailchimp/mailchimp.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,20 @@ import (
var sampleConfig string

type MailChimp struct {
api *chimpAPI

APIKey string `toml:"api_key"`
DaysOld int `toml:"days_old"`
CampaignID string `toml:"campaign_id"`
APIKey string `toml:"api_key"`
DaysOld int `toml:"days_old"`
CampaignID string `toml:"campaign_id"`
Log telegraf.Logger `toml:"-"`

Log telegraf.Logger `toml:"-"`
api *chimpAPI
}

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

func (m *MailChimp) Init() error {
m.api = NewChimpAPI(m.APIKey, m.Log)
m.api = newChimpAPI(m.APIKey, m.Log)

return nil
}
Expand All @@ -45,8 +44,8 @@ func (m *MailChimp) Gather(acc telegraf.Accumulator) error {
since = now.Add(-d).Format(time.RFC3339)
}

reports, err := m.api.GetReports(reportsParams{
SinceSendTime: since,
reports, err := m.api.getReports(reportsParams{
sinceSendTime: since,
})
if err != nil {
return err
Expand All @@ -57,7 +56,7 @@ func (m *MailChimp) Gather(acc telegraf.Accumulator) error {
gatherReport(acc, report, now)
}
} else {
report, err := m.api.GetReport(m.CampaignID)
report, err := m.api.getReport(m.CampaignID)
if err != nil {
return err
}
Expand Down
72 changes: 35 additions & 37 deletions plugins/inputs/marklogic/marklogic.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,69 +19,69 @@ import (
//go:embed sample.conf
var sampleConfig string

// Marklogic configuration toml
const (
// MarkLogic v2 management api endpoints for hosts status
statsPath = "/manage/v2/hosts/"
viewFormat = "view=status&format=json"
)

type Marklogic struct {
URL string `toml:"url"`
Hosts []string `toml:"hosts"`
Username string `toml:"username"`
Password string `toml:"password"`
Sources []string

tls.ClientConfig

client *http.Client
client *http.Client
sources []string
}

type MlPointInt struct {
type mlPointInt struct {
Value int `json:"value"`
}

type MlPointFloat struct {
type mlPointFloat struct {
Value float64 `json:"value"`
}

type MlPointBool struct {
type mlPointBool struct {
Value bool `json:"value"`
}

// MarkLogic v2 management api endpoints for hosts status
const statsPath = "/manage/v2/hosts/"
const viewFormat = "view=status&format=json"

type MlHost struct {
type mlHost struct {
HostStatus struct {
ID string `json:"id"`
Name string `json:"name"`
StatusProperties struct {
Online MlPointBool `json:"online"`
Online mlPointBool `json:"online"`
LoadProperties struct {
TotalLoad MlPointFloat `json:"total-load"`
TotalLoad mlPointFloat `json:"total-load"`
} `json:"load-properties"`
RateProperties struct {
TotalRate MlPointFloat `json:"total-rate"`
TotalRate mlPointFloat `json:"total-rate"`
} `json:"rate-properties"`
StatusDetail struct {
Cpus MlPointInt `json:"cpus"`
Cores MlPointInt `json:"cores"`
Cpus mlPointInt `json:"cpus"`
Cores mlPointInt `json:"cores"`
TotalCPUStatUser float64 `json:"total-cpu-stat-user"`
TotalCPUStatSystem float64 `json:"total-cpu-stat-system"`
TotalCPUStatIdle float64 `json:"total-cpu-stat-idle"`
TotalCPUStatIowait float64 `json:"total-cpu-stat-iowait"`
MemoryProcessSize MlPointInt `json:"memory-process-size"`
MemoryProcessRss MlPointInt `json:"memory-process-rss"`
MemorySystemTotal MlPointInt `json:"memory-system-total"`
MemorySystemFree MlPointInt `json:"memory-system-free"`
MemoryProcessSwapSize MlPointInt `json:"memory-process-swap-size"`
MemorySize MlPointInt `json:"memory-size"`
HostSize MlPointInt `json:"host-size"`
LogDeviceSpace MlPointInt `json:"log-device-space"`
DataDirSpace MlPointInt `json:"data-dir-space"`
QueryReadBytes MlPointInt `json:"query-read-bytes"`
QueryReadLoad MlPointInt `json:"query-read-load"`
MergeReadLoad MlPointInt `json:"merge-read-load"`
MergeWriteLoad MlPointInt `json:"merge-write-load"`
HTTPServerReceiveBytes MlPointInt `json:"http-server-receive-bytes"`
HTTPServerSendBytes MlPointInt `json:"http-server-send-bytes"`
MemoryProcessSize mlPointInt `json:"memory-process-size"`
MemoryProcessRss mlPointInt `json:"memory-process-rss"`
MemorySystemTotal mlPointInt `json:"memory-system-total"`
MemorySystemFree mlPointInt `json:"memory-system-free"`
MemoryProcessSwapSize mlPointInt `json:"memory-process-swap-size"`
MemorySize mlPointInt `json:"memory-size"`
HostSize mlPointInt `json:"host-size"`
LogDeviceSpace mlPointInt `json:"log-device-space"`
DataDirSpace mlPointInt `json:"data-dir-space"`
QueryReadBytes mlPointInt `json:"query-read-bytes"`
QueryReadLoad mlPointInt `json:"query-read-load"`
MergeReadLoad mlPointInt `json:"merge-read-load"`
MergeWriteLoad mlPointInt `json:"merge-write-load"`
HTTPServerReceiveBytes mlPointInt `json:"http-server-receive-bytes"`
HTTPServerSendBytes mlPointInt `json:"http-server-send-bytes"`
} `json:"status-detail"`
} `json:"status-properties"`
} `json:"host-status"`
Expand All @@ -91,7 +91,6 @@ func (*Marklogic) SampleConfig() string {
return sampleConfig
}

// Init parse all source URLs and place on the Marklogic struct
func (c *Marklogic) Init() error {
if len(c.URL) == 0 {
c.URL = "http://localhost:8002/"
Expand All @@ -108,12 +107,11 @@ func (c *Marklogic) Init() error {

addr.RawQuery = viewFormat
u := addr.String()
c.Sources = append(c.Sources, u)
c.sources = append(c.sources, u)
}
return nil
}

// Gather metrics from HTTP Server.
func (c *Marklogic) Gather(accumulator telegraf.Accumulator) error {
var wg sync.WaitGroup

Expand All @@ -127,7 +125,7 @@ func (c *Marklogic) Gather(accumulator telegraf.Accumulator) error {
}

// Range over all source URL's appended to the struct
for _, serv := range c.Sources {
for _, serv := range c.sources {
wg.Add(1)
go func(serv string) {
defer wg.Done()
Expand All @@ -143,7 +141,7 @@ func (c *Marklogic) Gather(accumulator telegraf.Accumulator) error {
}

func (c *Marklogic) fetchAndInsertData(acc telegraf.Accumulator, address string) error {
ml := &MlHost{}
ml := &mlHost{}
if err := c.gatherJSONData(address, ml); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/marklogic/marklogic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestMarklogic(t *testing.T) {
ml := &Marklogic{
Hosts: []string{"example1"},
URL: ts.URL,
// Sources: []string{"http://localhost:8002/manage/v2/hosts/hostname1?view=status&format=json"},
// sources: []string{"http://localhost:8002/manage/v2/hosts/hostname1?view=status&format=json"},
}

// Create a test accumulator
Expand Down
Loading

0 comments on commit b91a07c

Please sign in to comment.