Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pprof tweaks #272

Merged
merged 2 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions docs/gen/config/aperture-agent/config-swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ definitions:
description: Write timeout
format: string
type: string
x-go-default: 10s
x-go-default: 45s
x-go-name: WriteTimeout
x-go-validate: gte=0s
title: HTTPServerConfig holds configuration for HTTP Server.
Expand Down Expand Up @@ -757,15 +757,23 @@ definitions:
ProfilersConfig:
properties:
cpu_profiler:
description: Flag to enable cpu profiling
description: Flag to enable cpu profiling on process start and save it to
a file. HTTP interface will not work if this is enabled as CPU profile will
always be running.
type: boolean
x-go-default: "false"
x-go-name: CPUProfile
profiles_path:
description: Path to save performance profiles. This can be set via command
line arguments as well.
line arguments as well. E.g. default path for aperture-agent is /var/log/aperture/aperture-agent/profiles.
type: string
x-go-name: ProfilesPath
register_http_routes:
description: Register routes. Profile types profile, symbol and cmdline will
be registered at /debug/pprof/{profile,symbol,cmdline}.
type: boolean
x-go-default: "true"
x-go-name: RegisterHTTPRoutes
title: ProfilersConfig holds configuration for profilers.
type: object
x-go-package: github.com/fluxninja/aperture/pkg/profilers
Expand Down
14 changes: 11 additions & 3 deletions docs/gen/config/aperture-agent/swagger.md
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ HTTPServerConfig holds configuration for HTTP Server.
<dt>write_timeout</dt>
<dd>

(string, `gte=0s`, default: `10s`) Write timeout
(string, `gte=0s`, default: `45s`) Write timeout

</dd>
</dl>
Expand Down Expand Up @@ -1443,15 +1443,23 @@ ProfilersConfig holds configuration for profilers.
<dt>cpu_profiler</dt>
<dd>

(bool, default: `false`) Flag to enable cpu profiling
(bool, default: `false`) Flag to enable cpu profiling on process start and save it to a file. HTTP interface will not work if this is enabled as CPU profile will always be running.

</dd>
</dl>
<dl>
<dt>profiles_path</dt>
<dd>

(string) Path to save performance profiles. This can be set via command line arguments as well.
(string) Path to save performance profiles. This can be set via command line arguments as well. E.g. default path for aperture-agent is /var/log/aperture/aperture-agent/profiles.

</dd>
</dl>
<dl>
<dt>register_http_routes</dt>
<dd>

(bool, default: `true`) Register routes. Profile types profile, symbol and cmdline will be registered at /debug/pprof/{profile,symbol,cmdline}.

</dd>
</dl>
Expand Down
14 changes: 11 additions & 3 deletions docs/gen/config/aperture-controller/config-swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ definitions:
description: Write timeout
format: string
type: string
x-go-default: 10s
x-go-default: 45s
x-go-name: WriteTimeout
x-go-validate: gte=0s
title: HTTPServerConfig holds configuration for HTTP Server.
Expand Down Expand Up @@ -692,15 +692,23 @@ definitions:
ProfilersConfig:
properties:
cpu_profiler:
description: Flag to enable cpu profiling
description: Flag to enable cpu profiling on process start and save it to
a file. HTTP interface will not work if this is enabled as CPU profile will
always be running.
type: boolean
x-go-default: "false"
x-go-name: CPUProfile
profiles_path:
description: Path to save performance profiles. This can be set via command
line arguments as well.
line arguments as well. E.g. default path for aperture-agent is /var/log/aperture/aperture-agent/profiles.
type: string
x-go-name: ProfilesPath
register_http_routes:
description: Register routes. Profile types profile, symbol and cmdline will
be registered at /debug/pprof/{profile,symbol,cmdline}.
type: boolean
x-go-default: "true"
x-go-name: RegisterHTTPRoutes
title: ProfilersConfig holds configuration for profilers.
type: object
x-go-package: github.com/fluxninja/aperture/pkg/profilers
Expand Down
14 changes: 11 additions & 3 deletions docs/gen/config/aperture-controller/swagger.md
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ HTTPServerConfig holds configuration for HTTP Server.
<dt>write_timeout</dt>
<dd>

(string, `gte=0s`, default: `10s`) Write timeout
(string, `gte=0s`, default: `45s`) Write timeout

</dd>
</dl>
Expand Down Expand Up @@ -1307,15 +1307,23 @@ ProfilersConfig holds configuration for profilers.
<dt>cpu_profiler</dt>
<dd>

(bool, default: `false`) Flag to enable cpu profiling
(bool, default: `false`) Flag to enable cpu profiling on process start and save it to a file. HTTP interface will not work if this is enabled as CPU profile will always be running.

</dd>
</dl>
<dl>
<dt>profiles_path</dt>
<dd>

(string) Path to save performance profiles. This can be set via command line arguments as well.
(string) Path to save performance profiles. This can be set via command line arguments as well. E.g. default path for aperture-agent is /var/log/aperture/aperture-agent/profiles.

</dd>
</dl>
<dl>
<dt>register_http_routes</dt>
<dd>

(bool, default: `true`) Register routes. Profile types profile, symbol and cmdline will be registered at /debug/pprof/{profile,symbol,cmdline}.

</dd>
</dl>
Expand Down
2 changes: 1 addition & 1 deletion pkg/net/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type HTTPServerConfig struct {
// Read timeout
ReadTimeout config.Duration `json:"read_timeout" validate:"gte=0s" default:"10s"`
// Write timeout
WriteTimeout config.Duration `json:"write_timeout" validate:"gte=0s" default:"10s"`
WriteTimeout config.Duration `json:"write_timeout" validate:"gte=0s" default:"45s"`
// The lowest bucket in latency histogram
LatencyBucketStartMS float64 `json:"latency_bucket_start_ms" validate:"gte=0" default:"20"`
// Max header size in bytes
Expand Down
10 changes: 5 additions & 5 deletions pkg/profilers/profilers.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ func Module() fx.Option {
// ProfilersConfig holds configuration for profilers.
// swagger:model
type ProfilersConfig struct {
// Path to save performance profiles. This can be set via command line arguments as well.
// Register routes. Profile types profile, symbol and cmdline will be registered at /debug/pprof/{profile,symbol,cmdline}.
RegisterHTTPRoutes bool `json:"register_http_routes" default:"true"`
// Path to save performance profiles. This can be set via command line arguments as well. E.g. default path for aperture-agent is /var/log/aperture/aperture-agent/profiles.
ProfilesPath string `json:"profiles_path"`
// Flag to enable cpu profiling
// Flag to enable cpu profiling on process start and save it to a file. HTTP interface will not work if this is enabled as CPU profile will always be running.
CPUProfile bool `json:"cpu_profiler" default:"false"`
}

Expand All @@ -90,16 +92,14 @@ func (constructor Constructor) setupProfilers(unmarshaller config.Unmarshaller,

var cpuProfileFile *lumberjack.Logger
var err error
registerRoutes := false

if config.CPUProfile {
filename := path.Join(profilesPath, defaultCPUFile)
log.Debug().Str("filename", filename).Msg("opening cpu profile writer")
cpuProfileFile = newProfileWriter(filename)
registerRoutes = true
}

if registerRoutes {
if config.RegisterHTTPRoutes {
router.HandleFunc(httpPathPrefix, httppprof.Index)
router.HandleFunc(path.Join(httpPathPrefix, "cmdline"), httppprof.Cmdline)
router.HandleFunc(path.Join(httpPathPrefix, "profile"), httppprof.Profile)
Expand Down