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

PMM-5680 store logs #342

Open
wants to merge 70 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
167cbf3
Pmm-5680 store logs
qwest812 Mar 20, 2022
29764cc
Pmm-5680 store logs
qwest812 Mar 23, 2022
c8d2f68
Merge branch 'main' into PMM-5680-store-logs
qwest812 Mar 26, 2022
b673eaa
Pmm-5680 store logs
qwest812 Mar 27, 2022
9eda60e
Pmm-5680 store logs
qwest812 Mar 27, 2022
a6faa0b
Pmm-5680 store logs
qwest812 Apr 2, 2022
6f61509
Pmm-5680 store logs
qwest812 Apr 2, 2022
20a3ee2
Pmm-5680 store logs
qwest812 Apr 2, 2022
229845d
Pmm-5680 save logs process Done
qwest812 Apr 2, 2022
9161345
Pmm-5680 save logs process
qwest812 Apr 6, 2022
aa77af2
Pmm-5680 change dependency
qwest812 Apr 14, 2022
c6281e4
Merge branch 'main' into PMM-5680-store-logs
qwest812 Apr 14, 2022
5163ca9
Pmm-5680 update dependency
qwest812 Apr 14, 2022
e35cbc4
Pmm-5680 add mutex
qwest812 Apr 14, 2022
89a98da
Pmm-5680 fix tests
qwest812 Apr 14, 2022
989bb4f
Pmm-5680 fix tests
qwest812 Apr 14, 2022
9169b92
Pmm-5680 fix tests
qwest812 Apr 14, 2022
8562fbc
Pmm-5680 fix tests
qwest812 Apr 14, 2022
f0b2d6a
Pmm-5680 change process_child.go
qwest812 Apr 14, 2022
7a4863a
Pmm-5680 fix process_child.go
qwest812 Apr 14, 2022
c20a64c
Pmm-5680 fix mysql_show_table_status_action_test.go
qwest812 Apr 14, 2022
f2d3a40
Pmm-5680 gen
qwest812 Apr 14, 2022
50ebcaf
Pmm-5680 fix
qwest812 Apr 14, 2022
a0a6d44
Pmm-5680 update dependency
qwest812 Apr 14, 2022
a4bffaf
Pmm-5680 change name for logs
qwest812 Apr 14, 2022
fb64846
Pmm-5680 fix git actions
qwest812 Apr 15, 2022
fdc9f1a
Pmm-5680 fix git actions
qwest812 Apr 15, 2022
60dc79d
Pmm-5680 fix test
qwest812 Apr 15, 2022
8312f49
Pmm-5680 fix test
qwest812 Apr 15, 2022
3daddce
Pmm-5680 fix test
qwest812 Apr 15, 2022
dfc1597
Pmm-5680 fix lint
qwest812 Apr 16, 2022
cd38bd3
PMM-5680 Improvements
BupycHuk Apr 20, 2022
9ff8dc0
PMM-5680 Improvements
BupycHuk Apr 20, 2022
221a0b9
Pmm-5680 update storelogs
qwest812 Apr 20, 2022
729e3f1
Pmm-5680 remove function countLogs
qwest812 Apr 21, 2022
b24f6b5
Merge branch 'main' into PMM-5680-store-logs
qwest812 Apr 26, 2022
cb9c6b1
Merge branch 'PMM-5680-code-improvement-suggestions' into PMM-5680-st…
qwest812 Apr 26, 2022
7bd784b
Pmm-85680 update dependency
qwest812 Apr 27, 2022
b873ecc
Merge branch 'main' into PMM-5680-store-logs
qwest812 May 2, 2022
c53f291
Pmm-5680 response zipfile
qwest812 May 2, 2022
847932f
Pmm-5680 response zipfile
qwest812 May 2, 2022
77c8c83
Pmm-5680 fix mistake
qwest812 May 3, 2022
c686b5e
Pmm-5680 fix test
qwest812 May 3, 2022
c0bb005
Pmm-5680 fix test
qwest812 May 3, 2022
a709904
Pmm-5680 fix test
qwest812 May 3, 2022
e1da1ac
Pmm-5680 pretty
qwest812 May 3, 2022
5202e83
Pmm-5680 fix bug
qwest812 May 3, 2022
e44958a
Pmm-5680 fix bugs
qwest812 May 4, 2022
1657e70
Pmm-5680 change JSON to text
qwest812 May 9, 2022
c18be41
Pmm-5680 revert test
qwest812 May 9, 2022
1d77203
Pmm-5680 store serve logs
qwest812 May 9, 2022
c4151d3
Merge branch 'main' into PMM-5680-store-logs
qwest812 May 10, 2022
858e68c
Pmm-5680 store serve logs
qwest812 May 10, 2022
611c10e
Pmm-5680 fix test
qwest812 May 10, 2022
49cc0e6
Pmm-5680 remove struct AgentLogs
qwest812 May 10, 2022
60a0db6
Pmm-5680 remove id from map key
qwest812 May 10, 2022
ed5a7ce
Pmm-5680 set const number logs
qwest812 May 10, 2022
9d688bb
Pmm-5680 change function AgentsLogs
qwest812 May 10, 2022
545883a
Pmm-5680 remove comment
qwest812 May 11, 2022
96f10b0
Pmm-5680 fix linn err
qwest812 May 11, 2022
9880641
Pmm-5680 add small changes
qwest812 May 11, 2022
60e10a4
Pmm-5680 create test
qwest812 May 16, 2022
a0b10af
Pmm-5680 фвв еуые яшз ашду
qwest812 May 19, 2022
729bc50
Merge branch 'main' into PMM-5680-store-logs
qwest812 May 19, 2022
ecbac3d
Pmm-5680 make gen
qwest812 May 19, 2022
592965b
Pmm-5680 fix test
qwest812 May 20, 2022
f379d59
Pmm-5680 fix test
qwest812 May 25, 2022
29028f2
Pmm-5680 fix test
qwest812 May 25, 2022
f43cd91
Pmm-5680 fix test
qwest812 May 25, 2022
796c46d
pmm-5680 little changes
qwest812 Jun 1, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions agentlocal/agent_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ type Server struct {
reloadCloseOnce sync.Once
}

func (s *Server) mustEmbedUnimplementedAgentLocalServer() {
Copy link
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

//TODO implement me
panic("implement me")
}

// NewServer creates new server.
//
// Caller should call Run.
Expand Down
39 changes: 19 additions & 20 deletions agents/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ package process
import (
"context"
"fmt"
"github.com/percona/pmm-agent/storelogs"
"os/exec"
"strings"
"time"

"github.com/percona/pmm/api/inventorypb"
"github.com/percona/pmm/utils/pdeathsig"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"

"github.com/percona/pmm-agent/utils/backoff"
Expand Down Expand Up @@ -55,12 +55,11 @@ const (
// only to avoid stack overflow; there are no extra goroutines for states.
type Process struct {
params *Params
l *logrus.Entry
pl *processLogger
changes chan inventorypb.AgentStatus
backoff *backoff.Backoff
ctxDone chan struct{}

logs *storelogs.LogsStore
// recreated on each restart
cmd *exec.Cmd
cmdDone chan struct{}
Expand All @@ -87,14 +86,14 @@ func (p *Params) String() string {
}

// New creates new process.
func New(params *Params, redactWords []string, l *logrus.Entry) *Process {
func New(params *Params, redactWords []string, sl *storelogs.LogsStore) *Process {
return &Process{
params: params,
l: l,
pl: newProcessLogger(l, keepLogLines, redactWords),
pl: newProcessLogger(sl.Entry, keepLogLines, redactWords),
changes: make(chan inventorypb.AgentStatus, 10),
backoff: backoff.New(backoffMinDelay, backoffMaxDelay),
ctxDone: make(chan struct{}),
logs: sl,
}
}

Expand All @@ -103,14 +102,14 @@ func (p *Process) Run(ctx context.Context) {
go p.toStarting()

<-ctx.Done()
p.l.Infof("Process: context canceled.")
p.logs.Infof("Process: context canceled.")
close(p.ctxDone)
}

// STARTING -> RUNNING
// STARTING -> WAITING
func (p *Process) toStarting() {
p.l.Tracef("Process: starting.")
p.logs.Tracef("Process: starting.")
p.changes <- inventorypb.AgentStatus_STARTING

p.cmd = exec.Command(p.params.Path, p.params.Args...) //nolint:gosec
Expand All @@ -128,7 +127,7 @@ func (p *Process) toStarting() {
p.cmdDone = make(chan struct{})

if err := p.cmd.Start(); err != nil {
p.l.Warnf("Process: failed to start: %s.", err)
p.logs.Warnf("Process: failed to start: %s.", err)
go p.toWaiting()
return
}
Expand All @@ -145,15 +144,15 @@ func (p *Process) toStarting() {
case <-t.C:
go p.toRunning()
case <-p.cmdDone:
p.l.Warnf("Process: exited early: %s.", p.cmd.ProcessState)
p.logs.Warnf("Process: exited early: %s.", p.cmd.ProcessState)
go p.toWaiting()
}
}

// RUNNING -> STOPPING
// RUNNING -> WAITING
func (p *Process) toRunning() {
p.l.Tracef("Process: running.")
p.logs.Tracef("Process: running.")
p.changes <- inventorypb.AgentStatus_RUNNING

p.backoff.Reset()
Expand All @@ -162,7 +161,7 @@ func (p *Process) toRunning() {
case <-p.ctxDone:
go p.toStopping()
case <-p.cmdDone:
p.l.Warnf("Process: exited: %s.", p.cmd.ProcessState)
p.logs.Warnf("Process: exited: %s.", p.cmd.ProcessState)
go p.toWaiting()
}
}
Expand All @@ -172,7 +171,7 @@ func (p *Process) toRunning() {
func (p *Process) toWaiting() {
delay := p.backoff.Delay()

p.l.Infof("Process: waiting %s.", delay)
p.logs.Infof("Process: waiting %s.", delay)
p.changes <- inventorypb.AgentStatus_WAITING

t := time.NewTimer(delay)
Expand All @@ -183,7 +182,7 @@ func (p *Process) toWaiting() {
if p.params.Type == inventorypb.AgentType_VM_AGENT {
_, err := p.params.TemplateRenderer.RenderFiles(p.params.TemplateParams)
if err != nil {
p.l.Warnf("Process: failed to regenerate config in %s.", p.params.TemplateRenderer.TempDir)
p.logs.Warnf("Process: failed to regenerate config in %s.", p.params.TemplateRenderer.TempDir)
}
}

Expand All @@ -195,11 +194,11 @@ func (p *Process) toWaiting() {

// STOPPING -> DONE
func (p *Process) toStopping() {
p.l.Tracef("Process: stopping (sending SIGTERM)...")
p.logs.Tracef("Process: stopping (sending SIGTERM)...")
p.changes <- inventorypb.AgentStatus_STOPPING

if err := p.cmd.Process.Signal(unix.SIGTERM); err != nil {
p.l.Errorf("Process: failed to send SIGTERM: %s.", err)
p.logs.Errorf("Process: failed to send SIGTERM: %s.", err)
}

t := time.NewTimer(killT)
Expand All @@ -208,19 +207,19 @@ func (p *Process) toStopping() {
case <-p.cmdDone:
// nothing
case <-t.C:
p.l.Warnf("Process: still alive after %s, sending SIGKILL...", killT)
p.logs.Warnf("Process: still alive after %s, sending SIGKILL...", killT)
if err := p.cmd.Process.Signal(unix.SIGKILL); err != nil {
p.l.Errorf("Process: failed to send SIGKILL: %s.", err)
p.logs.Errorf("Process: failed to send SIGKILL: %s.", err)
}
<-p.cmdDone
}

p.l.Infof("Process: exited: %s.", p.cmd.ProcessState)
p.logs.Infof("Process: exited: %s.", p.cmd.ProcessState)
go p.toDone()
}

func (p *Process) toDone() {
p.l.Trace("Process: done.")
p.logs.Trace("Process: done.")
p.changes <- inventorypb.AgentStatus_DONE

close(p.changes)
Expand Down
3 changes: 2 additions & 1 deletion agents/process/process_child.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ func main() {
logger := logrus.New()
logger.SetOutput(ioutil.Discard)
l := logrus.NewEntry(logger)
ringLogs := ring.New(30)

p := process.New(&process.Params{Path: "sleep", Args: []string{"100500"}}, nil, l)
p := process.New(&process.Params{Path: "sleep", Args: []string{"100500"}}, nil, l, ringLogs)
go p.Run(context.Background())

// Wait until the process is running.
Expand Down
10 changes: 8 additions & 2 deletions agents/supervisor/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package supervisor
import (
"context"
"fmt"
"github.com/percona/pmm-agent/storelogs"
"path/filepath"
"regexp"
"runtime/pprof"
Expand Down Expand Up @@ -70,6 +71,7 @@ type agentProcessInfo struct {
done <-chan struct{} // closes when Process.Changes() channel closes
requestedState *agentpb.SetStateRequest_AgentProcess
listenPort uint16
logs *storelogs.LogsStore //store logs
}

// builtinAgentInfo describes built-in Agent.
Expand Down Expand Up @@ -119,11 +121,13 @@ func (s *Supervisor) AgentsList() []*agentlocalpb.AgentInfo {
res := make([]*agentlocalpb.AgentInfo, 0, len(s.agentProcesses)+len(s.builtinAgents))

for id, agent := range s.agentProcesses {
logs := agent.logs.GetLogs()
Copy link
Member

Choose a reason for hiding this comment

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

in scope of this task we don't have requirement to split logs per agent, but ok.
QAN(bultin) agents logs are missed

Copy link
Member

Choose a reason for hiding this comment

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

I'm surprised why it was made this way, although there was suggested implementation with a separate endpoint for logs. This implementation doesn't include all pmm-agent related logs(like logs related to connection to pmm-managed).

info := &agentlocalpb.AgentInfo{
AgentId: id,
AgentType: agent.requestedState.Type,
Status: s.lastStatuses[id],
ListenPort: uint32(agent.listenPort),
Logs: logs,
}
res = append(res, info)
}
Expand Down Expand Up @@ -345,8 +349,9 @@ func (s *Supervisor) startProcess(agentID string, agentProcess *agentpb.SetState
"type": agentType,
})
l.Debugf("Starting: %s.", processParams)

process := process.New(processParams, agentProcess.RedactWords, l)
ringLog := new(storelogs.LogsStore)
ringLog.SetUp(l)
process := process.New(processParams, agentProcess.RedactWords, ringLog)
go pprof.Do(ctx, pprof.Labels("agentID", agentID, "type", agentType), process.Run)

done := make(chan struct{})
Expand All @@ -368,6 +373,7 @@ func (s *Supervisor) startProcess(agentID string, agentProcess *agentpb.SetState
done: done,
requestedState: proto.Clone(agentProcess).(*agentpb.SetStateRequest_AgentProcess),
listenPort: port,
logs: ringLog,
}
return nil
}
Expand Down
34 changes: 16 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,28 @@ require (
github.com/davecgh/go-spew v1.1.1
github.com/go-openapi/runtime v0.19.20
github.com/go-sql-driver/mysql v1.5.0
github.com/golang/protobuf v1.4.3
github.com/grpc-ecosystem/grpc-gateway v1.15.1
github.com/golang/protobuf v1.5.2
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/hashicorp/go-version v1.3.0
github.com/lfittl/pg_query_go v1.0.2
github.com/lib/pq v1.10.0
github.com/percona/exporter_shared v0.7.3
github.com/percona/go-mysql v0.0.0-20200630114833-b77f37c0bfa2
github.com/percona/percona-toolkit v3.2.1+incompatible
github.com/percona/pmm v0.0.0-20220310104949-dd33560bcdde
github.com/percona/pmm v0.0.0-20220402125834-c15e36d4238d
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.5.1
github.com/prometheus/common v0.10.0
github.com/prometheus/client_golang v1.12.1
github.com/prometheus/common v0.32.1
github.com/sirupsen/logrus v1.6.0
github.com/stretchr/objx v0.2.0
github.com/stretchr/testify v1.6.1
github.com/stretchr/testify v1.7.1
go.mongodb.org/mongo-driver v1.7.1
golang.org/x/sys v0.0.0-20200724161237-0e2f3a69832c
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013
google.golang.org/grpc v1.32.0
google.golang.org/protobuf v1.25.0
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9
google.golang.org/genproto v0.0.0-20220302033224-9aa15565e42a
google.golang.org/grpc v1.45.0
google.golang.org/protobuf v1.27.1
gopkg.in/alecthomas/kingpin.v2 v2.2.6
gopkg.in/reform.v1 v1.5.0
gopkg.in/reform.v1 v1.5.1
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
)

Expand All @@ -50,7 +50,7 @@ require (
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/go-openapi/analysis v0.19.10 // indirect
github.com/go-openapi/errors v0.19.6 // indirect
github.com/go-openapi/jsonpointer v0.19.3 // indirect
Expand All @@ -63,7 +63,6 @@ require (
github.com/go-stack/stack v1.8.0 // indirect
github.com/gogo/protobuf v1.3.1 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/klauspost/compress v1.9.5 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect
github.com/mailru/easyjson v0.7.1 // indirect
Expand All @@ -73,15 +72,14 @@ require (
github.com/mwitkow/go-proto-validators v0.3.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/procfs v0.5.0 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.0.2 // indirect
github.com/xdg-go/stringprep v1.0.2 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
golang.org/x/net v0.0.0-20200707034311-ab3426394381 // indirect
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a // indirect
golang.org/x/text v0.3.5 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
Loading