Skip to content

add config of elasticsearch's user and password #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 54 commits into from
Jun 20, 2017

Conversation

WangXiangUSTC
Copy link
Contributor

@WangXiangUSTC WangXiangUSTC commented May 17, 2017

Add config of elasticsearch's user and password,
and add judge of HTTP response。

@WangXiangUSTC
Copy link
Contributor Author

It seems that my understand for error is different from your's

if err != nil {
return nil, errors.Trace(err)
}
if len(c.User) > 0 && len(c.Password) > 0 {
req.SetBasicAuth(c.User, c.Password)
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we meet the case that user is not empty but the password is?

river/river.go Outdated
@@ -66,7 +66,8 @@ func NewRiver(c *Config) (*River, error) {
return nil, errors.Trace(err)
}

r.es = elastic.NewClient(r.c.ESAddr)
r.es = elastic.NewClient(r.c.ESAddr, r.c.ESUser, r.c.ESPassword)
Copy link
Collaborator

Choose a reason for hiding this comment

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

please pass a config structure for client now.

@WangXiangUSTC
Copy link
Contributor Author

@siddontang @EagleChen
Thanks,ci check success!
And after merge this request, we can try to fix the bug when delete docs have parent.

@siddontang
Copy link
Collaborator

HI @WangXiangUSTC @EagleChen
I think we must send another PR to check the status code first, then we will add the password support.

It makes more sense.

@WangXiangUSTC
Copy link
Contributor Author

@siddontang you means add more test case? Can you say a little more detail

@siddontang
Copy link
Collaborator

Hi @WangXiangUSTC

I say use another PR to check the status code first, then you can the password support later.

I don't want to remove current tests if possible. For password, we can use other new tests especially.

@WangXiangUSTC
Copy link
Contributor Author

@siddontang I will try recently

@WangXiangUSTC
Copy link
Contributor Author

@siddontang Finally I decide to judge http response code after send http request, instead of return error when code is not 200.


// if index doesn't exist, will get 404 not found error, create index first
if err != nil {
if r.Code != http.StatusOK {
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we check 404 here directly?

river/sync.go Outdated
@@ -439,7 +439,7 @@ func (r *River) doBulk(reqs []*elastic.BulkRequest) error {
if resp, err := r.es.Bulk(reqs); err != nil {
log.Errorf("sync docs err %v after binlog %s", err, r.canal.SyncedPosition())
return errors.Trace(err)
} else if resp.Errors {
} else if resp.Code >= 300 || resp.Code < 200 || resp.Errors {
Copy link
Collaborator

Choose a reason for hiding this comment

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

resp.Code / 100 == 2 may be better?

@@ -198,7 +199,11 @@ func (s *riverTestSuite) testElasticGet(c *C, id string) *elastic.Response {
docType := "river"

r, err := s.r.es.Get(index, docType, id)
c.Assert(err, IsNil)
if err != nil {
r := new(elastic.Response)
Copy link
Collaborator

Choose a reason for hiding this comment

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

why return a response with Found=false here?

@WangXiangUSTC
Copy link
Contributor Author

@siddontang OK, I will check carefully tomorrow.

@@ -214,7 +228,7 @@ func (c *Client) CreateMapping(index string, docType string, mapping map[string]
return errors.Trace(err)
}

// index doesn't exist, create index first
// if index doesn't exist, will get 404 not found error, create index first
if r.Code != http.StatusOK {
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe we can check 404 here directly and return an error for other invalid statuses.

@WangXiangUSTC
Copy link
Contributor Author

@siddontang I have modify the code.

_, err = c.Do("PUT", reqUrl, nil)

if err != nil {
return errors.Trace(err)
}
} else if r.Code != http.StatusOK {
return errors.Trace(err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

seem the error may be nil here.

_, err = c.Do("PUT", reqUrl, nil)

if err != nil {
return errors.Trace(err)
}
} else if r.Code != http.StatusOK {
return errors.New(resp.Status)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess compiler may fail here.

@siddontang siddontang merged commit 4515d5b into go-mysql-org:master Jun 20, 2017
@siddontang
Copy link
Collaborator

Thanks @WangXiangUSTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants