-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from gianarb/feature/get-profiles-and-profile-…
…types feat(kubectl): add get commands
- Loading branch information
Showing
6 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewGetCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "get", | ||
Short: "", | ||
Run: func(cmd *cobra.Command, args []string) {}, | ||
} | ||
|
||
cmd.AddCommand(NewGetProfilesCmd()) | ||
cmd.AddCommand(NewGetProfileTypesCmd()) | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/gianarb/kube-profefe/pkg/profefe" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewGetProfileTypesCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "profile-types", | ||
Short: "Retrieve supported profile types", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
for _, v := range profefe.AllProfileTypes() { | ||
println(v) | ||
} | ||
return nil | ||
}, | ||
} | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/gianarb/kube-profefe/pkg/profefe" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
) | ||
|
||
var ( | ||
service string | ||
profileType string | ||
from time.Duration | ||
to time.Duration | ||
) | ||
|
||
func NewGetProfilesCmd() *cobra.Command { | ||
flags := pflag.NewFlagSet("kprofefe", pflag.ExitOnError) | ||
|
||
cmd := &cobra.Command{ | ||
Use: "profiles", | ||
Short: "Retrieve profiles from profefe", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx := context.Background() | ||
pClient := profefe.NewClient(profefe.Config{ | ||
HostPort: ProfefeHostPort, | ||
}, http.Client{}) | ||
|
||
req := profefe.GetProfilesRequest{} | ||
req.Service = service | ||
|
||
if profileType != "" { | ||
pt := profefe.NewProfileTypeFromString(profileType) | ||
if pt != profefe.UnknownProfile { | ||
req.Type = pt | ||
} | ||
} | ||
|
||
req.To = time.Now() | ||
req.From = req.To.Add(-from) | ||
|
||
resp, err := pClient.GetProfiles(ctx, req) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, v := range resp.Body { | ||
println(fmt.Sprintf("ID: %s Type: %s Service: %s CreateAt: %s", v.ID, v.Type, v.Service, v.CreatedAt.Format(time.RFC1123))) | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
flags.AddFlagSet(cmd.PersistentFlags()) | ||
flags.StringVar(&ProfefeHostPort, "profefe-hostport", "http://localhost:10100", `where profefe is located`) | ||
flags.StringVar(&profileType, "profile-type", "cpu", `The pprof profiles to retrieve`) | ||
flags.StringVar(&service, "service", "", ``) | ||
flags.DurationVar(&from, "from", 24*time.Hour, ``) | ||
flags.DurationVar(&to, "to", 0, ``) | ||
|
||
cmd.Flags().AddFlagSet(flags) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters