-
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?
Conversation
@qwest812 please make PR is ready for review if it's ready |
# Conflicts: # go.mod # go.sum
commands/summary.go
Outdated
logrus.Debugf("%s", err) | ||
b = []byte(err.Error()) | ||
} | ||
b = append(b, '\n') |
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 🐶
append only allowed to cuddle with appended value (wsl)
commands/summary.go
Outdated
b = []byte(err.Error()) | ||
} | ||
b = append(b, '\n') | ||
addData(zipW, "logs/"+pointer.GetString(agent.AgentType)+".json", now, bytes.NewReader(b)) |
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.
what is the reason to make it json?
I think it would be much easier to read if it would be just a text with some separator.
something like
agent id: /agent_id/xxxx1
agent type: mongodb_exporter
lorem ipsum log texts begin
...
lorem ipsum log texts
===============================================
agent id: /agent_id/xxxx2
agent type: mysqld_exporter
lorem ipsum log texts begin
...
lorem ipsum log texts
# Conflicts: # go.mod # go.sum
# Conflicts: # go.mod # go.sum
commands/summary.go
Outdated
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
you can find example of it in addServerData
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.
I did it
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.
LGTM, a few minor changes
commands/summary.go
Outdated
@@ -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 logs") |
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.
err = downloadFile(zipW, fmt.Sprintf("http://%s:%d/logs.zip", agentlocal.Localhost, agentlocal.DefaultPMMAgentListenPort), "pmm-admin logs") | |
err = downloadFile(zipW, fmt.Sprintf("http://%s:%d/logs.zip", agentlocal.Localhost, agentlocal.DefaultPMMAgentListenPort), "pmm-agent") |
commands/summary.go
Outdated
@@ -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 logs") | |||
if err != nil { | |||
logrus.Debugf("%s", err) |
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
commands/summary.go
Outdated
@@ -220,6 +223,43 @@ 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 comment
The reason will be displayed to describe this comment to others. Learn more.
// downloadFile download file to local destination | |
// downloadFile download file and includes into zip file |
commands/summary.go
Outdated
@@ -220,6 +223,43 @@ func getURL(ctx context.Context, url string) ([]byte, error) { | |||
return b, nil | |||
} | |||
|
|||
// downloadFile download file to local destination | |||
func downloadFile(zipW *zip.Writer, url, fileName string) error { | |||
|
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.
please remove this empty line, it makes CI fail
if err != nil { | ||
return err | ||
} | ||
defer response.Body.Close() |
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 🐶
Error return value of response.Body.Close
is not checked (errcheck)
} | ||
addData(zipW, path.Join(fileName, rf.Name), rf.Modified, rc) | ||
|
||
rc.Close() |
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 🐶
Error return value of rc.Close
is not checked (errcheck)
@@ -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) |
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)
logrus.Errorf("%s", err) | ||
continue | ||
} | ||
addData(zipW, path.Join(fileName, rf.Name), rf.Modified, rc) |
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 🐶
G305: File traversal when extracting zip/tar archive (gosec)
} | ||
defer response.Body.Close() | ||
|
||
if response.StatusCode != 200 { |
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 🐶
mnd: Magic number: 200, in detected (gomnd)
rc, err := rf.Open() | ||
if err != nil { | ||
logrus.Errorf("%s", err) | ||
continue |
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 🐶
continue with no blank line before (nlreturn)
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 comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci-lint] reported by reviewdog 🐶
error returned from external package is unwrapped: sig: func net/http.Get(url string) (resp *net/http.Response, err error) (wrapcheck)
PMM-5680
Build: SUBMODULES-2425