-
Notifications
You must be signed in to change notification settings - Fork 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
QueryIndex rollover when field mapping limit is reached #725
Changes from 4 commits
4d163d7
1dd3134
cb42b15
b9cbff2
72daba8
9173705
3dd83f9
63b8e4c
d4673e7
1a704b7
5fb8ab0
5472c53
a19f46d
b4e6335
ced5111
c8e8233
ffc8228
0618056
c688613
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import org.opensearch.ResourceAlreadyExistsException | |
import org.opensearch.action.admin.indices.alias.Alias | ||
import org.opensearch.action.admin.indices.create.CreateIndexRequest | ||
import org.opensearch.action.admin.indices.create.CreateIndexResponse | ||
import org.opensearch.action.admin.indices.delete.DeleteIndexRequest | ||
import org.opensearch.action.admin.indices.get.GetIndexRequest | ||
import org.opensearch.action.admin.indices.get.GetIndexResponse | ||
import org.opensearch.action.admin.indices.mapping.put.PutMappingRequest | ||
|
@@ -42,7 +43,7 @@ class DocLevelMonitorQueries(private val client: Client, private val clusterServ | |
const val PROPERTIES = "properties" | ||
const val NESTED = "nested" | ||
const val TYPE = "type" | ||
const val INDEX_PATTERN_SUFIX = "-000001" | ||
const val INDEX_PATTERN_SUFFIX = "-000001" | ||
@JvmStatic | ||
fun docLevelQueriesMappings(): String { | ||
return DocLevelMonitorQueries::class.java.classLoader.getResource("mappings/doc-level-queries.json").readText() | ||
|
@@ -51,8 +52,20 @@ class DocLevelMonitorQueries(private val client: Client, private val clusterServ | |
|
||
suspend fun initDocLevelQueryIndex(): Boolean { | ||
if (!docLevelQueryIndexExists()) { | ||
// Since we changed queryIndex to be alias now, for backwards compatibility, we have to delete index with same name | ||
// as our alias, to avoid name clash. | ||
if (clusterService.state().metadata.hasIndex(ScheduledJob.DOC_LEVEL_QUERIES_INDEX)) { | ||
val acknowledgedResponse: AcknowledgedResponse = client.suspendUntil { | ||
admin().indices().delete(DeleteIndexRequest(ScheduledJob.DOC_LEVEL_QUERIES_INDEX)) | ||
} | ||
if (!acknowledgedResponse.isAcknowledged) { | ||
val errorMessage = "Deletion of old queryIndex [${ScheduledJob.DOC_LEVEL_QUERIES_INDEX}] index is not acknowledged!" | ||
log.error(errorMessage) | ||
throw AlertingException.wrap(OpenSearchStatusException(errorMessage, RestStatus.INTERNAL_SERVER_ERROR)) | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to confirm, even when it gets deleted here, we don't care for the old data since we will recreate it anyways, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it is checked if it exist and recreated if not, on every monitor update/execute API call and every monitor execution by job scheduler |
||
val alias = ScheduledJob.DOC_LEVEL_QUERIES_INDEX | ||
val indexPattern = ScheduledJob.DOC_LEVEL_QUERIES_INDEX + INDEX_PATTERN_SUFIX | ||
val indexPattern = ScheduledJob.DOC_LEVEL_QUERIES_INDEX + INDEX_PATTERN_SUFFIX | ||
val indexRequest = CreateIndexRequest(indexPattern) | ||
.mapping(docLevelQueriesMappings()) | ||
.alias(Alias(alias)) | ||
petardz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
@@ -77,8 +90,20 @@ class DocLevelMonitorQueries(private val client: Client, private val clusterServ | |
if (dataSources.queryIndex == ScheduledJob.DOC_LEVEL_QUERIES_INDEX) { | ||
return initDocLevelQueryIndex() | ||
} | ||
// Since we changed queryIndex to be alias now, for backwards compatibility, we have to delete index with same name | ||
// as our alias, to avoid name clash. | ||
if (clusterService.state().metadata.hasIndex(dataSources.queryIndex)) { | ||
val acknowledgedResponse: AcknowledgedResponse = client.suspendUntil { | ||
admin().indices().delete(DeleteIndexRequest(dataSources.queryIndex)) | ||
} | ||
if (!acknowledgedResponse.isAcknowledged) { | ||
val errorMessage = "Deletion of old queryIndex [${dataSources.queryIndex}] index is not acknowledged!" | ||
log.error(errorMessage) | ||
throw AlertingException.wrap(OpenSearchStatusException(errorMessage, RestStatus.INTERNAL_SERVER_ERROR)) | ||
} | ||
} | ||
val alias = dataSources.queryIndex | ||
val indexPattern = dataSources.queryIndex + INDEX_PATTERN_SUFIX | ||
val indexPattern = dataSources.queryIndex + INDEX_PATTERN_SUFFIX | ||
if (!clusterService.state().metadata.hasAlias(alias)) { | ||
val indexRequest = CreateIndexRequest(indexPattern) | ||
.mapping(docLevelQueriesMappings()) | ||
|
@@ -340,7 +365,7 @@ class DocLevelMonitorQueries(private val client: Client, private val clusterServ | |
|
||
private suspend fun rolloverQueryIndex(monitor: Monitor): String? { | ||
val queryIndex = monitor.dataSources.queryIndex | ||
val queryIndexPattern = monitor.dataSources.queryIndex + INDEX_PATTERN_SUFIX | ||
val queryIndexPattern = monitor.dataSources.queryIndex + INDEX_PATTERN_SUFFIX | ||
|
||
val request = RolloverRequest(queryIndex, null) | ||
request.createIndexRequest.index(queryIndexPattern) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the number getting incremented during rollovers? If so, where?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is done by _rollover core's API here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks