PMM-4648 Rotate slowlog. - #116
Conversation
| name = "github.com/percona/pmm" | ||
| branch = "PMM-2.0" | ||
| #branch = "PMM-2.0" | ||
| branch = "PMM-4437-flush-slowlogs" |
| import agentpb "github.com/percona/pmm/api/agentpb" | ||
| import mock "github.com/stretchr/testify/mock" | ||
| import prometheus "github.com/prometheus/client_golang/prometheus" | ||
| import time "time" |
There was a problem hiding this comment.
Please run make init before make gen.
| dsn string | ||
| agentID string | ||
| slowLogFilePrefix string | ||
| sizeSlowLogs uint32 |
There was a problem hiding this comment.
int64 to drop conversions below.
| return errors.Wrap(err, "cannot rename slow log") | ||
| } | ||
|
|
||
| _, err = db.ExecContext(ctx, fmt.Sprintf("SET GLOBAL /* %s */ slow_query_log=on", queryTag)) //nolint:gosec |
There was a problem hiding this comment.
We should do it in defer. If we need to that at all. @rnovikovP
There was a problem hiding this comment.
This looks like modification in the Global setting. we are trying to avoid this
| return errors.Wrap(err, "cannot flush logs") | ||
| } | ||
|
|
||
| err = os.Rename(slowLogPath, slowLogPath+".old") |
There was a problem hiding this comment.
We should remove it, not rename. ContinuousFileReader will still be able to read removed file.
There was a problem hiding this comment.
We should also remove it before FLUSH LOGS. That the whole point of that SQL command.
| } else { | ||
| // get the size of slowlog | ||
| currSizeSlowLog := fi.Size() | ||
| if currSizeSlowLog > int64(s.sizeSlowLogs) { |
There was a problem hiding this comment.
We should skip the whole block if sizeSlowLogs <=0
|
|
||
| // makeBuckets is a pure function for easier testing. | ||
| func makeBuckets(agentID string, res event.Result, periodStart time.Time, periodLengthSecs uint32) []*agentpb.MetricsBucket { | ||
| func makeBuckets(agentID string, res event.Result, periodStart time.Time, periodLengthSecs uint32, disableQueryExamples bool) []*agentpb.MetricsBucket { |
There was a problem hiding this comment.
cyclomatic complexity 38 of func makeBuckets is high (> 30) (from gocyclo)
Codecov Report
@@ Coverage Diff @@
## master #116 +/- ##
==========================================
- Coverage 65.9% 65.39% -0.52%
==========================================
Files 53 53
Lines 5371 5418 +47
==========================================
+ Hits 3540 3543 +3
- Misses 1628 1665 +37
- Partials 203 210 +7
Continue to review full report at Codecov.
|
* PMM-6213 Remove go 1.13 from travis. * PMM-6213 Add go 1.15.x * PMM-6213 Add go tip.
https://jira.percona.com/browse/PMM-4459
https://jira.percona.com/browse/PMM-4437
depends on:
percona/pmm-admin#59
percona/pmm-managed#264
percona/qan-app#322
FB:
Percona-Lab/pmm-submodules#444
usage ex.:
pmm-admin add mysql --username=root --password=secret ps:3306 MySQLSlowLog --size-slow-logs=10MB