Skip to content

Commit

Permalink
chore: Fix linter findings for revive:exported in plugins/inputs/r*
Browse files Browse the repository at this point in the history
  • Loading branch information
zak-pawel committed Dec 20, 2024
1 parent d829a5b commit 1df5b7d
Show file tree
Hide file tree
Showing 19 changed files with 553 additions and 570 deletions.
6 changes: 3 additions & 3 deletions plugins/inputs/radius/radius.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import (
"github.com/influxdata/telegraf/plugins/inputs"
)

//go:embed sample.conf
var sampleConfig string

type Radius struct {
Servers []string `toml:"servers"`
Username config.Secret `toml:"username"`
Expand All @@ -29,9 +32,6 @@ type Radius struct {
client radius.Client
}

//go:embed sample.conf
var sampleConfig string

func (*Radius) SampleConfig() string {
return sampleConfig
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/raindrops/raindrops.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
var sampleConfig string

type Raindrops struct {
Urls []string
Urls []string `toml:"urls"`
httpClient *http.Client
}

Expand Down
149 changes: 74 additions & 75 deletions plugins/inputs/ras/ras.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,6 @@ import (
//go:embed sample.conf
var sampleConfig string

// Ras plugin gathers and counts errors provided by RASDaemon
type Ras struct {
DBPath string `toml:"db_path"`

Log telegraf.Logger `toml:"-"`

db *sql.DB
latestTimestamp time.Time
cpuSocketCounters map[int]metricCounters
serverCounters metricCounters
}

type machineCheckError struct {
ID int
Timestamp string
SocketID int
ErrorMsg string
MciStatusMsg string
}

type metricCounters map[string]int64

const (
mceQuery = `
SELECT
Expand Down Expand Up @@ -72,6 +50,27 @@ const (
unclassifiedMCEBase = "unclassified_mce_errors"
)

type Ras struct {
DBPath string `toml:"db_path"`

Log telegraf.Logger `toml:"-"`

db *sql.DB
latestTimestamp time.Time
cpuSocketCounters map[int]metricCounters
serverCounters metricCounters
}

type machineCheckError struct {
id int
timestamp string
socketID int
errorMsg string
mciStatusMsg string
}

type metricCounters map[string]int64

func (*Ras) SampleConfig() string {
return sampleConfig
}
Expand All @@ -91,16 +90,6 @@ func (r *Ras) Start(telegraf.Accumulator) error {
return nil
}

// Stop closes any existing DB connection
func (r *Ras) Stop() {
if r.db != nil {
err := r.db.Close()
if err != nil {
r.Log.Errorf("Error appeared during closing DB (%s): %v", r.DBPath, err)
}
}
}

// Gather reads the stats provided by RASDaemon and writes it to the Accumulator.
func (r *Ras) Gather(acc telegraf.Accumulator) error {
rows, err := r.db.Query(mceQuery, r.latestTimestamp)
Expand All @@ -114,7 +103,7 @@ func (r *Ras) Gather(acc telegraf.Accumulator) error {
if err != nil {
return err
}
tsErr := r.updateLatestTimestamp(mcError.Timestamp)
tsErr := r.updateLatestTimestamp(mcError.timestamp)
if tsErr != nil {
return err
}
Expand All @@ -127,6 +116,16 @@ func (r *Ras) Gather(acc telegraf.Accumulator) error {
return nil
}

// Stop closes any existing DB connection
func (r *Ras) Stop() {
if r.db != nil {
err := r.db.Close()
if err != nil {
r.Log.Errorf("Error appeared during closing DB (%s): %v", r.DBPath, err)
}
}
}

func (r *Ras) updateLatestTimestamp(timestamp string) error {
ts, err := parseDate(timestamp)
if err != nil {
Expand All @@ -140,11 +139,11 @@ func (r *Ras) updateLatestTimestamp(timestamp string) error {
}

func (r *Ras) updateCounters(mcError *machineCheckError) {
if strings.Contains(mcError.ErrorMsg, "No Error") {
if strings.Contains(mcError.errorMsg, "No Error") {
return
}

r.initializeCPUMetricDataIfRequired(mcError.SocketID)
r.initializeCPUMetricDataIfRequired(mcError.socketID)
r.updateSocketCounters(mcError)
r.updateServerCounters(mcError)
}
Expand All @@ -170,11 +169,11 @@ func newMetricCounters() *metricCounters {
}

func (r *Ras) updateServerCounters(mcError *machineCheckError) {
if strings.Contains(mcError.ErrorMsg, "CACHE Level-2") && strings.Contains(mcError.ErrorMsg, "Error") {
if strings.Contains(mcError.errorMsg, "CACHE Level-2") && strings.Contains(mcError.errorMsg, "Error") {
r.serverCounters[levelTwoCache]++
}

if strings.Contains(mcError.ErrorMsg, "UPI:") {
if strings.Contains(mcError.errorMsg, "UPI:") {
r.serverCounters[upi]++
}
}
Expand Down Expand Up @@ -210,71 +209,71 @@ func (r *Ras) updateSocketCounters(mcError *machineCheckError) {
r.updateMemoryCounters(mcError)
r.updateProcessorBaseCounters(mcError)

if strings.Contains(mcError.ErrorMsg, "Instruction TLB") && strings.Contains(mcError.ErrorMsg, "Error") {
r.cpuSocketCounters[mcError.SocketID][instructionTLB]++
if strings.Contains(mcError.errorMsg, "Instruction TLB") && strings.Contains(mcError.errorMsg, "Error") {
r.cpuSocketCounters[mcError.socketID][instructionTLB]++
}

if strings.Contains(mcError.ErrorMsg, "BUS") && strings.Contains(mcError.ErrorMsg, "Error") {
r.cpuSocketCounters[mcError.SocketID][processorBus]++
if strings.Contains(mcError.errorMsg, "BUS") && strings.Contains(mcError.errorMsg, "Error") {
r.cpuSocketCounters[mcError.socketID][processorBus]++
}

if (strings.Contains(mcError.ErrorMsg, "CACHE Level-0") ||
strings.Contains(mcError.ErrorMsg, "CACHE Level-1")) &&
strings.Contains(mcError.ErrorMsg, "Error") {
r.cpuSocketCounters[mcError.SocketID][instructionCache]++
if (strings.Contains(mcError.errorMsg, "CACHE Level-0") ||
strings.Contains(mcError.errorMsg, "CACHE Level-1")) &&
strings.Contains(mcError.errorMsg, "Error") {
r.cpuSocketCounters[mcError.socketID][instructionCache]++
}
}

func (r *Ras) updateProcessorBaseCounters(mcError *machineCheckError) {
if strings.Contains(mcError.ErrorMsg, "Internal Timer error") {
r.cpuSocketCounters[mcError.SocketID][internalTimer]++
r.cpuSocketCounters[mcError.SocketID][processorBase]++
if strings.Contains(mcError.errorMsg, "Internal Timer error") {
r.cpuSocketCounters[mcError.socketID][internalTimer]++
r.cpuSocketCounters[mcError.socketID][processorBase]++
}

if strings.Contains(mcError.ErrorMsg, "SMM Handler Code Access Violation") {
r.cpuSocketCounters[mcError.SocketID][smmHandlerCode]++
r.cpuSocketCounters[mcError.SocketID][processorBase]++
if strings.Contains(mcError.errorMsg, "SMM Handler Code Access Violation") {
r.cpuSocketCounters[mcError.socketID][smmHandlerCode]++
r.cpuSocketCounters[mcError.socketID][processorBase]++
}

if strings.Contains(mcError.ErrorMsg, "Internal parity error") {
r.cpuSocketCounters[mcError.SocketID][internalParity]++
r.cpuSocketCounters[mcError.SocketID][processorBase]++
if strings.Contains(mcError.errorMsg, "Internal parity error") {
r.cpuSocketCounters[mcError.socketID][internalParity]++
r.cpuSocketCounters[mcError.socketID][processorBase]++
}

if strings.Contains(mcError.ErrorMsg, "FRC error") {
r.cpuSocketCounters[mcError.SocketID][frc]++
r.cpuSocketCounters[mcError.SocketID][processorBase]++
if strings.Contains(mcError.errorMsg, "FRC error") {
r.cpuSocketCounters[mcError.socketID][frc]++
r.cpuSocketCounters[mcError.socketID][processorBase]++
}

if strings.Contains(mcError.ErrorMsg, "External error") {
r.cpuSocketCounters[mcError.SocketID][externalMCEBase]++
r.cpuSocketCounters[mcError.SocketID][processorBase]++
if strings.Contains(mcError.errorMsg, "External error") {
r.cpuSocketCounters[mcError.socketID][externalMCEBase]++
r.cpuSocketCounters[mcError.socketID][processorBase]++
}

if strings.Contains(mcError.ErrorMsg, "Microcode ROM parity error") {
r.cpuSocketCounters[mcError.SocketID][microcodeROMParity]++
r.cpuSocketCounters[mcError.SocketID][processorBase]++
if strings.Contains(mcError.errorMsg, "Microcode ROM parity error") {
r.cpuSocketCounters[mcError.socketID][microcodeROMParity]++
r.cpuSocketCounters[mcError.socketID][processorBase]++
}

if strings.Contains(mcError.ErrorMsg, "Unclassified") || strings.Contains(mcError.ErrorMsg, "Internal unclassified") {
r.cpuSocketCounters[mcError.SocketID][unclassifiedMCEBase]++
r.cpuSocketCounters[mcError.SocketID][processorBase]++
if strings.Contains(mcError.errorMsg, "Unclassified") || strings.Contains(mcError.errorMsg, "Internal unclassified") {
r.cpuSocketCounters[mcError.socketID][unclassifiedMCEBase]++
r.cpuSocketCounters[mcError.socketID][processorBase]++
}
}

func (r *Ras) updateMemoryCounters(mcError *machineCheckError) {
if strings.Contains(mcError.ErrorMsg, "Memory read error") {
if strings.Contains(mcError.MciStatusMsg, "Corrected_error") {
r.cpuSocketCounters[mcError.SocketID][memoryReadCorrected]++
if strings.Contains(mcError.errorMsg, "Memory read error") {
if strings.Contains(mcError.mciStatusMsg, "Corrected_error") {
r.cpuSocketCounters[mcError.socketID][memoryReadCorrected]++
} else {
r.cpuSocketCounters[mcError.SocketID][memoryReadUncorrected]++
r.cpuSocketCounters[mcError.socketID][memoryReadUncorrected]++
}
}
if strings.Contains(mcError.ErrorMsg, "Memory write error") {
if strings.Contains(mcError.MciStatusMsg, "Corrected_error") {
r.cpuSocketCounters[mcError.SocketID][memoryWriteCorrected]++
if strings.Contains(mcError.errorMsg, "Memory write error") {
if strings.Contains(mcError.mciStatusMsg, "Corrected_error") {
r.cpuSocketCounters[mcError.socketID][memoryWriteCorrected]++
} else {
r.cpuSocketCounters[mcError.SocketID][memoryWriteUncorrected]++
r.cpuSocketCounters[mcError.socketID][memoryWriteUncorrected]++
}
}
}
Expand Down Expand Up @@ -305,7 +304,7 @@ func addServerMetrics(acc telegraf.Accumulator, counters map[string]int64) {

func fetchMachineCheckError(rows *sql.Rows) (*machineCheckError, error) {
mcError := &machineCheckError{}
err := rows.Scan(&mcError.ID, &mcError.Timestamp, &mcError.ErrorMsg, &mcError.MciStatusMsg, &mcError.SocketID)
err := rows.Scan(&mcError.id, &mcError.timestamp, &mcError.errorMsg, &mcError.mciStatusMsg, &mcError.socketID)

if err != nil {
return nil, err
Expand Down
14 changes: 9 additions & 5 deletions plugins/inputs/ras/ras_notlinux.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ type Ras struct {
Log telegraf.Logger `toml:"-"`
}

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

func (r *Ras) Init() error {
r.Log.Warn("current platform is not supported")
r.Log.Warn("Current platform is not supported")
return nil
}
func (*Ras) SampleConfig() string { return sampleConfig }
func (*Ras) Gather(_ telegraf.Accumulator) error { return nil }
func (*Ras) Start(_ telegraf.Accumulator) error { return nil }
func (*Ras) Stop() {}

func (*Ras) Start(telegraf.Accumulator) error { return nil }

func (*Ras) Gather(telegraf.Accumulator) error { return nil }

func (*Ras) Stop() {}

func init() {
inputs.Add("ras", func() telegraf.Input {
Expand Down
Loading

0 comments on commit 1df5b7d

Please sign in to comment.