Skip to content
This repository was archived by the owner on Aug 24, 2022. It is now read-only.

PMM-5680 store logs - #342

Open
qwest812 wants to merge 70 commits into
mainfrom
PMM-5680-store-logs
Open

PMM-5680 store logs#342
qwest812 wants to merge 70 commits into
mainfrom
PMM-5680-store-logs

Conversation

@qwest812

@qwest812 qwest812 commented Mar 23, 2022

Copy link
Copy Markdown
Contributor

Comment thread 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)

Copy link
Copy Markdown
Contributor

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/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to buffer

Comment thread agentlocal/agent_local.go Outdated
reloadCloseOnce sync.Once
}

func (s *Server) mustEmbedUnimplementedAgentLocalServer() {

Copy link
Copy Markdown
Contributor

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

Comment thread storelogs/main.go Outdated

type LogsStore struct {
log *ring.Ring
Entry *logrus.Entry

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

entry *logrus.Entry

@qwest812 qwest812 Apr 12, 2022

Copy link
Copy Markdown
Contributor Author

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 YaroslavPodorvanov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mustEmbed need delete

Comment thread agentlocal/agent_local.go Outdated
}

//// AgentLogs contains information about Agent logs.
//type AgentLogs struct {

Copy link
Copy Markdown
Contributor

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)

Comment thread commands/run.go Outdated
// handle termination signals
signals := make(chan os.Signal, 1)
signal.Notify(signals, unix.SIGTERM, unix.SIGINT)
ringLog := storelogs.New(500)

Copy link
Copy Markdown
Contributor

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)

Comment thread 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()

Copy link
Copy Markdown
Contributor

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.

Comment thread commands/run.go Outdated
"github.com/percona/pmm-agent/versioner"
)

const COUNT_SERVER_LOGS = 500

Copy link
Copy Markdown
Contributor

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)

Comment thread 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

Copy link
Copy Markdown
Contributor

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)

Comment thread 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

Copy link
Copy Markdown
Contributor

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)

Comment thread 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

Copy link
Copy Markdown
Contributor

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)

Copy link
Copy Markdown
Contributor

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

Comment thread agents/supervisor/supervisor.go Outdated
res := make(map[string][]string)

for id, agent := range s.agentProcesses {
newId := strings.ReplaceAll(id, "/agent_id/", "")

Copy link
Copy Markdown
Contributor

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)

Comment thread agents/supervisor/supervisor.go Outdated
}

for id, agent := range s.builtinAgents {
newId := strings.ReplaceAll(id, "/agent_id/", "")

Copy link
Copy Markdown
Contributor

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)

@qwest812
qwest812 requested a review from BupycHuk May 11, 2022 08:54

@BupycHuk BupycHuk left a comment

Copy link
Copy Markdown
Contributor

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

Comment thread agentlocal/agent_local.go Outdated

// NewServer creates new server.
//
//`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's revert

Comment thread 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) {

Copy link
Copy Markdown
Contributor

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?

Comment thread 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

Copy link
Copy Markdown
Contributor

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

Comment thread 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

Copy link
Copy Markdown
Contributor

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

Comment thread agentlocal/agent_local.go
_ agentlocalpb.AgentLocalServer = (*Server)(nil)
)

func (s *Server) Zip(w http.ResponseWriter, r *http.Request) {

Copy link
Copy Markdown
Contributor

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) {

Copy link
Copy Markdown
Contributor

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) {

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

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)

Copy link
Copy Markdown
Contributor

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:
image

The failure message is impossible to understand, because it is a diff between two binary files

@ritbl ritbl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please see my comment

@qwest812
qwest812 requested a review from BupycHuk May 30, 2022 19:10
Comment thread agentlocal/agent_local.go Outdated
Comment on lines +71 to +76
//

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's revert it.

Comment thread agentlocal/agent_local.go Outdated
log.Fatal(err)
}
}
addData(writer, "server.txt", b.Bytes())

Copy link
Copy Markdown
Contributor

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.

Suggested change
addData(writer, "server.txt", b.Bytes())
addData(writer, "http-server.txt", b.Bytes())

Comment thread 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()

Copy link
Copy Markdown
Contributor

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.

@qwest812
qwest812 requested a review from ritbl June 1, 2022 12:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants