fix deleteIndex repeat append namespace#3017
Conversation
wu-sheng
left a comment
There was a problem hiding this comment.
I suggest you move the whole code block inside ElasticSearchClient as method #deleteTimeSeriesData(modelName, timeBefore). Then the delete codes without formatIndexName could ba placed inside method directly.
List<String> indexes = client.retrievalIndexByAliases(model.getName());
List<String> prepareDeleteIndexes = new ArrayList<>();
for (String index : indexes) {
long timeSeries = TimeSeriesUtils.indexTimeSeries(index);
if (timeBefore >= timeSeries) {
prepareDeleteIndexes.add(index);
}
}
if (indexes.size() == prepareDeleteIndexes.size()) {
client.createIndex(TimeSeriesUtils.timeSeries(model));
}
for (String prepareDeleteIndex : prepareDeleteIndexes) {
client.deleteIndex(prepareDeleteIndex);
}I think don't mixe these two kinds of OP(s) together should be much better.
| return deleteIndex(indexName, true); | ||
| } | ||
|
|
||
| public boolean deleteIndex(String indexName, boolean formatIndexName) throws IOException { |
There was a problem hiding this comment.
These two delete methods will make people very confused.
There was a problem hiding this comment.
I suggest you move the whole code block inside
ElasticSearchClientas method#deleteTimeSeriesData(modelName, timeBefore). Then the delete codes withoutformatIndexNamecould ba placed inside method directly.List<String> indexes = client.retrievalIndexByAliases(model.getName()); List<String> prepareDeleteIndexes = new ArrayList<>(); for (String index : indexes) { long timeSeries = TimeSeriesUtils.indexTimeSeries(index); if (timeBefore >= timeSeries) { prepareDeleteIndexes.add(index); } } if (indexes.size() == prepareDeleteIndexes.size()) { client.createIndex(TimeSeriesUtils.timeSeries(model)); } for (String prepareDeleteIndex : prepareDeleteIndexes) { client.deleteIndex(prepareDeleteIndex); }I think don't mixe these two kinds of OP(s) together should be much better.
This code block needs to use TimeSeriesUtils, but TimeSeriesUtils is located in storage-elasticsearch-plugin
There was a problem hiding this comment.
or delete the namespace in the #retrievalIndexByAliasesreturn result.
There was a problem hiding this comment.
Then build List ESTimeSeriesIndex, in each element, keep namespace and name in two fields. Then add a new delete method accepting ESTimeSeriesIndex
| return indexName; | ||
| } | ||
|
|
||
| public String undoFormatIndexName(String indexName) { |
| } | ||
|
|
||
| public String undoFormatIndexName(String indexName) { | ||
| if (StringUtils.isNotEmpty(namespace) && indexName.startsWith(namespacePrefix)) { |
There was a problem hiding this comment.
If !startWith(namespace, then you should raise an exception.
...ava/org/apache/skywalking/oap/server/library/client/elasticsearch/ITElasticSearchClient.java
Outdated
Show resolved
Hide resolved
|
done |
| client = new ElasticSearchClient(esAddress, "", "test", "test"); | ||
| final String esNamespace = System.getProperty("elastic.search.namespace", ""); | ||
| final String esUser = System.getProperty("elastic.search.user", "test"); | ||
| final String esPassword = System.getProperty("elastic.search.password", "test"); |
There was a problem hiding this comment.
One question, who will set these properties?
There was a problem hiding this comment.
If not, then, namespace feature hasn't been tested.
There was a problem hiding this comment.
Can I use the maven-failsafe-plugin, as follows
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<elastic.search.address>
${docker.hostname}:${es-port}
</elastic.search.address>
<elastic.search.namespace>
test
</elastic.search.namespace>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
There was a problem hiding this comment.
After adding namespace,getIndex has the same problem, which I will modify together
There was a problem hiding this comment.
System properties are used for uncertain variables, because of docker env. You don't need this, actually, you could add it to test codes directly, which will be more clear.
There was a problem hiding this comment.
Also, @Arugal #getIndex is not used in codes anymore, we only use it in IT test, let's move it to ITElasticSearchClient? That will make us has fewer codes concern of index name.
There was a problem hiding this comment.
Also, @Arugal
#getIndexis not used in codes anymore, we only use it in IT test, let's move it to ITElasticSearchClient? That will make us has fewer codes concern of index name.
#getIndex needs to invoker RestHighLevelClient#getLowLevelClient ,unless we can get a RestHighLevelClient instance via ElasticSearchClient
There was a problem hiding this comment.
System properties are used for uncertain variables, because of docker env. You don't need this, actually, you could add it to test codes directly, which will be more clear.
done
There was a problem hiding this comment.
Also, @Arugal
#getIndexis not used in codes anymore, we only use it in IT test, let's move it to ITElasticSearchClient? That will make us has fewer codes concern of index name.
#getIndexneeds to invokerRestHighLevelClient#getLowLevelClient,unless we can get aRestHighLevelClientinstance viaElasticSearchClient
getIndex method is still there. I think no ine uses it, should remove, right?
Can I do what I said above?
...ava/org/apache/skywalking/oap/server/library/client/elasticsearch/ITElasticSearchClient.java
Outdated
Show resolved
Hide resolved
...ava/org/apache/skywalking/oap/server/library/client/elasticsearch/ITElasticSearchClient.java
Outdated
Show resolved
Hide resolved
wu-sheng
left a comment
There was a problem hiding this comment.
You miss some suggestions from last review.
| private JsonObject undoFormatIndexName(JsonObject index) { | ||
| if (StringUtils.isNotEmpty(namespace) && index != null && index.size() > 0) { | ||
| Set<Map.Entry<String, JsonElement>> entrySet = index.entrySet(); | ||
| for (Map.Entry<String, JsonElement> entry : entrySet) { |
There was a problem hiding this comment.
Change this to index.foreach ->
| return Collections.EMPTY_LIST; | ||
| } | ||
|
|
||
| public JsonObject getIndex(String indexName) throws IOException { |
There was a problem hiding this comment.
getIndex method needs to move to ITElasticSearchClient with undoFormatIndexName(JsonObject index) method.
| public class ITElasticSearchClientOfNamespace extends ITElasticSearchClient { | ||
|
|
||
|
|
||
| public ITElasticSearchClientOfNamespace() { |
There was a problem hiding this comment.
Has this run? I haven't used this kind of test before. Please confirm in the log.
| return indexName; | ||
| } | ||
|
|
||
| private JsonObject undoFormatIndexName(JsonObject index) { |
There was a problem hiding this comment.
We don't need this method, this should move to test class only. Right?
Do I have any unfinished suggestions now? |
|
getIndex method is still there. I think no ine uses it, should remove, right? |
peng-yongsheng
left a comment
There was a problem hiding this comment.
I'm not suggest fixed it by this way. You can just add a new delete method without format. It is a very simply way.
|
@peng-yongsheng If you just want an easy way, please consider putting two good method names. Because time series indexes exist, we can't set these methods as |
Agree with my two hands. |
Now, I only think |
|
@peng-yongsheng @dmsolr Then this is my suggestion
Yes. But basically, we are just talking about naming style. For |
Yes, If you use it, it's not the only place that needs it. It is a strategy that how to manage the namespace. Not just for the delete method. So, I do not suggest you use this way. I had thought it at the time of I program the time series implementation. At that time, I had an ideal same as you. But, If we must keep the overall style of the code. I found there are too many codes that need to modify. |
@Arugal |
Yes, but wouldn't it be better to know the namespace with less code
Do I need to make any modification to this PR |
No problem, you can new an issue to discuss it.
Yes, just provide those two methods, '#deleteByIndexName' and '#deleteByModelName'. Rollback other changed files. |
|
I still recommend to remove getIndex method, only keep it in test case. Don't revert that. |
| private final String user; | ||
| private final String password; | ||
| private RestHighLevelClient client; | ||
| @Getter(value = AccessLevel.PACKAGE) private RestHighLevelClient client; |
There was a problem hiding this comment.
Use whitebox get from powermock to get this.
|
/run e2e |
wu-sheng
left a comment
There was a problem hiding this comment.
LGTM. @peng-yongsheng please confirm.
| public ElasticSearchClient(String clusterNodes, String namespace, String user, String password) { | ||
| this.clusterNodes = clusterNodes; | ||
| this.namespace = namespace; | ||
| this.namespacePrefix = namespace + "_"; |
There was a problem hiding this comment.
I think this.namespacePrefix attribute is no value because we have a common method named formatIndexName.
|
/run ci |
|
/run e2e |
|
/run ci |
|
ASF jenkins break, we are waiting. |
|
/run ci |
|
/run e2e |
Please answer these questions before submitting pull request
Why submit this pull request?
Bug fix
New feature provided
Improve performance
Related issues
Bug fix
org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base.HistoryDeleteEsDAO 的 57行 retrievalIndexByAliases 方法已经把 namespace 加上了 72行的 deleteIndex 方法又加了一遍namespace #3014
#formatIndexName optional
New feature or improvement