Skip to content

Commit

Permalink
Merge pull request prometheus-community#1335 from mattdurham/nil_stri…
Browse files Browse the repository at this point in the history
…ng_check
  • Loading branch information
jkroepke authored Nov 15, 2023
2 parents fcc18eb + 07f0569 commit 45b9999
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 25 deletions.
3 changes: 2 additions & 1 deletion pkg/collector/exchange/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/go-kit/log/level"
"github.com/prometheus-community/windows_exporter/pkg/perflib"
"github.com/prometheus-community/windows_exporter/pkg/types"
"github.com/prometheus-community/windows_exporter/pkg/utils"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down Expand Up @@ -211,7 +212,7 @@ func (c *collector) Build() error {
os.Exit(0)
}

if *c.exchangeCollectorsEnabled == "" {
if utils.IsEmpty(c.exchangeCollectorsEnabled) {
for _, collectorName := range exchangeAllCollectorNames {
c.enabledCollectors = append(c.enabledCollectors, collectorName)
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/collector/iis/iis.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
"sort"
"strings"

"github.com/prometheus-community/windows_exporter/pkg/perflib"
"github.com/prometheus-community/windows_exporter/pkg/types"

"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus-community/windows_exporter/pkg/perflib"
"github.com/prometheus-community/windows_exporter/pkg/types"
"github.com/prometheus-community/windows_exporter/pkg/utils"
"github.com/prometheus/client_golang/prometheus"
"golang.org/x/sys/windows/registry"
)
Expand Down Expand Up @@ -308,15 +308,15 @@ func (c *collector) GetPerfCounter() ([]string, error) {
}

func (c *collector) Build() error {
if *c.oldSiteExclude != "" {
if utils.HasValue(c.oldSiteExclude) {
if !c.siteExcludeSet {
_ = level.Warn(c.logger).Log("msg", "--collector.iis.site-blacklist is DEPRECATED and will be removed in a future release, use --collector.iis.site-exclude")
*c.siteExclude = *c.oldSiteExclude
} else {
return errors.New("--collector.iis.site-blacklist and --collector.iis.site-exclude are mutually exclusive")
}
}
if *c.oldSiteInclude != "" {
if utils.HasValue(c.oldSiteInclude) {
if !c.siteIncludeSet {
_ = level.Warn(c.logger).Log("msg", "--collector.iis.site-whitelist is DEPRECATED and will be removed in a future release, use --collector.iis.site-include")
*c.siteInclude = *c.oldSiteInclude
Expand All @@ -325,15 +325,15 @@ func (c *collector) Build() error {
}
}

if *c.oldAppExclude != "" {
if utils.HasValue(c.oldAppExclude) {
if !c.appExcludeSet {
_ = level.Warn(c.logger).Log("msg", "--collector.iis.app-blacklist is DEPRECATED and will be removed in a future release, use --collector.iis.app-exclude")
*c.appExclude = *c.oldAppExclude
} else {
return errors.New("--collector.iis.app-blacklist and --collector.iis.app-exclude are mutually exclusive")
}
}
if *c.oldAppInclude != "" {
if utils.HasValue(c.oldAppInclude) {
if !c.appIncludeSet {
_ = level.Warn(c.logger).Log("msg", "--collector.iis.app-whitelist is DEPRECATED and will be removed in a future release, use --collector.iis.app-include")
*c.appInclude = *c.oldAppInclude
Expand Down
5 changes: 3 additions & 2 deletions pkg/collector/logical_disk/logical_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/go-kit/log/level"
"github.com/prometheus-community/windows_exporter/pkg/perflib"
"github.com/prometheus-community/windows_exporter/pkg/types"
"github.com/prometheus-community/windows_exporter/pkg/utils"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down Expand Up @@ -125,15 +126,15 @@ func (c *collector) GetPerfCounter() ([]string, error) {
}

func (c *collector) Build() error {
if *c.volumeOldExclude != "" {
if utils.HasValue(c.volumeOldExclude) {
if !c.volumeExcludeSet {
_ = level.Warn(c.logger).Log("msg", "--collector.logical_disk.volume-blacklist is DEPRECATED and will be removed in a future release, use --collector.logical_disk.volume-exclude")
*c.volumeExclude = *c.volumeOldExclude
} else {
return errors.New("--collector.logical_disk.volume-blacklist and --collector.logical_disk.volume-exclude are mutually exclusive")
}
}
if *c.volumeOldInclude != "" {
if utils.HasValue(c.volumeOldInclude) {
if !c.volumeIncludeSet {
_ = level.Warn(c.logger).Log("msg", "--collector.logical_disk.volume-whitelist is DEPRECATED and will be removed in a future release, use --collector.logical_disk.volume-include")
*c.volumeInclude = *c.volumeOldInclude
Expand Down
8 changes: 4 additions & 4 deletions pkg/collector/msmq/msmq.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ package msmq
import (
"strings"

"github.com/prometheus-community/windows_exporter/pkg/types"
"github.com/prometheus-community/windows_exporter/pkg/wmi"

"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus-community/windows_exporter/pkg/types"
"github.com/prometheus-community/windows_exporter/pkg/utils"
"github.com/prometheus-community/windows_exporter/pkg/wmi"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down Expand Up @@ -72,7 +72,7 @@ func (c *collector) GetPerfCounter() ([]string, error) {
}

func (c *collector) Build() error {
if *c.queryWhereClause == "" {
if utils.IsEmpty(c.queryWhereClause) {
_ = level.Warn(c.logger).Log("msg", "No where-clause specified for msmq collector. This will generate a very large number of metrics!")
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/collector/net/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/go-kit/log/level"
"github.com/prometheus-community/windows_exporter/pkg/perflib"
"github.com/prometheus-community/windows_exporter/pkg/types"
"github.com/prometheus-community/windows_exporter/pkg/utils"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down Expand Up @@ -125,15 +126,15 @@ func (c *collector) GetPerfCounter() ([]string, error) {
}

func (c *collector) Build() error {
if *c.nicOldExclude != "" {
if utils.HasValue(c.nicOldExclude) {
if !c.nicExcludeSet {
_ = level.Warn(c.logger).Log("msg", "--collector.net.nic-blacklist is DEPRECATED and will be removed in a future release, use --collector.net.nic-exclude")
*c.nicExclude = *c.nicOldExclude
} else {
return errors.New("--collector.net.nic-blacklist and --collector.net.nic-exclude are mutually exclusive")
}
}
if *c.nicOldInclude != "" {
if utils.HasValue(c.nicOldInclude) {
if !c.nicIncludeSet {
_ = level.Warn(c.logger).Log("msg", "--collector.net.nic-whitelist is DEPRECATED and will be removed in a future release, use --collector.net.nic-include")
*c.nicInclude = *c.nicOldInclude
Expand Down
7 changes: 4 additions & 3 deletions pkg/collector/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/go-kit/log/level"
"github.com/prometheus-community/windows_exporter/pkg/perflib"
"github.com/prometheus-community/windows_exporter/pkg/types"
"github.com/prometheus-community/windows_exporter/pkg/utils"
"github.com/prometheus-community/windows_exporter/pkg/wmi"
"github.com/prometheus/client_golang/prometheus"
)
Expand Down Expand Up @@ -133,15 +134,15 @@ func (c *collector) GetPerfCounter() ([]string, error) {
}

func (c *collector) Build() error {
if *c.processOldExclude != "" {
if utils.HasValue(c.processOldExclude) {
if !c.processExcludeSet {
_ = level.Warn(c.logger).Log("msg", "--collector.process.blacklist is DEPRECATED and will be removed in a future release, use --collector.process.exclude")
*c.processExclude = *c.processOldExclude
} else {
return errors.New("--collector.process.blacklist and --collector.process.exclude are mutually exclusive")
}
}
if *c.processOldInclude != "" {
if utils.HasValue(c.processOldInclude) {
if !c.processIncludeSet {
_ = level.Warn(c.logger).Log("msg", "--collector.process.whitelist is DEPRECATED and will be removed in a future release, use --collector.process.include")
*c.processInclude = *c.processOldInclude
Expand All @@ -150,7 +151,7 @@ func (c *collector) Build() error {
}
}

if *c.processInclude == ".*" && *c.processExclude == "" {
if c.processInclude != nil && *c.processInclude == ".*" && utils.IsEmpty(c.processExclude) {
_ = level.Warn(c.logger).Log("msg", "No filters specified for process collector. This will generate a very large number of metrics!")
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/collector/scheduled_task/scheduled_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/go-ole/go-ole"
"github.com/go-ole/go-ole/oleutil"
"github.com/prometheus-community/windows_exporter/pkg/types"
"github.com/prometheus-community/windows_exporter/pkg/utils"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down Expand Up @@ -141,15 +142,15 @@ func (c *collector) GetPerfCounter() ([]string, error) {
}

func (c *collector) Build() error {
if *c.taskOldExclude != "" {
if utils.HasValue(c.taskOldExclude) {
if !c.taskExcludeSet {
_ = level.Warn(c.logger).Log("msg", "--collector.scheduled_task.blacklist is DEPRECATED and will be removed in a future release, use --collector.scheduled_task.exclude")
*c.taskExclude = *c.taskOldExclude
} else {
return errors.New("--collector.scheduled_task.blacklist and --collector.scheduled_task.exclude are mutually exclusive")
}
}
if *c.taskOldInclude != "" {
if utils.HasValue(c.taskOldInclude) {
if !c.taskIncludeSet {
_ = level.Warn(c.logger).Log("msg", "--collector.scheduled_task.whitelist is DEPRECATED and will be removed in a future release, use --collector.scheduled_task.include")
*c.taskInclude = *c.taskOldInclude
Expand Down
3 changes: 2 additions & 1 deletion pkg/collector/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus-community/windows_exporter/pkg/types"
"github.com/prometheus-community/windows_exporter/pkg/utils"
"github.com/prometheus-community/windows_exporter/pkg/wmi"
"github.com/prometheus/client_golang/prometheus"
"golang.org/x/sys/windows"
Expand Down Expand Up @@ -88,7 +89,7 @@ func (c *collector) GetPerfCounter() ([]string, error) {
}

func (c *collector) Build() error {
if *c.serviceWhereClause == "" {
if utils.IsEmpty(c.serviceWhereClause) {
_ = level.Warn(c.logger).Log("msg", "No where-clause specified for service collector. This will generate a very large number of metrics!")
}
if *c.useAPI {
Expand Down
5 changes: 3 additions & 2 deletions pkg/collector/smtp/smtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/go-kit/log/level"
"github.com/prometheus-community/windows_exporter/pkg/perflib"
"github.com/prometheus-community/windows_exporter/pkg/types"
"github.com/prometheus-community/windows_exporter/pkg/utils"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down Expand Up @@ -152,15 +153,15 @@ func (c *collector) GetPerfCounter() ([]string, error) {
func (c *collector) Build() error {
_ = level.Info(c.logger).Log("msg", "smtp collector is in an experimental state! Metrics for this collector have not been tested.")

if *c.serverOldExclude != "" {
if utils.HasValue(c.serverOldExclude) {
if !c.serverExcludeSet {
_ = level.Warn(c.logger).Log("msg", "--collector.smtp.server-blacklist is DEPRECATED and will be removed in a future release, use --collector.smtp.server-exclude")
*c.serverExclude = *c.serverOldExclude
} else {
return errors.New("--collector.smtp.server-blacklist and --collector.smtp.server-exclude are mutually exclusive")
}
}
if *c.serverOldInclude != "" {
if utils.HasValue(c.serverOldInclude) {
if !c.serverIncludeSet {
_ = level.Warn(c.logger).Log("msg", "--collector.smtp.server-whitelist is DEPRECATED and will be removed in a future release, use --collector.smtp.server-include")
*c.serverInclude = *c.serverOldInclude
Expand Down
3 changes: 2 additions & 1 deletion pkg/collector/textfile/textfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus-community/windows_exporter/pkg/types"
"github.com/prometheus-community/windows_exporter/pkg/utils"
"github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go"
"github.com/prometheus/common/expfmt"
Expand Down Expand Up @@ -103,7 +104,7 @@ func (c *collector) GetPerfCounter() ([]string, error) {

func (c *collector) Build() error {
c.directories = ""
if *c.textFileDirectory != "" || *c.textFileDirectories != "" {
if utils.HasValue(c.textFileDirectory) || utils.HasValue(c.textFileDirectories) {
c.directories = *c.textFileDirectory + "," + *c.textFileDirectories
c.directories = strings.Trim(c.directories, ",")
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ func BoolToFloat(b bool) float64 {
}
return 0.0
}

func HasValue(v *string) bool {
return !IsEmpty(v)
}

func IsEmpty(v *string) bool {
return v == nil || *v == ""
}

0 comments on commit 45b9999

Please sign in to comment.