feat!: Deprecate whitelist/blacklist flags

Flags have been deprecated in favour of include/exclude terminology.

Signed-off-by: Ben Reedy <breed808@breed808.com>
This commit is contained in:
Ben Reedy
2023-04-01 17:48:23 +10:00
parent 3627520559
commit fab77d9d31
17 changed files with 465 additions and 161 deletions

View File

@@ -4,6 +4,7 @@
package collector
import (
"errors"
"fmt"
"regexp"
@@ -14,17 +15,32 @@ import (
)
const (
FlagISSSiteBlacklist = "collector.iis.site-blacklist"
FlagISSSiteWhitelist = "collector.iis.site-whitelist"
FlagISSAppBlacklist = "collector.iis.app-blacklist"
FlagISSAppWhitelist = "collector.iis.app-whitelist"
FlagIISSiteOldExclude = "collector.iis.site-blacklist"
FlagIISSiteOldInclude = "collector.iis.site-whitelist"
FlagIISAppOldExclude = "collector.iis.app-blacklist"
FlagIISAppOldInclude = "collector.iis.app-whitelist"
FlagIISSiteExclude = "collector.iis.site-exclude"
FlagIISSiteInclude = "collector.iis.site-include"
FlagIISAppExclude = "collector.iis.app-exclude"
FlagIISAppInclude = "collector.iis.app-include"
)
var (
siteWhitelist *string
siteBlacklist *string
appWhitelist *string
appBlacklist *string
oldSiteInclude *string
oldSiteExclude *string
oldAppInclude *string
oldAppExclude *string
siteInclude *string
siteExclude *string
appInclude *string
appExclude *string
siteIncludeSet bool
siteExcludeSet bool
appIncludeSet bool
appExcludeSet bool
)
type simple_version struct {
@@ -89,8 +105,8 @@ type IISCollector struct {
TotalNotFoundErrors *prometheus.Desc
TotalRejectedAsyncIORequests *prometheus.Desc
siteWhitelistPattern *regexp.Regexp
siteBlacklistPattern *regexp.Regexp
siteIncludePattern *regexp.Regexp
siteExcludePattern *regexp.Regexp
// APP_POOL_WAS
CurrentApplicationPoolState *prometheus.Desc
@@ -192,29 +208,94 @@ type IISCollector struct {
ServiceCache_OutputCacheFlushedItemsTotal *prometheus.Desc
ServiceCache_OutputCacheFlushesTotal *prometheus.Desc
appWhitelistPattern *regexp.Regexp
appBlacklistPattern *regexp.Regexp
appIncludePattern *regexp.Regexp
appExcludePattern *regexp.Regexp
iis_version simple_version
}
func newIISCollectorFlags(app *kingpin.Application) {
siteWhitelist = kingpin.Flag(FlagISSSiteWhitelist, "Regexp of sites to whitelist. Site name must both match whitelist and not match blacklist to be included.").Default(".+").String()
siteBlacklist = kingpin.Flag(FlagISSSiteBlacklist, "Regexp of sites to blacklist. Site name must both match whitelist and not match blacklist to be included.").String()
appWhitelist = kingpin.Flag(FlagISSAppWhitelist, "Regexp of apps to whitelist. App name must both match whitelist and not match blacklist to be included.").Default(".+").String()
appBlacklist = kingpin.Flag(FlagISSAppBlacklist, "Regexp of apps to blacklist. App name must both match whitelist and not match blacklist to be included.").String()
oldSiteInclude = app.Flag(FlagIISSiteOldInclude, "DEPRECATED: Use --collector.iis.site-include").Default(".+").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(".+").PreAction(func(c *kingpin.ParseContext) error {
siteIncludeSet = true
return nil
}).String()
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(c *kingpin.ParseContext) error {
siteExcludeSet = true
return nil
}).String()
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(c *kingpin.ParseContext) error {
appIncludeSet = true
return nil
}).String()
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(c *kingpin.ParseContext) error {
siteExcludeSet = true
return nil
}).String()
}
func newIISCollector() (Collector, error) {
const subsystem = "iis"
if *oldSiteExclude != "" {
if !siteExcludeSet {
log.Warnln("msg", "--collector.iis.site-blacklist is DEPRECATED and will be removed in a future release, use --collector.iis.site-exclude")
*siteExclude = *oldSiteExclude
} else {
return nil, errors.New("--collector.iis.site-blacklist and --collector.iis.site-exclude are mutually exclusive")
}
}
if *oldSiteInclude != "" {
if !siteIncludeSet {
log.Warnln("msg", "--collector.iis.site-whitelist is DEPRECATED and will be removed in a future release, use --collector.iis.site-include")
*siteInclude = *oldSiteInclude
} else {
return nil, errors.New("--collector.iis.site-whitelist and --collector.iis.site-include are mutually exclusive")
}
}
if *oldAppExclude != "" {
if !appExcludeSet {
log.Warnln("msg", "--collector.iis.app-blacklist is DEPRECATED and will be removed in a future release, use --collector.iis.app-exclude")
*appExclude = *oldAppExclude
} else {
return nil, errors.New("--collector.iis.app-blacklist and --collector.iis.app-exclude are mutually exclusive")
}
}
if *oldAppInclude != "" {
if !appIncludeSet {
log.Warnln("msg", "--collector.iis.app-whitelist is DEPRECATED and will be removed in a future release, use --collector.iis.app-include")
*appInclude = *oldAppInclude
} else {
return nil, errors.New("--collector.iis.app-whitelist and --collector.iis.app-include are mutually exclusive")
}
}
const subsystem = "iis"
return &IISCollector{
iis_version: getIISVersion(),
siteWhitelistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *siteWhitelist)),
siteBlacklistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *siteBlacklist)),
appWhitelistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *appWhitelist)),
appBlacklistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *appBlacklist)),
siteIncludePattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *siteInclude)),
siteExcludePattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *siteExclude)),
appIncludePattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *appInclude)),
appExcludePattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *appExclude)),
// Web Service
CurrentAnonymousUsers: prometheus.NewDesc(
@@ -903,7 +984,7 @@ func (c *IISCollector) collectWebService(ctx *ScrapeContext, ch chan<- prometheu
}
for _, app := range WebService {
if app.Name == "_Total" || c.siteBlacklistPattern.MatchString(app.Name) || !c.siteWhitelistPattern.MatchString(app.Name) {
if app.Name == "_Total" || c.siteExcludePattern.MatchString(app.Name) || !c.siteIncludePattern.MatchString(app.Name) {
continue
}
@@ -1188,8 +1269,8 @@ func (c *IISCollector) collectAPP_POOL_WAS(ctx *ScrapeContext, ch chan<- prometh
for _, app := range APP_POOL_WAS {
if app.Name == "_Total" ||
c.appBlacklistPattern.MatchString(app.Name) ||
!c.appWhitelistPattern.MatchString(app.Name) {
c.appExcludePattern.MatchString(app.Name) ||
!c.appIncludePattern.MatchString(app.Name) {
continue
}
@@ -1366,8 +1447,8 @@ func (c *IISCollector) collectW3SVC_W3WP(ctx *ScrapeContext, ch chan<- prometheu
pid := workerProcessNameExtractor.ReplaceAllString(app.Name, "$1")
name := workerProcessNameExtractor.ReplaceAllString(app.Name, "$2")
if name == "" || name == "_Total" ||
c.appBlacklistPattern.MatchString(name) ||
!c.appWhitelistPattern.MatchString(name) {
c.appExcludePattern.MatchString(name) ||
!c.appIncludePattern.MatchString(name) {
continue
}
@@ -1618,8 +1699,8 @@ func (c *IISCollector) collectW3SVC_W3WP(ctx *ScrapeContext, ch chan<- prometheu
pid := workerProcessNameExtractor.ReplaceAllString(app.Name, "$1")
name := workerProcessNameExtractor.ReplaceAllString(app.Name, "$2")
if name == "" || name == "_Total" ||
c.appBlacklistPattern.MatchString(name) ||
!c.appWhitelistPattern.MatchString(name) {
c.appExcludePattern.MatchString(name) ||
!c.appIncludePattern.MatchString(name) {
continue
}

View File

@@ -4,6 +4,7 @@
package collector
import (
"errors"
"fmt"
"regexp"
@@ -13,13 +14,22 @@ import (
)
const (
FlagLogicalDiskVolumeBlacklist = "collector.logical_disk.volume-blacklist"
FlagLogicalDiskVolumeWhitelist = "collector.logical_disk.volume-whitelist"
FlagLogicalDiskVolumeOldExclude = "collector.logical_disk.volume-blacklist"
FlagLogicalDiskVolumeOldInclude = "collector.logical_disk.volume-whitelist"
FlagLogicalDiskVolumeExclude = "collector.logical_disk.volume-exclude"
FlagLogicalDiskVolumeInclude = "collector.logical_disk.volume-include"
)
var (
volumeWhitelist *string
volumeBlacklist *string
volumeOldInclude *string
volumeOldExclude *string
volumeInclude *string
volumeExclude *string
volumeIncludeSet bool
volumeExcludeSet bool
)
// A LogicalDiskCollector is a Prometheus collector for perflib logicalDisk metrics
@@ -41,24 +51,57 @@ type LogicalDiskCollector struct {
WriteLatency *prometheus.Desc
ReadWriteLatency *prometheus.Desc
volumeWhitelistPattern *regexp.Regexp
volumeBlacklistPattern *regexp.Regexp
volumeIncludePattern *regexp.Regexp
volumeExcludePattern *regexp.Regexp
}
// newLogicalDiskCollectorFlags ...
func newLogicalDiskCollectorFlags(app *kingpin.Application) {
volumeWhitelist = app.Flag(
FlagLogicalDiskVolumeWhitelist,
"Regexp of volumes to whitelist. Volume name must both match whitelist and not match blacklist to be included.",
).Default(".+").String()
volumeBlacklist = app.Flag(
FlagLogicalDiskVolumeBlacklist,
"Regexp of volumes to blacklist. Volume name must both match whitelist and not match blacklist to be included.",
).Default("").String()
volumeInclude = app.Flag(
FlagLogicalDiskVolumeInclude,
"Regexp of volumes to include. Volume name must both match include and not match exclude to be included.",
).Default(".+").PreAction(func(c *kingpin.ParseContext) error {
volumeIncludeSet = true
return nil
}).String()
volumeExclude = app.Flag(
FlagLogicalDiskVolumeExclude,
"Regexp of volumes to exclude. Volume name must both match include and not match exclude to be included.",
).Default("").PreAction(func(c *kingpin.ParseContext) error {
volumeExcludeSet = true
return nil
}).String()
volumeOldInclude = app.Flag(
FlagLogicalDiskVolumeOldInclude,
"DEPRECATED: Use --collector.logical_disk.volume-include",
).Hidden().String()
volumeOldExclude = app.Flag(
FlagLogicalDiskVolumeOldExclude,
"DEPRECATED: Use --collector.logical_disk.volume-exclude",
).Hidden().String()
}
// newLogicalDiskCollector ...
func newLogicalDiskCollector() (Collector, error) {
if *volumeOldExclude != "" {
if !volumeExcludeSet {
log.Warnln("msg", "--collector.logical_disk.volume-blacklist is DEPRECATED and will be removed in a future release, use --collector.logical_disk.volume-exclude")
*volumeExclude = *volumeOldExclude
} else {
return nil, errors.New("--collector.logical_disk.volume-blacklist and --collector.logical_disk.volume-exclude are mutually exclusive")
}
}
if *volumeOldInclude != "" {
if !volumeIncludeSet {
log.Warnln("msg", "--collector.logical_disk.volume-whitelist is DEPRECATED and will be removed in a future release, use --collector.logical_disk.volume-include")
*volumeInclude = *volumeOldInclude
} else {
return nil, errors.New("--collector.logical_disk.volume-whitelist and --collector.logical_disk.volume-include are mutually exclusive")
}
}
const subsystem = "logical_disk"
return &LogicalDiskCollector{
@@ -174,8 +217,8 @@ func newLogicalDiskCollector() (Collector, error) {
nil,
),
volumeWhitelistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *volumeWhitelist)),
volumeBlacklistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *volumeBlacklist)),
volumeIncludePattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *volumeInclude)),
volumeExcludePattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *volumeExclude)),
}, nil
}
@@ -220,8 +263,8 @@ func (c *LogicalDiskCollector) collect(ctx *ScrapeContext, ch chan<- prometheus.
for _, volume := range dst {
if volume.Name == "_Total" ||
c.volumeBlacklistPattern.MatchString(volume.Name) ||
!c.volumeWhitelistPattern.MatchString(volume.Name) {
c.volumeExcludePattern.MatchString(volume.Name) ||
!c.volumeIncludePattern.MatchString(volume.Name) {
continue
}

View File

@@ -6,8 +6,8 @@ import (
func BenchmarkLogicalDiskCollector(b *testing.B) {
// Whitelist is not set in testing context (kingpin flags not parsed), causing the collector to skip all disks.
localVolumeWhitelist := ".+"
volumeWhitelist = &localVolumeWhitelist
localVolumeInclude := ".+"
volumeInclude = &localVolumeInclude
benchmarkCollector(b, "logical_disk", newLogicalDiskCollector)
}

View File

@@ -4,6 +4,7 @@
package collector
import (
"errors"
"fmt"
"regexp"
@@ -13,13 +14,23 @@ import (
)
const (
FlagNicBlacklist = "collector.net.nic-blacklist"
FlagNicWhitelist = "collector.net.nic-whitelist"
FlagNicOldExclude = "collector.net.nic-blacklist"
FlagNicOldInclude = "collector.net.nic-whitelist"
FlagNicExclude = "collector.net.nic-exclude"
FlagNicInclude = "collector.net.nic-include"
)
var (
nicWhitelist *string
nicBlacklist *string
nicOldInclude *string
nicOldExclude *string
nicInclude *string
nicExclude *string
nicIncludeSet bool
nicExcludeSet bool
nicNameToUnderscore = regexp.MustCompile("[^a-zA-Z0-9]")
)
@@ -39,24 +50,58 @@ type NetworkCollector struct {
PacketsSentTotal *prometheus.Desc
CurrentBandwidth *prometheus.Desc
nicWhitelistPattern *regexp.Regexp
nicBlacklistPattern *regexp.Regexp
nicIncludePattern *regexp.Regexp
nicExcludePattern *regexp.Regexp
}
// newNetworkCollectorFlags ...
func newNetworkCollectorFlags(app *kingpin.Application) {
nicWhitelist = app.Flag(
FlagNicWhitelist,
"Regexp of NIC:s to whitelist. NIC name must both match whitelist and not match blacklist to be included.",
).Default(".+").String()
nicBlacklist = app.Flag(
FlagNicBlacklist,
"Regexp of NIC:s to blacklist. NIC name must both match whitelist and not match blacklist to be included.",
).Default("").String()
nicInclude = app.Flag(
FlagNicInclude,
"Regexp of NIC:s to include. NIC name must both match include and not match exclude to be included.",
).Default(".+").PreAction(func(c *kingpin.ParseContext) error {
nicIncludeSet = true
return nil
}).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("").PreAction(func(c *kingpin.ParseContext) error {
nicExcludeSet = true
return nil
}).String()
nicOldInclude = app.Flag(
FlagNicOldInclude,
"DEPRECATED: Use --collector.net.nic-include",
).Hidden().String()
nicOldExclude = app.Flag(
FlagNicOldExclude,
"DEPRECATED: Use --collector.net.nic-exclude",
).Hidden().String()
}
// newNetworkCollector ...
func newNetworkCollector() (Collector, error) {
if *nicOldExclude != "" {
if !nicExcludeSet {
log.Warnln("msg", "--collector.net.nic-blacklist is DEPRECATED and will be removed in a future release, use --collector.net.nic-exclude")
*nicExclude = *nicOldExclude
} else {
return nil, errors.New("--collector.net.nic-blacklist and --collector.net.nic-exclude are mutually exclusive")
}
}
if *nicOldInclude != "" {
if !nicIncludeSet {
log.Warnln("msg", "--collector.net.nic-whitelist is DEPRECATED and will be removed in a future release, use --collector.net.nic-include")
*nicInclude = *nicOldInclude
} else {
return nil, errors.New("--collector.net.nic-whitelist and --collector.net.nic-include are mutually exclusive")
}
}
const subsystem = "net"
return &NetworkCollector{
@@ -139,8 +184,8 @@ func newNetworkCollector() (Collector, error) {
nil,
),
nicWhitelistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *nicWhitelist)),
nicBlacklistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *nicBlacklist)),
nicIncludePattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *nicInclude)),
nicExcludePattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *nicExclude)),
}, nil
}
@@ -187,8 +232,8 @@ func (c *NetworkCollector) collect(ctx *ScrapeContext, ch chan<- prometheus.Metr
}
for _, nic := range dst {
if c.nicBlacklistPattern.MatchString(nic.Name) ||
!c.nicWhitelistPattern.MatchString(nic.Name) {
if c.nicExcludePattern.MatchString(nic.Name) ||
!c.nicIncludePattern.MatchString(nic.Name) {
continue
}

View File

@@ -20,8 +20,8 @@ func TestNetworkToInstanceName(t *testing.T) {
}
func BenchmarkNetCollector(b *testing.B) {
// Whitelist is not set in testing context (kingpin flags not parsed), causing the collector to skip all interfaces.
localNicWhitelist := ".+"
nicWhitelist = &localNicWhitelist
// Include is not set in testing context (kingpin flags not parsed), causing the collector to skip all interfaces.
localNicInclude := ".+"
nicInclude = &localNicInclude
benchmarkCollector(b, "net", newNetworkCollector)
}

View File

@@ -4,6 +4,7 @@
package collector
import (
"errors"
"fmt"
"regexp"
"strconv"
@@ -16,13 +17,22 @@ import (
)
const (
FlagProcessBlacklist = "collector.process.blacklist"
FlagProcessWhitelist = "collector.process.whitelist"
FlagProcessOldExclude = "collector.process.blacklist"
FlagProcessOldInclude = "collector.process.whitelist"
FlagProcessExclude = "collector.process.exclude"
FlagProcessInclude = "collector.process.include"
)
var (
processWhitelist *string
processBlacklist *string
processOldInclude *string
processOldExclude *string
processInclude *string
processExclude *string
processIncludeSet bool
processExcludeSet bool
)
type processCollector struct {
@@ -42,27 +52,60 @@ type processCollector struct {
WorkingSetPeak *prometheus.Desc
WorkingSet *prometheus.Desc
processWhitelistPattern *regexp.Regexp
processBlacklistPattern *regexp.Regexp
processIncludePattern *regexp.Regexp
processExcludePattern *regexp.Regexp
}
// newProcessCollectorFlags ...
func newProcessCollectorFlags(app *kingpin.Application) {
processWhitelist = app.Flag(
FlagProcessWhitelist,
"Regexp of processes to include. Process name must both match whitelist and not match blacklist to be included.",
).Default(".*").String()
processBlacklist = app.Flag(
FlagProcessBlacklist,
"Regexp of processes to exclude. Process name must both match whitelist and not match blacklist to be included.",
).Default("").String()
processInclude = app.Flag(
FlagProcessInclude,
"Regexp of processes to include. Process name must both match include and not match exclude to be included.",
).Default(".*").PreAction(func(c *kingpin.ParseContext) error {
processIncludeSet = true
return nil
}).String()
processExclude = app.Flag(
FlagProcessExclude,
"Regexp of processes to exclude. Process name must both match include and not match exclude to be included.",
).Default("").PreAction(func(c *kingpin.ParseContext) error {
processExcludeSet = true
return nil
}).String()
processOldInclude = app.Flag(
FlagProcessOldInclude,
"DEPRECATED: Use --collector.process.include",
).Hidden().String()
processOldExclude = app.Flag(
FlagProcessOldExclude,
"DEPRECATED: Use --collector.process.exclude",
).Hidden().String()
}
// NewProcessCollector ...
func newProcessCollector() (Collector, error) {
const subsystem = "process"
if *processWhitelist == ".*" && *processBlacklist == "" {
if *processOldExclude != "" {
if !processExcludeSet {
log.Warnln("msg", "--collector.process.blacklist is DEPRECATED and will be removed in a future release, use --collector.process.exclude")
*processExclude = *processOldExclude
} else {
return nil, errors.New("--collector.process.blacklist and --collector.process.exclude are mutually exclusive")
}
}
if *processOldInclude != "" {
if !processIncludeSet {
log.Warnln("msg", "--collector.process.whitelist is DEPRECATED and will be removed in a future release, use --collector.process.include")
*processInclude = *processOldInclude
} else {
return nil, errors.New("--collector.process.whitelist and --collector.process.include are mutually exclusive")
}
}
if *processInclude == ".*" && *processExclude == "" {
log.Warn("No filters specified for process collector. This will generate a very large number of metrics!")
}
@@ -157,8 +200,8 @@ func newProcessCollector() (Collector, error) {
[]string{"process", "process_id", "creating_process_id"},
nil,
),
processWhitelistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *processWhitelist)),
processBlacklistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *processBlacklist)),
processIncludePattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *processInclude)),
processExcludePattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *processExclude)),
}, nil
}
@@ -214,8 +257,8 @@ func (c *processCollector) Collect(ctx *ScrapeContext, ch chan<- prometheus.Metr
for _, process := range data {
if process.Name == "_Total" ||
c.processBlacklistPattern.MatchString(process.Name) ||
!c.processWhitelistPattern.MatchString(process.Name) {
c.processExcludePattern.MatchString(process.Name) ||
!c.processIncludePattern.MatchString(process.Name) {
continue
}
// Duplicate processes are suffixed # and an index number. Remove those.

View File

@@ -5,9 +5,9 @@ import (
)
func BenchmarkProcessCollector(b *testing.B) {
// Whitelist is not set in testing context (kingpin flags not parsed), causing the collector to skip all processes.
localProcessWhitelist := ".+"
processWhitelist = &localProcessWhitelist
// Include is not set in testing context (kingpin flags not parsed), causing the collector to skip all processes.
localProcessInclude := ".+"
processInclude = &localProcessInclude
// No context name required as collector source is WMI
benchmarkCollector(b, "", newProcessCollector)

View File

@@ -4,6 +4,7 @@
package collector
import (
"errors"
"fmt"
"regexp"
"runtime"
@@ -17,13 +18,22 @@ import (
)
const (
FlagScheduledTaskBlacklist = "collector.scheduled_task.blacklist"
FlagScheduledTaskWhitelist = "collector.scheduled_task.whitelist"
FlagScheduledTaskOldExclude = "collector.scheduled_task.blacklist"
FlagScheduledTaskOldInclude = "collector.scheduled_task.whitelist"
FlagScheduledTaskExclude = "collector.scheduled_task.exclude"
FlagScheduledTaskInclude = "collector.scheduled_task.include"
)
var (
taskWhitelist *string
taskBlacklist *string
taskOldExclude *string
taskOldInclude *string
taskExclude *string
taskInclude *string
taskIncludeSet bool
taskExcludeSet bool
)
type ScheduledTaskCollector struct {
@@ -31,8 +41,8 @@ type ScheduledTaskCollector struct {
MissedRuns *prometheus.Desc
State *prometheus.Desc
taskWhitelistPattern *regexp.Regexp
taskBlacklistPattern *regexp.Regexp
taskIncludePattern *regexp.Regexp
taskExcludePattern *regexp.Regexp
}
// TaskState ...
@@ -64,18 +74,51 @@ type ScheduledTasks []ScheduledTask
// newScheduledTask ...
func newScheduledTaskFlags(app *kingpin.Application) {
taskWhitelist = app.Flag(
FlagScheduledTaskWhitelist,
"Regexp of tasks to whitelist. Task path must both match whitelist and not match blacklist to be included.",
).Default(".+").String()
taskBlacklist = app.Flag(
FlagScheduledTaskBlacklist,
"Regexp of tasks to blacklist. Task path must both match whitelist and not match blacklist to be included.",
).String()
taskInclude = app.Flag(
FlagScheduledTaskInclude,
"Regexp of tasks to include. Task path must both match include and not match exclude to be included.",
).Default(".+").PreAction(func(c *kingpin.ParseContext) error {
taskIncludeSet = true
return nil
}).String()
taskExclude = app.Flag(
FlagScheduledTaskExclude,
"Regexp of tasks to exclude. Task path must both match include and not match exclude to be included.",
).Default("").PreAction(func(c *kingpin.ParseContext) error {
taskExcludeSet = true
return nil
}).String()
taskOldInclude = app.Flag(
FlagScheduledTaskOldInclude,
"DEPRECATED: Use --collector.scheduled_task.include",
).Hidden().String()
taskOldExclude = app.Flag(
FlagScheduledTaskOldExclude,
"DEPRECATED: Use --collector.scheduled_task.exclude",
).Hidden().String()
}
// newScheduledTask ...
func newScheduledTask() (Collector, error) {
if *taskOldExclude != "" {
if !taskExcludeSet {
log.Warnln("msg", "--collector.scheduled_task.blacklist is DEPRECATED and will be removed in a future release, use --collector.scheduled_task.exclude")
*taskExclude = *taskOldExclude
} else {
return nil, errors.New("--collector.scheduled_task.blacklist and --collector.scheduled_task.exclude are mutually exclusive")
}
}
if *taskOldInclude != "" {
if !taskIncludeSet {
log.Warnln("msg", "--collector.scheduled_task.whitelist is DEPRECATED and will be removed in a future release, use --collector.scheduled_task.include")
*taskInclude = *taskOldInclude
} else {
return nil, errors.New("--collector.scheduled_task.whitelist and --collector.scheduled_task.include are mutually exclusive")
}
}
const subsystem = "scheduled_task"
runtime.LockOSThread()
@@ -112,8 +155,8 @@ func newScheduledTask() (Collector, error) {
nil,
),
taskWhitelistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *taskWhitelist)),
taskBlacklistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *taskBlacklist)),
taskIncludePattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *taskInclude)),
taskExcludePattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *taskExclude)),
}, nil
}
@@ -135,8 +178,8 @@ func (c *ScheduledTaskCollector) collect(ch chan<- prometheus.Metric) (*promethe
}
for _, task := range scheduledTasks {
if c.taskBlacklistPattern.MatchString(task.Path) ||
!c.taskWhitelistPattern.MatchString(task.Path) {
if c.taskExcludePattern.MatchString(task.Path) ||
!c.taskIncludePattern.MatchString(task.Path) {
continue
}

View File

@@ -4,6 +4,7 @@
package collector
import (
"errors"
"fmt"
"github.com/alecthomas/kingpin/v2"
"github.com/prometheus-community/windows_exporter/log"
@@ -12,13 +13,22 @@ import (
)
const (
FlagSmtpServerBlacklist = "collector.smtp.server-blacklist"
FlagSmtpServerWhitelist = "collector.smtp.server-whitelist"
FlagSmtpServerOldExclude = "collector.smtp.server-blacklist"
FlagSmtpServerOldInclude = "collector.smtp.server-whitelist"
FlagSmtpServerExclude = "collector.smtp.server-exclude"
FlagSmtpServerInclude = "collector.smtp.server-include"
)
var (
serverWhitelist *string
serverBlacklist *string
serverOldInclude *string
serverOldExclude *string
serverInclude *string
serverExclude *string
serverIncludeSet bool
serverExcludeSet bool
)
type SMTPCollector struct {
@@ -65,19 +75,58 @@ type SMTPCollector struct {
RemoteRetryQueueLength *prometheus.Desc
RoutingTableLookupsTotal *prometheus.Desc
serverWhitelistPattern *regexp.Regexp
serverBlacklistPattern *regexp.Regexp
serverIncludePattern *regexp.Regexp
serverExcludePattern *regexp.Regexp
}
func newSMTPCollectorFlags(app *kingpin.Application) {
serverWhitelist = app.Flag(FlagSmtpServerWhitelist, "Regexp of virtual servers to whitelist. Server name must both match whitelist and not match blacklist to be included.").Default(".+").String()
serverBlacklist = app.Flag(FlagSmtpServerBlacklist, "Regexp of virtual servers to blacklist. Server name must both match whitelist and not match blacklist to be included.").String()
serverInclude = app.Flag(
FlagSmtpServerInclude,
"Regexp of virtual servers to include. Server name must both match include and not match exclude to be included.",
).Default(".+").PreAction(func(c *kingpin.ParseContext) error {
serverIncludeSet = true
return nil
}).String()
serverExclude = app.Flag(
FlagSmtpServerExclude,
"Regexp of virtual servers to exclude. Server name must both match include and not match exclude to be included.",
).Default("").PreAction(func(c *kingpin.ParseContext) error {
serverExcludeSet = true
return nil
}).String()
serverOldInclude = app.Flag(
FlagSmtpServerOldInclude,
"DEPRECATED: Use --collector.smtp.server-include",
).Hidden().String()
serverOldExclude = app.Flag(
FlagSmtpServerOldExclude,
"DEPRECATED: Use --collector.smtp.server-exclude",
).Hidden().String()
}
func newSMTPCollector() (Collector, error) {
log.Info("smtp collector is in an experimental state! Metrics for this collector have not been tested.")
const subsystem = "smtp"
if *serverOldExclude != "" {
if !serverExcludeSet {
log.Warnln("msg", "--collector.smtp.server-blacklist is DEPRECATED and will be removed in a future release, use --collector.smtp.server-exclude")
*serverExclude = *serverOldExclude
} else {
return nil, errors.New("--collector.smtp.server-blacklist and --collector.smtp.server-exclude are mutually exclusive")
}
}
if *serverOldInclude != "" {
if !serverIncludeSet {
log.Warnln("msg", "--collector.smtp.server-whitelist is DEPRECATED and will be removed in a future release, use --collector.smtp.server-include")
*serverInclude = *serverOldInclude
} else {
return nil, errors.New("--collector.smtp.server-whitelist and --collector.smtp.server-include are mutually exclusive")
}
}
const subsystem = "smtp"
return &SMTPCollector{
BadmailedMessagesBadPickupFileTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "badmailed_messages_bad_pickup_file_total"),
@@ -332,8 +381,8 @@ func newSMTPCollector() (Collector, error) {
nil,
),
serverWhitelistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *serverWhitelist)),
serverBlacklistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *serverBlacklist)),
serverIncludePattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *serverInclude)),
serverExcludePattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *serverExclude)),
}, nil
}
@@ -403,8 +452,8 @@ func (c *SMTPCollector) collect(ctx *ScrapeContext, ch chan<- prometheus.Metric)
for _, server := range dst {
if server.Name == "_Total" ||
c.serverBlacklistPattern.MatchString(server.Name) ||
!c.serverWhitelistPattern.MatchString(server.Name) {
c.serverExcludePattern.MatchString(server.Name) ||
!c.serverIncludePattern.MatchString(server.Name) {
continue
}