Commit 33aeb1cb authored by Matthew Holt's avatar Matthew Holt

telemetry: Add CLI option to selectively disable some metrics

Also fix a couple metrics that were named wrong or reported in excess.
parent 8bdd13b5
......@@ -617,7 +617,7 @@ func ValidateAndExecuteDirectives(cdyfile Input, inst *Instance, justValidate bo
return fmt.Errorf("error inspecting server blocks: %v", err)
}
telemetry.Set("http_num_server_blocks", len(sblocks))
telemetry.Set("num_server_blocks", len(sblocks))
return executeDirectives(inst, cdyfile.Path(), stype.Directives(), sblocks, justValidate)
}
......
......@@ -46,6 +46,7 @@ func init() {
flag.StringVar(&caddytls.DefaultCAUrl, "ca", "https://acme-v01.api.letsencrypt.org/directory", "URL to certificate authority's ACME server directory")
flag.BoolVar(&caddytls.DisableHTTPChallenge, "disable-http-challenge", caddytls.DisableHTTPChallenge, "Disable the ACME HTTP challenge")
flag.BoolVar(&caddytls.DisableTLSSNIChallenge, "disable-tls-sni-challenge", caddytls.DisableTLSSNIChallenge, "Disable the ACME TLS-SNI challenge")
flag.StringVar(&disabledMetrics, "disabled-metrics", "", "Comma-separated list of telemetry metrics to disable")
flag.StringVar(&conf, "conf", "", "Caddyfile to load (default \""+caddy.DefaultConfigFile+"\")")
flag.StringVar(&cpu, "cpu", "100%", "CPU cap")
flag.BoolVar(&plugins, "plugins", false, "List installed plugins")
......@@ -91,6 +92,8 @@ func Run() {
// initialize telemetry client
if enableTelemetry {
initTelemetry()
} else if disabledMetrics != "" {
mustLogFatalf("[ERROR] Cannot disable specific metrics because telemetry is disabled")
}
// Check for one-time actions
......@@ -326,7 +329,7 @@ func initTelemetry() {
}
}
telemetry.Init(id)
telemetry.Init(id, strings.Split(disabledMetrics, ","))
}
const appName = "Caddy"
......@@ -341,6 +344,7 @@ var (
version bool
plugins bool
validate bool
disabledMetrics string
)
// Build information obtained with the help of -ldflags
......
......@@ -254,7 +254,6 @@ func setupTLS(c *caddy.Controller) error {
return c.Errf("Unable to load certificate and key files for '%s': %v", c.Key, err)
}
log.Printf("[INFO] Successfully loaded TLS assets from %s and %s", certificateFile, keyFile)
telemetry.Increment("tls_manual_cert_count")
}
// load a directory of certificates, if specified
......@@ -355,7 +354,6 @@ func loadCertsInDir(cfg *Config, c *caddy.Controller, dir string) error {
return c.Errf("%s: failed to load cert and key for '%s': %v", path, c.Key, err)
}
log.Printf("[INFO] Successfully loaded TLS assets from %s", path)
telemetry.Increment("tls_manual_cert_count")
}
return nil
})
......
......@@ -28,7 +28,11 @@ import (
// may safely be used. If this function is not
// called, the collector functions may still be
// invoked, but they will be no-ops.
func Init(instanceID uuid.UUID) {
//
// Any metrics keys that are passed in the second
// argument will be permanently disabled for the
// lifetime of the process.
func Init(instanceID uuid.UUID, disabledMetricsKeys []string) {
if enabled {
panic("already initialized")
}
......@@ -37,6 +41,11 @@ func Init(instanceID uuid.UUID) {
panic("empty UUID")
}
instanceUUID = instanceID
disabledMetricsMu.Lock()
for _, key := range disabledMetricsKeys {
disabledMetrics[key] = false
}
disabledMetricsMu.Unlock()
enabled = true
}
......
......@@ -158,12 +158,15 @@ func emit(final bool) error {
// update the list of enabled/disabled keys, if any
for _, key := range reply.EnableKeys {
disabledMetricsMu.Lock()
// only re-enable this metric if it is temporarily disabled
if temp, ok := disabledMetrics[key]; ok && temp {
delete(disabledMetrics, key)
}
disabledMetricsMu.Unlock()
}
for _, key := range reply.DisableKeys {
disabledMetricsMu.Lock()
disabledMetrics[key] = struct{}{}
disabledMetrics[key] = true // all remotely-disabled keys are "temporarily" disabled
disabledMetricsMu.Unlock()
}
......@@ -359,10 +362,17 @@ var (
updateTimer *time.Timer
updateTimerMu sync.Mutex
// disabledMetrics is a list of metric keys
// disabledMetrics is a set of metric keys
// that should NOT be saved to the buffer
// or sent to the telemetry server.
disabledMetrics = make(map[string]struct{})
// or sent to the telemetry server. The value
// indicates whether the entry is temporary.
// If the value is true, it may be removed if
// the metric is re-enabled remotely later. If
// the value is false, it is permanent
// (presumably becaues the user explicitly
// disabled it) and can only be re-enabled
// with user consent.
disabledMetrics = make(map[string]bool)
disabledMetricsMu sync.RWMutex
// instanceUUID is the ID of the current instance.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment