Add external cluster support to skip ephemeral startup#76
Merged
Conversation
Adds the ability to skip starting a local ephemeral Elasticsearch cluster
when a remote cluster is already available. This dramatically reduces
integration test iteration time during development (no ~60s bootstrap wait).
## How it works
`ElasticsearchCluster<TConfiguration>.InitializeAsync()` now checks for an
external cluster before launching an ephemeral one. Resolution order:
1. `TryUseExternalCluster()` virtual method (programmatic hook)
2. `TEST_ELASTICSEARCH_URL` environment variable
3. Fall through to ephemeral startup (existing behavior)
## Environment variable usage (zero code changes)
```bash
# Point at a running cluster — no code changes needed
TEST_ELASTICSEARCH_URL=https://localhost:9200 dotnet run --project MyTests/
# With API key authentication
TEST_ELASTICSEARCH_URL=https://localhost:9200 \
TEST_ELASTICSEARCH_API_KEY=your-api-key-here \
dotnet run --project MyTests/
```
## Programmatic hook
Override `TryUseExternalCluster()` for custom logic (service discovery,
config files, per-developer overrides, etc.):
```csharp
public class MyTestCluster : ElasticsearchCluster
{
public MyTestCluster() : base(new ElasticsearchConfiguration("latest-9")) { }
protected override ExternalClusterConfiguration TryUseExternalCluster()
{
var url = Environment.GetEnvironmentVariable("MY_DEV_CLUSTER_URL");
if (string.IsNullOrEmpty(url))
return null; // fall through to ephemeral startup
return new ExternalClusterConfiguration(
new Uri(url),
Environment.GetEnvironmentVariable("MY_DEV_CLUSTER_KEY")
);
}
}
```
## Changes
- New `ExternalClusterConfiguration` class (URI + optional API key + connectivity
validation via GET `/`)
- `ElasticsearchCluster<TConfiguration>`:
- `TryUseExternalCluster()` — virtual hook, returns null by default
- `TEST_ELASTICSEARCH_URL` / `TEST_ELASTICSEARCH_API_KEY` env var detection
- `NodesUris()` override returns external URI when in external mode
- `DisposeAsync()` is a no-op for external clusters
- `IsExternal` / `ExternalApiKey` properties for inspection
- `ElasticsearchCluster` (non-generic): default `Client` auto-wires API key auth
- Complex example: added `ProgrammaticExternalCluster` demo, API key handling
in `TestGenericCluster`
- Updated READMEs for both Core and Elasticsearch packages
Co-authored-by: Cursor <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds the ability to skip starting a local ephemeral Elasticsearch cluster
when a remote cluster is already available. This dramatically reduces
integration test iteration time during development (no ~60s bootstrap wait).
How it works
ElasticsearchCluster<TConfiguration>.InitializeAsync()now checks for anexternal cluster before launching an ephemeral one. Resolution order:
TryUseExternalCluster()virtual method (programmatic hook)TEST_ELASTICSEARCH_URLenvironment variableEnvironment variable usage (zero code changes)
Programmatic hook
Override
TryUseExternalCluster()for custom logic (service discovery,config files, per-developer overrides, etc.):
Changes
ExternalClusterConfigurationclass (URI + optional API key + connectivityvalidation via GET
/)ElasticsearchCluster<TConfiguration>:TryUseExternalCluster()— virtual hook, returns null by defaultTEST_ELASTICSEARCH_URL/TEST_ELASTICSEARCH_API_KEYenv var detectionNodesUris()override returns external URI when in external modeDisposeAsync()is a no-op for external clustersIsExternal/ExternalApiKeyproperties for inspectionElasticsearchCluster(non-generic): defaultClientauto-wires API key authProgrammaticExternalClusterdemo, API key handlingin
TestGenericClusterCo-authored-by: Cursor [email protected]