Navigation Menu

Skip to content

Commit

Permalink
MB-39525 Do not accept cpu or memory profile names in settings endpoint
Browse files Browse the repository at this point in the history
BP of MB-39735 to MH

The profile names will be defaulted to "indexer_cpu.pprof",
"indexer_mem.pprof", "projector_cpu.pprof", "projector_mem.pprof"

Additionally, the user can specify a directory where these files can
go to using the options: "cpuProfDir", "memProfDir". Note that the
directory should exist and has write permissions for couchbase user.
Otherwise, the call would silently fail.

Sample usage:
curl -u <username>:<password> http://localhost:9102/settings
        -X POST -d '{"indexer.settings.cpuProfile":true,
                     "indexer.settings.cpuProfDir":"logs/"}'

Change-Id: Ie17bae353c93776980825529b5d239b5f04db8e0
(cherry picked from commit 3081e22)
  • Loading branch information
varunv-cb committed Jun 8, 2020
1 parent e975dc9 commit 146d585
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 63 deletions.
20 changes: 12 additions & 8 deletions secondary/common/config.go
Expand Up @@ -205,9 +205,10 @@ var SystemConfig = Config{
true, // immutable
false, // case-insensitive
},
"projector.cpuProfFname": ConfigValue{
"projector.cpuProfDir": ConfigValue{
"",
"filename to dump cpu-profile for projector.",
"Directory at which cpu_profile will be generated for projector." +
"Name of the generated cpu_profile file: projector_cpu.pprof",
"",
false, // mutable
true, // case-sensitive
Expand All @@ -219,9 +220,10 @@ var SystemConfig = Config{
false, // mutable
false, // case-insensitive
},
"projector.memProfFname": ConfigValue{
"projector.memProfDir": ConfigValue{
"",
"filename to dump mem-profile for projector.",
"Directory at which mem-profile will be generated for projector." +
"Name of the generated mem_profile file: projector_mem.pprof",
"",
false, // mutable
true, // case-sensitive
Expand Down Expand Up @@ -1910,9 +1912,10 @@ var SystemConfig = Config{
false, // case-insensitive
},

"indexer.settings.cpuProfFname": ConfigValue{
"indexer.settings.cpuProfDir": ConfigValue{
"",
"filename to dump cpu-profile for indexer.",
"Directory at which cpu-profile will be generated for indexer." +
"Name of the generated cpu_profile file: indexer_cpu.pprof",
"",
false, // mutable
true, // case-sensitive
Expand All @@ -1924,9 +1927,10 @@ var SystemConfig = Config{
false, // mutable
false, // case-insensitive
},
"indexer.settings.memProfFname": ConfigValue{
"indexer.settings.memProfDir": ConfigValue{
"",
"filename to dump mem-profile for indexer.",
"Directory at which mem-profile will be generated for indexer." +
"Name of the generated mem_profile file: indexer_mem.pprof",
"",
false, // mutable
true, // case-sensitive
Expand Down
31 changes: 13 additions & 18 deletions secondary/indexer/indexer.go
Expand Up @@ -6909,36 +6909,31 @@ func (idx *indexer) setProfilerOptions(config common.Config) {
// CPU-profiling
cpuProfile, ok := config["settings.cpuProfile"]
if ok && cpuProfile.Bool() && idx.cpuProfFd == nil {
cpuProfFname, ok := config["settings.cpuProfFname"]
if ok {
fname := cpuProfFname.String()
logging.Infof("Indexer:: cpu profiling => %q\n", fname)
idx.cpuProfFd = startCPUProfile(fname)

} else {
logging.Errorf("Indexer:: Missing cpu-profile o/p filename\n")
cpuProfDir, ok := config["settings.cpuProfDir"]
fname := "indexer_cpu.prof"
if ok && cpuProfDir.String() != "" {
fname = filepath.Join(cpuProfDir.String(), fname)
}

logging.Infof("Indexer:: cpu profiling => %q\n", fname)
idx.cpuProfFd = startCPUProfile(fname)
} else if ok && !cpuProfile.Bool() {
if idx.cpuProfFd != nil {
pprof.StopCPUProfile()
logging.Infof("Indexer:: cpu profiling stopped\n")
}
idx.cpuProfFd = nil

}

// MEM-profiling
memProfile, ok := config["settings.memProfile"]
if ok && memProfile.Bool() {
memProfFname, ok := config["settings.memProfFname"]
if ok {
fname := memProfFname.String()
if dumpMemProfile(fname) {
logging.Infof("Indexer:: mem profile => %q\n", fname)
}
} else {
logging.Errorf("Indexer:: Missing mem-profile o/p filename\n")
memProfDir, ok := config["settings.memProfDir"]
fname := "indexer_mem.pprof"
if ok && memProfDir.String() != "" {
fname = filepath.Join(memProfDir.String(), fname)
}
if dumpMemProfile(fname) {
logging.Infof("Indexer:: mem profile => %q\n", fname)
}
}
}
Expand Down
74 changes: 37 additions & 37 deletions secondary/projector/projector.go
@@ -1,26 +1,29 @@
package projector

import "expvar"
import "fmt"
import "sync"
import "io"
import "time"
import "os"
import "net/http"
import "strings"
import "encoding/json"
import "runtime"
import "runtime/pprof"
import "runtime/debug"

import ap "github.com/couchbase/indexing/secondary/adminport"
import c "github.com/couchbase/indexing/secondary/common"
import mc "github.com/couchbase/indexing/secondary/dcp/transport/client"
import projC "github.com/couchbase/indexing/secondary/projector/client"
import protobuf "github.com/couchbase/indexing/secondary/protobuf/projector"
import "github.com/golang/protobuf/proto"
import "github.com/couchbase/indexing/secondary/logging"
import "github.com/couchbase/indexing/secondary/security"
import (
"encoding/json"
"expvar"
"fmt"
"io"
"net/http"
"os"
"path/filepath"
"runtime"
"runtime/debug"
"runtime/pprof"
"strings"
"sync"
"time"

ap "github.com/couchbase/indexing/secondary/adminport"
c "github.com/couchbase/indexing/secondary/common"
mc "github.com/couchbase/indexing/secondary/dcp/transport/client"
"github.com/couchbase/indexing/secondary/logging"
projC "github.com/couchbase/indexing/secondary/projector/client"
protobuf "github.com/couchbase/indexing/secondary/protobuf/projector"
"github.com/couchbase/indexing/secondary/security"
"github.com/golang/protobuf/proto"
)

// UUID of the node on which the projector process executes
var nodeUUID string
Expand Down Expand Up @@ -204,15 +207,13 @@ func (p *Projector) ResetConfig(config c.Config) {
// CPU-profiling
cpuProfile, ok := config["projector.cpuProfile"]
if ok && cpuProfile.Bool() && p.cpuProfFd == nil {
cpuProfFname, ok := config["projector.cpuProfFname"]
if ok {
fname := cpuProfFname.String()
logging.Infof("%v cpu profiling => %q\n", p.logPrefix, fname)
p.cpuProfFd = p.startCPUProfile(fname)

} else {
logging.Errorf("Missing cpu-profile o/p filename\n")
cpuProfDir, ok := config["projector.cpuProfDir"]
fname := "projector_cpu.pprof"
if ok && cpuProfDir.String() != "" {
fname = filepath.Join(cpuProfDir.String(), fname)
}
logging.Infof("%v cpu profiling => %q\n", p.logPrefix, fname)
p.cpuProfFd = p.startCPUProfile(fname)

} else if ok && !cpuProfile.Bool() {
if p.cpuProfFd != nil {
Expand All @@ -228,14 +229,13 @@ func (p *Projector) ResetConfig(config c.Config) {
// MEM-profiling
memProfile, ok := config["projector.memProfile"]
if ok && memProfile.Bool() {
memProfFname, ok := config["projector.memProfFname"]
if ok {
fname := memProfFname.String()
if p.takeMEMProfile(fname) {
logging.Infof("%v mem profile => %q\n", p.logPrefix, fname)
}
} else {
logging.Errorf("Missing mem-profile o/p filename\n")
memProfDir, ok := config["projector.memProfDir"]
fname := "projector_mem.pprof"
if ok && memProfDir.String() != "" {
fname = filepath.Join(memProfDir.String(), fname)
}
if p.takeMEMProfile(fname) {
logging.Infof("%v mem profile => %q\n", p.logPrefix, fname)
}
}

Expand Down

0 comments on commit 146d585

Please sign in to comment.