You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by he...@apache.org on 2023/09/15 08:09:47 UTC
[shenyu] branch master updated: [type:bug] fix indexName not working for es-logging (#5158)
This is an automated email from the ASF dual-hosted git repository.
hefengen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 7727b2e1ae [type:bug] fix indexName not working for es-logging (#5158)
7727b2e1ae is described below
commit 7727b2e1aead1cc6a4ecfceb017e977961eb607a
Author: Misaya295 <45...@users.noreply.github.com>
AuthorDate: Fri Sep 15 16:09:41 2023 +0800
[type:bug] fix indexName not working for es-logging (#5158)
* fix indexName not working for es-logging
* fix indexName not working for es-logging
* fix ci
* judge index name isBlank
* fix ci
---------
Co-authored-by: moremind <he...@apache.org>
---
.../client/ElasticSearchLogCollectClient.java | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-elasticsearch/src/main/java/org/apache/shenyu/plugin/logging/elasticsearch/client/ElasticSearchLogCollectClient.java b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-elasticsearch/src/main/java/org/apache/shenyu/plugin/logging/elasticsearch/client/ElasticSearchLogCollectClient.java
index 29def36fb9..15aa9a3cf7 100644
--- a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-elasticsearch/src/main/java/org/apache/shenyu/plugin/logging/elasticsearch/client/ElasticSearchLogCollectClient.java
+++ b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-elasticsearch/src/main/java/org/apache/shenyu/plugin/logging/elasticsearch/client/ElasticSearchLogCollectClient.java
@@ -58,6 +58,8 @@ public class ElasticSearchLogCollectClient extends AbstractLogConsumeClient<Elas
private ElasticsearchClient client;
+ private String indexName = GenericLoggingConstant.INDEX;
+
/**
* init elasticsearch client.
*
@@ -84,29 +86,34 @@ public class ElasticSearchLogCollectClient extends AbstractLogConsumeClient<Elas
restClient = builder.build();
transport = new RestClientTransport(restClient, new JacksonJsonpMapper());
client = new ElasticsearchClient(transport);
+ indexName = StringUtils.isNoneBlank(config.getIndexName()) ? config.getIndexName() : GenericLoggingConstant.INDEX;
LogUtils.info(LOG, "init ElasticSearchLogCollectClient success");
// Determine whether the index exists, and create it if it does not exist
- if (!existsIndex(config.getIndexName())) {
- createIndex(config.getIndexName());
+ if (!existsIndex(indexName)) {
+ createIndex(indexName);
LogUtils.info(LOG, "create index success");
}
}
+ /**
+ * consume logs.
+ * @param logs logs
+ */
@Override
public void consume0(@NonNull final List<ShenyuRequestLog> logs) {
List<BulkOperation> bulkOperations = new ArrayList<>();
logs.forEach(log -> {
try {
- bulkOperations.add(new BulkOperation.Builder().create(d -> d.document(log).index(GenericLoggingConstant.INDEX)).build());
+ bulkOperations.add(new BulkOperation.Builder().create(d -> d.document(log).index(indexName)).build());
} catch (Exception e) {
LogUtils.error(LOG, "add logs error: ", e);
}
});
// Bulk storage
try {
- client.bulk(e -> e.index(GenericLoggingConstant.INDEX).operations(bulkOperations));
+ client.bulk(e -> e.index(indexName).operations(bulkOperations));
} catch (Exception e) {
- LogUtils.error(LOG, "elasticsearch store logs error:", e);
+ LogUtils.error(LOG, "elasticsearch store logs error: ", e);
}
}