-
Notifications
You must be signed in to change notification settings - Fork 39
PMM-4879 Adding support for defaults-file in new mysql service. #1068
Conversation
) | ||
|
||
// ParseDefaultsFile requests from agent to parse defaultsFile. | ||
type ParseDefaultsFile struct { |
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.
maybe DefaultsFileParser will be better naming for this struct?
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.
Sure, fixed.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in a cases below, please use fields too
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.
Changed.
services/management/mysql.go
Outdated
@@ -78,6 +83,30 @@ func (s *MySQLService) Add(ctx context.Context, req *managementpb.AddMySQLReques | |||
if err != nil { | |||
return err | |||
} | |||
|
|||
if len(req.DefaultsFile) != 0 { |
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.
if len(req.DefaultsFile) != 0 { | |
if req.DefaultsFile != "" { |
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.
the same for cases below
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.
Done.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
Changed.
services/management/mysql.go
Outdated
@@ -39,15 +42,17 @@ type MySQLService struct { | |||
state agentsStateUpdater | |||
cc connectionChecker | |||
vc versionCache | |||
pfd defaultsFileParser |
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.
pfd defaultsFileParser | |
dfp defaultsFileParser |
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.
Refactored.
@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
@@ -356,3 +356,50 @@ func TestUnexpectedResponsePayloadFromAgent(t *testing.T) { | |||
close(stopServer) | |||
<-stop | |||
} | |||
|
|||
func TestChannelForDefaultsFileParser(t *testing.T) { |
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
} | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: it would be good to know that value has been overridden, can we log.debug that?
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use t.Cleanup
instead.
PMM-4879
Build: SUBMODULES-2465