-
Notifications
You must be signed in to change notification settings - Fork 39
PMM-4879 Adding support for defaults-file in new mysql service. #1068
Changes from 17 commits
860c132
2f7f34d
2168c85
f6c7690
ea8e53e
67e20e5
6964cfd
5f78aa2
53bb457
868c96b
1d179ca
031c091
5cb6346
64538ce
2b875c8
9889453
bdd11c2
469b7bc
f0d0326
5267092
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// pmm-managed | ||
// Copyright (C) 2017 Percona LLC | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
package models | ||
|
||
// ParseDefaultsFileResult contains result of parsing defaults file. | ||
type ParseDefaultsFileResult struct { | ||
Username string | ||
Password string | ||
Host string | ||
Port uint32 | ||
Socket string | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,98 @@ | ||||||
// pmm-managed | ||||||
// Copyright (C) 2017 Percona LLC | ||||||
// | ||||||
// This program is free software: you can redistribute it and/or modify | ||||||
// it under the terms of the GNU Affero General Public License as published by | ||||||
// the Free Software Foundation, either version 3 of the License, or | ||||||
// (at your option) any later version. | ||||||
// | ||||||
// This program is distributed in the hope that it will be useful, | ||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||
// GNU Affero General Public License for more details. | ||||||
// | ||||||
// You should have received a copy of the GNU Affero General Public License | ||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||||
|
||||||
package agents | ||||||
|
||||||
import ( | ||||||
"context" | ||||||
"time" | ||||||
|
||||||
"github.com/percona/pmm/api/agentpb" | ||||||
"github.com/percona/pmm/api/inventorypb" | ||||||
"github.com/pkg/errors" | ||||||
|
||||||
"github.com/percona/pmm-managed/models" | ||||||
"github.com/percona/pmm-managed/utils/logger" | ||||||
) | ||||||
|
||||||
// DefaultsFileParser requests from agent to parse defaultsFile. | ||||||
type DefaultsFileParser struct { | ||||||
r *Registry | ||||||
} | ||||||
|
||||||
// NewDefaultsFileParser creates new ParseDefaultsFile request. | ||||||
func NewDefaultsFileParser(r *Registry) *DefaultsFileParser { | ||||||
return &DefaultsFileParser{ | ||||||
r: r, | ||||||
} | ||||||
} | ||||||
|
||||||
// ParseDefaultsFile sends request (with file path) to pmm-agent to parse defaults file. | ||||||
func (p *DefaultsFileParser) ParseDefaultsFile(ctx context.Context, pmmAgentID, filePath string, serviceType models.ServiceType) (*models.ParseDefaultsFileResult, error) { | ||||||
l := logger.Get(ctx) | ||||||
|
||||||
pmmAgent, err := p.r.get(pmmAgentID) | ||||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
|
||||||
start := time.Now() | ||||||
defer func() { | ||||||
if dur := time.Since(start); dur > 5*time.Second { | ||||||
l.Warnf("ParseDefaultsFile took %s.", dur) | ||||||
} | ||||||
}() | ||||||
Comment on lines
+52
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it realistic? Reading a file with few lines should not be a problem. And, I think, it should be handed in agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That can be written like this:
But yes, I also don't see benefit of this log |
||||||
|
||||||
request, err := createRequest(filePath, serviceType) | ||||||
if err != nil { | ||||||
l.Debugf("can't create ParseDefaultsFileRequest %s", err) | ||||||
return nil, err | ||||||
} | ||||||
|
||||||
resp, err := pmmAgent.channel.SendAndWaitResponse(request) | ||||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
|
||||||
l.Infof("ParseDefaultsFile response from agent: %+v.", resp) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||||||
parserResponse, ok := resp.(*agentpb.ParseDefaultsFileResponse) | ||||||
if !ok { | ||||||
return nil, errors.New("wrong response from agent (not ParseDefaultsFileResponse model)") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add info regarding actual type? |
||||||
} | ||||||
if parserResponse.Error != "" { | ||||||
return nil, errors.New(parserResponse.Error) | ||||||
} | ||||||
|
||||||
return &models.ParseDefaultsFileResult{ | ||||||
Username: parserResponse.Username, | ||||||
Password: parserResponse.Password, | ||||||
Host: parserResponse.Host, | ||||||
Port: parserResponse.Port, | ||||||
Socket: parserResponse.Socket, | ||||||
}, nil | ||||||
} | ||||||
|
||||||
func createRequest(configPath string, serviceType models.ServiceType) (*agentpb.ParseDefaultsFileRequest, error) { | ||||||
if serviceType == models.MySQLServiceType { | ||||||
request := &agentpb.ParseDefaultsFileRequest{ | ||||||
ServiceType: inventorypb.ServiceType_MYSQL_SERVICE, | ||||||
ConfigPath: configPath, | ||||||
} | ||||||
return request, nil | ||||||
} else { | ||||||
return nil, errors.Errorf("unhandled service type %s", serviceType) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// pmm-managed | ||
// Copyright (C) 2017 Percona LLC | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
package agents | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/percona/pmm-managed/models" | ||
) | ||
|
||
func TestCreateRequest(t *testing.T) { | ||
t.Parallel() | ||
response, err := createRequest("/path/to/file", models.MySQLServiceType) | ||
|
||
require.NoError(t, err) | ||
require.NotNil(t, response, "ParseDefaultsFileRequest is nil") | ||
} | ||
|
||
func TestCreateRequestNotSupported(t *testing.T) { | ||
t.Parallel() | ||
response, err := createRequest("/path/to/file", models.PostgreSQLServiceType) | ||
|
||
require.Error(t, err) | ||
require.Nil(t, response, "ParseDefaultsFileRequest is not nil") | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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'm not sure what are we testing here