-
Notifications
You must be signed in to change notification settings - Fork 593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rpk: add rpk debug remote-bundle
; collect a cluster-wide bundle
#23986
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev
Previous commit
rpk: add
rpk debug remote bundle
Fixes DEVEX-44 This commit introduces the rpk debug remote bundle command, which allows the user to request a debug bundle using the Admin API.
- Loading branch information
commit b88a85700ac4bb34140d3d8c53f1780d0e74a7f5
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
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
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
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,58 @@ | ||
package common | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSanitizeName(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
input string | ||
exp string | ||
}{ | ||
{ | ||
name: "No forbidden characters", | ||
input: "validName", | ||
exp: "validName", | ||
}, | ||
{ | ||
name: "Single forbidden character", | ||
input: "invalid:8083", | ||
exp: "invalid-8083", | ||
}, | ||
{ | ||
name: "Multiple forbidden characters", | ||
input: "name/with|forbidden?chars", | ||
exp: "name-with-forbidden-chars", | ||
}, | ||
{ | ||
name: "Only forbidden characters", | ||
input: `<>:\"/\\|?*`, | ||
exp: "-----------", | ||
}, | ||
{ | ||
name: "Empty string", | ||
input: "", | ||
exp: "", | ||
}, | ||
{ | ||
name: "No change with already sanitized name", | ||
input: "cleanName123", | ||
exp: "cleanName123", | ||
}, | ||
{ | ||
name: "Name with numbers and special characters", | ||
input: "name123|test*<>", | ||
exp: "name123-test---", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
actual := SanitizeName(tt.input) | ||
require.Equal(t, tt.exp, actual) | ||
}) | ||
} | ||
} |
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,27 @@ | ||
load("@rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "remotebundle", | ||
srcs = [ | ||
"cancel.go", | ||
"download.go", | ||
"remote.go", | ||
"start.go", | ||
"status.go", | ||
], | ||
importpath = "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/debug/remotebundle", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//src/go/rpk/pkg/adminapi", | ||
"//src/go/rpk/pkg/cli/debug/common", | ||
"//src/go/rpk/pkg/config", | ||
"//src/go/rpk/pkg/out", | ||
"@com_github_docker_go_units//:go-units", | ||
"@com_github_google_uuid//:uuid", | ||
"@com_github_redpanda_data_common_go_rpadmin//:rpadmin", | ||
"@com_github_spf13_afero//:afero", | ||
"@com_github_spf13_cobra//:cobra", | ||
"@io_k8s_apimachinery//pkg/labels", | ||
"@org_golang_x_sync//errgroup", | ||
], | ||
) |
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,121 @@ | ||
// Copyright 2024 Redpanda Data, Inc. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.md | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0 | ||
|
||
package remotebundle | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"sync" | ||
|
||
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" | ||
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/out" | ||
"github.com/spf13/afero" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type cancelResponse struct { | ||
Broker string | ||
Canceled bool | ||
Error string | ||
} | ||
|
||
func newCancelCommand(fs afero.Fs, p *config.Params) *cobra.Command { | ||
var noConfirm bool | ||
var jobID string | ||
cmd := &cobra.Command{ | ||
Use: "cancel", | ||
Short: "Cancel a remote bundle execution", | ||
Long: `Cancel a remote bundle execution. | ||
|
||
This command cancels the debug collection process in a remote cluster that | ||
you configured in flags, environment variables, or your rpk profile. | ||
|
||
Use the flag '--job-id' to only cancel the debug bundle with | ||
the given job ID. | ||
|
||
Use the flag '--no-confirm' to avoid the confirmation prompt. | ||
`, | ||
Args: cobra.NoArgs, | ||
Run: func(cmd *cobra.Command, _ []string) { | ||
p, err := p.LoadVirtualProfile(fs) | ||
out.MaybeDie(err, "rpk unable to load config: %v", err) | ||
config.CheckExitCloudAdmin(p) | ||
|
||
status, anyErr, _, cache := executeBundleStatus(cmd.Context(), fs, p) | ||
if jobID != "" { | ||
status = filterStatusByJobID(status, jobID) | ||
} | ||
if !noConfirm { | ||
printTextBundleStatus(status, anyErr) | ||
confirmed, err := out.Confirm("Confirm debug bundle cancel from these brokers?") | ||
out.MaybeDie(err, "unable to confirm cancel: %v; if you want to select a single broker, use -X admin.hosts=<brokers,to,cancel>", err) | ||
if !confirmed { | ||
out.Exit("operation canceled; if you want to select a single broker, use -X admin.hosts=<brokers,to,cancel>") | ||
} | ||
} | ||
var ( | ||
wg sync.WaitGroup | ||
rwMu sync.RWMutex // read from cache. | ||
mu sync.Mutex // write to status. | ||
response []cancelResponse | ||
anyCancelErr bool | ||
) | ||
updateStatus := func(resp cancelResponse, err error) { | ||
mu.Lock() | ||
defer mu.Unlock() | ||
anyCancelErr = anyCancelErr || err != nil | ||
response = append(response, resp) | ||
} | ||
for _, s := range status { | ||
wg.Add(1) | ||
go func(addr, jobID string) { | ||
defer wg.Done() | ||
rwMu.RLock() | ||
cl := cache[addr] | ||
rwMu.RUnlock() | ||
resp := cancelResponse{Broker: addr} | ||
err := cl.CancelDebugBundleProcess(cmd.Context(), jobID) | ||
if err != nil { | ||
resp.Error = fmt.Sprintf("unable to cancel debug bundle: %s", tryMessageFromErr(err)) | ||
updateStatus(resp, err) | ||
return | ||
} | ||
resp.Canceled = true | ||
updateStatus(resp, nil) | ||
}(s.Broker, s.JobID) | ||
} | ||
wg.Wait() | ||
headers := []string{"broker", "canceled"} | ||
if anyCancelErr { | ||
headers = append(headers, "error") | ||
defer os.Exit(1) | ||
} | ||
|
||
tw := out.NewTable(headers...) | ||
defer tw.Flush() | ||
for _, row := range response { | ||
tw.PrintStructFields(row) | ||
} | ||
}, | ||
} | ||
cmd.Flags().StringVar(&jobID, "job-id", "", "ID of the job to cancel the debug bundle") | ||
cmd.Flags().BoolVar(&noConfirm, "no-confirm", false, "Disable confirmation prompt") | ||
return cmd | ||
} | ||
|
||
func filterStatusByJobID(status []statusResponse, jobID string) []statusResponse { | ||
var filtered []statusResponse | ||
for _, s := range status { | ||
if s.JobID == jobID { | ||
filtered = append(filtered, s) | ||
} | ||
} | ||
return filtered | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as the above on periods.