Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Make 'learn' an alias for 'apidump' #168

Merged
merged 2 commits into from
Nov 3, 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
31 changes: 31 additions & 0 deletions apidump/defaults.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package apidump

import "time"

// Specifies default values for command-line parameters.
const (
// Whether to send TCP and TLS reports to the back end.
//
// Invariant: if this is true, then so is DefaultParseTLSHandshakes.
DefaultCollectTCPAndTLSReports = false

// The name of the deployment.
DefaultDeployment = "default"

// Whether to enable parsing of TLS handshakes.
//
// Invariant: if this is false, then so is DefaultCollectTCPAndTLSReports.
DefaultParseTLSHandshakes = true

// How many requests to capture per minute.
DefaultRateLimit = 1000.0

// How long to wait after starting up before printing packet-capture statistics.
DefaultStatsLogDelay_seconds = 60

// How often to upload client telemetry.
DefaultTelemetryInterval_seconds = 5 * 60 // 5 minutes

// How often to rotate traces in the back end.
DefaultTraceRotateInterval = time.Hour
)
49 changes: 49 additions & 0 deletions cmd/internal/akiflag/ignore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package akiflag

import (
"time"

"github.com/spf13/pflag"
)

// Convenience functions for creating legacy command-line flags whose values are
// ignored.

func IgnoreDurationFlags(fs *pflag.FlagSet, flagNames []string, usage string) {
var ignored time.Duration
for _, flagName := range flagNames {
fs.DurationVar(
&ignored,
flagName,
0,
usage,
)
fs.MarkDeprecated(flagName, "and is now ignored. Please remove this flag from your command.")
}
}

func IgnoreIntFlags(fs *pflag.FlagSet, flagNames []string, usage string) {
var ignored int
for _, flagName := range flagNames {
fs.IntVar(
&ignored,
flagName,
0,
usage,
)
fs.MarkDeprecated(flagName, "and is now ignored. Please remove this flag from your command.")
}
}

func IgnoreStringFlags(fs *pflag.FlagSet, flagNames []string, usage string) {
var ignored string
for _, flagName := range flagNames {
fs.StringVar(
&ignored,
flagName,
"",
usage,
)
fs.MarkDeprecated(flagName, "and is now ignored. Please remove this flag from your command.")
}
}
10 changes: 6 additions & 4 deletions cmd/internal/akiflag/rename.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
package akiflag

import (
"fmt"

"github.com/spf13/pflag"
)

// Rename a flag by creating 2 flags that share the same variable:
// - one that uses the old name but is hidden
// - one that uses the old name but is deprecated
// - one that uses the new name

func RenameStringFlag(fs *pflag.FlagSet, flagVar *string, oldName, newName, defaultVal, usage string) {
fs.StringVar(flagVar, oldName, defaultVal, usage)
fs.StringVar(flagVar, newName, defaultVal, usage)
fs.MarkHidden(oldName)
fs.MarkDeprecated(oldName, fmt.Sprintf("use --%s instead.", newName))
}

func RenameStringSliceFlag(fs *pflag.FlagSet, flagVar *[]string, oldName, newName string, defaultVal []string, usage string) {
fs.StringSliceVar(flagVar, oldName, defaultVal, usage)
fs.StringSliceVar(flagVar, newName, defaultVal, usage)
fs.MarkHidden(oldName)
fs.MarkDeprecated(oldName, fmt.Sprintf("use --%s instead.", newName))
}

func RenameIntFlag(fs *pflag.FlagSet, flagVar *int, oldName, newName string, defaultVal int, usage string) {
fs.IntVar(flagVar, oldName, defaultVal, usage)
fs.IntVar(flagVar, newName, defaultVal, usage)
fs.MarkHidden(oldName)
fs.MarkDeprecated(oldName, fmt.Sprintf("use --%s instead.", newName))
}
27 changes: 16 additions & 11 deletions cmd/internal/apidump/apidump.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ var Cmd = &cobra.Command{
}
} else {
if outFlag.AkitaURI.ObjectName == "" {
traceRotateInterval = time.Hour
traceRotateInterval = apidump.DefaultTraceRotateInterval
}
}
}

if deploymentFlag == "" {
deploymentFlag = "default"
deploymentFlag = apidump.DefaultDeployment
if os.Getenv("AKITA_DEPLOYMENT") != "" {
deploymentFlag = os.Getenv("AKITA_DEPLOYMENT")
}
Expand Down Expand Up @@ -195,13 +195,15 @@ func init() {
&serviceFlag,
"service",
"",
"Your Akita project. DEPRECATED, prefer --project.")
"Your Akita project.")
Cmd.Flags().MarkDeprecated("service", "use --project instead.")

Cmd.Flags().StringVar(
&serviceFlag,
"cluster",
"",
"Your Akita project. DEPRECATED, prefer --project.")
"Your Akita project.")
Cmd.Flags().MarkDeprecated("cluster", "use --project instead.")

Cmd.Flags().StringVar(
&filterFlag,
Expand All @@ -219,13 +221,14 @@ func init() {
&sampleRateFlag,
"sample-rate",
1.0,
"A number between [0.0, 1.0] to control sampling. DEPRECATED, prefer --rate-limit.",
"A number between [0.0, 1.0] to control sampling.",
)
Cmd.Flags().MarkDeprecated("sample-rate", "use --rate-limit instead.")

Cmd.Flags().Float64Var(
&rateLimitFlag,
"rate-limit",
1000.0,
apidump.DefaultRateLimit,
"Number of requests per minute to capture.",
)

Expand All @@ -241,6 +244,7 @@ func init() {
"append-by-tag",
false,
"Add to the most recent Akita trace with matching tag.")
Cmd.Flags().MarkDeprecated("append-by-tag", "and is no longer necessary. All traces in a project are now combined into a single model. Please remove this flag.")

Cmd.Flags().StringSliceVar(
&pathExclusionsFlag,
Expand Down Expand Up @@ -306,36 +310,37 @@ func init() {
&deploymentFlag,
"deployment",
"",
"Deployment name to use. DEPRECATED, prefer creating separate projects for different deployment environments, e.g. 'my-project-prod' and 'my-project-staging'.",
"Deployment name to use.",
)
Cmd.Flags().MarkDeprecated("deployment", "create separate projects for different deployment environments instead. For example, 'my-project-prod' and 'my-project-staging'.")

Cmd.Flags().IntVar(
&statsLogDelay,
"stats-log-delay",
60,
apidump.DefaultStatsLogDelay_seconds,
"Print packet capture statistics after N seconds.",
)

Cmd.Flags().IntVar(
&telemetryInterval,
"telemetry-interval",
5*60, // 5 minutes
apidump.DefaultTelemetryInterval_seconds,
"Upload client telemetry every N seconds.",
)
Cmd.Flags().MarkHidden("telemetry-interval")

Cmd.Flags().BoolVar(
&collectTCPAndTLSReports,
"report-tcp-and-tls",
false,
apidump.DefaultCollectTCPAndTLSReports,
"Collect TCP and TLS reports.",
)
Cmd.Flags().MarkHidden("report-tcp-and-tls")

Cmd.Flags().BoolVar(
&parseTLSHandshakes,
"parse-tls-handshakes",
true,
apidump.DefaultParseTLSHandshakes,
"Parse TLS handshake packets.",
)
Cmd.Flags().MarkHidden("parse-tls-handshakes")
Expand Down
2 changes: 1 addition & 1 deletion cmd/internal/apispec/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func parseTime(s string) (time.Time, error) {
}

var Cmd = &cobra.Command{
Deprecated: "API specs are created automatically in the Akita app.",
Deprecated: "API models are created automatically in the Akita app.",
Use: "apispec",
Short: "Convert traces into an OpenAPI3 specification.",
SilenceUsage: true,
Expand Down
Loading