Skip to content
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

CC-12445: Replace the JestClient with the ElasticsearchRestClient #468

Merged
merged 13 commits into from Dec 7, 2020

Conversation

levzem
Copy link
Contributor

@levzem levzem commented Nov 10, 2020

Signed-off-by: Lev Zemlyanov lev@confluent.io

Problem

the jest client is outdated and needs to be replaced by the supported and maintained ES high level rest client

Solution

replace the client

major points

  • BulkProcessor is no longer required as ES provides its own
  • all Jest classes are no longer necessary
  • ElasticsearchWriter was absorbed into SinkTask
  • retries are supported for all operations
  • some configs are deprecated/not used anymore WIP, full list TBD)
    • type.name as it is deprecated as of ES 7.x
Does this solution apply anywhere else?
  • yes
  • no
If yes, where?

Test Strategy

an additional manual upgrade test was performed. write records to ES cloud with a v10.0.2, then upgrade to the new client and try writing to the same ES cloud index

Testing done:
  • Unit tests
  • Integration tests
  • System tests
  • Manual tests

Release Plan

master because this is a major change

Copy link
Member

@kkonstantine kkonstantine left a comment

Choose a reason for hiding this comment

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

Thanks @levzem
This is going to be a tremendous upgrade!

Took a first quick pass over half the files and left a few comments. Will have to return soon for a more careful read.

url ->
credentialsProvider.setCredentials(
new AuthScope(new HttpHost(url)),
new UsernamePasswordCredentials(config.username(), config.password().value())
Copy link
Contributor

Choose a reason for hiding this comment

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

Can password be null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

try {
client.indices().create(request, RequestOptions.DEFAULT);
} catch (ElasticsearchStatusException | IOException e) {
if (!e.getMessage().contains(RESOURCE_ALREADY_EXISTS_EXCEPTION)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it still possible to get this exception if we already checked whether the index exists earlier?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we have seen it before in escalations and this maintains the previous behavior of the JestClient so I kept it just to be safe

unfortunately we have not been able to understand why this happens

* @param id the document id
* @param record the record
*/
private void addToRecordMap(String id, SinkRecord record) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that it's called once, do we need this method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

leftover from BulkProcessor implementation, while yes it is only called once, given it is wrapped in a null check it is probably better to abstract it away in case of future use


@Override
public void afterBulk(long executionId, BulkRequest request, Throwable failure) {
error.compareAndSet(null, new ConnectException("Bulk request failed.", failure));
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we keeping the document in the recordMap?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this will fail the task so it wont matter if we empty the map or not, but I added it regardless

response.getIndex()
);

reportBadRecord(response);
Copy link
Contributor

Choose a reason for hiding this comment

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

The method's Javadoc and the warn message says we are ignoring version conflict,s but it seems like we are still reporting this record. Is that intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reporting the record is the same as ignoring it (reporting a bad record does not fail anything), but I figured the user should be know which records had version conflicts in case they want to remediate manually somehow

return Version.getVersion();
}

private void checkMapping(SinkRecord record) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This method name is a bit misleading IMO, maybe consider renaming it to maybeCreateMapping?

}

@Test
public void testCallWithRetriesSomeRetries() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: add a unit-test that ensures wait time is always lesser than MAX_RETRY_TIME_MS?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@avocader avocader left a comment

Choose a reason for hiding this comment

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

I left a few non-critical suggestions, LGTM otherwise, thanks @levzem !

Copy link
Member

@kkonstantine kkonstantine left a comment

Choose a reason for hiding this comment

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

Another round of comments. Mostly done. I have a few more files to check. Mostly tests.

pom.xml Outdated Show resolved Hide resolved
pom.xml Outdated Show resolved Hide resolved
@levzem
Copy link
Contributor Author

levzem commented Dec 2, 2020

@kkonstantine, addressed all review comments, ready for another pass!

Signed-off-by: Lev Zemlyanov <lev@confluent.io>
Lev Zemlyanov added 2 commits December 2, 2020 14:15
Signed-off-by: Lev Zemlyanov <lev@confluent.io>
Signed-off-by: Lev Zemlyanov <lev@confluent.io>
Copy link
Member

@kkonstantine kkonstantine left a comment

Choose a reason for hiding this comment

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

Very nice work.
Left a few more minor comments.
Also please make sure to run mvn javadoc:javadoc and fix the javadoc issues because they'll break during the release.

But this LGTM! 👏

client.close();
}

@Test(expected = ConnectException.class)
Copy link
Member

Choose a reason for hiding this comment

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

It'd be nice to start using assertThrows and available hamcrest matchers for maps etc. But we can consider on a follow up.

Lev Zemlyanov added 4 commits December 6, 2020 08:52
Signed-off-by: Lev Zemlyanov <lev@confluent.io>
Signed-off-by: Lev Zemlyanov <lev@confluent.io>
Signed-off-by: Lev Zemlyanov <lev@confluent.io>
Signed-off-by: Lev Zemlyanov <lev@confluent.io>
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.

None yet

3 participants