-
Notifications
You must be signed in to change notification settings - Fork 20
PMM-5680 store logs #342
base: main
Are you sure you want to change the base?
PMM-5680 store logs #342
Conversation
storelogs/main.go
Outdated
| dt := time.Now() | ||
| log = dt.Format("01-02-2006 15:04:05") + " " + l.entry.Level.String() + ": " + log | ||
| for _, v := range l.entry.Data { | ||
| log = log + fmt.Sprintf(" %v", v) |
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.
1 solution make slice of strings and then join
2 solution by any buffer
in log = log + fmt.Sprintf(" %v", v) too many garbage https://gosamples.dev/concatenate-strings/
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.
changed to buffer
agentlocal/agent_local.go
Outdated
| reloadCloseOnce sync.Once | ||
| } | ||
|
|
||
| func (s *Server) mustEmbedUnimplementedAgentLocalServer() { |
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.
it's wrong, possible solution remove this requirement by some protoc --arg or by embeding [agentlocalpb|agentpb].UnimplementedAgentLocalServer
storelogs/main.go
Outdated
|
|
||
| type LogsStore struct { | ||
| log *ring.Ring | ||
| Entry *logrus.Entry |
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.
entry *logrus.Entry
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 need use it here newProcessLogger(sl.Entry, keepLogLines, redactWords),
YaroslavPodorvanov
left a comment
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.
mustEmbed need delete
# Conflicts: # go.mod # go.sum
agentlocal/agent_local.go
Outdated
| } | ||
|
|
||
| //// AgentLogs contains information about Agent logs. | ||
| //type AgentLogs struct { |
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 🐶
commentFormatting: put a space between // and comment text (gocritic)
commands/run.go
Outdated
| // handle termination signals | ||
| signals := make(chan os.Signal, 1) | ||
| signal.Notify(signals, unix.SIGTERM, unix.SIGINT) | ||
| ringLog := storelogs.New(500) |
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: 500, in detected (gomnd)
agents/supervisor/supervisor.go
Outdated
| var res map[string][]string | ||
|
|
||
| for id, agent := range s.agentProcesses { | ||
| res[fmt.Sprintf("%s %s", id, agent.requestedState.Type.String())] = agent.logs.GetLogs() |
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 put type to the beginning and let's remove /agent_id/ from id.
commands/run.go
Outdated
| "github.com/percona/pmm-agent/versioner" | ||
| ) | ||
|
|
||
| const COUNT_SERVER_LOGS = 500 |
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 🐶
don't use ALL_CAPS in Go names; use CamelCase (golint)
agents/supervisor/supervisor.go
Outdated
| const ( | ||
| type_TEST_SLEEP inventorypb.AgentType = 998 // process | ||
| type_TEST_NOOP inventorypb.AgentType = 999 // built-in | ||
| type_TEST_SLEEP inventorypb.AgentType = 998 // process |
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 🐶
var-naming: don't use underscores in Go names; const type_TEST_SLEEP should be typeTESTSLEEP (revive)
agents/supervisor/supervisor.go
Outdated
| type_TEST_SLEEP inventorypb.AgentType = 998 // process | ||
| type_TEST_NOOP inventorypb.AgentType = 999 // built-in | ||
| type_TEST_SLEEP inventorypb.AgentType = 998 // process | ||
| type_TEST_NOOP inventorypb.AgentType = 999 // built-in |
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 🐶
var-naming: don't use underscores in Go names; const type_TEST_NOOP should be typeTESTNOOP (revive)
agents/supervisor/supervisor.go
Outdated
| type_TEST_NOOP inventorypb.AgentType = 999 // built-in | ||
| type_TEST_SLEEP inventorypb.AgentType = 998 // process | ||
| type_TEST_NOOP inventorypb.AgentType = 999 // built-in | ||
| COUNT_AGENT_LOGS = 10 |
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 🐶
var-naming: don't use ALL_CAPS in Go names; use CamelCase (revive)
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 use camelCase.
In the cases above snake_case is used because they are mocks for enum and it's better to move them to supervisor_test.go
agents/supervisor/supervisor.go
Outdated
| res := make(map[string][]string) | ||
|
|
||
| for id, agent := range s.agentProcesses { | ||
| newId := strings.ReplaceAll(id, "/agent_id/", "") |
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 🐶
var newId should be newID (golint)
agents/supervisor/supervisor.go
Outdated
| } | ||
|
|
||
| for id, agent := range s.builtinAgents { | ||
| newId := strings.ReplaceAll(id, "/agent_id/", "") |
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 🐶
var newId should be newID (golint)
BupycHuk
left a comment
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.
looks good to me, just a few minor comments
agentlocal/agent_local.go
Outdated
|
|
||
| // NewServer creates new server. | ||
| // | ||
| //` |
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 revert
agentlocal/agent_local.go
Outdated
| mux.Handle("/debug/", http.DefaultServeMux) | ||
| mux.Handle("/debug", debugPageHandler) | ||
| mux.Handle("/", proxyMux) | ||
| mux.HandleFunc("/logs.zip", func(w http.ResponseWriter, r *http.Request) { |
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.
can we add a test for logs.zip?
agents/supervisor/supervisor.go
Outdated
| type_TEST_NOOP inventorypb.AgentType = 999 // built-in | ||
| type_TEST_SLEEP inventorypb.AgentType = 998 // process | ||
| type_TEST_NOOP inventorypb.AgentType = 999 // built-in | ||
| COUNT_AGENT_LOGS = 10 |
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 increase the value
agents/supervisor/supervisor.go
Outdated
| type_TEST_NOOP inventorypb.AgentType = 999 // built-in | ||
| type_TEST_SLEEP inventorypb.AgentType = 998 // process | ||
| type_TEST_NOOP inventorypb.AgentType = 999 // built-in | ||
| COUNT_AGENT_LOGS = 10 |
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 use camelCase.
In the cases above snake_case is used because they are mocks for enum and it's better to move them to supervisor_test.go
# Conflicts: # agents/supervisor/supervisor.go
| _ agentlocalpb.AgentLocalServer = (*Server)(nil) | ||
| ) | ||
|
|
||
| func (s *Server) Zip(w http.ResponseWriter, r *http.Request) { |
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 🐶
exported method Server.Zip should have comment or be unexported (golint)
| }) | ||
| } | ||
|
|
||
| func TestGetZipFile(t *testing.T) { |
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 🐶
Function TestGetZipFile missing the call to method parallel (paralleltest)
| } | ||
|
|
||
| func TestGetZipFile(t *testing.T) { | ||
| setup := func(t *testing.T) ([]*agentlocalpb.AgentInfo, *mockSupervisor, *mockClient, *config.Config) { |
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 🐶
test helper function should start from t.Helper() (thelper)
| for _, serverLog := range s.ringLogs.GetLogs() { | ||
| _, err := b.WriteString(serverLog) | ||
| if err != nil { | ||
| return nil, 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 (*bytes.Buffer).WriteString(s string) (n int, err error) (wrapcheck)
| for _, l := range logs { | ||
| _, err := b.WriteString(l + "\n") | ||
| if err != nil { | ||
| return nil, 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 (*bytes.Buffer).WriteString(s string) (n int, err error) (wrapcheck)
| } | ||
| err := writer.Close() | ||
| if err != nil { | ||
| return nil, 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 (*archive/zip.Writer).Close() error (wrapcheck)
| b, err := ioutil.ReadAll(rec.Body) | ||
| require.NoError(t, err) | ||
|
|
||
| expectedFile, err := generateTestZip(s) |
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 are generating zip file that you will later compare with, but what if it fails? The output will be not readable.
I think it would be better to unzip received file, and verify content.
Here is example of equality check failing:

The failure message is impossible to understand, because it is a diff between two binary files
ritbl
left a comment
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 see my comment
agentlocal/agent_local.go
Outdated
| // | ||
|
|
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 revert it.
agentlocal/agent_local.go
Outdated
| log.Fatal(err) | ||
| } | ||
| } | ||
| addData(writer, "server.txt", b.Bytes()) |
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 think it's better to rename it to pmm-agent.txt or http-server if it contains only http server logs.
| addData(writer, "server.txt", b.Bytes()) | |
| addData(writer, "http-server.txt", b.Bytes()) |
storelogs/storelogs.go
Outdated
| func (l *LogsStore) Write(b []byte) (n int, err error) { | ||
| l.m.Lock() | ||
| l.log.Value = string(b) | ||
| l.m.Unlock() |
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 unlock it one line below.
PMM-5680
Build: SUBMODULES-2425