Skip to content

Commit f7e2831

Browse files
committed
cleanup cli config
Signed-off-by: Sandor Szücs <[email protected]>
1 parent c42035a commit f7e2831

File tree

4 files changed

+156
-150
lines changed

4 files changed

+156
-150
lines changed

config/config.go

+45-57
Original file line numberDiff line numberDiff line change
@@ -69,55 +69,51 @@ type Config struct {
6969
CompressEncodings *listFlag `yaml:"compress-encodings"`
7070

7171
// logging, metrics, profiling, tracing:
72-
EnablePrometheusMetrics bool `yaml:"enable-prometheus-metrics"`
73-
OpenTracing string `yaml:"opentracing"`
74-
OpenTracingInitialSpan string `yaml:"opentracing-initial-span"`
75-
OpenTracingExcludedProxyTags string `yaml:"opentracing-excluded-proxy-tags"`
76-
OpenTracingDisableFilterSpans bool `yaml:"opentracing-disable-filter-spans"`
77-
OpentracingLogFilterLifecycleEvents bool `yaml:"opentracing-log-filter-lifecycle-events"`
78-
OpentracingLogStreamEvents bool `yaml:"opentracing-log-stream-events"`
79-
OpentracingBackendNameTag bool `yaml:"opentracing-backend-name-tag"`
80-
MetricsListener string `yaml:"metrics-listener"`
81-
MetricsPrefix string `yaml:"metrics-prefix"`
82-
EnableProfile bool `yaml:"enable-profile"`
83-
BlockProfileRate int `yaml:"block-profile-rate"`
84-
MutexProfileFraction int `yaml:"mutex-profile-fraction"`
85-
MemProfileRate int `yaml:"memory-profile-rate"`
86-
EnableFlightRecorder bool `yaml:"enable-flight-recorder"`
87-
FlightRecorderSize int `yaml:"flight-recorder-size"`
88-
FlightRecorderPeriod time.Duration `yaml:"flight-recorder-period"`
89-
FlightRecorderProxyTookTooLong time.Duration `yaml:"flight-recorder-proxy-took-too-long"`
90-
FlightRecorderTargetURL string `yaml:"flight-recorder-target-url"`
91-
DebugGcMetrics bool `yaml:"debug-gc-metrics"`
92-
RuntimeMetrics bool `yaml:"runtime-metrics"`
93-
ServeRouteMetrics bool `yaml:"serve-route-metrics"`
94-
ServeRouteCounter bool `yaml:"serve-route-counter"`
95-
ServeHostMetrics bool `yaml:"serve-host-metrics"`
96-
ServeHostCounter bool `yaml:"serve-host-counter"`
97-
ServeMethodMetric bool `yaml:"serve-method-metric"`
98-
ServeStatusCodeMetric bool `yaml:"serve-status-code-metric"`
99-
BackendHostMetrics bool `yaml:"backend-host-metrics"`
100-
AllFiltersMetrics bool `yaml:"all-filters-metrics"`
101-
CombinedResponseMetrics bool `yaml:"combined-response-metrics"`
102-
RouteResponseMetrics bool `yaml:"route-response-metrics"`
103-
RouteBackendErrorCounters bool `yaml:"route-backend-error-counters"`
104-
RouteStreamErrorCounters bool `yaml:"route-stream-error-counters"`
105-
RouteBackendMetrics bool `yaml:"route-backend-metrics"`
106-
RouteCreationMetrics bool `yaml:"route-creation-metrics"`
107-
MetricsUseExpDecaySample bool `yaml:"metrics-exp-decay-sample"`
108-
HistogramMetricBucketsString string `yaml:"histogram-metric-buckets"`
109-
HistogramMetricBuckets []float64 `yaml:"-"`
110-
DisableMetricsCompat bool `yaml:"disable-metrics-compat"`
111-
ApplicationLog string `yaml:"application-log"`
112-
ApplicationLogLevel log.Level `yaml:"-"`
113-
ApplicationLogLevelString string `yaml:"application-log-level"`
114-
ApplicationLogPrefix string `yaml:"application-log-prefix"`
115-
ApplicationLogJSONEnabled bool `yaml:"application-log-json-enabled"`
116-
AccessLog string `yaml:"access-log"`
117-
AccessLogDisabled bool `yaml:"access-log-disabled"`
118-
AccessLogJSONEnabled bool `yaml:"access-log-json-enabled"`
119-
AccessLogStripQuery bool `yaml:"access-log-strip-query"`
120-
SuppressRouteUpdateLogs bool `yaml:"suppress-route-update-logs"`
72+
EnablePrometheusMetrics bool `yaml:"enable-prometheus-metrics"`
73+
OpenTracing string `yaml:"opentracing"`
74+
OpenTracingInitialSpan string `yaml:"opentracing-initial-span"`
75+
OpenTracingExcludedProxyTags string `yaml:"opentracing-excluded-proxy-tags"`
76+
OpenTracingDisableFilterSpans bool `yaml:"opentracing-disable-filter-spans"`
77+
OpentracingLogFilterLifecycleEvents bool `yaml:"opentracing-log-filter-lifecycle-events"`
78+
OpentracingLogStreamEvents bool `yaml:"opentracing-log-stream-events"`
79+
OpentracingBackendNameTag bool `yaml:"opentracing-backend-name-tag"`
80+
MetricsListener string `yaml:"metrics-listener"`
81+
MetricsPrefix string `yaml:"metrics-prefix"`
82+
EnableProfile bool `yaml:"enable-profile"`
83+
BlockProfileRate int `yaml:"block-profile-rate"`
84+
MutexProfileFraction int `yaml:"mutex-profile-fraction"`
85+
MemProfileRate int `yaml:"memory-profile-rate"`
86+
FlightRecorderTargetURL string `yaml:"flight-recorder-target-url"`
87+
DebugGcMetrics bool `yaml:"debug-gc-metrics"`
88+
RuntimeMetrics bool `yaml:"runtime-metrics"`
89+
ServeRouteMetrics bool `yaml:"serve-route-metrics"`
90+
ServeRouteCounter bool `yaml:"serve-route-counter"`
91+
ServeHostMetrics bool `yaml:"serve-host-metrics"`
92+
ServeHostCounter bool `yaml:"serve-host-counter"`
93+
ServeMethodMetric bool `yaml:"serve-method-metric"`
94+
ServeStatusCodeMetric bool `yaml:"serve-status-code-metric"`
95+
BackendHostMetrics bool `yaml:"backend-host-metrics"`
96+
AllFiltersMetrics bool `yaml:"all-filters-metrics"`
97+
CombinedResponseMetrics bool `yaml:"combined-response-metrics"`
98+
RouteResponseMetrics bool `yaml:"route-response-metrics"`
99+
RouteBackendErrorCounters bool `yaml:"route-backend-error-counters"`
100+
RouteStreamErrorCounters bool `yaml:"route-stream-error-counters"`
101+
RouteBackendMetrics bool `yaml:"route-backend-metrics"`
102+
RouteCreationMetrics bool `yaml:"route-creation-metrics"`
103+
MetricsUseExpDecaySample bool `yaml:"metrics-exp-decay-sample"`
104+
HistogramMetricBucketsString string `yaml:"histogram-metric-buckets"`
105+
HistogramMetricBuckets []float64 `yaml:"-"`
106+
DisableMetricsCompat bool `yaml:"disable-metrics-compat"`
107+
ApplicationLog string `yaml:"application-log"`
108+
ApplicationLogLevel log.Level `yaml:"-"`
109+
ApplicationLogLevelString string `yaml:"application-log-level"`
110+
ApplicationLogPrefix string `yaml:"application-log-prefix"`
111+
ApplicationLogJSONEnabled bool `yaml:"application-log-json-enabled"`
112+
AccessLog string `yaml:"access-log"`
113+
AccessLogDisabled bool `yaml:"access-log-disabled"`
114+
AccessLogJSONEnabled bool `yaml:"access-log-json-enabled"`
115+
AccessLogStripQuery bool `yaml:"access-log-strip-query"`
116+
SuppressRouteUpdateLogs bool `yaml:"suppress-route-update-logs"`
121117

122118
// route sources:
123119
EtcdUrls string `yaml:"etcd-urls"`
@@ -383,10 +379,6 @@ func NewConfig() *Config {
383379
flag.IntVar(&cfg.BlockProfileRate, "block-profile-rate", 0, "block profile sample rate, see runtime.SetBlockProfileRate")
384380
flag.IntVar(&cfg.MutexProfileFraction, "mutex-profile-fraction", 0, "mutex profile fraction rate, see runtime.SetMutexProfileFraction")
385381
flag.IntVar(&cfg.MemProfileRate, "memory-profile-rate", 0, "memory profile rate, see runtime.SetMemProfileRate, keeps default 512 kB")
386-
flag.BoolVar(&cfg.EnableFlightRecorder, "enable-flight-recorder", false, "enable flightrecorder Go tracer")
387-
flag.IntVar(&cfg.FlightRecorderSize, "flight-recorder-size", 0, "max flight-recorder trace data size")
388-
flag.DurationVar(&cfg.FlightRecorderPeriod, "flight-recorder-period", 0, "sets the approximate time duration that the flight recorder's circular buffer represents.")
389-
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.")
390382
flag.StringVar(&cfg.FlightRecorderTargetURL, "flight-recorder-target-url", "", "sets the flight recorder target URL that is used to write out the trace to.")
391383
flag.BoolVar(&cfg.DebugGcMetrics, "debug-gc-metrics", false, "enables reporting of the Go garbage collector statistics exported in debug.GCStats")
392384
flag.BoolVar(&cfg.RuntimeMetrics, "runtime-metrics", true, "enables reporting of the Go runtime statistics exported in runtime and specifically runtime.MemStats")
@@ -755,10 +747,6 @@ func (c *Config) ToOptions() skipper.Options {
755747
EnableProfile: c.EnableProfile,
756748
BlockProfileRate: c.BlockProfileRate,
757749
MutexProfileFraction: c.MutexProfileFraction,
758-
EnableFlightRecorder: c.EnableFlightRecorder,
759-
FlightRecorderSize: c.FlightRecorderSize,
760-
FlightRecorderPeriod: c.FlightRecorderPeriod,
761-
FlightRecorderProxyTookTooLong: c.FlightRecorderProxyTookTooLong,
762750
FlightRecorderTargetURL: c.FlightRecorderTargetURL,
763751
EnableDebugGcMetrics: c.DebugGcMetrics,
764752
EnableRuntimeMetrics: c.RuntimeMetrics,

proxy/flightrecorder_test.go

+15-3
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,20 @@ func TestFlightRecorder(t *testing.T) {
5252
rr := eskip.MustParse(doc)
5353

5454
pr := proxytest.WithParams(fr, proxy.Params{
55-
FlightRecorder: flightRecorder,
55+
FlightRecorder: flightRecorder,
56+
FlightRecorderTargetURL: service.URL,
5657
}, rr...)
57-
_ = pr
58-
pr.Client().Get(pr.URL)
58+
defer pr.Close()
59+
60+
rsp, err := pr.Client().Get(pr.URL)
61+
if err != nil {
62+
t.Fatalf("Failed to GET %q: %v", pr.URL, err)
63+
}
64+
65+
switch rsp.StatusCode {
66+
case 200, 201, 204:
67+
// ok
68+
default:
69+
t.Fatalf("Failed to get status OK: %d", rsp.StatusCode)
70+
}
5971
}

proxy/proxy.go

+55-57
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,6 @@ type Params struct {
324324
// FlightRecorderTargetURL is the target to write the trace
325325
// to. Supported targets are http URL and file URL.
326326
FlightRecorderTargetURL string
327-
328-
// FlightRecorderProxyTookTooLong defines the threshold when to write out a trace
329-
FlightRecorderProxyTookTooLong time.Duration
330327
}
331328

332329
type (
@@ -396,34 +393,33 @@ type PriorityRoute interface {
396393
// Proxy instances implement Skipper proxying functionality. For
397394
// initializing, see the WithParams the constructor and Params.
398395
type Proxy struct {
399-
experimentalUpgrade bool
400-
experimentalUpgradeAudit bool
401-
accessLogDisabled bool
402-
maxLoops int
403-
defaultHTTPStatus int
404-
routing *routing.Routing
405-
registry *routing.EndpointRegistry
406-
fadein *fadeIn
407-
heathlyEndpoints *healthyEndpoints
408-
roundTripper http.RoundTripper
409-
priorityRoutes []PriorityRoute
410-
flags Flags
411-
metrics metrics.Metrics
412-
quit chan struct{}
413-
flushInterval time.Duration
414-
breakers *circuit.Registry
415-
limiters *ratelimit.Registry
416-
log logging.Logger
417-
tracing *proxyTracing
418-
upgradeAuditLogOut io.Writer
419-
upgradeAuditLogErr io.Writer
420-
auditLogHook chan struct{}
421-
clientTLS *tls.Config
422-
hostname string
423-
onPanicSometimes rate.Sometimes
424-
flightRecorder *trace.FlightRecorder
425-
flightRecorderURL *url.URL
426-
flightRecorderProxyTookTooLong time.Duration
396+
experimentalUpgrade bool
397+
experimentalUpgradeAudit bool
398+
accessLogDisabled bool
399+
maxLoops int
400+
defaultHTTPStatus int
401+
routing *routing.Routing
402+
registry *routing.EndpointRegistry
403+
fadein *fadeIn
404+
heathlyEndpoints *healthyEndpoints
405+
roundTripper http.RoundTripper
406+
priorityRoutes []PriorityRoute
407+
flags Flags
408+
metrics metrics.Metrics
409+
quit chan struct{}
410+
flushInterval time.Duration
411+
breakers *circuit.Registry
412+
limiters *ratelimit.Registry
413+
log logging.Logger
414+
tracing *proxyTracing
415+
upgradeAuditLogOut io.Writer
416+
upgradeAuditLogErr io.Writer
417+
auditLogHook chan struct{}
418+
clientTLS *tls.Config
419+
hostname string
420+
onPanicSometimes rate.Sometimes
421+
flightRecorder *trace.FlightRecorder
422+
flightRecorderURL *url.URL
427423
}
428424

429425
// proxyError is used to wrap errors during proxying and to indicate
@@ -828,30 +824,29 @@ func WithParams(p Params) *Proxy {
828824
rnd: rand.New(loadbalancer.NewLockedSource()),
829825
endpointRegistry: p.EndpointRegistry,
830826
},
831-
heathlyEndpoints: healthyEndpointsChooser,
832-
roundTripper: p.CustomHttpRoundTripperWrap(tr),
833-
priorityRoutes: p.PriorityRoutes,
834-
flags: p.Flags,
835-
metrics: m,
836-
quit: quit,
837-
flushInterval: p.FlushInterval,
838-
experimentalUpgrade: p.ExperimentalUpgrade,
839-
experimentalUpgradeAudit: p.ExperimentalUpgradeAudit,
840-
maxLoops: p.MaxLoopbacks,
841-
breakers: p.CircuitBreakers,
842-
limiters: p.RateLimiters,
843-
log: &logging.DefaultLog{},
844-
defaultHTTPStatus: defaultHTTPStatus,
845-
tracing: newProxyTracing(p.OpenTracing),
846-
accessLogDisabled: p.AccessLogDisabled,
847-
upgradeAuditLogOut: os.Stdout,
848-
upgradeAuditLogErr: os.Stderr,
849-
clientTLS: tr.TLSClientConfig,
850-
hostname: hostname,
851-
onPanicSometimes: rate.Sometimes{First: 3, Interval: 1 * time.Minute},
852-
flightRecorder: p.FlightRecorder,
853-
flightRecorderURL: frURL,
854-
flightRecorderProxyTookTooLong: p.FlightRecorderProxyTookTooLong,
827+
heathlyEndpoints: healthyEndpointsChooser,
828+
roundTripper: p.CustomHttpRoundTripperWrap(tr),
829+
priorityRoutes: p.PriorityRoutes,
830+
flags: p.Flags,
831+
metrics: m,
832+
quit: quit,
833+
flushInterval: p.FlushInterval,
834+
experimentalUpgrade: p.ExperimentalUpgrade,
835+
experimentalUpgradeAudit: p.ExperimentalUpgradeAudit,
836+
maxLoops: p.MaxLoopbacks,
837+
breakers: p.CircuitBreakers,
838+
limiters: p.RateLimiters,
839+
log: &logging.DefaultLog{},
840+
defaultHTTPStatus: defaultHTTPStatus,
841+
tracing: newProxyTracing(p.OpenTracing),
842+
accessLogDisabled: p.AccessLogDisabled,
843+
upgradeAuditLogOut: os.Stdout,
844+
upgradeAuditLogErr: os.Stderr,
845+
clientTLS: tr.TLSClientConfig,
846+
hostname: hostname,
847+
onPanicSometimes: rate.Sometimes{First: 3, Interval: 1 * time.Minute},
848+
flightRecorder: p.FlightRecorder,
849+
flightRecorderURL: frURL,
855850
}
856851
}
857852

@@ -860,7 +855,7 @@ func (p *Proxy) writeTraceIfTooSlow(ctx *context) {
860855
return
861856
}
862857

863-
d := p.flightRecorderProxyTookTooLong
858+
var d time.Duration
864859
if e, ok := ctx.StateBag()[filters.TraceName]; ok {
865860
d = e.(time.Duration)
866861
}
@@ -1668,7 +1663,10 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
16681663
func (p *Proxy) Close() error {
16691664
close(p.quit)
16701665
p.registry.Close()
1671-
p.flightRecorder.Stop()
1666+
if p.flightRecorder != nil {
1667+
p.flightRecorder.Stop()
1668+
}
1669+
16721670
return nil
16731671
}
16741672

0 commit comments

Comments
 (0)