-
Notifications
You must be signed in to change notification settings - Fork 67
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
global: allow using an index prefix #145
global: allow using an index prefix #145
Conversation
0e45f34
to
054a3e1
Compare
This seems to be all that is needed. I'm changing the api of one of the utils methods, so this might break someone's code. |
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.
I think utils.build_index_name
is only used in the module, so changing the signature is probably ok.
One small issue I see is that the prefixing only applies to index names and not aliases... On the other hand, I think that ESonDemand, allowed creation of aliases even without using a prefix... (e.g. I managed to create esod_prefix-records-v1.0.0
and then the records
alias which pointed to it worked fine... Maybe the next guy that would try to create a records
alias would have issues ¯\_(ツ)_/¯
)
invenio_search/api.py
Outdated
kwargs.setdefault('index', getattr(self.Meta, 'index', None)) | ||
kwargs.setdefault( | ||
'index', | ||
current_app.config['SEARCH_INDEX_PREFIX'] + '-' + |
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.
Maybe it would be better if the dash (-
) was part of the SEARCH_INDEX_PREFIX
? I know it's how it's done by ESoD, but it will be hard to change in the future if somebody wants to do it differently
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.
Yep :), I just did that change locally, will push soon.
invenio_search/api.py
Outdated
@@ -83,7 +83,11 @@ class Meta: | |||
|
|||
def __init__(self, **kwargs): | |||
"""Use Meta to set kwargs defaults.""" | |||
kwargs.setdefault('index', getattr(self.Meta, 'index', None)) | |||
kwargs.setdefault( |
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.
There are currently two ways to perform queries to different indices using this class:
- Sub-classing and overriding
Meta.index
- Passing
index
explicitly as a keyword argument
The first case is of course covered... Though the usage of kwargs.setdefault
instead of setting the value directly is probably because of the fact that this constructor was written before the need for prefixing index names "magically" existed...
Maybe it would be better to make Meta.index
some kind of property which relies on some _index
field? @lnielsen WDYT?
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.
Locally I solved it by checking if the kwargs['index']
is prefixed, and if not then adding it (at some point there's also a list passed to it instead a string...)
054a3e1
to
6752274
Compare
6752274
to
562bca7
Compare
Btw. this current version does take care of the aliases too \o/ |
74f62a9
to
2e8e8bb
Compare
@@ -79,3 +79,5 @@ | |||
<https://www.elastic.co/guide/en/elasticsearch/reference/current/ | |||
search-request-min-score.html>`_ for more information. | |||
""" | |||
|
|||
SEARCH_INDEX_PREFIX = '' |
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.
I would have some documentation maybe here, as for the other config variables.
@slint agree that It would be also nice to update the doc and put there an example. |
2e8e8bb
to
f01f40d
Compare
Now using the setting `SEARCH_INDEX_PREFIX` you can define a prefix to use for all your indices. Signed-off-by: David Caro <[email protected]>
f01f40d
to
8a303a2
Compare
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 a lot for the PR. It's much appreciated and needed by everyone.
I'm ok with changing the signature of build_index_name
as long as it's properly documented in the CHANGES.rst once the new version is released (i.e. 1.1.0).
Regarding aliases, would you mind adding a quick test that demonstrates the prefix for aliases work as well.
Also, what about the ES templates, do they need prefixes as well?
:returns: A string with the new index name prefixed in needed. | ||
""" | ||
index_prefix = app.config['SEARCH_INDEX_PREFIX'] | ||
if index.startswith(index_prefix): |
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.
Which cases is this covering? Is it only when SEARCH_INDEX_PREFIX == ''
or are there other cases?
Example: If you decided to name your prefix records
and your index starts with records
I would still expect the final index name to be records-records
(might not make much sense, but it's consistent 😄).
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.
That is there because the libs at some point start doing nested calls passing the index string around, so if you have to make sure to prepend the perfix only once. Unfortunately, all the info you get is the index name string, so you can't add random info (like a boolean property prefixed
). But, if you want your indices to end up as record-record
the prefix should be record-
, with the last dash, and that will not really collide (unless you want record-record-something
). But I don't know how to prevent that from happening without changing substantially the code.
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.
Got it. Yeah, not much to do about it. Perhaps just add a quick comment in the code, that this line is there due to nested calls.
I'll try. So far the aliases and indices use the same function to get the names, and that one is the one that does the prefixing (
|
After some testing I see that the aliases have the prefix:
But for the templates if I understand correctly we'll need to add it, as after registering a sample one, it's registered in the following way:
|
We've been digging into the prefixing in the current Invenio sprint, and I'd like to discuss if it's worthwhile adding support for prefixing indexes. Template problem {
"template": "<prefix>-events-stats-record-view-*",
...
"aliases": {
"<prefix>-events-recordview": {}
}
} It's not clear, if it's only Workaround
Similar for templates, you can add your prefix inside the template JSON body manually. CERN Central Elasticsearch Service Shared Elasticsearch for multiple Invenio instances The down-side by using a shared Elasticsearch instance for multiple Invenio instances, is that each instance will have read/write access to all instances unless you add the expensive X-Pack from Elastic with support for authorization and permissions. OTOH you only need to operate one ES instance and thereby save resources. What to do? |
Something that this seems not to address is having multiple invenio instances on CERN Central Elasticsearch Service, as that would require duplicating all the mappings on two different subdirectories no? (for example, having a 'dev', a 'qa' and a 'prod' instances). |
Correct. The Another issue is that the support for templates in the central Elasticsearch service. Right now this is handled via a git repo instead of via the API. This would mean e.g. the statistics module won't be usable on the central service (or at least it will be rather cumbersome). I'm worried that prefixing is not robust enough to properly sandbox two Invenio instances running on the same ES cluster and make sure they don't interfere with each other in any way. |
I am closing this PR because it is outdated, the new PR is here: #156 |
Now using the setting
SEARCH_INDEX_PREFIX
you can define a prefix touse for all your indices.
This partially addresses #129
Signed-off-by: David Caro [email protected]