-
Notifications
You must be signed in to change notification settings - Fork 12
PMM-5680 store agents logs #197
base: main
Are you sure you want to change the base?
Changes from 10 commits
3bc9d37
2db5722
e1df266
1fc2698
df0f287
65cb23f
1a9381c
4a86454
ed34aaf
1e5e1ab
3d9236e
253991c
3b5020a
e23d761
f69bd1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -121,17 +121,15 @@ func addClientData(ctx context.Context, zipW *zip.Writer) { | |||||
logrus.Errorf("%s", err) | ||||||
return | ||||||
} | ||||||
|
||||||
addVMAgentTargets(ctx, zipW, status.AgentsInfo) | ||||||
|
||||||
now := time.Now() | ||||||
|
||||||
b, err := json.MarshalIndent(status, "", " ") | ||||||
if err != nil { | ||||||
logrus.Debugf("%s", err) | ||||||
b = []byte(err.Error()) | ||||||
} | ||||||
b = append(b, '\n') | ||||||
now := time.Now() | ||||||
addData(zipW, "client/status.json", now, bytes.NewReader(b)) | ||||||
|
||||||
// FIXME get it via pmm-agent's API - it is _not_ a good idea to use exec there | ||||||
|
@@ -145,6 +143,14 @@ func addClientData(ctx context.Context, zipW *zip.Writer) { | |||||
|
||||||
addData(zipW, "client/pmm-admin-version.txt", now, bytes.NewReader([]byte(version.FullInfo()))) | ||||||
|
||||||
fileName := "pmm-admin-summary.zip" | ||||||
err = downloadFile(fmt.Sprintf("http://%s:%d/logs.zip", agentlocal.Localhost, agentlocal.DefaultPMMAgentListenPort), fileName) | ||||||
if err != nil { | ||||||
logrus.Debugf("%s", err) | ||||||
b = []byte(err.Error()) | ||||||
} | ||||||
logrus.Info("pmm-admin-summary.zip created") | ||||||
|
||||||
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. we are on a right track, as a next step let's include files from logs.zip into main zip file 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. you can find example of it in 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. I did it |
||||||
if status.ConfigFilepath != "" { | ||||||
addFile(zipW, "client/pmm-agent-config.yaml", status.ConfigFilepath) | ||||||
} | ||||||
|
@@ -220,6 +226,34 @@ func getURL(ctx context.Context, url string) ([]byte, error) { | |||||
return b, nil | ||||||
} | ||||||
|
||||||
// downloadFile download file to local destination | ||||||
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.
Suggested change
|
||||||
func downloadFile(url, fileName string) error { | ||||||
//Get the response bytes from the url | ||||||
response, err := http.Get(url) | ||||||
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. 🚫 [golangci-lint] reported by reviewdog 🐶 |
||||||
if err != nil { | ||||||
return err | ||||||
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. 🚫 [golangci-lint] reported by reviewdog 🐶 |
||||||
} | ||||||
defer response.Body.Close() | ||||||
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. 🚫 [golangci-lint] reported by reviewdog 🐶 |
||||||
|
||||||
if response.StatusCode != 200 { | ||||||
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. 🚫 [golangci-lint] reported by reviewdog 🐶 |
||||||
return errors.New("Received non 200 response code") | ||||||
} | ||||||
|
||||||
//Create an empty file | ||||||
file, err := os.Create(fileName) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
defer file.Close() | ||||||
|
||||||
//Write the bytes to the file | ||||||
_, err = io.Copy(file, response.Body) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
return nil | ||||||
} | ||||||
|
||||||
type pprofData struct { | ||||||
name string | ||||||
data []byte | ||||||
|
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.
let's write it in warn level