Skip to content

Commit

Permalink
Merge branch 'v3-api-breaking-changes' into PMM-13020-drop-identifier…
Browse files Browse the repository at this point in the history
  • Loading branch information
ademidoff committed Jun 6, 2024
2 parents ef43b74 + 483ba4d commit 41d36cd
Show file tree
Hide file tree
Showing 156 changed files with 13,439 additions and 4,717 deletions.
19 changes: 9 additions & 10 deletions .github/workflows/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,18 @@ jobs:
run: make test-cover

- name: Upload coverage results
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
file: cover.out
flags: admin
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}

- name: Run debug commands on failure
if: ${{ failure() }}
run: |
env
go version
go env
pwd
env | sort
go env | sort
git status
cli-test:
Expand Down Expand Up @@ -160,9 +159,9 @@ jobs:
- name: Run debug commands on failure
if: ${{ failure() }}
run: |
env
go version
go env
node --version
pwd
env | sort
go env | sort
git status
node --version
npx --version
npx playwright --version
3 changes: 2 additions & 1 deletion .github/workflows/agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,13 @@ jobs:
run: make test-cover

- name: Upload coverage results
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
file: cover.out
flags: agent
env_vars: MYSQL_IMAGE,MONGO_IMAGE,POSTGRES_IMAGE,PMM_SERVER_IMAGE
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}

- name: Run debug commands on failure
if: ${{ failure() }}
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/api-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,8 @@ jobs:
container_name: pmm-agent_pmm-server
environment:
- PMM_DEBUG=1
- PERCONA_TEST_CHECKS_INTERVAL=10s
- PERCONA_TEST_PLATFORM_ADDRESS=https://check-dev.percona.com
- PERCONA_TEST_PLATFORM_PUBLIC_KEY=RWTg+ZmCCjt7O8eWeAmTLAqW+1ozUbpRSKSwNTmO+exlS5KEIPYWuYdX
- PMM_DEV_PERCONA_PLATFORM_ADDRESS=https://check-dev.percona.com
- PMM_DEV_PERCONA_PLATFORM_PUBLIC_KEY=RWTg+ZmCCjt7O8eWeAmTLAqW+1ozUbpRSKSwNTmO+exlS5KEIPYWuYdX
ports:
- 80:8080
- 443:8443
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/clean.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
go:
- version: 1.21.x
- version: 1.22.x
may-fail: false
- version: tip
may-fail: true
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/managed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jobs:
PMM_SERVER_IMAGE: perconalab/pmm-server:3-dev-latest
AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }}
AWS_SECRET_KEY: ${{ secrets.AWS_SECRET_KEY }}
OAUTH_PMM_CLIENT_ID: ${{ secrets.OAUTH_PMM_CLIENT_ID }}
OAUTH_PMM_CLIENT_SECRET: ${{ secrets.OAUTH_PMM_CLIENT_SECRET }}
PMM_DEV_OAUTH_CLIENT_ID: ${{ secrets.OAUTH_PMM_CLIENT_ID }}
PMM_DEV_OAUTH_CLIENT_SECRET: ${{ secrets.OAUTH_PMM_CLIENT_SECRET }}
DEVCONTAINER_CACHE_ENABLED: false

steps:
Expand Down Expand Up @@ -99,12 +99,13 @@ jobs:
# docker exec -i pmm-server make -C managed test-update
- name: Upload coverage results
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
file: managed/cover.out
flags: managed
env_vars: PMM_SERVER_IMAGE
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}

- name: Cache
if: ${{ fromJSON(env.DEVCONTAINER_CACHE_ENABLED) }}
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ jobs:
run: docker exec pmm-update-server make -C /root/go/src/github.com/percona/pmm/update run-race-cover RUN_FLAGS='-debug -check'

- name: Upload coverage results
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
file: cover.out
flags: update
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}

9 changes: 4 additions & 5 deletions .github/workflows/vmproxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,16 @@ jobs:
run: make test-cover

- name: Upload coverage results
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
file: cover.out
flags: vmproxy
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}

- name: Run debug commands on failure
if: ${{ failure() }}
run: |
env
go version
go env
pwd
env | sort
go env | sort
git status
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This Dockerfile is used only for API tests.

FROM golang:1.21
FROM golang:1.22

RUN export GOPATH=$(go env GOPATH) && \
mkdir -p $GOPATH/src/github.com/percona/pmm
Expand Down
4 changes: 3 additions & 1 deletion agent/agents/mongodb/internal/profiler/profiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ func testProfiler(t *testing.T, url string) {
Query: findBucket.Common.Example,
}

ex := actions.NewMongoDBExplainAction(id, 5*time.Second, params, os.TempDir())
ex, err := actions.NewMongoDBExplainAction(id, 5*time.Second, params, os.TempDir())
require.NoError(t, err)

ctx, cancel := context.WithTimeout(context.Background(), ex.Timeout())
defer cancel()
res, err := ex.Run(ctx)
Expand Down
2 changes: 1 addition & 1 deletion agent/agents/mysql/perfschema/perfschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func getPerfschemaHistorySize(q reform.Querier, l *logrus.Entry) uint {
// New creates new PerfSchema QAN service.
func New(params *Params, l *logrus.Entry) (*PerfSchema, error) {
if params.TextFiles != nil {
err := tlshelpers.RegisterMySQLCerts(params.TextFiles.Files)
err := tlshelpers.RegisterMySQLCerts(params.TextFiles.Files, params.TLSSkipVerify)
if err != nil {
return nil, err
}
Expand Down
18 changes: 16 additions & 2 deletions agent/agents/mysql/slowlog/slowlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ package slowlog

import (
"context"
"crypto/md5" //nolint:gosec
"database/sql"
"encoding/hex"
"fmt"
"io"
"math"
Expand Down Expand Up @@ -82,7 +84,7 @@ type slowLogInfo struct {
// New creates new SlowLog QAN service.
func New(params *Params, l *logrus.Entry) (*SlowLog, error) {
if params.TextFiles != nil {
err := tlshelpers.RegisterMySQLCerts(params.TextFiles.Files)
err := tlshelpers.RegisterMySQLCerts(params.TextFiles.Files, params.TLSSkipVerify)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -370,7 +372,7 @@ func (s *SlowLog) processFile(ctx context.Context, file string, outlierTime floa

s.l.Tracef("Parsed slowlog event: %+v.", e)
fingerprint := query.Fingerprint(e.Query)
digest := query.Id(fingerprint)
digest := hashIntoQueryID(fingerprint)
aggregator.AddEvent(e, digest, e.User, e.Host, e.Db, e.Server, e.Query)

case <-t.C:
Expand All @@ -391,6 +393,18 @@ func (s *SlowLog) processFile(ctx context.Context, file string, outlierTime floa
}
}

// hashIntoQueryID returns slowlog query ID hashed by MD5 from given fingerprint.
func hashIntoQueryID(fingerprint string) string {
// MD5 is used only to hash fingerprint into query ID, so there is no risk.
// It is ideal due to its length (32 chars) and it corresponds to Perfschema query ID length.
id := md5.New() //nolint:gosec
_, err := io.WriteString(id, fingerprint)
if err != nil {
logrus.Debugf("cannot hash fingerprint into query ID: %s", err.Error())
}
return strings.ToUpper(hex.EncodeToString(id.Sum(nil)))
}

// makeBuckets is a pure function for easier testing.
//
//nolint:cyclop,maintidx
Expand Down
31 changes: 18 additions & 13 deletions agent/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,10 @@ func (c *Client) handleStartActionRequest(p *agentv1.StartActionRequest) error {

cfg := c.cfg.Get()
var action actions.Action
var err error
switch params := p.Params.(type) {
case *agentv1.StartActionRequest_MysqlExplainParams:
action = actions.NewMySQLExplainAction(p.ActionId, timeout, params.MysqlExplainParams)
action, err = actions.NewMySQLExplainAction(p.ActionId, timeout, params.MysqlExplainParams)

case *agentv1.StartActionRequest_MysqlShowCreateTableParams:
action = actions.NewMySQLShowCreateTableAction(p.ActionId, timeout, params.MysqlShowCreateTableParams)
Expand All @@ -468,13 +469,13 @@ func (c *Client) handleStartActionRequest(p *agentv1.StartActionRequest) error {
action = actions.NewMySQLShowIndexAction(p.ActionId, timeout, params.MysqlShowIndexParams)

case *agentv1.StartActionRequest_PostgresqlShowCreateTableParams:
action = actions.NewPostgreSQLShowCreateTableAction(p.ActionId, timeout, params.PostgresqlShowCreateTableParams, cfg.Paths.TempDir)
action, err = actions.NewPostgreSQLShowCreateTableAction(p.ActionId, timeout, params.PostgresqlShowCreateTableParams, cfg.Paths.TempDir)

case *agentv1.StartActionRequest_PostgresqlShowIndexParams:
action = actions.NewPostgreSQLShowIndexAction(p.ActionId, timeout, params.PostgresqlShowIndexParams, cfg.Paths.TempDir)
action, err = actions.NewPostgreSQLShowIndexAction(p.ActionId, timeout, params.PostgresqlShowIndexParams, cfg.Paths.TempDir)

case *agentv1.StartActionRequest_MongodbExplainParams:
action = actions.NewMongoDBExplainAction(p.ActionId, timeout, params.MongodbExplainParams, cfg.Paths.TempDir)
action, err = actions.NewMongoDBExplainAction(p.ActionId, timeout, params.MongodbExplainParams, cfg.Paths.TempDir)

case *agentv1.StartActionRequest_MysqlQueryShowParams:
action = actions.NewMySQLQueryShowAction(p.ActionId, timeout, params.MysqlQueryShowParams)
Expand All @@ -483,13 +484,13 @@ func (c *Client) handleStartActionRequest(p *agentv1.StartActionRequest) error {
action = actions.NewMySQLQuerySelectAction(p.ActionId, timeout, params.MysqlQuerySelectParams)

case *agentv1.StartActionRequest_PostgresqlQueryShowParams:
action = actions.NewPostgreSQLQueryShowAction(p.ActionId, timeout, params.PostgresqlQueryShowParams, cfg.Paths.TempDir)
action, err = actions.NewPostgreSQLQueryShowAction(p.ActionId, timeout, params.PostgresqlQueryShowParams, cfg.Paths.TempDir)

case *agentv1.StartActionRequest_PostgresqlQuerySelectParams:
action = actions.NewPostgreSQLQuerySelectAction(p.ActionId, timeout, params.PostgresqlQuerySelectParams, cfg.Paths.TempDir)
action, err = actions.NewPostgreSQLQuerySelectAction(p.ActionId, timeout, params.PostgresqlQuerySelectParams, cfg.Paths.TempDir)

case *agentv1.StartActionRequest_MongodbQueryGetparameterParams:
action = actions.NewMongoDBQueryAdmincommandAction(
action, err = actions.NewMongoDBQueryAdmincommandAction(
p.ActionId,
timeout,
params.MongodbQueryGetparameterParams.Dsn,
Expand All @@ -499,7 +500,7 @@ func (c *Client) handleStartActionRequest(p *agentv1.StartActionRequest) error {
cfg.Paths.TempDir)

case *agentv1.StartActionRequest_MongodbQueryBuildinfoParams:
action = actions.NewMongoDBQueryAdmincommandAction(
action, err = actions.NewMongoDBQueryAdmincommandAction(
p.ActionId,
timeout,
params.MongodbQueryBuildinfoParams.Dsn,
Expand All @@ -509,7 +510,7 @@ func (c *Client) handleStartActionRequest(p *agentv1.StartActionRequest) error {
cfg.Paths.TempDir)

case *agentv1.StartActionRequest_MongodbQueryGetcmdlineoptsParams:
action = actions.NewMongoDBQueryAdmincommandAction(
action, err = actions.NewMongoDBQueryAdmincommandAction(
p.ActionId,
timeout,
params.MongodbQueryGetcmdlineoptsParams.Dsn,
Expand All @@ -519,7 +520,7 @@ func (c *Client) handleStartActionRequest(p *agentv1.StartActionRequest) error {
cfg.Paths.TempDir)

case *agentv1.StartActionRequest_MongodbQueryReplsetgetstatusParams:
action = actions.NewMongoDBQueryAdmincommandAction(
action, err = actions.NewMongoDBQueryAdmincommandAction(
p.ActionId,
timeout,
params.MongodbQueryReplsetgetstatusParams.Dsn,
Expand All @@ -529,7 +530,7 @@ func (c *Client) handleStartActionRequest(p *agentv1.StartActionRequest) error {
cfg.Paths.TempDir)

case *agentv1.StartActionRequest_MongodbQueryGetdiagnosticdataParams:
action = actions.NewMongoDBQueryAdmincommandAction(
action, err = actions.NewMongoDBQueryAdmincommandAction(
p.ActionId,
timeout,
params.MongodbQueryGetdiagnosticdataParams.Dsn,
Expand Down Expand Up @@ -565,6 +566,10 @@ func (c *Client) handleStartActionRequest(p *agentv1.StartActionRequest) error {
return errors.Wrapf(agenterrors.ErrInvalidArgument, "invalid action type request: %T", params)
}

if err != nil {
return errors.Wrap(err, "failed to create action")
}

return c.runner.StartAction(action)
}

Expand Down Expand Up @@ -645,7 +650,7 @@ func (c *Client) handleStartJobRequest(p *agentv1.StartJobRequest) error {
return errors.WithStack(err)
}

job, err = jobs.NewMongoDBBackupJob(p.JobId, timeout, j.MongodbBackup.Name, &dsn, locationConfig,
job, err = jobs.NewMongoDBBackupJob(p.JobId, timeout, j.MongodbBackup.Name, dsn, locationConfig,
j.MongodbBackup.EnablePitr, j.MongodbBackup.DataModel, j.MongodbBackup.Folder)
if err != nil {
return err
Expand Down Expand Up @@ -678,7 +683,7 @@ func (c *Client) handleStartJobRequest(p *agentv1.StartJobRequest) error {
}

job = jobs.NewMongoDBRestoreJob(p.JobId, timeout, j.MongodbRestoreBackup.Name,
j.MongodbRestoreBackup.PitrTimestamp.AsTime(), &dsn, locationConfig,
j.MongodbRestoreBackup.PitrTimestamp.AsTime(), dsn, locationConfig,
c.supervisor, j.MongodbRestoreBackup.Folder, j.MongodbRestoreBackup.PbmMetadata.Name)
default:
return errors.Errorf("unknown job type: %T", j)
Expand Down
4 changes: 2 additions & 2 deletions agent/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func TestClient(t *testing.T) {
s.On("AgentsList").Return([]*agentlocal.AgentInfo{})
s.On("ClearChangesChannel").Return()

r := runner.New(cfgStorage.Get().RunnerCapacity)
r := runner.New(cfgStorage.Get().RunnerCapacity, cfgStorage.Get().RunnerMaxConnectionsPerService)
client := New(cfgStorage, &s, r, nil, nil, nil, connectionuptime.NewService(time.Hour), nil)
err := client.Run(context.Background())
assert.NoError(t, err)
Expand Down Expand Up @@ -281,7 +281,7 @@ func TestUnexpectedActionType(t *testing.T) {
s.On("AgentsList").Return([]*agentlocal.AgentInfo{})
s.On("ClearChangesChannel").Return()

r := runner.New(cfgStorage.Get().RunnerCapacity)
r := runner.New(cfgStorage.Get().RunnerCapacity, cfgStorage.Get().RunnerMaxConnectionsPerService)
client := New(cfgStorage, s, r, nil, nil, nil, connectionuptime.NewService(time.Hour), nil)
err := client.Run(context.Background())
assert.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion agent/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func Run() {
supervisor := supervisor.NewSupervisor(ctx, v, configStorage)
connectionChecker := connectionchecker.New(configStorage)
serviceInfoBroker := serviceinfobroker.New(configStorage)
r := runner.New(cfg.RunnerCapacity)
r := runner.New(cfg.RunnerCapacity, cfg.RunnerMaxConnectionsPerService)
client := client.New(configStorage, supervisor, r, connectionChecker, v, serviceInfoBroker, prepareConnectionService(ctx, cfg), logStore)
localServer := agentlocal.NewServer(configStorage, supervisor, client, configFilepath, logStore)

Expand Down
11 changes: 7 additions & 4 deletions agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,11 @@ type Setup struct {
type Config struct { //nolint:musttag
// no config file there

ID string `yaml:"id"`
ListenAddress string `yaml:"listen-address"`
ListenPort uint16 `yaml:"listen-port"`
RunnerCapacity uint16 `yaml:"runner-capacity,omitempty"`
ID string `yaml:"id"`
ListenAddress string `yaml:"listen-address"`
ListenPort uint16 `yaml:"listen-port"`
RunnerCapacity uint16 `yaml:"runner-capacity,omitempty"`
RunnerMaxConnectionsPerService uint16 `yaml:"runner-max-connections-per-service,omitempty"`

Server Server `yaml:"server"`
Paths Paths `yaml:"paths"`
Expand Down Expand Up @@ -357,6 +358,8 @@ func Application(cfg *Config) (*kingpin.Application, *string) {
Envar("PMM_AGENT_LISTEN_PORT").Uint16Var(&cfg.ListenPort)
app.Flag("runner-capacity", "Agent internal actions/jobs runner capacity [PMM_AGENT_RUNNER_CAPACITY]").
Envar("PMM_AGENT_RUNNER_CAPACITY").Uint16Var(&cfg.RunnerCapacity)
app.Flag("runner-max-connections-per-service", "Agent internal action/job runner connection limit per DB instance").
Envar("PMM_AGENT_RUNNER_MAX_CONNECTIONS_PER_SERVICE").Uint16Var(&cfg.RunnerMaxConnectionsPerService)

app.Flag("server-address", "PMM Server address [PMM_AGENT_SERVER_ADDRESS]").
Envar("PMM_AGENT_SERVER_ADDRESS").PlaceHolder("<host:port>").StringVar(&cfg.Server.Address)
Expand Down
4 changes: 2 additions & 2 deletions agent/connectionchecker/connection_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ func (cc *ConnectionChecker) sqlPing(ctx context.Context, db *sql.DB) error {
return err
}

func (cc *ConnectionChecker) checkMySQLConnection(ctx context.Context, dsn string, files *agentv1.TextFiles, tlsSkipVerify bool, id uint32) *agentv1.CheckConnectionResponse { //nolint:lll,unparam,revive
func (cc *ConnectionChecker) checkMySQLConnection(ctx context.Context, dsn string, files *agentv1.TextFiles, tlsSkipVerify bool, id uint32) *agentv1.CheckConnectionResponse { //nolint:lll
var res agentv1.CheckConnectionResponse
var err error

if files != nil {
err = tlshelpers.RegisterMySQLCerts(files.Files)
err = tlshelpers.RegisterMySQLCerts(files.Files, tlsSkipVerify)
if err != nil {
cc.l.Debugf("checkMySQLConnection: failed to register cert: %s", err)
res.Error = err.Error()
Expand Down
Loading

0 comments on commit 41d36cd

Please sign in to comment.