Skip to content

Commit

Permalink
origin inspector (#101)
Browse files Browse the repository at this point in the history
* Add support for Origin Inspector

Co-authored-by: Peter Bourgon <[email protected]>
Co-authored-by: Herman Schaaf <[email protected]>
  • Loading branch information
3 people authored May 23, 2022
1 parent f77df0b commit e0cd02b
Show file tree
Hide file tree
Showing 22 changed files with 867 additions and 1,332 deletions.
65 changes: 40 additions & 25 deletions cmd/fastly-exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,31 @@ var programVersion = "dev"

func main() {
var (
token string
listen string
namespace string
subsystem string
serviceShard string
serviceIDs stringslice
serviceAllowlist stringslice
serviceBlocklist stringslice
metricAllowlist stringslice
metricBlocklist stringslice
datacenterRefresh time.Duration
serviceRefresh time.Duration
apiTimeout time.Duration
rtTimeout time.Duration
debug bool
versionFlag bool
configFileExample bool
token string
listen string
namespace string
deprecatedSubsystem string
serviceShard string
serviceIDs stringslice
serviceAllowlist stringslice
serviceBlocklist stringslice
metricAllowlist stringslice
metricBlocklist stringslice
datacenterRefresh time.Duration
serviceRefresh time.Duration
apiTimeout time.Duration
rtTimeout time.Duration
debug bool
versionFlag bool
configFileExample bool
)

fs := flag.NewFlagSet("fastly-exporter", flag.ContinueOnError)
{
fs.StringVar(&token, "token", "", "Fastly API token (required)")
fs.StringVar(&listen, "listen", "127.0.0.1:8080", "listen address for Prometheus metrics")
fs.StringVar(&namespace, "namespace", "fastly", "Prometheus namespace")
fs.StringVar(&subsystem, "subsystem", "rt", "Prometheus subsystem")
fs.StringVar(&deprecatedSubsystem, "subsystem", "rt", "DEPRECATED -- will be fixed to 'rt' in a future version")
fs.StringVar(&serviceShard, "service-shard", "", "if set, only include services whose hashed IDs modulo m equal n-1 (format 'n/m')")
fs.Var(&serviceIDs, "service", "if set, only include this service ID (repeatable)")
fs.Var(&serviceAllowlist, "service-allowlist", "if set, only include services whose names match this regex (repeatable)")
Expand Down Expand Up @@ -92,11 +92,7 @@ func main() {
var logger log.Logger
{
logger = log.NewLogfmtLogger(os.Stderr)
loglevel := level.AllowInfo()
if debug {
loglevel = level.AllowDebug()
}
logger = level.NewFilter(logger, loglevel)
logger = level.NewFilter(logger, getLogLevel(debug))
}

if token == "" {
Expand All @@ -106,6 +102,16 @@ func main() {
}
}

switch deprecatedSubsystem {
case "rt":
// good
case "origin":
level.Error(logger).Log("err", "-subsystem cannot be 'origin'")
os.Exit(1)
default:
level.Warn(logger).Log("msg", "-subsystem is DEPRECATED and will be fixed to 'rt' in a future version")
}

fs.Visit(func(f *flag.Flag) {
if f.Name == "api-refresh" {
level.Warn(logger).Log("msg", "-api-refresh is deprecated and will be removed in a future version, please use -service-refresh instead")
Expand Down Expand Up @@ -278,7 +284,7 @@ func main() {

var defaultGatherers prometheus.Gatherers
{
dcs, err := datacenterCache.Gatherer(namespace, subsystem)
dcs, err := datacenterCache.Gatherer(namespace, deprecatedSubsystem)
if err != nil {
level.Error(apiLogger).Log("during", "create datacenter gatherer", "err", err)
os.Exit(1)
Expand All @@ -288,7 +294,7 @@ func main() {

var registry *prom.Registry
{
registry = prom.NewRegistry(programVersion, namespace, subsystem, metricNameFilter, defaultGatherers)
registry = prom.NewRegistry(programVersion, namespace, deprecatedSubsystem, metricNameFilter, defaultGatherers)
}

var manager *rt.Manager
Expand Down Expand Up @@ -458,3 +464,12 @@ service-blocklist Dev
metric-blocklist imgopto
`)

func getLogLevel(debug bool) level.Option {
switch {
case debug:
return level.AllowDebug()
default:
return level.AllowInfo()
}
}
181 changes: 0 additions & 181 deletions cmd/fieldgen/api_fields.json

This file was deleted.

145 changes: 0 additions & 145 deletions cmd/fieldgen/exporter_metrics.json

This file was deleted.

Loading

0 comments on commit e0cd02b

Please sign in to comment.