Skip to content

Commit

Permalink
pprof and metrics server cmd in kopia (#2650)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexvbg committed Feb 6, 2024
1 parent af3d689 commit cab3979
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
2 changes: 2 additions & 0 deletions pkg/kopia/command/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ const (
tlsGenerateCertFlag = "--tls-generate-cert"
tlsKeyFilePath = "--tls-key-file"
userPasswordFlag = "--user-password"
enablePprof = "--enable-pprof"
metricsListerAddress = "--metrics-listen-addr"

// Repository specific
repositorySubCommand = "repository"
Expand Down
24 changes: 17 additions & 7 deletions pkg/kopia/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ package command

type ServerStartCommandArgs struct {
*CommandArgs
ServerAddress string
TLSCertFile string
TLSKeyFile string
ServerUsername string
ServerPassword string
AutoGenerateCert bool
Background bool
ServerAddress string
TLSCertFile string
TLSKeyFile string
ServerUsername string
ServerPassword string
AutoGenerateCert bool
Background bool
EnablePprof bool
MetricsListenAddress string
}

// ServerStart returns the kopia command for starting the Kopia API Server
Expand All @@ -46,6 +48,14 @@ func ServerStart(cmdArgs ServerStartCommandArgs) []string {
// TODO: Remove when GRPC support is added
args = args.AppendLoggable(noGrpcFlag)

if cmdArgs.EnablePprof {
args = args.AppendLoggable(enablePprof)
}

if cmdArgs.MetricsListenAddress != "" {
args = args.AppendLoggableKV(metricsListerAddress, cmdArgs.MetricsListenAddress)
}

if cmdArgs.Background {
// To start the server and run in the background
args = args.AppendLoggable(redirectToDevNull, runInBackground)
Expand Down
18 changes: 18 additions & 0 deletions pkg/kopia/command/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ func (kServer *KopiaServerTestSuite) TestServerCommands(c *C) {
f func() []string
expectedLog string
}{
{
f: func() []string {
args := ServerStartCommandArgs{
CommandArgs: commandArgs,
ServerAddress: "a-server-address",
TLSCertFile: "/path/to/cert/tls.crt",
TLSKeyFile: "/path/to/key/tls.key",
ServerUsername: "a-username@a-hostname",
ServerPassword: "a-user-password",
AutoGenerateCert: true,
Background: true,
EnablePprof: true,
MetricsListenAddress: "a-server-address:51516",
}
return ServerStart(args)
},
expectedLog: "bash -o errexit -c kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log server start --tls-generate-cert --address=a-server-address --tls-cert-file=/path/to/cert/tls.crt --tls-key-file=/path/to/key/tls.key --server-username=a-username@a-hostname --server-password=a-user-password --server-control-username=a-username@a-hostname --server-control-password=a-user-password --no-grpc --enable-pprof --metrics-listen-addr=a-server-address:51516 > /dev/null 2>&1 &",
},
{
f: func() []string {
args := ServerStartCommandArgs{
Expand Down

0 comments on commit cab3979

Please sign in to comment.