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

QueryIndex rollover when field mapping limit is reached #725

Merged
merged 19 commits into from
Dec 31, 2022

Conversation

petardz
Copy link
Contributor

@petardz petardz commented Dec 21, 2022

Signed-off-by: Petar Dzepina [email protected]

Issue #, if available:

Description of changes:

Added handling of situation when queryIndex has more fields in mapping then set limit(default 1000).

queryIndex is now alias instead of concrete index
Index pattern is computed like this: queryIndex + "-1"

We keep mapping of source_index+monitorId --> concreteQueryIndex in map inside Monitor object.

CheckList:
[ ] Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Petar Dzepina <[email protected]>
@petardz petardz requested a review from a team December 21, 2022 22:19
Signed-off-by: Petar Dzepina <[email protected]>
Signed-off-by: Petar Dzepina <[email protected]>
…hema; removed unused code

Signed-off-by: Petar Dzepina <[email protected]>
Signed-off-by: Petar Dzepina <[email protected]>
@codecov-commenter
Copy link

codecov-commenter commented Dec 28, 2022

Codecov Report

Merging #725 (c688613) into main (817d9ef) will decrease coverage by 0.81%.
The diff coverage is 66.36%.

@@             Coverage Diff              @@
##               main     #725      +/-   ##
============================================
- Coverage     76.11%   75.30%   -0.82%     
  Complexity      116      116              
============================================
  Files           124      125       +1     
  Lines          6618     6822     +204     
  Branches        982     1021      +39     
============================================
+ Hits           5037     5137     +100     
- Misses         1083     1154      +71     
- Partials        498      531      +33     
Impacted Files Coverage Δ
...in/kotlin/org/opensearch/alerting/MonitorRunner.kt 63.29% <ø> (-0.46%) ⬇️
...pensearch/alerting/model/AlertingConfigAccessor.kt 75.00% <ø> (-3.38%) ⬇️
...tlin/org/opensearch/alerting/util/AlertingUtils.kt 53.12% <ø> (-7.41%) ⬇️
...alerting/transport/TransportDeleteMonitorAction.kt 66.29% <55.88%> (-8.34%) ⬇️
.../opensearch/alerting/DocumentLevelMonitorRunner.kt 77.58% <63.15%> (-4.58%) ⬇️
...n/org/opensearch/alerting/model/MonitorMetadata.kt 44.31% <64.00%> (+5.51%) ⬆️
.../org/opensearch/alerting/MonitorMetadataService.kt 65.07% <65.07%> (ø)
...lerting/transport/TransportExecuteMonitorAction.kt 82.08% <66.66%> (+0.55%) ⬆️
...opensearch/alerting/util/DocLevelMonitorQueries.kt 72.87% <69.81%> (-7.49%) ⬇️
.../alerting/transport/TransportIndexMonitorAction.kt 54.93% <75.00%> (-5.01%) ⬇️
... and 10 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Comment on lines 57 to 66
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))
}
}
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Comment on lines +339 to +340
// If we reached limit for total number of fields in mappings after rollover
// it means that source index has more then (FIELD_LIMIT - 3) fields (every query index has 3 fields defined)
Copy link
Member

Choose a reason for hiding this comment

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

Can't we rollover multiple times?

Copy link
Contributor Author

@petardz petardz Dec 28, 2022

Choose a reason for hiding this comment

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

queryIndex already has 3 fields in mappings so when source_index has 997 fields or more, we couldn't succeed ever so we must abort

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but in any other case, yea, we can rollover

Copy link
Member

Choose a reason for hiding this comment

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

Ahh I see. Can we add a TODO to support indices that have at least 997 fields by looking into breaking up the data amongst multiple rolled over indices?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

Signed-off-by: Petar Dzepina <[email protected]>
Copy link
Collaborator

@sbcd90 sbcd90 left a comment

Choose a reason for hiding this comment

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

@petardz can we add an integration test for this scenario?

@sbcd90
Copy link
Collaborator

sbcd90 commented Dec 29, 2022

@petardz can we add an integration test for this scenario?

i see it added. thanks @petardz

Signed-off-by: Petar Dzepina <[email protected]>
Signed-off-by: Petar Dzepina <[email protected]>
const val PROPERTIES = "properties"
const val NESTED = "nested"
const val TYPE = "type"
const val INDEX_PATTERN_SUFFIX = "-000001"
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

Choose a reason for hiding this comment

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

Thanks

Assert.assertTrue(alerts.size == 1)

// Both monitors used same queryIndex. Since source index has close to limit amount of fields in mappings,
// we expect that creation of second monitor would rollover queryIndex
Copy link
Member

Choose a reason for hiding this comment

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

Wait is the expectation that the queryIndex is rolled over or not? It is not getting rolled over here.

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 comment was incorrect. I fixed it with new commit and added few more in other tests

Assert.assertTrue(alerts.size == 2)
}

fun `test queryIndex bwc`() {
Copy link
Member

Choose a reason for hiding this comment

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

Update name to test queryIndex bwc when index was not an alias

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

Signed-off-by: Petar Dzepina <[email protected]>
Signed-off-by: Petar Dzepina <[email protected]>
Signed-off-by: Petar Dzepina <[email protected]>
xContentRegistry,
settings
)

Copy link
Collaborator

Choose a reason for hiding this comment

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

are these objects needed? looks like lot of old alerting code is refactored into these classes?

this.settings = settings
}

suspend fun newInstance(monitor: Monitor, createWithRunContext: Boolean): MonitorMetadata {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is an unused method?

@sbcd90 sbcd90 merged commit 6f48746 into opensearch-project:main Dec 31, 2022
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.x 2.x
# Navigate to the new working tree
cd .worktrees/backport-2.x
# Create a new branch
git switch --create backport/backport-725-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 6f487462862d92def1334599c1d0aaad5201a270
# Push it to GitHub
git push --set-upstream origin backport/backport-725-to-2.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-725-to-2.x.

@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.3 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.3 2.3
# Navigate to the new working tree
cd .worktrees/backport-2.3
# Create a new branch
git switch --create backport/backport-725-to-2.3
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 6f487462862d92def1334599c1d0aaad5201a270
# Push it to GitHub
git push --set-upstream origin backport/backport-725-to-2.3
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.3

Then, create a pull request where the base branch is 2.3 and the compare/head branch is backport/backport-725-to-2.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants