Skip to content

Commit

Permalink
fix: no default profefe hostport for capture
Browse files Browse the repository at this point in the history
The flags are colliding between commands. It means that the
profefe-hostport gets the default specified in order commands.

But for the kubectl profefe capture the empty string needs to be the
default one becuase it is used to discriminate if profiles needs to be
pushed in profefe or stored locally.

By default they get stored locally in /tmp

Signed-off-by: Gianluca Arbezzano <gianarb92@gmail.com>
  • Loading branch information
Gianluca Arbezzano committed Dec 10, 2019
1 parent aa1c580 commit d872458
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 7 additions & 6 deletions pkg/cmd/capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ const (
)

var (
OutputDir string
ProfefeHostPort string
OutputDir string
ProfefeHostPort string
ProfefeHostPortE string
)

func NewCaptureCmd(configFlag *genericclioptions.ConfigFlags, rbFlags *genericclioptions.ResourceBuilderFlags, streams genericclioptions.IOStreams) *cobra.Command {
Expand Down Expand Up @@ -139,9 +140,9 @@ func NewCaptureCmd(configFlag *genericclioptions.ConfigFlags, rbFlags *genericcl
}

var pClient *profefe.Client
if ProfefeHostPort != "" {
if ProfefeHostPortE != "" {
pClient = profefe.NewClient(profefe.Config{
HostPort: ProfefeHostPort,
HostPort: ProfefeHostPortE,
}, http.Client{})
}

Expand All @@ -158,7 +159,7 @@ func NewCaptureCmd(configFlag *genericclioptions.ConfigFlags, rbFlags *genericcl
}
flagsCapture := pflag.NewFlagSet("kubectl-profefe-capture", pflag.ExitOnError)
flagsCapture.StringVar(&OutputDir, "output-dir", "/tmp", "Directory where to place the profiles")
flagsCapture.StringVar(&ProfefeHostPort, "profefe-hostport", "", `Where profefe
flagsCapture.StringVar(&ProfefeHostPortE, "profefe-hostport", "", `Where profefe
is (eg http://localhost:10100). If not set the profiles will be store in
your /tmp directory. When set the profiles will be only pushed in
profefe.`)
Expand Down Expand Up @@ -189,7 +190,7 @@ func writeProfiles(ctx context.Context, pClient *profefe.Client, profiles map[pp
if err != nil {
println(fmt.Sprintf("%s type=%s profile_type=%s", err.Error(), profefeType, profile.PeriodType.Type))
} else {
println(fmt.Sprintf("%s/api/0/profiles/%s type=%s", ProfefeHostPort, saved.Body.ID, profefeType))
println(fmt.Sprintf("%s/api/0/profiles/%s type=%s", ProfefeHostPortE, saved.Body.ID, profefeType))
}
} else {
f, err := os.OpenFile(
Expand Down
4 changes: 4 additions & 0 deletions pkg/cmd/kprofefe.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func NewKProfefeCmd(logger *zap.Logger, streams genericclioptions.IOStreams) *co
kubeConfigFlags := genericclioptions.NewConfigFlags(false)
kubeResouceBuilderFlags := genericclioptions.NewResourceBuilderFlags()

if ProfefeHostPort == "" {
ProfefeHostPort = "http://localhost:10100"
}

cmd := &cobra.Command{
Use: "kprofefe",
Short: "kprofefe collects profiles from inside a kubernetes cluster",
Expand Down

0 comments on commit d872458

Please sign in to comment.