Skip to content

Commit

Permalink
cleanup cli config
Browse files Browse the repository at this point in the history
Signed-off-by: Sandor Szücs <[email protected]>
  • Loading branch information
szuecs committed Mar 22, 2024
1 parent c42035a commit f7e2831
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 150 deletions.
102 changes: 45 additions & 57 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,55 +69,51 @@ type Config struct {
CompressEncodings *listFlag `yaml:"compress-encodings"`

// logging, metrics, profiling, tracing:
EnablePrometheusMetrics bool `yaml:"enable-prometheus-metrics"`
OpenTracing string `yaml:"opentracing"`
OpenTracingInitialSpan string `yaml:"opentracing-initial-span"`
OpenTracingExcludedProxyTags string `yaml:"opentracing-excluded-proxy-tags"`
OpenTracingDisableFilterSpans bool `yaml:"opentracing-disable-filter-spans"`
OpentracingLogFilterLifecycleEvents bool `yaml:"opentracing-log-filter-lifecycle-events"`
OpentracingLogStreamEvents bool `yaml:"opentracing-log-stream-events"`
OpentracingBackendNameTag bool `yaml:"opentracing-backend-name-tag"`
MetricsListener string `yaml:"metrics-listener"`
MetricsPrefix string `yaml:"metrics-prefix"`
EnableProfile bool `yaml:"enable-profile"`
BlockProfileRate int `yaml:"block-profile-rate"`
MutexProfileFraction int `yaml:"mutex-profile-fraction"`
MemProfileRate int `yaml:"memory-profile-rate"`
EnableFlightRecorder bool `yaml:"enable-flight-recorder"`
FlightRecorderSize int `yaml:"flight-recorder-size"`
FlightRecorderPeriod time.Duration `yaml:"flight-recorder-period"`
FlightRecorderProxyTookTooLong time.Duration `yaml:"flight-recorder-proxy-took-too-long"`
FlightRecorderTargetURL string `yaml:"flight-recorder-target-url"`
DebugGcMetrics bool `yaml:"debug-gc-metrics"`
RuntimeMetrics bool `yaml:"runtime-metrics"`
ServeRouteMetrics bool `yaml:"serve-route-metrics"`
ServeRouteCounter bool `yaml:"serve-route-counter"`
ServeHostMetrics bool `yaml:"serve-host-metrics"`
ServeHostCounter bool `yaml:"serve-host-counter"`
ServeMethodMetric bool `yaml:"serve-method-metric"`
ServeStatusCodeMetric bool `yaml:"serve-status-code-metric"`
BackendHostMetrics bool `yaml:"backend-host-metrics"`
AllFiltersMetrics bool `yaml:"all-filters-metrics"`
CombinedResponseMetrics bool `yaml:"combined-response-metrics"`
RouteResponseMetrics bool `yaml:"route-response-metrics"`
RouteBackendErrorCounters bool `yaml:"route-backend-error-counters"`
RouteStreamErrorCounters bool `yaml:"route-stream-error-counters"`
RouteBackendMetrics bool `yaml:"route-backend-metrics"`
RouteCreationMetrics bool `yaml:"route-creation-metrics"`
MetricsUseExpDecaySample bool `yaml:"metrics-exp-decay-sample"`
HistogramMetricBucketsString string `yaml:"histogram-metric-buckets"`
HistogramMetricBuckets []float64 `yaml:"-"`
DisableMetricsCompat bool `yaml:"disable-metrics-compat"`
ApplicationLog string `yaml:"application-log"`
ApplicationLogLevel log.Level `yaml:"-"`
ApplicationLogLevelString string `yaml:"application-log-level"`
ApplicationLogPrefix string `yaml:"application-log-prefix"`
ApplicationLogJSONEnabled bool `yaml:"application-log-json-enabled"`
AccessLog string `yaml:"access-log"`
AccessLogDisabled bool `yaml:"access-log-disabled"`
AccessLogJSONEnabled bool `yaml:"access-log-json-enabled"`
AccessLogStripQuery bool `yaml:"access-log-strip-query"`
SuppressRouteUpdateLogs bool `yaml:"suppress-route-update-logs"`
EnablePrometheusMetrics bool `yaml:"enable-prometheus-metrics"`
OpenTracing string `yaml:"opentracing"`
OpenTracingInitialSpan string `yaml:"opentracing-initial-span"`
OpenTracingExcludedProxyTags string `yaml:"opentracing-excluded-proxy-tags"`
OpenTracingDisableFilterSpans bool `yaml:"opentracing-disable-filter-spans"`
OpentracingLogFilterLifecycleEvents bool `yaml:"opentracing-log-filter-lifecycle-events"`
OpentracingLogStreamEvents bool `yaml:"opentracing-log-stream-events"`
OpentracingBackendNameTag bool `yaml:"opentracing-backend-name-tag"`
MetricsListener string `yaml:"metrics-listener"`
MetricsPrefix string `yaml:"metrics-prefix"`
EnableProfile bool `yaml:"enable-profile"`
BlockProfileRate int `yaml:"block-profile-rate"`
MutexProfileFraction int `yaml:"mutex-profile-fraction"`
MemProfileRate int `yaml:"memory-profile-rate"`
FlightRecorderTargetURL string `yaml:"flight-recorder-target-url"`
DebugGcMetrics bool `yaml:"debug-gc-metrics"`
RuntimeMetrics bool `yaml:"runtime-metrics"`
ServeRouteMetrics bool `yaml:"serve-route-metrics"`
ServeRouteCounter bool `yaml:"serve-route-counter"`
ServeHostMetrics bool `yaml:"serve-host-metrics"`
ServeHostCounter bool `yaml:"serve-host-counter"`
ServeMethodMetric bool `yaml:"serve-method-metric"`
ServeStatusCodeMetric bool `yaml:"serve-status-code-metric"`
BackendHostMetrics bool `yaml:"backend-host-metrics"`
AllFiltersMetrics bool `yaml:"all-filters-metrics"`
CombinedResponseMetrics bool `yaml:"combined-response-metrics"`
RouteResponseMetrics bool `yaml:"route-response-metrics"`
RouteBackendErrorCounters bool `yaml:"route-backend-error-counters"`
RouteStreamErrorCounters bool `yaml:"route-stream-error-counters"`
RouteBackendMetrics bool `yaml:"route-backend-metrics"`
RouteCreationMetrics bool `yaml:"route-creation-metrics"`
MetricsUseExpDecaySample bool `yaml:"metrics-exp-decay-sample"`
HistogramMetricBucketsString string `yaml:"histogram-metric-buckets"`
HistogramMetricBuckets []float64 `yaml:"-"`
DisableMetricsCompat bool `yaml:"disable-metrics-compat"`
ApplicationLog string `yaml:"application-log"`
ApplicationLogLevel log.Level `yaml:"-"`
ApplicationLogLevelString string `yaml:"application-log-level"`
ApplicationLogPrefix string `yaml:"application-log-prefix"`
ApplicationLogJSONEnabled bool `yaml:"application-log-json-enabled"`
AccessLog string `yaml:"access-log"`
AccessLogDisabled bool `yaml:"access-log-disabled"`
AccessLogJSONEnabled bool `yaml:"access-log-json-enabled"`
AccessLogStripQuery bool `yaml:"access-log-strip-query"`
SuppressRouteUpdateLogs bool `yaml:"suppress-route-update-logs"`

// route sources:
EtcdUrls string `yaml:"etcd-urls"`
Expand Down Expand Up @@ -383,10 +379,6 @@ func NewConfig() *Config {
flag.IntVar(&cfg.BlockProfileRate, "block-profile-rate", 0, "block profile sample rate, see runtime.SetBlockProfileRate")
flag.IntVar(&cfg.MutexProfileFraction, "mutex-profile-fraction", 0, "mutex profile fraction rate, see runtime.SetMutexProfileFraction")
flag.IntVar(&cfg.MemProfileRate, "memory-profile-rate", 0, "memory profile rate, see runtime.SetMemProfileRate, keeps default 512 kB")
flag.BoolVar(&cfg.EnableFlightRecorder, "enable-flight-recorder", false, "enable flightrecorder Go tracer")
flag.IntVar(&cfg.FlightRecorderSize, "flight-recorder-size", 0, "max flight-recorder trace data size")
flag.DurationVar(&cfg.FlightRecorderPeriod, "flight-recorder-period", 0, "sets the approximate time duration that the flight recorder's circular buffer represents.")
flag.DurationVar(&cfg.FlightRecorderProxyTookTooLong, "flight-recorder-proxy-took-too-long", 0, "sets the threshold, if proxy took longer than that the flight recorder will write out a trace.")
flag.StringVar(&cfg.FlightRecorderTargetURL, "flight-recorder-target-url", "", "sets the flight recorder target URL that is used to write out the trace to.")
flag.BoolVar(&cfg.DebugGcMetrics, "debug-gc-metrics", false, "enables reporting of the Go garbage collector statistics exported in debug.GCStats")
flag.BoolVar(&cfg.RuntimeMetrics, "runtime-metrics", true, "enables reporting of the Go runtime statistics exported in runtime and specifically runtime.MemStats")
Expand Down Expand Up @@ -755,10 +747,6 @@ func (c *Config) ToOptions() skipper.Options {
EnableProfile: c.EnableProfile,
BlockProfileRate: c.BlockProfileRate,
MutexProfileFraction: c.MutexProfileFraction,
EnableFlightRecorder: c.EnableFlightRecorder,
FlightRecorderSize: c.FlightRecorderSize,
FlightRecorderPeriod: c.FlightRecorderPeriod,
FlightRecorderProxyTookTooLong: c.FlightRecorderProxyTookTooLong,
FlightRecorderTargetURL: c.FlightRecorderTargetURL,
EnableDebugGcMetrics: c.DebugGcMetrics,
EnableRuntimeMetrics: c.RuntimeMetrics,
Expand Down
18 changes: 15 additions & 3 deletions proxy/flightrecorder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,20 @@ func TestFlightRecorder(t *testing.T) {
rr := eskip.MustParse(doc)

pr := proxytest.WithParams(fr, proxy.Params{
FlightRecorder: flightRecorder,
FlightRecorder: flightRecorder,
FlightRecorderTargetURL: service.URL,
}, rr...)
_ = pr
pr.Client().Get(pr.URL)
defer pr.Close()

rsp, err := pr.Client().Get(pr.URL)
if err != nil {
t.Fatalf("Failed to GET %q: %v", pr.URL, err)
}

switch rsp.StatusCode {
case 200, 201, 204:
// ok
default:
t.Fatalf("Failed to get status OK: %d", rsp.StatusCode)
}
}
112 changes: 55 additions & 57 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,6 @@ type Params struct {
// FlightRecorderTargetURL is the target to write the trace
// to. Supported targets are http URL and file URL.
FlightRecorderTargetURL string

// FlightRecorderProxyTookTooLong defines the threshold when to write out a trace
FlightRecorderProxyTookTooLong time.Duration
}

type (
Expand Down Expand Up @@ -396,34 +393,33 @@ type PriorityRoute interface {
// Proxy instances implement Skipper proxying functionality. For
// initializing, see the WithParams the constructor and Params.
type Proxy struct {
experimentalUpgrade bool
experimentalUpgradeAudit bool
accessLogDisabled bool
maxLoops int
defaultHTTPStatus int
routing *routing.Routing
registry *routing.EndpointRegistry
fadein *fadeIn
heathlyEndpoints *healthyEndpoints
roundTripper http.RoundTripper
priorityRoutes []PriorityRoute
flags Flags
metrics metrics.Metrics
quit chan struct{}
flushInterval time.Duration
breakers *circuit.Registry
limiters *ratelimit.Registry
log logging.Logger
tracing *proxyTracing
upgradeAuditLogOut io.Writer
upgradeAuditLogErr io.Writer
auditLogHook chan struct{}
clientTLS *tls.Config
hostname string
onPanicSometimes rate.Sometimes
flightRecorder *trace.FlightRecorder
flightRecorderURL *url.URL
flightRecorderProxyTookTooLong time.Duration
experimentalUpgrade bool
experimentalUpgradeAudit bool
accessLogDisabled bool
maxLoops int
defaultHTTPStatus int
routing *routing.Routing
registry *routing.EndpointRegistry
fadein *fadeIn
heathlyEndpoints *healthyEndpoints
roundTripper http.RoundTripper
priorityRoutes []PriorityRoute
flags Flags
metrics metrics.Metrics
quit chan struct{}
flushInterval time.Duration
breakers *circuit.Registry
limiters *ratelimit.Registry
log logging.Logger
tracing *proxyTracing
upgradeAuditLogOut io.Writer
upgradeAuditLogErr io.Writer
auditLogHook chan struct{}
clientTLS *tls.Config
hostname string
onPanicSometimes rate.Sometimes
flightRecorder *trace.FlightRecorder
flightRecorderURL *url.URL
}

// proxyError is used to wrap errors during proxying and to indicate
Expand Down Expand Up @@ -828,30 +824,29 @@ func WithParams(p Params) *Proxy {
rnd: rand.New(loadbalancer.NewLockedSource()),
endpointRegistry: p.EndpointRegistry,
},
heathlyEndpoints: healthyEndpointsChooser,
roundTripper: p.CustomHttpRoundTripperWrap(tr),
priorityRoutes: p.PriorityRoutes,
flags: p.Flags,
metrics: m,
quit: quit,
flushInterval: p.FlushInterval,
experimentalUpgrade: p.ExperimentalUpgrade,
experimentalUpgradeAudit: p.ExperimentalUpgradeAudit,
maxLoops: p.MaxLoopbacks,
breakers: p.CircuitBreakers,
limiters: p.RateLimiters,
log: &logging.DefaultLog{},
defaultHTTPStatus: defaultHTTPStatus,
tracing: newProxyTracing(p.OpenTracing),
accessLogDisabled: p.AccessLogDisabled,
upgradeAuditLogOut: os.Stdout,
upgradeAuditLogErr: os.Stderr,
clientTLS: tr.TLSClientConfig,
hostname: hostname,
onPanicSometimes: rate.Sometimes{First: 3, Interval: 1 * time.Minute},
flightRecorder: p.FlightRecorder,
flightRecorderURL: frURL,
flightRecorderProxyTookTooLong: p.FlightRecorderProxyTookTooLong,
heathlyEndpoints: healthyEndpointsChooser,
roundTripper: p.CustomHttpRoundTripperWrap(tr),
priorityRoutes: p.PriorityRoutes,
flags: p.Flags,
metrics: m,
quit: quit,
flushInterval: p.FlushInterval,
experimentalUpgrade: p.ExperimentalUpgrade,
experimentalUpgradeAudit: p.ExperimentalUpgradeAudit,
maxLoops: p.MaxLoopbacks,
breakers: p.CircuitBreakers,
limiters: p.RateLimiters,
log: &logging.DefaultLog{},
defaultHTTPStatus: defaultHTTPStatus,
tracing: newProxyTracing(p.OpenTracing),
accessLogDisabled: p.AccessLogDisabled,
upgradeAuditLogOut: os.Stdout,
upgradeAuditLogErr: os.Stderr,
clientTLS: tr.TLSClientConfig,
hostname: hostname,
onPanicSometimes: rate.Sometimes{First: 3, Interval: 1 * time.Minute},
flightRecorder: p.FlightRecorder,
flightRecorderURL: frURL,
}
}

Expand All @@ -860,7 +855,7 @@ func (p *Proxy) writeTraceIfTooSlow(ctx *context) {
return
}

d := p.flightRecorderProxyTookTooLong
var d time.Duration
if e, ok := ctx.StateBag()[filters.TraceName]; ok {
d = e.(time.Duration)
}
Expand Down Expand Up @@ -1668,7 +1663,10 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
func (p *Proxy) Close() error {
close(p.quit)
p.registry.Close()
p.flightRecorder.Stop()
if p.flightRecorder != nil {
p.flightRecorder.Stop()
}

return nil
}

Expand Down
Loading

0 comments on commit f7e2831

Please sign in to comment.