Skip to content

Commit

Permalink
feat: Remove init functions from collectors
Browse files Browse the repository at this point in the history
Behaviour of init functions has been centralised in `collector/init.go`,
and can be called during exporter startup. This allows the exporter to
control the timing of collector initialisation, rather than relying on
the import & `init()` method.

This should reduce unexpected behaviour arising from the use of
`init()`, such as prometheus-community#551.

Signed-off-by: Ben Reedy <[email protected]>
  • Loading branch information
breed808 committed Dec 21, 2022
1 parent 015b7c0 commit 1a974bf
Show file tree
Hide file tree
Showing 49 changed files with 297 additions and 216 deletions.
4 changes: 0 additions & 4 deletions collector/ad.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ import (
"github.com/prometheus/client_golang/prometheus"
)

func init() {
registerCollector("ad", NewADCollector)
}

// A ADCollector is a Prometheus collector for WMI Win32_PerfRawData_DirectoryServices_DirectoryServices metrics
type ADCollector struct {
AddressBookOperationsTotal *prometheus.Desc
Expand Down
4 changes: 0 additions & 4 deletions collector/adcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import (
"strings"
)

func init() {
registerCollector("adcs", adcsCollectorMethod, "Certification Authority")
}

type adcsCollector struct {
RequestsPerSecond *prometheus.Desc
RequestProcessingTime *prometheus.Desc
Expand Down
4 changes: 0 additions & 4 deletions collector/adfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import (
"math"
)

func init() {
registerCollector("adfs", newADFSCollector, "AD FS")
}

type adfsCollector struct {
adLoginConnectionFailures *prometheus.Desc
certificateAuthentications *prometheus.Desc
Expand Down
4 changes: 0 additions & 4 deletions collector/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import (
"github.com/prometheus/client_golang/prometheus"
)

func init() {
registerCollector("cache", newCacheCollector, "Cache")
}

// A CacheCollector is a Prometheus collector for Perflib Cache metrics
type CacheCollector struct {
AsyncCopyReadsTotal *prometheus.Desc
Expand Down
4 changes: 0 additions & 4 deletions collector/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import (
"github.com/prometheus/client_golang/prometheus"
)

func init() {
registerCollector("container", NewContainerMetricsCollector)
}

// A ContainerMetricsCollector is a Prometheus collector for containers metrics
type ContainerMetricsCollector struct {
// Presence
Expand Down
11 changes: 0 additions & 11 deletions collector/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,6 @@ import (
"github.com/prometheus/client_golang/prometheus"
)

func init() {
var deps string
// See below for 6.05 magic value
if getWindowsVersion() > 6.05 {
deps = "Processor Information"
} else {
deps = "Processor"
}
registerCollector("cpu", newCPUCollector, deps)
}

type cpuCollectorBasic struct {
CStateSecondsTotal *prometheus.Desc
TimeTotal *prometheus.Desc
Expand Down
4 changes: 0 additions & 4 deletions collector/cpu_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ import (
"github.com/prometheus/client_golang/prometheus"
)

func init() {
registerCollector("cpu_info", newCpuInfoCollector)
}

// If you are adding additional labels to the metric, make sure that they get added in here as well. See below for explanation.
const (
win32ProcessorQuery = "SELECT Architecture, DeviceId, Description, Family, L2CacheSize, L3CacheSize, Name FROM Win32_Processor"
Expand Down
4 changes: 0 additions & 4 deletions collector/cs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import (
"github.com/prometheus/client_golang/prometheus"
)

func init() {
registerCollector("cs", NewCSCollector)
}

// A CSCollector is a Prometheus collector for WMI metrics
type CSCollector struct {
PhysicalMemoryBytes *prometheus.Desc
Expand Down
10 changes: 0 additions & 10 deletions collector/dfsr.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ import (

var dfsrEnabledCollectors = kingpin.Flag("collectors.dfsr.sources-enabled", "Comma-seperated list of DFSR Perflib sources to use.").Default("connection,folder,volume").String()

func init() {
// Perflib sources are dynamic, depending on the enabled child collectors
var perflibDependencies []string
for _, source := range expandEnabledChildCollectors(*dfsrEnabledCollectors) {
perflibDependencies = append(perflibDependencies, dfsrGetPerfObjectName(source))
}

registerCollector("dfsr", NewDFSRCollector, perflibDependencies...)
}

// DFSRCollector contains the metric and state data of the DFSR collectors.
type DFSRCollector struct {
// Connection source
Expand Down
4 changes: 0 additions & 4 deletions collector/dhcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import (
"github.com/prometheus/client_golang/prometheus"
)

func init() {
registerCollector("dhcp", NewDhcpCollector, "DHCP Server")
}

// A DhcpCollector is a Prometheus collector perflib DHCP metrics
type DhcpCollector struct {
PacketsReceivedTotal *prometheus.Desc
Expand Down
4 changes: 0 additions & 4 deletions collector/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ import (
"github.com/prometheus/client_golang/prometheus"
)

func init() {
registerCollector("dns", NewDNSCollector)
}

// A DNSCollector is a Prometheus collector for WMI Win32_PerfRawData_DNS_DNS metrics
type DNSCollector struct {
ZoneTransferRequestsReceived *prometheus.Desc
Expand Down
14 changes: 0 additions & 14 deletions collector/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,6 @@ import (
"gopkg.in/alecthomas/kingpin.v2"
)

func init() {
registerCollector("exchange", newExchangeCollector,
"MSExchange ADAccess Processes",
"MSExchangeTransport Queues",
"MSExchange HttpProxy",
"MSExchange ActiveSync",
"MSExchange Availability Service",
"MSExchange OWA",
"MSExchangeAutodiscover",
"MSExchange WorkloadManagement Workloads",
"MSExchange RpcClientAccess",
)
}

type exchangeCollector struct {
LDAPReadTime *prometheus.Desc
LDAPSearchTime *prometheus.Desc
Expand Down
4 changes: 0 additions & 4 deletions collector/fsrmquota.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import (
"github.com/prometheus/client_golang/prometheus"
)

func init() {
registerCollector("fsrmquota", newFSRMQuotaCollector)
}

type FSRMQuotaCollector struct {
QuotasCount *prometheus.Desc
Path *prometheus.Desc
Expand Down
4 changes: 0 additions & 4 deletions collector/hyperv.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ import (
"github.com/prometheus/client_golang/prometheus"
)

func init() {
registerCollector("hyperv", NewHyperVCollector)
}

// HyperVCollector is a Prometheus collector for hyper-v
type HyperVCollector struct {
// Win32_PerfRawData_VmmsVirtualMachineStats_HyperVVirtualMachineHealthSummary
Expand Down
4 changes: 0 additions & 4 deletions collector/iis.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ import (
"gopkg.in/alecthomas/kingpin.v2"
)

func init() {
registerCollector("iis", NewIISCollector, "Web Service", "APP_POOL_WAS", "Web Service Cache", "W3SVC_W3WP")
}

var (
siteWhitelist = kingpin.Flag("collector.iis.site-whitelist", "Regexp of sites to whitelist. Site name must both match whitelist and not match blacklist to be included.").Default(".+").String()
siteBlacklist = kingpin.Flag("collector.iis.site-blacklist", "Regexp of sites to blacklist. Site name must both match whitelist and not match blacklist to be included.").String()
Expand Down
Loading

0 comments on commit 1a974bf

Please sign in to comment.