-
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 14 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,11 @@ func addClientData(ctx context.Context, zipW *zip.Writer) { | |
|
||
addData(zipW, "client/pmm-admin-version.txt", now, bytes.NewReader([]byte(version.FullInfo()))) | ||
|
||
err = downloadFile(zipW, fmt.Sprintf("http://%s:%d/logs.zip", agentlocal.Localhost, agentlocal.DefaultPMMAgentListenPort), "pmm-admin") | ||
if err != nil { | ||
logrus.Warnf("%s", err) | ||
} | ||
|
||
if status.ConfigFilepath != "" { | ||
addFile(zipW, "client/pmm-agent-config.yaml", status.ConfigFilepath) | ||
} | ||
|
@@ -220,6 +223,42 @@ func getURL(ctx context.Context, url string) ([]byte, error) { | |
return b, nil | ||
} | ||
|
||
// downloadFile download file and includes into zip file | ||
func downloadFile(zipW *zip.Writer, url, fileName string) error { | ||
response, err := http.Get(url) | ||
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") | ||
} | ||
|
||
b, err := ioutil.ReadAll(response.Body) | ||
if err != nil { | ||
return errors.Wrap(err, "cannot read response body") | ||
} | ||
bufR := bytes.NewReader(b) | ||
|
||
zipR, err := zip.NewReader(bufR, bufR.Size()) | ||
if err != nil { | ||
return errors.Wrap(err, "cannot create Zip reader") | ||
} | ||
|
||
for _, rf := range zipR.File { | ||
BupycHuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rc, err := rf.Open() | ||
BupycHuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
logrus.Errorf("%s", err) | ||
continue | ||
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 🐶 |
||
} | ||
addData(zipW, path.Join(fileName, rf.Name), rf.Modified, rc) | ||
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 🐶 |
||
|
||
rc.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 🐶 |
||
} | ||
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.
🚫 [golangci-lint] reported by reviewdog 🐶
G107: Potential HTTP request made with variable url (gosec)