Skip to content

Commit

Permalink
Avoid logging duplicate deprecation warnings multiple times (#1660)
Browse files Browse the repository at this point in the history
* Avoid logging duplicate deprecation warnings multiple times

Signed-off-by: Vacha <vachshah@amazon.com>

* Fixes test failures

Signed-off-by: Vacha <vachshah@amazon.com>

* Adding deprecation logger tests

Signed-off-by: Vacha <vachshah@amazon.com>

* Using ConcurrentHashMap keySet

Signed-off-by: Vacha Shah <vachshah@amazon.com>
  • Loading branch information
VachaShah authored Dec 15, 2021
1 parent 10e51bb commit e66ea2c
Show file tree
Hide file tree
Showing 84 changed files with 395 additions and 279 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@

public class BulkProcessorIT extends OpenSearchRestHighLevelClientTestCase {

@Override
protected boolean enableWarningsCheck() {
return false;
}

private static BulkProcessor.Builder initBulkProcessorBuilder(BulkProcessor.Listener listener) {
return BulkProcessor.builder(
(request, bulkListener) -> highLevelClient().bulkAsync(request, RequestOptions.DEFAULT, bulkListener),
Expand All @@ -95,7 +100,7 @@ private static BulkProcessor.Builder initBulkProcessorBuilderUsingTypes(BulkProc
return BulkProcessor.builder(
(request, bulkListener) -> highLevelClient().bulkAsync(
request,
expectWarnings(RestBulkAction.TYPES_DEPRECATION_MESSAGE),
expectWarningsOnce(RestBulkAction.TYPES_DEPRECATION_MESSAGE),
bulkListener
),
listener
Expand Down Expand Up @@ -506,11 +511,6 @@ private MultiGetRequest indexDocs(
} else {
BytesArray data = bytesBulkRequest(localIndex, localType, i);
processor.add(data, globalIndex, globalType, globalPipeline, XContentType.JSON);

if (localType != null) {
// If the payload contains types, parsing it into a bulk request results in a warning.
assertWarnings(RestBulkAction.TYPES_DEPRECATION_MESSAGE);
}
}
multiGetRequest.add(localIndex, Integer.toString(i));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ private BulkResponse bulkWithTypes(BulkRequest request) throws IOException {
request,
highLevelClient()::bulk,
highLevelClient()::bulkAsync,
expectWarnings(RestBulkAction.TYPES_DEPRECATION_MESSAGE)
expectWarningsOnce(RestBulkAction.TYPES_DEPRECATION_MESSAGE)
);
assertFalse(bulkResponse.hasFailures());
return bulkResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,15 @@ public void testDeleteWithTypes() throws IOException {
indexRequest,
highLevelClient()::index,
highLevelClient()::indexAsync,
expectWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE)
expectWarningsOnce(RestIndexAction.TYPES_DEPRECATION_MESSAGE)
);

DeleteRequest deleteRequest = new DeleteRequest("index", "type", docId);
DeleteResponse deleteResponse = execute(
deleteRequest,
highLevelClient()::delete,
highLevelClient()::deleteAsync,
expectWarnings(RestDeleteAction.TYPES_DEPRECATION_MESSAGE)
expectWarningsOnce(RestDeleteAction.TYPES_DEPRECATION_MESSAGE)
);

assertEquals("index", deleteResponse.getIndex());
Expand Down Expand Up @@ -425,15 +425,15 @@ public void testGetWithTypes() throws IOException {
indexRequest,
highLevelClient()::index,
highLevelClient()::indexAsync,
expectWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE)
expectWarningsOnce(RestIndexAction.TYPES_DEPRECATION_MESSAGE)
);

GetRequest getRequest = new GetRequest("index", "type", "id");
GetResponse getResponse = execute(
getRequest,
highLevelClient()::get,
highLevelClient()::getAsync,
expectWarnings(RestGetAction.TYPES_DEPRECATION_MESSAGE)
expectWarningsOnce(RestGetAction.TYPES_DEPRECATION_MESSAGE)
);

assertEquals("index", getResponse.getIndex());
Expand Down Expand Up @@ -512,7 +512,7 @@ public void testMultiGetWithTypes() throws IOException {
bulk.add(new IndexRequest("index", "type", "id1").source("{\"field\":\"value1\"}", XContentType.JSON));
bulk.add(new IndexRequest("index", "type", "id2").source("{\"field\":\"value2\"}", XContentType.JSON));

highLevelClient().bulk(bulk, expectWarnings(RestBulkAction.TYPES_DEPRECATION_MESSAGE));
highLevelClient().bulk(bulk, expectWarningsOnce(RestBulkAction.TYPES_DEPRECATION_MESSAGE));
MultiGetRequest multiGetRequest = new MultiGetRequest();
multiGetRequest.add("index", "id1");
multiGetRequest.add("index", "type", "id2");
Expand All @@ -521,7 +521,7 @@ public void testMultiGetWithTypes() throws IOException {
multiGetRequest,
highLevelClient()::mget,
highLevelClient()::mgetAsync,
expectWarnings(RestMultiGetAction.TYPES_DEPRECATION_MESSAGE)
expectWarningsOnce(RestMultiGetAction.TYPES_DEPRECATION_MESSAGE)
);
assertEquals(2, response.getResponses().length);

Expand Down Expand Up @@ -747,7 +747,7 @@ public void testIndexWithTypes() throws IOException {
indexRequest,
highLevelClient()::index,
highLevelClient()::indexAsync,
expectWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE)
expectWarningsOnce(RestIndexAction.TYPES_DEPRECATION_MESSAGE)
);
assertEquals(RestStatus.CREATED, indexResponse.status());
assertEquals("index", indexResponse.getIndex());
Expand Down Expand Up @@ -962,7 +962,7 @@ public void testUpdateWithTypes() throws IOException {
indexRequest,
highLevelClient()::index,
highLevelClient()::indexAsync,
expectWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE)
expectWarningsOnce(RestIndexAction.TYPES_DEPRECATION_MESSAGE)
);

UpdateRequest updateRequest = new UpdateRequest("index", "type", "id");
Expand All @@ -971,7 +971,7 @@ public void testUpdateWithTypes() throws IOException {
updateRequest,
highLevelClient()::update,
highLevelClient()::updateAsync,
expectWarnings(RestUpdateAction.TYPES_DEPRECATION_MESSAGE)
expectWarningsOnce(RestUpdateAction.TYPES_DEPRECATION_MESSAGE)
);

assertEquals(RestStatus.OK, updateResponse.status());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public void testCreateIndexWithTypes() throws IOException {
createIndexRequest,
highLevelClient().indices()::create,
highLevelClient().indices()::createAsync,
expectWarnings(RestCreateIndexAction.TYPES_DEPRECATION_MESSAGE)
expectWarningsOnce(RestCreateIndexAction.TYPES_DEPRECATION_MESSAGE)
);
assertTrue(createIndexResponse.isAcknowledged());

Expand Down Expand Up @@ -326,7 +326,7 @@ public void testCreateIndexWithTypes() throws IOException {
createIndexRequest,
highLevelClient().indices()::create,
highLevelClient().indices()::createAsync,
expectWarnings(RestCreateIndexAction.TYPES_DEPRECATION_MESSAGE)
expectWarningsOnce(RestCreateIndexAction.TYPES_DEPRECATION_MESSAGE)
);
assertTrue(createIndexResponse.isAcknowledged());

Expand Down Expand Up @@ -505,7 +505,7 @@ public void testGetIndexWithTypes() throws IOException {
getIndexRequest,
highLevelClient().indices()::get,
highLevelClient().indices()::getAsync,
expectWarnings(RestGetIndicesAction.TYPES_DEPRECATION_MESSAGE)
expectWarningsOnce(RestGetIndicesAction.TYPES_DEPRECATION_MESSAGE)
);

// default settings should be null
Expand Down Expand Up @@ -601,7 +601,7 @@ public void testPutMappingWithTypes() throws IOException {
putMappingRequest,
highLevelClient().indices()::putMapping,
highLevelClient().indices()::putMappingAsync,
expectWarnings(RestPutMappingAction.TYPES_DEPRECATION_MESSAGE)
expectWarningsOnce(RestPutMappingAction.TYPES_DEPRECATION_MESSAGE)
);
assertTrue(putMappingResponse.isAcknowledged());

Expand Down Expand Up @@ -676,7 +676,7 @@ public void testGetMappingWithTypes() throws IOException {
request,
highLevelClient().indices()::getMapping,
highLevelClient().indices()::getMappingAsync,
expectWarnings(RestGetMappingAction.TYPES_DEPRECATION_MESSAGE)
expectWarningsOnce(RestGetMappingAction.TYPES_DEPRECATION_MESSAGE)
);

Map<String, Object> mappings = getMappingsResponse.getMappings().get(indexName).get("_doc").sourceAsMap();
Expand Down Expand Up @@ -750,7 +750,7 @@ public void testGetFieldMappingWithTypes() throws IOException {
getFieldMappingsRequest,
highLevelClient().indices()::getFieldMapping,
highLevelClient().indices()::getFieldMappingAsync,
expectWarnings(RestGetFieldMappingAction.TYPES_DEPRECATION_MESSAGE)
expectWarningsOnce(RestGetFieldMappingAction.TYPES_DEPRECATION_MESSAGE)
);

final Map<String, org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetadata> fieldMappingMap =
Expand Down Expand Up @@ -1090,7 +1090,7 @@ public void testSyncedFlush() throws IOException {
syncedFlushRequest,
highLevelClient().indices()::flushSynced,
highLevelClient().indices()::flushSyncedAsync,
expectWarnings(SyncedFlushService.SYNCED_FLUSH_DEPRECATION_MESSAGE)
expectWarningsOnce(SyncedFlushService.SYNCED_FLUSH_DEPRECATION_MESSAGE)
);
assertThat(flushResponse.totalShards(), equalTo(1));
assertThat(flushResponse.successfulShards(), equalTo(1));
Expand All @@ -1106,7 +1106,7 @@ public void testSyncedFlush() throws IOException {
syncedFlushRequest,
highLevelClient().indices()::flushSynced,
highLevelClient().indices()::flushSyncedAsync,
expectWarnings(SyncedFlushService.SYNCED_FLUSH_DEPRECATION_MESSAGE)
expectWarningsOnce(SyncedFlushService.SYNCED_FLUSH_DEPRECATION_MESSAGE)
)
);
assertEquals(RestStatus.NOT_FOUND, exception.status());
Expand Down Expand Up @@ -1368,7 +1368,7 @@ public void testRolloverWithTypes() throws IOException {
rolloverRequest,
highLevelClient().indices()::rollover,
highLevelClient().indices()::rolloverAsync,
expectWarnings(RestRolloverIndexAction.TYPES_DEPRECATION_MESSAGE)
expectWarningsOnce(RestRolloverIndexAction.TYPES_DEPRECATION_MESSAGE)
);
assertTrue(rolloverResponse.isRolledOver());
assertFalse(rolloverResponse.isDryRun());
Expand Down Expand Up @@ -1782,7 +1782,7 @@ public void testPutTemplateWithTypes() throws Exception {
putTemplateRequest,
highLevelClient().indices()::putTemplate,
highLevelClient().indices()::putTemplateAsync,
expectWarnings(RestPutIndexTemplateAction.TYPES_DEPRECATION_MESSAGE)
expectWarningsOnce(RestPutIndexTemplateAction.TYPES_DEPRECATION_MESSAGE)
);
assertThat(putTemplateResponse.isAcknowledged(), equalTo(true));

Expand Down Expand Up @@ -1846,7 +1846,7 @@ public void testPutTemplateWithDeprecatedTemplateField() throws Exception {
putTemplateRequest,
highLevelClient().indices()::putTemplate,
highLevelClient().indices()::putTemplateAsync,
expectWarnings("Deprecated field [template] used, replaced by [index_patterns]")
expectWarningsOnce("Deprecated field [template] used, replaced by [index_patterns]")
);
assertThat(putTemplateResponse.isAcknowledged(), equalTo(true));

Expand Down Expand Up @@ -1916,7 +1916,7 @@ public void testPutTemplateWithNoTypesUsingTypedApi() throws Exception {
putTemplateRequest,
highLevelClient().indices()::putTemplate,
highLevelClient().indices()::putTemplateAsync,
expectWarnings(RestPutIndexTemplateAction.TYPES_DEPRECATION_MESSAGE)
expectWarningsOnce(RestPutIndexTemplateAction.TYPES_DEPRECATION_MESSAGE)
);
assertThat(putTemplateResponse.isAcknowledged(), equalTo(true));

Expand Down Expand Up @@ -2026,7 +2026,7 @@ public void testCRUDIndexTemplateWithTypes() throws Exception {
putTemplate1,
client.indices()::putTemplate,
client.indices()::putTemplateAsync,
expectWarnings(RestPutIndexTemplateAction.TYPES_DEPRECATION_MESSAGE)
expectWarningsOnce(RestPutIndexTemplateAction.TYPES_DEPRECATION_MESSAGE)
).isAcknowledged(),
equalTo(true)
);
Expand All @@ -2040,7 +2040,7 @@ public void testCRUDIndexTemplateWithTypes() throws Exception {
putTemplate2,
client.indices()::putTemplate,
client.indices()::putTemplateAsync,
expectWarnings(RestPutIndexTemplateAction.TYPES_DEPRECATION_MESSAGE)
expectWarningsOnce(RestPutIndexTemplateAction.TYPES_DEPRECATION_MESSAGE)
).isAcknowledged(),
equalTo(true)
);
Expand All @@ -2049,7 +2049,7 @@ public void testCRUDIndexTemplateWithTypes() throws Exception {
new GetIndexTemplatesRequest("template-1"),
client.indices()::getTemplate,
client.indices()::getTemplateAsync,
expectWarnings(RestGetIndexTemplateAction.TYPES_DEPRECATION_MESSAGE)
expectWarningsOnce(RestGetIndexTemplateAction.TYPES_DEPRECATION_MESSAGE)
);
assertThat(getTemplate1.getIndexTemplates(), hasSize(1));
org.opensearch.cluster.metadata.IndexTemplateMetadata template1 = getTemplate1.getIndexTemplates().get(0);
Expand All @@ -2062,7 +2062,7 @@ public void testCRUDIndexTemplateWithTypes() throws Exception {
new GetIndexTemplatesRequest("template-2"),
client.indices()::getTemplate,
client.indices()::getTemplateAsync,
expectWarnings(RestGetIndexTemplateAction.TYPES_DEPRECATION_MESSAGE)
expectWarningsOnce(RestGetIndexTemplateAction.TYPES_DEPRECATION_MESSAGE)
);
assertThat(getTemplate2.getIndexTemplates(), hasSize(1));
org.opensearch.cluster.metadata.IndexTemplateMetadata template2 = getTemplate2.getIndexTemplates().get(0);
Expand All @@ -2080,7 +2080,7 @@ public void testCRUDIndexTemplateWithTypes() throws Exception {
getBothRequest,
client.indices()::getTemplate,
client.indices()::getTemplateAsync,
expectWarnings(RestGetIndexTemplateAction.TYPES_DEPRECATION_MESSAGE)
expectWarningsOnce(RestGetIndexTemplateAction.TYPES_DEPRECATION_MESSAGE)
);
assertThat(getBoth.getIndexTemplates(), hasSize(2));
assertThat(
Expand All @@ -2093,7 +2093,7 @@ public void testCRUDIndexTemplateWithTypes() throws Exception {
getAllRequest,
client.indices()::getTemplate,
client.indices()::getTemplateAsync,
expectWarnings(RestGetIndexTemplateAction.TYPES_DEPRECATION_MESSAGE)
expectWarningsOnce(RestGetIndexTemplateAction.TYPES_DEPRECATION_MESSAGE)
);
assertThat(getAll.getIndexTemplates().size(), greaterThanOrEqualTo(2));
assertThat(
Expand Down Expand Up @@ -2132,7 +2132,7 @@ public void testCRUDIndexTemplateWithTypes() throws Exception {
new GetIndexTemplatesRequest("template-*"),
client.indices()::getTemplate,
client.indices()::getTemplateAsync,
expectWarnings(RestGetIndexTemplateAction.TYPES_DEPRECATION_MESSAGE)
expectWarningsOnce(RestGetIndexTemplateAction.TYPES_DEPRECATION_MESSAGE)
).getIndexTemplates(),
hasSize(1)
);
Expand All @@ -2141,7 +2141,7 @@ public void testCRUDIndexTemplateWithTypes() throws Exception {
new GetIndexTemplatesRequest("template-*"),
client.indices()::getTemplate,
client.indices()::getTemplateAsync,
expectWarnings(RestGetIndexTemplateAction.TYPES_DEPRECATION_MESSAGE)
expectWarningsOnce(RestGetIndexTemplateAction.TYPES_DEPRECATION_MESSAGE)
).getIndexTemplates().get(0).name(),
equalTo("template-2")
);
Expand All @@ -2157,7 +2157,7 @@ public void testCRUDIndexTemplateWithTypes() throws Exception {
new GetIndexTemplatesRequest("template-*"),
client.indices()::getTemplate,
client.indices()::getTemplateAsync,
expectWarnings(RestGetIndexTemplateAction.TYPES_DEPRECATION_MESSAGE)
expectWarningsOnce(RestGetIndexTemplateAction.TYPES_DEPRECATION_MESSAGE)
)
).status(),
equalTo(RestStatus.NOT_FOUND)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,23 @@ public class SearchIT extends OpenSearchRestHighLevelClientTestCase {
public void indexDocuments() throws IOException {
{
Request doc1 = new Request(HttpPut.METHOD_NAME, "/index/type/1");
doc1.setOptions(expectWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE));
doc1.setOptions(expectWarningsOnce(RestIndexAction.TYPES_DEPRECATION_MESSAGE));
doc1.setJsonEntity("{\"type\":\"type1\", \"id\":1, \"num\":10, \"num2\":50}");
client().performRequest(doc1);
Request doc2 = new Request(HttpPut.METHOD_NAME, "/index/type/2");
doc2.setOptions(expectWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE));
doc2.setOptions(expectWarningsOnce(RestIndexAction.TYPES_DEPRECATION_MESSAGE));
doc2.setJsonEntity("{\"type\":\"type1\", \"id\":2, \"num\":20, \"num2\":40}");
client().performRequest(doc2);
Request doc3 = new Request(HttpPut.METHOD_NAME, "/index/type/3");
doc3.setOptions(expectWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE));
doc3.setOptions(expectWarningsOnce(RestIndexAction.TYPES_DEPRECATION_MESSAGE));
doc3.setJsonEntity("{\"type\":\"type1\", \"id\":3, \"num\":50, \"num2\":35}");
client().performRequest(doc3);
Request doc4 = new Request(HttpPut.METHOD_NAME, "/index/type/4");
doc4.setOptions(expectWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE));
doc4.setOptions(expectWarningsOnce(RestIndexAction.TYPES_DEPRECATION_MESSAGE));
doc4.setJsonEntity("{\"type\":\"type2\", \"id\":4, \"num\":100, \"num2\":10}");
client().performRequest(doc4);
Request doc5 = new Request(HttpPut.METHOD_NAME, "/index/type/5");
doc5.setOptions(expectWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE));
doc5.setOptions(expectWarningsOnce(RestIndexAction.TYPES_DEPRECATION_MESSAGE));
doc5.setJsonEntity("{\"type\":\"type2\", \"id\":5, \"num\":100, \"num2\":10}");
client().performRequest(doc5);
}
Expand Down Expand Up @@ -1445,7 +1445,6 @@ public void testCountMultipleIndicesMatchQuery() throws IOException {
}

public void testCountAllIndicesMatchQuery() throws IOException {

CountRequest countRequest = new CountRequest();
countRequest.source(new SearchSourceBuilder().query(new MatchQueryBuilder("field", "value1")));
CountResponse countResponse = execute(countRequest, highLevelClient()::count, highLevelClient()::countAsync);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public TokenFilterFactory getSynonymFilter() {
throw new IllegalArgumentException("Token filter [" + name() + "] cannot be used to parse synonyms");
} else {
DEPRECATION_LOGGER.deprecate(
"synonym_tokenfilters",
name() + "_synonym_tokenfilters",
"Token filter [" + name() + "] will not be usable to parse synonyms after v7.0"
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public TokenFilterFactory getSynonymFilter() {
throw new IllegalArgumentException("Token filter [" + name() + "] cannot be used to parse synonyms");
} else {
DEPRECATION_LOGGER.deprecate(
"synonym_tokenfilters",
name() + "_synonym_tokenfilters",
"Token filter [" + name() + "] will not be usable to parse synonyms after v7.0"
);
}
Expand Down
Loading

0 comments on commit e66ea2c

Please sign in to comment.