This repository has been archived by the owner on Jun 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* PMM-4879 Adding support for defaults-file in new mysql service. * PMM-4879 defaults-file adjustments. * PMM-4879 Linter & tests fix. * PMM-4879 Adding support for configuration entry: socket. * PMM-4879 Code review adjustments. * PMM-4879 Code review adjustments: replacing API dependencies. * PMM-4879 Code review adjustments: replacing API dependencies. * PMM-4879 Code review adjustments: fixing code for CI. * PMM-4879 Added coverage tests. * PMM-4879 Added coverage tests. * PMM-4879 Code review adjustments. * PMM-4879 Updating api-tests. Co-authored-by: Alexey Mukas <[email protected]>
- Loading branch information
Showing
14 changed files
with
482 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
}() | ||
|
||
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) | ||
parserResponse, ok := resp.(*agentpb.ParseDefaultsFileResponse) | ||
if !ok { | ||
return nil, errors.New("wrong response from agent (not ParseDefaultsFileResponse model)") | ||
} | ||
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.