Skip to content

Commit

Permalink
chore: fix lint issues with revive and unconvert
Browse files Browse the repository at this point in the history
  • Loading branch information
tbelda-ems committed Jun 11, 2023
1 parent 1e73224 commit 1357ec8
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 48 deletions.
26 changes: 14 additions & 12 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@ import (
"github.com/tesibelda/ovirtstat/plugins/inputs/ovirtstat"
)

var pollInterval = flag.Duration(
"poll_interval",
60*time.Second,
"how often to send metrics (default 1m)",
)
var configFile = flag.String("config", "", "path to the config file for this plugin")
var showVersion = flag.Bool("version", false, "show ovirtstat version and exit")

// Version cotains the actual version of ovirtstat
var Version string = ""
var err error
var Version string

func main() {
var (
pollInterval = flag.Duration(
"poll_interval",
60*time.Second,
"how often to send metrics (default 1m)",
)
configFile = flag.String("config", "", "path to the config file for this plugin")
showVersion = flag.Bool("version", false, "show ovirtstat version and exit")
err error
)

// parse command line options
flag.Parse()
if *showVersion {
Expand All @@ -54,9 +56,9 @@ func main() {
}

// Tell ovirtstat shim the configured polling interval
vcCfg, ok := shim.Input.(*ovirtstat.OVirtstatConfig)
vcCfg, ok := shim.Input.(*ovirtstat.Config)
if !ok {
fmt.Fprintf(os.Stderr, "Error getting shim input as OVirtstatConfig\n")
fmt.Fprintf(os.Stderr, "Error getting shim input as ovirtstat Config\n")
os.Exit(1)
}
if err = vcCfg.SetPollInterval(*pollInterval); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/netplus/tgplus.go → internal/netplus/netplus.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
var ErrorURLParsing = errors.New("error parsing URL")

// PaseURL parses an URL params
func PaseURL(anUrl, user, pass string) (*url.URL, error) {
u, err := url.Parse(anUrl)
func PaseURL(anURL, user, pass string) (*url.URL, error) {
u, err := url.Parse(anURL)
if err != nil {
return nil, fmt.Errorf("%s: %w", ErrorURLParsing.Error(), err)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/ovirtcollector/api_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
ovirtsdk "github.com/ovirt/go-ovirt"
)

// CollectApiSummaryInfo gathers oVirt api's summary info
func (c *OVirtCollector) CollectApiSummaryInfo(
// CollectAPISummaryInfo gathers oVirt api's summary info
func (c *OVirtCollector) CollectAPISummaryInfo(
ctx context.Context,
acc telegraf.Accumulator,
) error {
Expand Down
14 changes: 7 additions & 7 deletions internal/ovirtcollector/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type VcCache struct {
lastDCUpdate time.Time
lastHoUpdate time.Time
lastSdUpdate time.Time
lastVmUpdate time.Time
lastVMUpdate time.Time
}

func (c *OVirtCollector) getDatacentersAndClusters(ctx context.Context) error {
Expand Down Expand Up @@ -114,7 +114,7 @@ func (c *OVirtCollector) getAllDatacentersStorageDomains(ctx context.Context) er
func (c *OVirtCollector) getAllDatacentersVMs(ctx context.Context) error {
var err error

if time.Since(c.lastVmUpdate) < c.dataDuration {
if time.Since(c.lastVMUpdate) < c.dataDuration {
return nil
}
if err = c.getAllDatacentersHosts(ctx); err != nil {
Expand All @@ -132,13 +132,13 @@ func (c *OVirtCollector) getAllDatacentersVMs(ctx context.Context) error {
return fmt.Errorf("could not get VM list or it is empty")
}
c.vms = vms
c.lastVmUpdate = time.Now()
c.lastVMUpdate = time.Now()

return nil
}

// datacenterNameFromId returns the datacenter name given its Id
func (c *OVirtCollector) datacenterNameFromId(id string) string {
// datacenterNameFromID returns the datacenter name given its Id
func (c *OVirtCollector) datacenterNameFromID(id string) string {
var clid, name string
var ok bool

Expand All @@ -158,7 +158,7 @@ func (c *OVirtCollector) countClustersInDc(id string) int16 {
var (
edc *ovirtsdk.DataCenter
dcid string
nclusters int16 = 0
nclusters int16
ok bool
)

Expand Down Expand Up @@ -207,7 +207,7 @@ func (c *OVirtCollector) clusterDatacenterName(cl *ovirtsdk.Cluster) string {
if clid == id {
if dc, ok = cl.DataCenter(); ok {
if dcid, ok = dc.Id(); ok {
name = c.datacenterNameFromId(dcid)
name = c.datacenterNameFromID(dcid)
break
}
}
Expand Down
6 changes: 3 additions & 3 deletions internal/ovirtcollector/ovirtcollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ type OVirtCollector struct {
// New returns a new OVirtCollector associated with the provided OVirt URL
func New(
ctx context.Context,
ovirtUrl, user, pass string,
ovirtURL, user, pass string,
clicfg *tls.ClientConfig,
dataDuration time.Duration,
) (*OVirtCollector, error) {
var err error

ovc := OVirtCollector{
urlString: ovirtUrl,
urlString: ovirtURL,
user: user,
pass: pass,
conn: nil,
Expand All @@ -72,7 +72,7 @@ func New(
ovc.TLSCA = clicfg.TLSCA
ovc.InsecureSkipVerify = clicfg.InsecureSkipVerify

ovc.url, err = netplus.PaseURL(ovirtUrl, user, pass)
ovc.url, err = netplus.PaseURL(ovirtURL, user, pass)
if err != nil {
return nil, err
}
Expand Down
44 changes: 22 additions & 22 deletions plugins/inputs/ovirtstat/ovirtstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
"github.com/tesibelda/vcstat/pkg/tgplus"
)

type OVirtstatConfig struct {
type Config struct {
tls.ClientConfig
OVirtUrl string `toml:"ovirturl"`
OVirtURL string `toml:"ovirturl"`
Username string `toml:"username"`
Password string `toml:"password"`
InternalAlias string `toml:"internal_alias"`
Expand Down Expand Up @@ -95,8 +95,8 @@ var sampleConfig = `

func init() {
inputs.Add("ovirtstat", func() telegraf.Input {
return &OVirtstatConfig{
OVirtUrl: "https://ovirt-engine.local/ovirt-engine/api",
return &Config{
OVirtURL: "https://ovirt-engine.local/ovirt-engine/api",
Username: "user@internal",
Password: "secret",
InternalAlias: "",
Expand All @@ -106,7 +106,7 @@ func init() {
}

// Init initializes internal ovirtstat variables with the provided configuration
func (ovc *OVirtstatConfig) Init() error {
func (ovc *Config) Init() error {
var err error

ovc.ctx, ovc.cancel = context.WithCancel(context.Background())
Expand All @@ -115,7 +115,7 @@ func (ovc *OVirtstatConfig) Init() error {
}
ovc.ovc, err = ovirtcollector.New(
ovc.ctx,
ovc.OVirtUrl,
ovc.OVirtURL,
ovc.Username,
ovc.Password,
&ovc.ClientConfig,
Expand All @@ -127,7 +127,7 @@ func (ovc *OVirtstatConfig) Init() error {

/// Set ovirtcollector options
ovc.ovc.SetDataDuration(time.Duration(ovc.pollInterval.Seconds() * 0.9))
ovc.ovc.SetMaxResponseTime(time.Duration(ovc.pollInterval))
ovc.ovc.SetMaxResponseTime(ovc.pollInterval)
err = ovc.ovc.SetFilterClusters(ovc.ClustersInclude, ovc.ClustersExclude)
if err != nil {
return fmt.Errorf("error parsing clusters filters: %w", err)
Expand All @@ -146,7 +146,7 @@ func (ovc *OVirtstatConfig) Init() error {
}

// selfmonitoring
u, err := url.Parse(ovc.OVirtUrl)
u, err := url.Parse(ovc.OVirtURL)
if err != nil {
return fmt.Errorf("error parsing URL for ovurl: %w", err)
}
Expand All @@ -162,33 +162,33 @@ func (ovc *OVirtstatConfig) Init() error {

// Stop is called from telegraf core when a plugin is stopped and allows it to
// perform shutdown tasks.
func (ovc *OVirtstatConfig) Stop() {
func (ovc *Config) Stop() {
if ovc.ovc != nil {
ovc.ovc.Close(ovc.ctx)
}
ovc.cancel()
}

// SetPollInterval allows telegraf shim to tell ovirtstat the configured polling interval
func (ovc *OVirtstatConfig) SetPollInterval(pollInterval time.Duration) error {
func (ovc *Config) SetPollInterval(pollInterval time.Duration) error {
ovc.pollInterval = pollInterval
return nil
}

// SampleConfig returns a set of default configuration to be used as a boilerplate when setting up
// Telegraf.
func (ovc *OVirtstatConfig) SampleConfig() string {
func (ovc *Config) SampleConfig() string {
return sampleConfig
}

// Description returns a short textual description of the plugin
func (ovc *OVirtstatConfig) Description() string {
func (ovc *Config) Description() string {
return "Gathers status and basic stats from OVirt Engine"
}

// Gather is the main data collection function called by the Telegraf core. It performs all
// the data collection and writes all metrics into the Accumulator passed as an argument.
func (ovc *OVirtstatConfig) Gather(acc telegraf.Accumulator) error {
func (ovc *Config) Gather(acc telegraf.Accumulator) error {
var startTime time.Time
var err error

Expand All @@ -198,7 +198,7 @@ func (ovc *OVirtstatConfig) Gather(acc telegraf.Accumulator) error {
acc.SetPrecision(tgplus.GetPrecision(ovc.pollInterval))

// poll using a context with timeout
ctxT, cancelT := context.WithTimeout(ovc.ctx, time.Duration(ovc.pollInterval))
ctxT, cancelT := context.WithTimeout(ovc.ctx, ovc.pollInterval)
defer cancelT()
startTime = time.Now()

Expand All @@ -219,7 +219,7 @@ func (ovc *OVirtstatConfig) Gather(acc telegraf.Accumulator) error {
}

// selfmonitoring
ovc.GatherTime.Set(int64(time.Since(startTime).Nanoseconds()))
ovc.GatherTime.Set(time.Since(startTime).Nanoseconds())
for _, m := range selfstat.Metrics() {
if m.Name() != "internal_agent" {
acc.AddMetric(m)
Expand All @@ -230,7 +230,7 @@ func (ovc *OVirtstatConfig) Gather(acc telegraf.Accumulator) error {
}

// keepActiveSession keeps an active session with vsphere
func (ovc *OVirtstatConfig) keepActiveSession(acc telegraf.Accumulator) error {
func (ovc *Config) keepActiveSession(acc telegraf.Accumulator) error {
var col *ovirtcollector.OVirtCollector
var err error

Expand All @@ -254,7 +254,7 @@ func (ovc *OVirtstatConfig) keepActiveSession(acc telegraf.Accumulator) error {
}

// gatherHighLevelEntities gathers datacenters and clusters stats
func (ovc *OVirtstatConfig) gatherHighLevelEntities(
func (ovc *Config) gatherHighLevelEntities(
ctx context.Context,
acc telegraf.Accumulator,
) error {
Expand All @@ -267,7 +267,7 @@ func (ovc *OVirtstatConfig) gatherHighLevelEntities(
}

//--- Get OVirt api summary stats
if err = col.CollectApiSummaryInfo(ctx, acc); err != nil {
if err = col.CollectAPISummaryInfo(ctx, acc); err != nil {
return err
}

Expand All @@ -280,7 +280,7 @@ func (ovc *OVirtstatConfig) gatherHighLevelEntities(
}

// gatherHost gathers info and stats per host
func (ovc *OVirtstatConfig) gatherHost(
func (ovc *Config) gatherHost(
ctx context.Context,
acc telegraf.Accumulator,
) error {
Expand All @@ -299,7 +299,7 @@ func (ovc *OVirtstatConfig) gatherHost(
}

// gatherStorage gathers storage entities info
func (ovc *OVirtstatConfig) gatherStorage(
func (ovc *Config) gatherStorage(
ctx context.Context,
acc telegraf.Accumulator,
) error {
Expand All @@ -321,7 +321,7 @@ func (ovc *OVirtstatConfig) gatherStorage(
}

// gatherVM gathers virtual machine's info
func (ovc *OVirtstatConfig) gatherVM(ctx context.Context, acc telegraf.Accumulator) error {
func (ovc *Config) gatherVM(ctx context.Context, acc telegraf.Accumulator) error {
var col *ovirtcollector.OVirtCollector
var err error
var exist bool
Expand All @@ -337,7 +337,7 @@ func (ovc *OVirtstatConfig) gatherVM(ctx context.Context, acc telegraf.Accumulat
}

// setFilterCollectors sets collectors to use given the include and exclude filters
func (ovc *OVirtstatConfig) setFilterCollectors(include, exclude []string) error {
func (ovc *Config) setFilterCollectors(include, exclude []string) error {
var allcollectors = []string{"Datacenters", "GlusterVolumes", "Hosts", "StorageDomains", "VMs"}
var err error

Expand Down

0 comments on commit 1357ec8

Please sign in to comment.