Snap.Cluster.Namespace (Snap v0.14.0)
View SourceManages the namespacing of a cluster, so a cluster can be scoped to only operate on indexes with a specific prefix.
This is useful for a few purposes:
Running multiple instances of
Snap, across completely different applications, against a single cluster. You might not want do this in production, but it's useful to only run one ElasticSearch/OpenSearch server locally when working on multiple applications.Running multiple environments of the same application. You don't want your tests to blow away all your development data each time they run.
Running tests in parallel, so each test process cannot see or act upon indexes that another test is operating on. This gives you the benefits of
Ectostyle sandboxing, meaning your tests can run withasync: trueeven though ElasticSearch/OpenSearch doesn't support isolated transactions.
All of the convenience modules respect namespacing:
The low level HTTP API on Snap does not.
There are two types of namespace:
Config namespace
You can namespace the entire Snap.Cluster in the config. This is used to
achieve isolation at a per application and environment level.
For example, to isolate your development and test environments, set
index_namespace: "dev" in your dev config, and index_namespace: "test" in
your test config.
You might even want to isolate multiple applications on a per environment
basis, with index_namespace: "app1-dev", for example.
Process namespace
The process namespace is used to achieve isolation between parallel running tests. It's not likely you'll want to use this in other situations.
For more information, see Snap.Test.
Summary
Functions
Given an index, adds the namespace to the supplied index for the
Snap.Cluster in the currently running process.
Clears the previously set process namespace, if any.
Returns the previously set process namespace, if any.
Returns a boolean indicating whether the namespaced index is inside the currently defined namespace.
Given an index, returns the index namespace for the Snap.Cluster in the
currently running process.
Sets an index namespace for the currently running process.
Remove the namespace prefix from a namespaced index, returning the remainder.
Functions
Given an index, adds the namespace to the supplied index for the
Snap.Cluster in the currently running process.
Clears the previously set process namespace, if any.
Returns the previously set process namespace, if any.
Will walk up to an ancestor process if the current process doesn't have a namespace defined. This makes it easy to set a namespace in a test process, and ensuring that any child processes within the test also respect the namespace (e.g. LiveViews).
Returns a boolean indicating whether the namespaced index is inside the currently defined namespace.
Given an index, returns the index namespace for the Snap.Cluster in the
currently running process.
Sets an index namespace for the currently running process.
Remove the namespace prefix from a namespaced index, returning the remainder.