PMM-4879 Adding support for defaults-file in new mysql service.#1068
PMM-4879 Adding support for defaults-file in new mysql service.#1068pkadej merged 20 commits intopercona:mainfrom
Conversation
| ) | ||
|
|
||
| // ParseDefaultsFile requests from agent to parse defaultsFile. | ||
| type ParseDefaultsFile struct { |
There was a problem hiding this comment.
maybe DefaultsFileParser will be better naming for this struct?
| if !ok { | ||
| return nil, errors.New("wrong response from agent (not ParseDefaultsFileResponse model)") | ||
| } | ||
| if len(parserResponse.GetError()) != 0 { |
There was a problem hiding this comment.
let's use field instead of method, we had to use methods in some places to not duplicate code
There was a problem hiding this comment.
in a cases below, please use fields too
services/management/mysql.go
Outdated
| return err | ||
| } | ||
|
|
||
| if len(req.DefaultsFile) != 0 { |
There was a problem hiding this comment.
| if len(req.DefaultsFile) != 0 { | |
| if req.DefaultsFile != "" { |
services/management/mysql.go
Outdated
| if len(result.Username) != 0 { | ||
| req.Username = result.Username | ||
| } | ||
| if len(result.Password) != 0 { | ||
| req.Password = result.Password | ||
| } | ||
|
|
||
| if len(result.Host) != 0 { | ||
| req.Address = result.Host | ||
| } | ||
|
|
||
| if result.Port > 0 { | ||
| req.Port = result.Port | ||
| } |
There was a problem hiding this comment.
based on discussion in Jira ticket we should set values from defaults file only if they weren't passed as a separate field in request.
services/management/mysql.go
Outdated
| state agentsStateUpdater | ||
| cc connectionChecker | ||
| vc versionCache | ||
| pfd defaultsFileParser |
There was a problem hiding this comment.
| pfd defaultsFileParser | |
| dfp defaultsFileParser |
|
@pkadej could you please commit changes in go modules, so we can see result of CI. |
|
|
@pkadej yes, updated go.mod with |
Codecov Report
@@ Coverage Diff @@
## main #1068 +/- ##
==========================================
+ Coverage 48.67% 48.98% +0.30%
==========================================
Files 181 182 +1
Lines 21264 21323 +59
==========================================
+ Hits 10351 10445 +94
+ Misses 9775 9723 -52
- Partials 1138 1155 +17
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
b4c8c0a to
64538ce
Compare
| <-stop | ||
| } | ||
|
|
||
| func TestChannelForDefaultsFileParser(t *testing.T) { |
There was a problem hiding this comment.
I'm not sure what are we testing here
| } | ||
| return request, nil | ||
| } else { | ||
| return nil, errors.Errorf("unhandled service type %s", serviceType) |
There was a problem hiding this comment.
| return nil, errors.Errorf("unhandled service type %s", serviceType) | |
| return nil, errors.Errorf("unsupported service type %s", serviceType) |
| start := time.Now() | ||
| defer func() { | ||
| if dur := time.Since(start); dur > 5*time.Second { | ||
| l.Warnf("ParseDefaultsFile took %s.", dur) | ||
| } | ||
| }() |
There was a problem hiding this comment.
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.
That can be written like this:
defer func(start time.Time) {
if dur := time.Since(start); dur > 5*time.Second {
l.Warnf("ParseDefaultsFile took %s.", dur)
}
}(time.Now())
But yes, I also don't see benefit of this log
| 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)") |
There was a problem hiding this comment.
Can we add info regarding actual type?
| return status.Error(codes.FailedPrecondition, fmt.Sprintf("Defaults file error: %s.", err)) | ||
| } | ||
|
|
||
| // set username and password from parsed defaults file by agent |
There was a problem hiding this comment.
nit: it would be good to know that value has been overridden, can we log.debug that?
artemgavrilov
left a comment
There was a problem hiding this comment.
LGTM with comments
| start := time.Now() | ||
| defer func() { | ||
| if dur := time.Since(start); dur > 5*time.Second { | ||
| l.Warnf("ParseDefaultsFile took %s.", dur) | ||
| } | ||
| }() |
There was a problem hiding this comment.
That can be written like this:
defer func(start time.Time) {
if dur := time.Since(start); dur > 5*time.Second {
l.Warnf("ParseDefaultsFile took %s.", dur)
}
}(time.Now())
But yes, I also don't see benefit of this log
| return nil, err | ||
| } | ||
|
|
||
| l.Infof("ParseDefaultsFile response from agent: %+v.", resp) |
There was a problem hiding this comment.
I think Debug level fits better here.
| if req.DefaultsFile != "" { | ||
| result, err := s.dfp.ParseDefaultsFile(ctx, req.PmmAgentId, req.DefaultsFile, models.MySQLServiceType) | ||
| if err != nil { | ||
| return status.Error(codes.FailedPrecondition, fmt.Sprintf("Defaults file error: %s.", err)) |
There was a problem hiding this comment.
| return status.Error(codes.FailedPrecondition, fmt.Sprintf("Defaults file error: %s.", err)) | |
| return status.Errorf(codes.FailedPrecondition, "Defaults file error: %s.", err) |
| versionCache := &mockVersionCache{} | ||
| versionCache.Test(t) | ||
|
|
||
| teardown := func(t *testing.T) { |
There was a problem hiding this comment.
You can use t.Cleanup instead.
PMM-4879
Build: SUBMODULES-2465