Upload profile zip to SUBNET (#4226)

When the `--airgap` flag is not passed, the generated profile zip will
be uploaded to SUBNET.
This commit is contained in:
Shireesh Anjal
2022-09-15 22:18:14 -07:00
committed by GitHub
parent 6347b436ff
commit cdb6b179d3
5 changed files with 55 additions and 36 deletions
+3 -7
View File
@@ -31,10 +31,6 @@ import (
const licRegisterMsgTag = "licenseRegisterMessage"
var licenseRegisterFlags = append([]cli.Flag{
cli.StringFlag{
Name: "api-key",
Usage: "SUBNET API key",
},
cli.StringFlag{
Name: "name",
Usage: "Specify the name to associate to this MinIO cluster in SUBNET",
@@ -170,9 +166,9 @@ func mainLicenseRegister(ctx *cli.Context) error {
regInfo := getClusterRegInfo(getAdminInfo(aliasedURL), clusterName)
alreadyRegistered := false
apiKey, lic, e := getSubnetCreds(alias)
fatalIf(probe.NewError(e), "Error in fetching subnet credentials")
if len(apiKey) > 0 || len(lic) > 0 {
apiKey, _, e := getSubnetCreds(alias)
fatalIf(probe.NewError(e), "Error in fetching subnet API Key")
if len(apiKey) > 0 {
alreadyRegistered = true
if len(accAPIKey) == 0 {
accAPIKey = apiKey
+4
View File
@@ -70,6 +70,10 @@ mr/cKCUyBL7rcAvg0zNq1vcSrUSGlAmY3SEDCu3GOKnjG/U4E7+p957ocWSV+mQU
Usage: "Development mode - talks to local SUBNET",
Hidden: true,
},
cli.StringFlag{
Name: "api-key",
Usage: "API Key of the account on SUBNET",
},
}
)
-4
View File
@@ -42,10 +42,6 @@ import (
)
var supportDiagFlags = append([]cli.Flag{
cli.StringFlag{
Name: "api-key",
Usage: "SUBNET API key",
},
HealthDataTypeFlag{
Name: "test",
Usage: "choose specific diagnostics to run [" + options.String() + "]",
+48 -21
View File
@@ -34,7 +34,7 @@ import (
// profile command flags.
var (
profileFlags = []cli.Flag{
profileFlags = append([]cli.Flag{
cli.IntFlag{
Name: "duration",
Usage: "start profiling for the specified duration in seconds",
@@ -45,9 +45,11 @@ var (
Usage: "profiler type, possible values are 'cpu', 'cpuio', 'mem', 'block', 'mutex', 'trace', 'threads' and 'goroutines'",
Value: "cpu,mem,block,mutex,threads,goroutines",
},
}
}, subnetCommonFlags...)
)
const profileFile = "profile.zip"
var supportProfileCmd = cli.Command{
Name: "profile",
Usage: "generate profile data for debugging",
@@ -132,7 +134,7 @@ func moveFile(sourcePath, destPath string) error {
return os.Remove(sourcePath)
}
func getProfileData(data io.ReadCloser) string {
func saveProfileFile(data io.ReadCloser) {
// Create profile zip file
tmpFile, e := ioutil.TempFile("", "mc-profile-")
fatalIf(probe.NewError(e), "Unable to download profile data.")
@@ -145,45 +147,70 @@ func getProfileData(data io.ReadCloser) string {
data.Close()
tmpFile.Close()
downloadPath := "profile.zip"
downloadedFile := downloadPath + "." + time.Now().Format(dateTimeFormatFilename)
downloadedFile := profileFile + "." + time.Now().Format(dateTimeFormatFilename)
fi, e := os.Stat(downloadPath)
fi, e := os.Stat(profileFile)
if e == nil && !fi.IsDir() {
e = moveFile(downloadPath, downloadedFile)
e = moveFile(profileFile, downloadedFile)
fatalIf(probe.NewError(e), "Unable to create a backup of profile.zip")
} else {
if !os.IsNotExist(e) {
fatal(probe.NewError(e), "Unable to save profile data")
}
}
fatalIf(probe.NewError(moveFile(tmpFile.Name(), downloadPath)), "Unable to save profile data")
return downloadPath
fatalIf(probe.NewError(moveFile(tmpFile.Name(), profileFile)), "Unable to save profile data")
}
// mainSupportProfile is the handle for "mc support profile" command.
func mainSupportProfile(ctx *cli.Context) error {
// Check for command syntax
checkAdminProfileSyntax(ctx)
// Get the alias parameter from cli
args := ctx.Args()
aliasedURL := args.Get(0)
// Get the alias parameter from cli
aliasedURL := ctx.Args().Get(0)
alias, apiKey := initSubnetConnectivity(ctx, aliasedURL)
// if `--airgap` is provided do not try to upload to SUBNET.
if !globalAirgapped {
fatalIf(checkURLReachable(subnetBaseURL()).Trace(aliasedURL), "Unable to reach %s to upload MinIO profile file, please use --airgap to upload manually", subnetBaseURL())
}
// Create a new MinIO Admin Client
client := getClient(aliasedURL)
// Main execution
execSupportProfile(ctx, client, alias, apiKey)
return nil
}
func execSupportProfile(ctx *cli.Context, client *madmin.AdminClient, alias string, apiKey string) {
var reqURL string
var headers map[string]string
profilers := ctx.String("type")
duration := ctx.Int("duration")
// Create a new MinIO Admin Client
client, err := newAdminClient(aliasedURL)
if err != nil {
fatalIf(err.Trace(aliasedURL), "Unable to initialize admin client")
return nil
if !globalAirgapped {
// Retrieve subnet credentials (login/license) beforehand as
// it can take a long time to fetch the profile data
uploadURL := subnetUploadURL("profile", profileFile)
reqURL, headers = prepareSubnetUploadURL(uploadURL, alias, profileFile, apiKey)
}
console.Infof("Profiling '%s' for %d seconds... ", aliasedURL, duration)
console.Infof("Profiling '%s' for %d seconds... ", alias, duration)
data, e := client.Profile(globalContext, madmin.ProfilerType(profilers), time.Second*time.Duration(duration))
fatalIf(probe.NewError(e), "Unable to save profile data")
saveProfileFile(data)
clr := color.New(color.FgGreen, color.Bold)
clr.Printf("saved successfully at '%s'\n", getProfileData(data))
return nil
if !globalAirgapped {
_, e := uploadFileToSubnet(alias, profileFile, reqURL, headers)
fatalIf(probe.NewError(e), "Unable to upload profile file to SUBNET portal")
if len(apiKey) > 0 {
setSubnetAPIKey(alias, apiKey)
}
clr.Println("uploaded successfully to SUBNET.")
} else {
clr.Printf("saved successfully at '%s'\n", profileFile)
}
}
-4
View File
@@ -23,10 +23,6 @@ import (
)
var supportRegisterFlags = append([]cli.Flag{
cli.StringFlag{
Name: "api-key",
Usage: "SUBNET API key",
},
cli.StringFlag{
Name: "name",
Usage: "Specify the name to associate to this MinIO cluster in SUBNET",