Switch to kingpin flags (#639)
* Switch to kingpin flags * Fix logrus vendoring * Fix flags in main tests * Fix vendoring versions
This commit is contained in:
parent
1467d845fb
commit
dfe07eaae8
84 changed files with 9904 additions and 196 deletions
|
|
@ -17,7 +17,6 @@ package collector
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
|
@ -27,6 +26,7 @@ import (
|
|||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/common/log"
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -35,7 +35,7 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
ignoredDevices = flag.String("collector.diskstats.ignored-devices", "^(ram|loop|fd|(h|s|v|xv)d[a-z]|nvme\\d+n\\d+p)\\d+$", "Regexp of devices to ignore for diskstats.")
|
||||
ignoredDevices = kingpin.Flag("collector.diskstats.ignored-devices", "Regexp of devices to ignore for diskstats.").Default("^(ram|loop|fd|(h|s|v|xv)d[a-z]|nvme\\d+n\\d+p)\\d+$").String()
|
||||
)
|
||||
|
||||
type diskstatsCollector struct {
|
||||
|
|
|
|||
|
|
@ -17,10 +17,10 @@
|
|||
package collector
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"regexp"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
// Arch-dependent implementation must define:
|
||||
|
|
@ -30,15 +30,14 @@ import (
|
|||
// * filesystemCollector.GetStats
|
||||
|
||||
var (
|
||||
ignoredMountPoints = flag.String(
|
||||
ignoredMountPoints = kingpin.Flag(
|
||||
"collector.filesystem.ignored-mount-points",
|
||||
defIgnoredMountPoints,
|
||||
"Regexp of mount points to ignore for filesystem collector.")
|
||||
|
||||
ignoredFSTypes = flag.String(
|
||||
"Regexp of mount points to ignore for filesystem collector.",
|
||||
).Default(defIgnoredMountPoints).String()
|
||||
ignoredFSTypes = kingpin.Flag(
|
||||
"collector.filesystem.ignored-fs-types",
|
||||
defIgnoredFSTypes,
|
||||
"Regexp of filesystem types to ignore for filesystem collector.")
|
||||
"Regexp of filesystem types to ignore for filesystem collector.",
|
||||
).Default(defIgnoredFSTypes).String()
|
||||
|
||||
filesystemLabelNames = []string{"device", "mountpoint", "fstype"}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@
|
|||
package collector
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
|
@ -24,10 +23,11 @@ import (
|
|||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
func TestIPVSCollector(t *testing.T) {
|
||||
if err := flag.Set("collector.procfs", "fixtures/proc"); err != nil {
|
||||
if _, err := kingpin.CommandLine.Parse([]string{"--collector.procfs", "fixtures/proc"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
collector, err := newIPVSCollector()
|
||||
|
|
@ -76,7 +76,7 @@ func (c miniCollector) Describe(ch chan<- *prometheus.Desc) {
|
|||
}
|
||||
|
||||
func TestIPVSCollectorResponse(t *testing.T) {
|
||||
if err := flag.Set("collector.procfs", "fixtures/proc"); err != nil {
|
||||
if _, err := kingpin.CommandLine.Parse([]string{"--collector.procfs", "fixtures/proc"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
collector, err := NewIPVSCollector()
|
||||
|
|
|
|||
|
|
@ -17,13 +17,13 @@ package collector
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"flag"
|
||||
"io"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -32,7 +32,7 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
megacliCommand = flag.String("collector.megacli.command", defaultMegaCli, "Command to run megacli.")
|
||||
megacliCommand = kingpin.Flag("collector.megacli.command", "Command to run megacli.").Default(defaultMegaCli).String()
|
||||
)
|
||||
|
||||
type megaCliCollector struct {
|
||||
|
|
|
|||
|
|
@ -16,11 +16,11 @@
|
|||
package collector
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -74,7 +74,7 @@ func TestMegaCliDisks(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMegaCliCollectorDoesntCrash(t *testing.T) {
|
||||
if err := flag.Set("collector.megacli.command", "./fixtures/megacli"); err != nil {
|
||||
if _, err := kingpin.CommandLine.Parse([]string{"--collector.megacli.command", "./fixtures/megacli"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
collector, err := NewMegaCliCollector()
|
||||
|
|
|
|||
|
|
@ -17,18 +17,16 @@
|
|||
package collector
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
var (
|
||||
netdevIgnoredDevices = flag.String(
|
||||
"collector.netdev.ignored-devices", "^$",
|
||||
"Regexp of net devices to ignore for netdev collector.")
|
||||
netdevIgnoredDevices = kingpin.Flag("collector.netdev.ignored-devices", "Regexp of net devices to ignore for netdev collector.").Default("^$").String()
|
||||
)
|
||||
|
||||
type netDevCollector struct {
|
||||
|
|
|
|||
|
|
@ -16,17 +16,17 @@
|
|||
package collector
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/beevik/ntp"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/common/log"
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
var (
|
||||
ntpServer = flag.String("collector.ntp.server", "", "NTP server to use for ntp collector.")
|
||||
ntpProtocolVersion = flag.Int("collector.ntp.protocol-version", 4, "NTP protocol version")
|
||||
ntpServer = kingpin.Flag("collector.ntp.server", "NTP server to use for ntp collector.").Default("").String()
|
||||
ntpProtocolVersion = kingpin.Flag("collector.ntp.protocol-version", "NTP protocol version").Default("4").Int()
|
||||
)
|
||||
|
||||
type ntpCollector struct {
|
||||
|
|
|
|||
|
|
@ -14,16 +14,16 @@
|
|||
package collector
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"path"
|
||||
|
||||
"github.com/prometheus/procfs"
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
var (
|
||||
// The path of the proc filesystem.
|
||||
procPath = flag.String("collector.procfs", procfs.DefaultMountPoint, "procfs mountpoint.")
|
||||
sysPath = flag.String("collector.sysfs", "/sys", "sysfs mountpoint.")
|
||||
procPath = kingpin.Flag("collector.procfs", "procfs mountpoint.").Default(procfs.DefaultMountPoint).String()
|
||||
sysPath = kingpin.Flag("collector.sysfs", "sysfs mountpoint.").Default("/sys").String()
|
||||
)
|
||||
|
||||
func procFilePath(name string) string {
|
||||
|
|
|
|||
|
|
@ -14,14 +14,14 @@
|
|||
package collector
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"testing"
|
||||
|
||||
"github.com/prometheus/procfs"
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
func TestDefaultProcPath(t *testing.T) {
|
||||
if err := flag.Set("collector.procfs", procfs.DefaultMountPoint); err != nil {
|
||||
if _, err := kingpin.CommandLine.Parse([]string{"--collector.procfs", procfs.DefaultMountPoint}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ func TestDefaultProcPath(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCustomProcPath(t *testing.T) {
|
||||
if err := flag.Set("collector.procfs", "./../some/./place/"); err != nil {
|
||||
if _, err := kingpin.CommandLine.Parse([]string{"--collector.procfs", "./../some/./place/"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
|
@ -49,7 +49,7 @@ func TestCustomProcPath(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDefaultSysPath(t *testing.T) {
|
||||
if err := flag.Set("collector.sysfs", "/sys"); err != nil {
|
||||
if _, err := kingpin.CommandLine.Parse([]string{"--collector.sysfs", "/sys"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
|
@ -63,7 +63,7 @@ func TestDefaultSysPath(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCustomSysPath(t *testing.T) {
|
||||
if err := flag.Set("collector.sysfs", "./../some/./place/"); err != nil {
|
||||
if _, err := kingpin.CommandLine.Parse([]string{"--collector.sysfs", "./../some/./place/"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,12 +17,12 @@ package collector
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/ema/qdisc"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
type qdiscStatCollector struct {
|
||||
|
|
@ -34,7 +34,7 @@ type qdiscStatCollector struct {
|
|||
}
|
||||
|
||||
var (
|
||||
collectorQdisc = flag.String("collector.qdisc", "", "test fixtures to use for qdisc collector end-to-end testing")
|
||||
collectorQdisc = kingpin.Flag("collector.qdisc", "test fixtures to use for qdisc collector end-to-end testing").Default("").String()
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
|
|
|||
|
|
@ -16,17 +16,13 @@
|
|||
package collector
|
||||
|
||||
import (
|
||||
"flag"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/common/log"
|
||||
"github.com/soundcloud/go-runit/runit"
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
var runitServiceDir = flag.String(
|
||||
"collector.runit.servicedir",
|
||||
"/etc/service",
|
||||
"Path to runit service directory.")
|
||||
var runitServiceDir = kingpin.Flag("collector.runit.servicedir", "Path to runit service directory.").Default("/etc/service").String()
|
||||
|
||||
type runitCollector struct {
|
||||
state, stateDesired, stateNormal, stateTimestamp typedDesc
|
||||
|
|
|
|||
|
|
@ -16,15 +16,14 @@
|
|||
package collector
|
||||
|
||||
import (
|
||||
"flag"
|
||||
|
||||
"github.com/kolo/xmlrpc"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/common/log"
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
var (
|
||||
supervisordURL = flag.String("collector.supervisord.url", "http://localhost:9001/RPC2", "XML RPC endpoint")
|
||||
supervisordURL = kingpin.Flag("collector.supervisord.url", "XML RPC endpoint.").Default("http://localhost:9001/RPC2").String()
|
||||
)
|
||||
|
||||
type supervisordCollector struct {
|
||||
|
|
|
|||
|
|
@ -16,18 +16,19 @@
|
|||
package collector
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"github.com/coreos/go-systemd/dbus"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/common/log"
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
var (
|
||||
unitWhitelist = flag.String("collector.systemd.unit-whitelist", ".+", "Regexp of systemd units to whitelist. Units must both match whitelist and not match blacklist to be included.")
|
||||
unitBlacklist = flag.String("collector.systemd.unit-blacklist", ".+\\.scope", "Regexp of systemd units to blacklist. Units must both match whitelist and not match blacklist to be included.")
|
||||
unitWhitelist = kingpin.Flag("collector.systemd.unit-whitelist", "Regexp of systemd units to whitelist. Units must both match whitelist and not match blacklist to be included.").Default(".+").String()
|
||||
unitBlacklist = kingpin.Flag("collector.systemd.unit-blacklist", "Regexp of systemd units to blacklist. Units must both match whitelist and not match blacklist to be included.").Default(".+\\.scope").String()
|
||||
systemdPrivate = kingpin.Flag("collector.systemd.private", "Establish a private, direct connection to systemd without dbus.").Bool()
|
||||
)
|
||||
|
||||
type systemdCollector struct {
|
||||
|
|
@ -39,14 +40,6 @@ type systemdCollector struct {
|
|||
|
||||
var unitStatesName = []string{"active", "activating", "deactivating", "inactive", "failed"}
|
||||
|
||||
var (
|
||||
systemdPrivate = flag.Bool(
|
||||
"collector.systemd.private",
|
||||
false,
|
||||
"Establish a private, direct connection to systemd without dbus.",
|
||||
)
|
||||
)
|
||||
|
||||
func init() {
|
||||
Factories["systemd"] = NewSystemdCollector
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
package collector
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
|
@ -30,10 +29,11 @@ import (
|
|||
dto "github.com/prometheus/client_model/go"
|
||||
"github.com/prometheus/common/expfmt"
|
||||
"github.com/prometheus/common/log"
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
var (
|
||||
textFileDirectory = flag.String("collector.textfile.directory", "", "Directory to read text files with metrics from.")
|
||||
textFileDirectory = kingpin.Flag("collector.textfile.directory", "Directory to read text files with metrics from.").Default("").String()
|
||||
)
|
||||
|
||||
type textFileCollector struct {
|
||||
|
|
|
|||
|
|
@ -14,13 +14,14 @@
|
|||
package collector
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"io/ioutil"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/prometheus/common/log"
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
func TestParseTextFiles(t *testing.T) {
|
||||
|
|
@ -49,7 +50,8 @@ func TestParseTextFiles(t *testing.T) {
|
|||
|
||||
// Suppress a log message about `nonexistent_path` not existing, this is
|
||||
// expected and clutters the test output.
|
||||
err := flag.Set("log.level", "fatal")
|
||||
log.AddFlags(kingpin.CommandLine)
|
||||
_, err := kingpin.CommandLine.Parse([]string{"--log.level", "fatal"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ package collector
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
|
@ -24,6 +23,7 @@ import (
|
|||
"github.com/mdlayher/wifi"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/common/log"
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
type wifiCollector struct {
|
||||
|
|
@ -41,7 +41,7 @@ type wifiCollector struct {
|
|||
}
|
||||
|
||||
var (
|
||||
collectorWifi = flag.String("collector.wifi", "", "test fixtures to use for wifi collector metrics")
|
||||
collectorWifi = kingpin.Flag("collector.wifi", "test fixtures to use for wifi collector metrics").Default("").String()
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue