Skip to content

Commit

Permalink
Merge pull request #1337 from jkroepke/remove-old-flags
Browse files Browse the repository at this point in the history
  • Loading branch information
jkroepke committed Nov 17, 2023
2 parents ab05f43 + b779891 commit c6b6a23
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 373 deletions.
107 changes: 20 additions & 87 deletions pkg/collector/iis/iis.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package iis

import (
"errors"
"fmt"
"regexp"
"sort"
Expand All @@ -14,17 +13,12 @@ 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"
"golang.org/x/sys/windows/registry"
)

const (
Name = "iis"
FlagIISSiteOldExclude = "collector.iis.site-blacklist"
FlagIISSiteOldInclude = "collector.iis.site-whitelist"
FlagIISAppOldExclude = "collector.iis.app-blacklist"
FlagIISAppOldInclude = "collector.iis.app-whitelist"
Name = "iis"

FlagIISSiteExclude = "collector.iis.site-exclude"
FlagIISSiteInclude = "collector.iis.site-include"
Expand Down Expand Up @@ -86,21 +80,11 @@ func getIISVersion(logger log.Logger) simple_version {
type collector struct {
logger log.Logger

oldSiteInclude *string
oldSiteExclude *string
oldAppInclude *string
oldAppExclude *string

siteInclude *string
siteExclude *string
appInclude *string
appExclude *string

siteIncludeSet bool
siteExcludeSet bool
appIncludeSet bool
appExcludeSet bool

// Web Service
CurrentAnonymousUsers *prometheus.Desc
CurrentBlockedAsyncIORequests *prometheus.Desc
Expand Down Expand Up @@ -251,44 +235,27 @@ func New(logger log.Logger, config *Config) types.Collector {

func NewWithFlags(app *kingpin.Application) types.Collector {
c := &collector{
oldSiteInclude: app.Flag(FlagIISSiteOldInclude, "DEPRECATED: Use --collector.iis.site-include").Hidden().String(),
oldSiteExclude: app.Flag(FlagIISSiteOldExclude, "DEPRECATED: Use --collector.iis.site-exclude").Hidden().String(),
oldAppInclude: app.Flag(FlagIISAppOldInclude, "DEPRECATED: Use --collector.iis.app-include").Hidden().String(),
oldAppExclude: app.Flag(FlagIISAppOldExclude, "DEPRECATED: Use --collector.iis.app-exclude").Hidden().String(),
siteInclude: app.Flag(
FlagIISSiteInclude,
"Regexp of sites to include. Site name must both match include and not match exclude to be included.",
).Default(ConfigDefaults.SiteInclude).String(),

siteExclude: app.Flag(
FlagIISSiteExclude,
"Regexp of sites to exclude. Site name must both match include and not match exclude to be included.",
).Default(ConfigDefaults.SiteExclude).String(),

appInclude: app.Flag(
FlagIISAppInclude,
"Regexp of apps to include. App name must both match include and not match exclude to be included.",
).Default(ConfigDefaults.AppInclude).String(),

appExclude: app.Flag(
FlagIISAppExclude,
"Regexp of apps to exclude. App name must both match include and not match exclude to be included.",
).Default(ConfigDefaults.AppExclude).String(),
}

c.siteInclude = app.Flag(
FlagIISSiteInclude,
"Regexp of sites to include. Site name must both match include and not match exclude to be included.",
).Default(".+").PreAction(func(_ *kingpin.ParseContext) error {
c.siteIncludeSet = true
return nil
}).String()

c.siteExclude = app.Flag(
FlagIISSiteExclude,
"Regexp of sites to exclude. Site name must both match include and not match exclude to be included.",
).Default("").PreAction(func(_ *kingpin.ParseContext) error {
c.siteExcludeSet = true
return nil
}).String()

c.appInclude = app.Flag(
FlagIISAppInclude,
"Regexp of apps to include. App name must both match include and not match exclude to be included.",
).Default(".+").PreAction(func(_ *kingpin.ParseContext) error {
c.appIncludeSet = true
return nil
}).String()

c.appExclude = app.Flag(
FlagIISAppExclude,
"Regexp of apps to include. App name must both match include and not match exclude to be included.",
).Default("").PreAction(func(_ *kingpin.ParseContext) error {
c.siteExcludeSet = true
return nil
}).String()

return c
}

Expand All @@ -310,40 +277,6 @@ func (c *collector) GetPerfCounter() ([]string, error) {
}

func (c *collector) Build() error {
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 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
} else {
return errors.New("--collector.iis.site-whitelist and --collector.iis.site-include are mutually exclusive")
}
}

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 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
} else {
return errors.New("--collector.iis.app-whitelist and --collector.iis.app-include are mutually exclusive")
}
}

c.iis_version = getIISVersion(c.logger)

var err error
Expand Down
65 changes: 11 additions & 54 deletions pkg/collector/logical_disk/logical_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package logical_disk

import (
"errors"
"fmt"
"regexp"

Expand All @@ -12,14 +11,11 @@ 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"
)

const (
Name = "logical_disk"
FlagLogicalDiskVolumeOldExclude = "collector.logical_disk.volume-blacklist"
FlagLogicalDiskVolumeOldInclude = "collector.logical_disk.volume-whitelist"
Name = "logical_disk"

FlagLogicalDiskVolumeExclude = "collector.logical_disk.volume-exclude"
FlagLogicalDiskVolumeInclude = "collector.logical_disk.volume-include"
Expand All @@ -39,15 +35,9 @@ var ConfigDefaults = Config{
type collector struct {
logger log.Logger

volumeOldInclude *string
volumeOldExclude *string

volumeInclude *string
volumeExclude *string

volumeIncludeSet bool
volumeExcludeSet bool

RequestsQueued *prometheus.Desc
AvgReadQueue *prometheus.Desc
AvgWriteQueue *prometheus.Desc
Expand Down Expand Up @@ -83,32 +73,16 @@ func New(logger log.Logger, config *Config) types.Collector {
}

func NewWithFlags(app *kingpin.Application) types.Collector {
c := &collector{}

c.volumeInclude = app.Flag(
FlagLogicalDiskVolumeInclude,
"Regexp of volumes to include. Volume name must both match include and not match exclude to be included.",
).Default(ConfigDefaults.VolumeInclude).PreAction(func(_ *kingpin.ParseContext) error {
c.volumeIncludeSet = true
return nil
}).String()

c.volumeExclude = app.Flag(
FlagLogicalDiskVolumeExclude,
"Regexp of volumes to exclude. Volume name must both match include and not match exclude to be included.",
).Default(ConfigDefaults.VolumeExclude).PreAction(func(_ *kingpin.ParseContext) error {
c.volumeExcludeSet = true
return nil
}).String()

c.volumeOldInclude = app.Flag(
FlagLogicalDiskVolumeOldInclude,
"DEPRECATED: Use --collector.logical_disk.volume-include",
).Hidden().String()
c.volumeOldExclude = app.Flag(
FlagLogicalDiskVolumeOldExclude,
"DEPRECATED: Use --collector.logical_disk.volume-exclude",
).Hidden().String()
c := &collector{
volumeInclude: app.Flag(
FlagLogicalDiskVolumeInclude,
"Regexp of volumes to include. Volume name must both match include and not match exclude to be included.",
).Default(ConfigDefaults.VolumeInclude).String(),
volumeExclude: app.Flag(
FlagLogicalDiskVolumeExclude,
"Regexp of volumes to exclude. Volume name must both match include and not match exclude to be included.",
).Default(ConfigDefaults.VolumeExclude).String(),
}

return c
}
Expand All @@ -126,23 +100,6 @@ func (c *collector) GetPerfCounter() ([]string, error) {
}

func (c *collector) Build() error {
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 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
} else {
return errors.New("--collector.logical_disk.volume-whitelist and --collector.logical_disk.volume-include are mutually exclusive")
}
}

c.RequestsQueued = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "requests_queued"),
"The number of requests queued to the disk (LogicalDisk.CurrentDiskQueueLength)",
Expand Down
64 changes: 11 additions & 53 deletions pkg/collector/net/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package net

import (
"errors"
"fmt"
"regexp"

Expand All @@ -12,16 +11,12 @@ 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"
)

const (
Name = "net"

FlagNicOldExclude = "collector.net.nic-blacklist"
FlagNicOldInclude = "collector.net.nic-whitelist"

FlagNicExclude = "collector.net.nic-exclude"
FlagNicInclude = "collector.net.nic-include"
)
Expand All @@ -42,15 +37,9 @@ var nicNameToUnderscore = regexp.MustCompile("[^a-zA-Z0-9]")
type collector struct {
logger log.Logger

nicOldInclude *string
nicOldExclude *string

nicInclude *string
nicExclude *string

nicIncludeSet bool
nicExcludeSet bool

BytesReceivedTotal *prometheus.Desc
BytesSentTotal *prometheus.Desc
BytesTotal *prometheus.Desc
Expand Down Expand Up @@ -83,32 +72,17 @@ func New(logger log.Logger, config *Config) types.Collector {
}

func NewWithFlags(app *kingpin.Application) types.Collector {
c := &collector{}

c.nicInclude = app.Flag(
FlagNicInclude,
"Regexp of NIC:s to include. NIC name must both match include and not match exclude to be included.",
).Default(ConfigDefaults.NicInclude).PreAction(func(_ *kingpin.ParseContext) error {
c.nicIncludeSet = true
return nil
}).String()

c.nicExclude = app.Flag(
FlagNicExclude,
"Regexp of NIC:s to exclude. NIC name must both match include and not match exclude to be included.",
).Default(ConfigDefaults.NicExclude).PreAction(func(_ *kingpin.ParseContext) error {
c.nicExcludeSet = true
return nil
}).String()

c.nicOldInclude = app.Flag(
FlagNicOldInclude,
"DEPRECATED: Use --collector.net.nic-include",
).Hidden().String()
c.nicOldExclude = app.Flag(
FlagNicOldExclude,
"DEPRECATED: Use --collector.net.nic-exclude",
).Hidden().String()
c := &collector{
nicInclude: app.Flag(
FlagNicInclude,
"Regexp of NIC:s to include. NIC name must both match include and not match exclude to be included.",
).Default(ConfigDefaults.NicInclude).String(),

nicExclude: app.Flag(
FlagNicExclude,
"Regexp of NIC:s to exclude. NIC name must both match include and not match exclude to be included.",
).Default(ConfigDefaults.NicExclude).String(),
}

return c
}
Expand All @@ -126,22 +100,6 @@ func (c *collector) GetPerfCounter() ([]string, error) {
}

func (c *collector) Build() error {
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 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
} else {
return errors.New("--collector.net.nic-whitelist and --collector.net.nic-include are mutually exclusive")
}
}
c.BytesReceivedTotal = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "bytes_received_total"),
"(Network.BytesReceivedPerSec)",
Expand Down
Loading

0 comments on commit c6b6a23

Please sign in to comment.