Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

chore(cmdline): Fix up various commandline options #52

Merged
merged 2 commits into from
Jul 11, 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
20 changes: 0 additions & 20 deletions badger/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ type Options struct {
// AllowStopTheWorld determines whether the DropPrefix will be blocking/non-blocking.
AllowStopTheWorld bool

// DetectConflicts determines whether the transactions would be checked for
// conflicts. The transactions can be processed at a higher rate when
// conflict detection is disabled.
DetectConflicts bool

// NamespaceOffset specifies the offset from where the next 8 bytes contains the namespace.
NamespaceOffset int

Expand Down Expand Up @@ -151,7 +146,6 @@ func DefaultOptions(path string) Options {
Logger: defaultLogger(INFO),
EncryptionKey: []byte{},
EncryptionKeyRotationDuration: 10 * 24 * time.Hour, // Default 10 days.
DetectConflicts: true,
NamespaceOffset: -1,
}
}
Expand Down Expand Up @@ -651,20 +645,6 @@ func (opt Options) WithIndexCacheSize(size int64) Options {
return opt
}

// WithDetectConflicts returns a new Options value with DetectConflicts set to the given value.
//
// Detect conflicts options determines if the transactions would be checked for
// conflicts before committing them. When this option is set to false
// (detectConflicts=false) badger can process transactions at a higher rate.
// Setting this options to false might be useful when the user application
// deals with conflict detection and resolution.
//
// The default value of Detect conflicts is True.
func (opt Options) WithDetectConflicts(b bool) Options {
opt.DetectConflicts = b
return opt
}

// WithNamespaceOffset returns a new Options value with NamespaceOffset set to the given value. DB
// will expect the namespace in each key at the 8 bytes starting from NamespaceOffset. A negative
// value means that namespace is not stored in the key.
Expand Down
2 changes: 1 addition & 1 deletion edgraph/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ type existingGQLSchemaQryResp struct {
}

// PeriodicallyPostTelemetry periodically reports telemetry data for alpha.
func PeriodicallyPostTelemetry() {
func PeriodicallyPostTelemetry_XXX() {
glog.V(2).Infof("Starting telemetry data collection for alpha...")

start := time.Now()
Expand Down
6 changes: 3 additions & 3 deletions ee/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ const (
)

func RegisterAclAndEncFlags(flag *pflag.FlagSet) {
registerAclFlag(flag)
// registerAclFlag(flag)
registerEncFlag(flag)
registerVaultFlag(flag, true, true)
// registerVaultFlag(flag, true, true)
}

func RegisterEncFlag(flag *pflag.FlagSet) {
Expand Down Expand Up @@ -137,7 +137,7 @@ func registerAclFlag(flag *pflag.FlagSet) {

func registerEncFlag(flag *pflag.FlagSet) {
helpText := z.NewSuperFlagHelp(EncDefaults).
Head("[Enterprise Feature] Encryption At Rest options").
Head("Encryption At Rest options").
Flag("key-file", "The file that stores the symmetric key of length 16, 24, or 32 bytes."+
"The key size determines the chosen AES cipher (AES-128, AES-192, and AES-256 respectively).").
String()
Expand Down
72 changes: 36 additions & 36 deletions outserv/cmd/alpha/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,41 +236,41 @@ func init() {
"Restarts the lambda server after given duration of unresponsiveness").
String())

flag.String("cdc", worker.CDCDefaults, z.NewSuperFlagHelp(worker.CDCDefaults).
Head("Change Data Capture options").
Flag("file",
"The path where audit logs will be stored.").
Flag("kafka",
"A comma separated list of Kafka hosts.").
Flag("sasl-user",
"The SASL username for Kafka.").
Flag("sasl-password",
"The SASL password for Kafka.").
Flag("sasl-mechanism",
"The SASL mechanism for Kafka (PLAIN, SCRAM-SHA-256 or SCRAM-SHA-512)").
Flag("ca-cert",
"The path to CA cert file for TLS encryption.").
Flag("client-cert",
"The path to client cert file for TLS encryption.").
Flag("client-key",
"The path to client key file for TLS encryption.").
String())

flag.String("audit", worker.AuditDefaults, z.NewSuperFlagHelp(worker.AuditDefaults).
Head("Audit options").
Flag("output",
`[stdout, /path/to/dir] This specifies where audit logs should be output to.
"stdout" is for standard output. You can also specify the directory where audit logs
will be saved. When stdout is specified as output other fields will be ignored.`).
Flag("compress",
"Enables the compression of old audit logs.").
Flag("encrypt-file",
"The path to the key file to be used for audit log encryption.").
Flag("days",
"The number of days audit logs will be preserved.").
Flag("size",
"The audit log max size in MB after which it will be rolled over.").
String())
// flag.String("cdc", worker.CDCDefaults, z.NewSuperFlagHelp(worker.CDCDefaults).
// Head("Change Data Capture options").
// Flag("file",
// "The path where audit logs will be stored.").
// Flag("kafka",
// "A comma separated list of Kafka hosts.").
// Flag("sasl-user",
// "The SASL username for Kafka.").
// Flag("sasl-password",
// "The SASL password for Kafka.").
// Flag("sasl-mechanism",
// "The SASL mechanism for Kafka (PLAIN, SCRAM-SHA-256 or SCRAM-SHA-512)").
// Flag("ca-cert",
// "The path to CA cert file for TLS encryption.").
// Flag("client-cert",
// "The path to client cert file for TLS encryption.").
// Flag("client-key",
// "The path to client key file for TLS encryption.").
// String())

// flag.String("audit", worker.AuditDefaults, z.NewSuperFlagHelp(worker.AuditDefaults).
// Head("Audit options").
// Flag("output",
// `[stdout, /path/to/dir] This specifies where audit logs should be output to.
// "stdout" is for standard output. You can also specify the directory where audit logs
// will be saved. When stdout is specified as output other fields will be ignored.`).
// Flag("compress",
// "Enables the compression of old audit logs.").
// Flag("encrypt-file",
// "The path to the key file to be used for audit log encryption.").
// Flag("days",
// "The number of days audit logs will be preserved.").
// Flag("size",
// "The audit log max size in MB after which it will be rolled over.").
// String())

flag.String("wallet", billing.WalletDefaults, z.NewSuperFlagHelp(billing.WalletDefaults).
Head("Wallet options").
Expand Down Expand Up @@ -778,7 +778,7 @@ func run() {
x.WorkerConfig.Parse(Alpha.Conf)

if telemetry.GetBool("reports") {
go edgraph.PeriodicallyPostTelemetry()
go edgraph.PeriodicallyPostTelemetry_XXX()
}

// Set the directory for temporary buffers.
Expand Down
2 changes: 1 addition & 1 deletion outserv/cmd/debuginfo/debugging.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func saveMetrics(addr, pathPrefix string, seconds uint32, metricTypes []string)
case "trace":
source += fmt.Sprintf("%s%d", "?seconds=", seconds)
}
savePath := fmt.Sprintf("%s%s.gz", pathPrefix, metricType)
savePath := fmt.Sprintf("%s%s.txt", pathPrefix, metricType)
if err := saveDebug(source, savePath, duration); err != nil {
glog.Errorf("error while saving metric from %s: %s", source, err)
continue
Expand Down
109 changes: 43 additions & 66 deletions outserv/cmd/debuginfo/run.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright 2019-2021 Dgraph Labs, Inc. and Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Portions Copyright 2019-2021 Dgraph Labs, Inc. are available under the Apache License v2.0.
// Portions Copyright 2022 Outcaste LLC are available under the Sustainable License v1.0.

package debuginfo

Expand All @@ -27,8 +14,8 @@ import (
"github.com/spf13/cobra"
)

type debugInfoCmdOpts struct {
alphaAddr string
type profileOpts struct {
outservAddr string
zeroAddr string
archive bool
directory string
Expand All @@ -37,119 +24,109 @@ type debugInfoCmdOpts struct {
}

var (
DebugInfo x.SubCommand
debugInfoCmd = debugInfoCmdOpts{}
Profile x.SubCommand
profileCmd = profileOpts{}
)

var metricMap = map[string]string{
"jemalloc": "/debug/jemalloc",
"state": "/state",
"block": "/debug/pprof/block",
"cpu": "/debug/pprof/profile",
"goroutine": "/debug/pprof/goroutine?debug=2",
"health": "/health",
"vars": "/debug/vars",
"metrics": "/metrics",
"heap": "/debug/pprof/heap",
"goroutine": "/debug/pprof/goroutine?debug=2",
"threadcreate": "/debug/pprof/threadcreate",
"block": "/debug/pprof/block",
"jemalloc": "/debug/jemalloc",
"metrics": "/metrics",
"mutex": "/debug/pprof/mutex",
"cpu": "/debug/pprof/profile",
"state": "/state",
"threadcreate": "/debug/pprof/threadcreate",
"trace": "/debug/pprof/trace",
"vars": "/debug/vars",
}

var metricList = []string{
"heap",
"block",
"cpu",
"state",
"goroutine",
"health",
"heap",
"jemalloc",
"trace",
"metrics",
"vars",
"trace",
"goroutine",
"block",
"mutex",
"state",
"threadcreate",
"trace",
"vars",
}

func init() {
DebugInfo.Cmd = &cobra.Command{
Use: "debuginfo",
Short: "Generate debug information on the current node",
Profile.Cmd = &cobra.Command{
Use: "profile",
Short: "Collect profile and debug info from given Outserv instance",
Run: func(cmd *cobra.Command, args []string) {
if err := collectDebugInfo(); err != nil {
glog.Errorf("error while collecting dgraph debug info: %s", err)
glog.Errorf("error while collecting Outserv profile: %s", err)
os.Exit(1)
}
},
Annotations: map[string]string{"group": "debug"},
}

DebugInfo.EnvPrefix = "DGRAPH_AGENT_DEBUGINFO"
DebugInfo.Cmd.SetHelpTemplate(x.NonRootTemplate)
Profile.EnvPrefix = "OUTSERV_AGENT_DEBUGINFO"
Profile.Cmd.SetHelpTemplate(x.NonRootTemplate)

flags := DebugInfo.Cmd.Flags()
flags.StringVarP(&debugInfoCmd.alphaAddr, "alpha", "a", "localhost:8080",
"Address of running dgraph alpha.")
flags.StringVarP(&debugInfoCmd.zeroAddr, "zero", "z", "", "Address of running dgraph zero.")
flags.StringVarP(&debugInfoCmd.directory, "directory", "d", "",
flags := Profile.Cmd.Flags()
flags.StringVarP(&profileCmd.outservAddr, "outserv", "o", "localhost:8080",
"HTTP address of running Outserv instance.")
flags.StringVarP(&profileCmd.directory, "directory", "d", "",
"Directory to write the debug info into.")
flags.BoolVarP(&debugInfoCmd.archive, "archive", "x", true,
flags.BoolVarP(&profileCmd.archive, "archive", "x", true,
"Whether to archive the generated report")
flags.Uint32VarP(&debugInfoCmd.seconds, "seconds", "s", 30,
flags.Uint32VarP(&profileCmd.seconds, "seconds", "s", 30,
"Duration for time-based metric collection.")
flags.StringSliceVarP(&debugInfoCmd.metricTypes, "metrics", "m", metricList,
flags.StringSliceVarP(&profileCmd.metricTypes, "metrics", "m", metricList,
"List of metrics & profile to dump in the report.")

}

func collectDebugInfo() (err error) {
if debugInfoCmd.directory == "" {
debugInfoCmd.directory, err = ioutil.TempDir("/tmp", "dgraph-debuginfo")
if profileCmd.directory == "" {
profileCmd.directory, err = ioutil.TempDir("/tmp", "outserv-debuginfo")
if err != nil {
return fmt.Errorf("error while creating temporary directory: %s", err)
}
} else {
err = os.MkdirAll(debugInfoCmd.directory, 0644)
err = os.MkdirAll(profileCmd.directory, 0644)
if err != nil {
return err
}
}
glog.Infof("using directory %s for debug info dump.", debugInfoCmd.directory)
glog.Infof("using directory %s for debug info dump.", profileCmd.directory)

collectDebug()

if debugInfoCmd.archive {
if profileCmd.archive {
return archiveDebugInfo()
}
return nil
}

func collectDebug() {
if debugInfoCmd.alphaAddr != "" {
filePrefix := filepath.Join(debugInfoCmd.directory, "alpha_")

saveMetrics(debugInfoCmd.alphaAddr, filePrefix, debugInfoCmd.seconds, debugInfoCmd.metricTypes)

}

if debugInfoCmd.zeroAddr != "" {
filePrefix := filepath.Join(debugInfoCmd.directory, "zero_")
if profileCmd.outservAddr != "" {
filePrefix := filepath.Join(profileCmd.directory, "alpha_")

saveMetrics(debugInfoCmd.zeroAddr, filePrefix, debugInfoCmd.seconds, debugInfoCmd.metricTypes)
saveMetrics(profileCmd.outservAddr, filePrefix, profileCmd.seconds, profileCmd.metricTypes)

}
}

func archiveDebugInfo() error {
archivePath, err := createGzipArchive(debugInfoCmd.directory)
archivePath, err := createGzipArchive(profileCmd.directory)
if err != nil {
return fmt.Errorf("error while archiving debuginfo directory: %s", err)
}

glog.Infof("Debuginfo archive successful: %s", archivePath)

if err = os.RemoveAll(debugInfoCmd.directory); err != nil {
if err = os.RemoveAll(profileCmd.directory); err != nil {
glog.Warningf("error while removing debuginfo directory: %s", err)
}
return nil
Expand Down
7 changes: 2 additions & 5 deletions outserv/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/outcaste-io/outserv/outserv/cmd/debug"
"github.com/outcaste-io/outserv/outserv/cmd/debuginfo"
"github.com/outcaste-io/outserv/outserv/cmd/decrypt"
"github.com/outcaste-io/outserv/outserv/cmd/migrate"
"github.com/outcaste-io/outserv/outserv/cmd/version"
"github.com/outcaste-io/outserv/outserv/cmd/wallet"
"github.com/outcaste-io/outserv/x"
Expand Down Expand Up @@ -68,8 +67,8 @@ var subcommands = []*x.SubCommand{
// TODO: Consider if we need bulk loader.
// TODO: Consider if we need live loader.
&cert.Cert,
&alpha.Alpha, &version.Version, &debug.Debug, &migrate.Migrate,
&debuginfo.DebugInfo, &decrypt.Decrypt, &wallet.Wallet,
&alpha.Alpha, &version.Version, &debug.Debug,
&debuginfo.Profile, &decrypt.Decrypt, &wallet.Wallet,
}

func initCmds() {
Expand Down Expand Up @@ -192,9 +191,7 @@ func setGlogFlags(conf *viper.Viper) {
}

func shellCompletionCmd() *cobra.Command {

cmd := &cobra.Command{

Use: "completion",
Short: "Generates shell completion scripts for bash or zsh",
Annotations: map[string]string{"group": "tool"},
Expand Down
Loading