Skip to content

Commit 7f7caa9

Browse files
[poa-2928] Add repro mode flag to kube run (#85)
Changes: * Added a `--repro-mode` persistent flag to the `kube run` command * Remove `INSIGHTS_REPRO_MODE_ENABLED` env var * Added `RemovePodFromMap` to `isEndState()` * Remove debug level check in dump map function; this table will be logged every 5 minutes, which should not be noisy. * Improvement over this would be to print only when there is a change in the map since last time.
1 parent bd886af commit 7f7caa9

File tree

5 files changed

+27
-15
lines changed

5 files changed

+27
-15
lines changed

cmd/internal/kube/daemonset/constants.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const (
1111
POSTMAN_INSIGHTS_ENV = "POSTMAN_ENV" // This is same as root POSTMAN_ENV
1212
POSTMAN_INSIGHTS_VERIFICATION_TOKEN = "POSTMAN_INSIGHTS_VERIFICATION_TOKEN"
1313
POSTMAN_INSIGHTS_CLUSTER_NAME = "POSTMAN_INSIGHTS_CLUSTER_NAME"
14-
POSTMAN_INSIGHTS_REPRO_MODE_ENABLED = "POSTMAN_INSIGHTS_REPRO_MODE_ENABLED"
1514

1615
// Workers intervals
1716
DefaultTelemetryInterval = 5 * time.Minute

cmd/internal/kube/daemonset/daemonset.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ const (
2626
agentImage = "public.ecr.aws/postman/postman-insights-agent:latest"
2727
)
2828

29+
type DaemonsetArgs struct {
30+
ReproMode bool
31+
}
32+
2933
type Daemonset struct {
3034
ClusterName string
3135
InsightsEnvironment string
@@ -46,7 +50,7 @@ type Daemonset struct {
4650
TelemetryInterval time.Duration
4751
}
4852

49-
func StartDaemonset() error {
53+
func StartDaemonset(args DaemonsetArgs) error {
5054
// Check if the agent is running in a linux environment
5155
if runtime.GOOS != "linux" {
5256
return errors.New("This command is only supported on linux images")
@@ -95,13 +99,10 @@ func StartDaemonset() error {
9599
return errors.Wrap(err, "failed to create CRI client")
96100
}
97101

98-
insightsReproModeEnabled := os.Getenv(POSTMAN_INSIGHTS_REPRO_MODE_ENABLED) == "true"
99-
insightsEnvironment := os.Getenv(POSTMAN_INSIGHTS_ENV)
100-
101102
daemonsetRun := &Daemonset{
102103
ClusterName: clusterName,
103-
InsightsEnvironment: insightsEnvironment,
104-
InsightsReproModeEnabled: insightsReproModeEnabled,
104+
InsightsEnvironment: os.Getenv(POSTMAN_INSIGHTS_ENV),
105+
InsightsReproModeEnabled: args.ReproMode,
105106
KubeClient: kubeClient,
106107
CRIClient: criClient,
107108
FrontClient: frontClient,

cmd/internal/kube/daemonset/pod_args.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,10 @@ func (p *PodArgs) changePodTrafficMonitorState(
9696

9797
// isEndState checks if the pod traffic monitor state is in the final state.
9898
func (p *PodArgs) isEndState() bool {
99-
return p.PodTrafficMonitorState == TrafficMonitoringEnded || p.PodTrafficMonitorState == TrafficMonitoringFailed
99+
switch p.PodTrafficMonitorState {
100+
case TrafficMonitoringEnded, TrafficMonitoringFailed, RemovePodFromMap:
101+
return true
102+
default:
103+
return false
104+
}
100105
}

cmd/internal/kube/daemonset/telemetry.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"time"
66

77
"github.com/postmanlabs/postman-insights-agent/printer"
8-
"github.com/spf13/viper"
98
"k8s.io/apimachinery/pkg/types"
109
)
1110

@@ -25,12 +24,9 @@ func (d *Daemonset) sendTelemetry() {
2524
}
2625
}
2726

28-
// dumpPodsApiDumpProcessState logs the current state of active pods if the debug mode is enabled.
27+
// dumpPodsApiDumpProcessState logs the current state of active pods.
2928
// It prints a formatted table with the pod name, project ID, and current state for each pod.
3029
func (d *Daemonset) dumpPodsApiDumpProcessState() {
31-
if !viper.GetBool("debug") {
32-
return
33-
}
3430
logf := printer.Debugf
3531

3632
const hrBr = "================================================================================" +

cmd/internal/kube/run.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ import (
66
"github.com/spf13/cobra"
77
)
88

9-
func StartDaemonsetAndHibernateOnError(_ *cobra.Command, args []string) error {
10-
err := daemonset.StartDaemonset()
9+
var (
10+
reproMode bool
11+
)
1112

13+
func StartDaemonsetAndHibernateOnError(_ *cobra.Command, args []string) error {
14+
err := daemonset.StartDaemonset(daemonset.DaemonsetArgs{ReproMode: reproMode})
1215
if err == nil {
1316
return nil
1417
}
@@ -28,6 +31,14 @@ var runCmd = &cobra.Command{
2831
}
2932

3033
func init() {
34+
runCmd.PersistentFlags().BoolVar(
35+
&reproMode,
36+
"repro-mode",
37+
false,
38+
"Enable Repro Mode to capture request and response payloads for debugging.",
39+
)
40+
_ = runCmd.PersistentFlags().MarkHidden("repro-mode")
41+
3142
Cmd.AddCommand(runCmd)
3243

3344
// Mark the inherited `project` flag as hidden

0 commit comments

Comments
 (0)