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

How to create custom MongoDB indexes #6280

Open
n-tanaka-idcf opened this issue Nov 18, 2024 · 3 comments
Open

How to create custom MongoDB indexes #6280

n-tanaka-idcf opened this issue Nov 18, 2024 · 3 comments

Comments

@n-tanaka-idcf
Copy link

  • I am trying to use ST2 REST API to get executions.
    • The request is as follows:
curl -s \
  -H 'Content-Type: application/json'
  -H "St2-Api-Key: ${ST2_API_KEY}"\
  -k 'localhost:80/api/v1/executions?offset=0&limit=100&parent=null'
  • This request takes about 5 to 8 seconds in our environment.

  • I checked the mongoDB's execution plan and found that the sorting process took a long time.

  • I created a following index to speed up the sorting process.

db.action_execution_d_b.createIndex({ parent: 1, start_timestamp: -1, 'action.ref': 1 }, { background: true })
  • The index has improved request speed. However, the created index is automatically deleted.
2024-11-15T03:22:50.069+0900 I ACCESS   [conn965898] Successfully authenticated as principal st2admin on st2 from client xxx.xxx.xxx.xxx:50468
2024-11-15T03:22:50.103+0900 I COMMAND  [conn965898] CMD: dropIndexes st2.action_execution_d_b
  • Then I have two questions
    • Is it a specification that user-created index is deleted?
    • Is there a way to prevent user-created index from being automatically deleted?
@chain312
Copy link
Contributor

The registration function will automatically clean up the mongo index, and you can add additional index passes in the code file below
st2common/st2common/models/db/action.py

@n-tanaka-idcf
Copy link
Author

Thank you for your response.

I added an index to st2common/models/db/execution.py and the index was created the next day and has been maintained to date!
It seems that ST2 periodically manages the index automatically, but is it possible to reflect changes in the files under models/db/ at any given time?

@chain312
Copy link
Contributor

chain312 commented Dec 2, 2024

I remember that the index will be rebuilt when the service is restarted. You can check the source code for this

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

No branches or pull requests

2 participants