-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[management/client] Integrate Job API with Job Stream and Client Engine #4428
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
08641b7
integrate api
aliamerj 171925d
fix typo and fix validation
aliamerj e47e648
use real daemon address
aliamerj dec307f
redo the connect via address
aliamerj f1cc9e4
Refactor the debug bundle generator to be ready to use from engine (#…
pappz 9cb9fc4
fix tests
aliamerj 7fba07b
fix lint
aliamerj 7c60ad6
fix bug with stream
aliamerj 36215b8
try refactor status 1
aliamerj 426a6f2
fix convert fullStatus to statusOutput & add logFile
aliamerj 3ee24d7
fix tests
aliamerj b1077aa
fix tests
aliamerj d82d56a
fix not enough arguments in call to nbstatus.ConvertToStatusOutputOve…
aliamerj 9d5694f
fix status_test
aliamerj 889c3c8
fix(engine): avoid deadlock when stopping engine during debug bundle
aliamerj 3027029
use atomic for lock-free
aliamerj 2eba4af
use new lock
aliamerj 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
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -196,7 +196,8 @@ func runInForegroundMode(ctx context.Context, cmd *cobra.Command, activeProf *pr | |
| r := peer.NewRecorder(config.ManagementURL.String()) | ||
| r.GetFullStatus() | ||
|
|
||
| connectClient := internal.NewConnectClient(ctx, config, r) | ||
| //todo: do we need to pass logFile here ? | ||
| connectClient := internal.NewConnectClient(ctx, config, r, "") | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| SetupDebugHandler(ctx, config, r, connectClient, "") | ||
|
|
||
| return connectClient.Run(nil) | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -131,7 +131,9 @@ func (c *Client) Start(startCtx context.Context) error { | |
| } | ||
|
|
||
| recorder := peer.NewRecorder(c.config.ManagementURL.String()) | ||
| client := internal.NewConnectClient(ctx, c.config, recorder) | ||
|
|
||
| //todo: do we need to pass logFile here ? | ||
| client := internal.NewConnectClient(ctx, c.config, recorder, "") | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| // either startup error (permanent backoff err) or nil err (successful engine up) | ||
| // TODO: make after-startup backoff err available | ||
|
|
||
This file contains hidden or 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 hidden or 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,101 @@ | ||
| package debug | ||
|
|
||
| import ( | ||
| "context" | ||
| "crypto/sha256" | ||
| "encoding/json" | ||
| "fmt" | ||
| "io" | ||
| "net/http" | ||
| "os" | ||
|
|
||
| "github.com/netbirdio/netbird/upload-server/types" | ||
| ) | ||
|
|
||
| const maxBundleUploadSize = 50 * 1024 * 1024 | ||
|
|
||
| func UploadDebugBundle(ctx context.Context, url, managementURL, filePath string) (key string, err error) { | ||
| response, err := getUploadURL(ctx, url, managementURL) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| err = upload(ctx, filePath, response) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| return response.Key, nil | ||
| } | ||
|
|
||
| func upload(ctx context.Context, filePath string, response *types.GetURLResponse) error { | ||
| fileData, err := os.Open(filePath) | ||
| if err != nil { | ||
| return fmt.Errorf("open file: %w", err) | ||
| } | ||
|
|
||
| defer fileData.Close() | ||
|
|
||
| stat, err := fileData.Stat() | ||
| if err != nil { | ||
| return fmt.Errorf("stat file: %w", err) | ||
| } | ||
|
|
||
| if stat.Size() > maxBundleUploadSize { | ||
| return fmt.Errorf("file size exceeds maximum limit of %d bytes", maxBundleUploadSize) | ||
| } | ||
|
|
||
| req, err := http.NewRequestWithContext(ctx, "PUT", response.URL, fileData) | ||
| if err != nil { | ||
| return fmt.Errorf("create PUT request: %w", err) | ||
| } | ||
|
|
||
| req.ContentLength = stat.Size() | ||
| req.Header.Set("Content-Type", "application/octet-stream") | ||
|
|
||
| putResp, err := http.DefaultClient.Do(req) | ||
| if err != nil { | ||
| return fmt.Errorf("upload failed: %v", err) | ||
| } | ||
| defer putResp.Body.Close() | ||
|
|
||
| if putResp.StatusCode != http.StatusOK { | ||
| body, _ := io.ReadAll(putResp.Body) | ||
| return fmt.Errorf("upload status %d: %s", putResp.StatusCode, string(body)) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func getUploadURL(ctx context.Context, url string, managementURL string) (*types.GetURLResponse, error) { | ||
| id := getURLHash(managementURL) | ||
| getReq, err := http.NewRequestWithContext(ctx, "GET", url+"?id="+id, nil) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("create GET request: %w", err) | ||
| } | ||
|
|
||
| getReq.Header.Set(types.ClientHeader, types.ClientHeaderValue) | ||
|
|
||
| resp, err := http.DefaultClient.Do(getReq) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("get presigned URL: %w", err) | ||
| } | ||
| defer resp.Body.Close() | ||
|
|
||
| if resp.StatusCode != http.StatusOK { | ||
| body, _ := io.ReadAll(resp.Body) | ||
| return nil, fmt.Errorf("get presigned URL status %d: %s", resp.StatusCode, string(body)) | ||
| } | ||
|
|
||
| urlBytes, err := io.ReadAll(resp.Body) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("read response body: %w", err) | ||
| } | ||
| var response types.GetURLResponse | ||
| if err := json.Unmarshal(urlBytes, &response); err != nil { | ||
| return nil, fmt.Errorf("unmarshal response: %w", err) | ||
| } | ||
| return &response, nil | ||
| } | ||
|
|
||
| func getURLHash(url string) string { | ||
| return fmt.Sprintf("%x", sha256.Sum256([]byte(url))) | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
logFilehere