Skip to content
This repository was archived by the owner on Jun 21, 2022. It is now read-only.

PMM-4879 Adding support for defaults-file in new mysql service. - #1068

Merged
pkadej merged 20 commits into
percona:mainfrom
pkadej:PMM-4879-defaults-file
Jun 11, 2022
Merged

PMM-4879 Adding support for defaults-file in new mysql service.#1068
pkadej merged 20 commits into
percona:mainfrom
pkadej:PMM-4879-defaults-file

Conversation

@pkadej

@pkadej pkadej commented Apr 12, 2022

Copy link
Copy Markdown
Contributor

@it-percona-cla

it-percona-cla commented Apr 12, 2022

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Comment thread services/agents/parse_defaults_file.go Outdated
)

// ParseDefaultsFile requests from agent to parse defaultsFile.
type ParseDefaultsFile struct {

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, fixed.

Comment thread services/agents/parse_defaults_file.go Outdated
if !ok {
return nil, errors.New("wrong response from agent (not ParseDefaultsFileResponse model)")
}
if len(parserResponse.GetError()) != 0 {

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

Comment thread services/management/mysql.go Outdated
return err
}

if len(req.DefaultsFile) != 0 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if len(req.DefaultsFile) != 0 {
if req.DefaultsFile != "" {

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread services/management/mysql.go Outdated
Comment on lines +94 to +107
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
}

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

Comment thread services/management/mysql.go Outdated
state agentsStateUpdater
cc connectionChecker
vc versionCache
pfd defaultsFileParser

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pfd defaultsFileParser
dfp defaultsFileParser

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored.

@pkadej
pkadej requested a review from BupycHuk April 23, 2022 13:03
@BupycHuk

Copy link
Copy Markdown
Contributor

@pkadej could you please commit changes in go modules, so we can see result of CI.

@pkadej

pkadej commented Apr 24, 2022

Copy link
Copy Markdown
Contributor Author

@pkadej could you please commit changes in go modules, so we can see result of CI.
@BupycHuk Did you mean temporary updating mod.go with pmm replaced with my fork or with version after percona/pmm#863 being merged?

@BupycHuk

BupycHuk commented Apr 25, 2022

Copy link
Copy Markdown
Contributor

@pkadej yes, updated go.mod with replace directive for now and once PR in pmm is merged update go.mod to use that version.

@pkadej

pkadej commented Apr 25, 2022

Copy link
Copy Markdown
Contributor Author

@pkadej yes, updated go.mod with replace directive for now and once PR in pmm is merged update go.mod to use that version.

@BupycHuk
Done. Unfortunately i don't have permission to trigger runflow.

@codecov

codecov Bot commented Apr 26, 2022

Copy link
Copy Markdown

Codecov Report

Merging #1068 (5267092) into main (05124a1) will increase coverage by 0.30%.
The diff coverage is 42.62%.

@@            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     
Flag Coverage Δ
all 48.64% <42.62%> (+0.30%) ⬆️
cover 49.14% <42.62%> (+0.33%) ⬆️
crosscover 48.98% <42.62%> (+0.30%) ⬆️
update 12.84% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
main.go 0.00% <0.00%> (ø)
services/agents/parse_defaults_file.go 20.00% <20.00%> (ø)
services/agents/channel/channel.go 62.28% <100.00%> (+0.43%) ⬆️
services/management/mysql.go 54.03% <100.00%> (+54.03%) ⬆️
services/management/management.go 28.26% <0.00%> (+18.47%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 05124a1...5267092. Read the comment docs.

@pkadej
pkadej force-pushed the PMM-4879-defaults-file branch from b4c8c0a to 64538ce Compare April 27, 2022 17:56
<-stop
}

func TestChannelForDefaultsFileParser(t *testing.T) {

Copy link
Copy Markdown
Contributor

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return nil, errors.Errorf("unhandled service type %s", serviceType)
return nil, errors.Errorf("unsupported service type %s", serviceType)

Comment on lines +52 to +57
start := time.Now()
defer func() {
if dur := time.Since(start); dur > 5*time.Second {
l.Warnf("ParseDefaultsFile took %s.", dur)
}
}()

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

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)")

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

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?

@artemgavrilov artemgavrilov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with comments

Comment on lines +52 to +57
start := time.Now()
defer func() {
if dur := time.Since(start); dur > 5*time.Second {
l.Warnf("ParseDefaultsFile took %s.", dur)
}
}()

Copy link
Copy Markdown
Contributor

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)

Copy link
Copy Markdown
Contributor

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))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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) {

Copy link
Copy Markdown
Contributor

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.

@pkadej
pkadej merged commit 1011fab into percona:main Jun 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants