Skip to content

Commit

Permalink
Migrate CCR to new ES JS client.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcenizal committed May 14, 2021
1 parent df47ae1 commit 78d822b
Show file tree
Hide file tree
Showing 36 changed files with 520 additions and 902 deletions.
9 changes: 5 additions & 4 deletions x-pack/plugins/cross_cluster_replication/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

You can run a local cluster and simulate a remote cluster within a single Kibana directory.

1. Start your "local" cluster by running `yarn es snapshot --license=trial` and `yarn start` to start Kibana.
2. Start your "remote" cluster by running `yarn es snapshot --license=trial -E cluster.name=europe -E transport.port=9400` in a separate terminal tab.
3. Index a document into your remote cluster by running `curl -X PUT http://elastic:changeme@localhost:9201/my-leader-index --data '{"settings":{"number_of_shards":1,"soft_deletes.enabled":true}}' --header "Content-Type: application/json"`.
Note that these settings are required for testing auto-follow pattern conflicts errors (see below).
1. Ensure Kibana isn't running so it doesn't load up any data into your cluster. Run `yarn es snapshot --license=trial` to install a fresh snapshot. Wait for ES to finish setting up.
2. Create a "remote" copy of your ES snapshot by running: `cp -R .es/8.0.0 .es/8.0.0-2`.
4. Start your "remote" cluster by running `.es/8.0.0-2/bin/elasticsearch -E cluster.name=europe -E transport.port=9400`.
4. Run `yarn start` to start Kibana.
5. Index a document into your remote cluster by running `curl -X PUT http://elastic:changeme@localhost:9201/my-leader-index --data '{"settings":{"number_of_shards":1,"soft_deletes.enabled":true}}' --header "Content-Type: application/json"`. Note that these settings are required for testing auto-follow pattern conflicts errors (see below).

Now you can create follower indices and auto-follow patterns to replicate the `my-leader-index`
index on the remote cluster that's available at `127.0.0.1:9400`.
Expand Down

This file was deleted.

This file was deleted.

35 changes: 5 additions & 30 deletions x-pack/plugins/cross_cluster_replication/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { first } from 'rxjs/operators';
import {
CoreSetup,
CoreStart,
ILegacyCustomClusterClient,
Plugin,
Logger,
PluginInitializerContext,
Expand All @@ -19,20 +18,12 @@ import {

import { Index } from '../../index_management/server';
import { PLUGIN } from '../common/constants';
import { SetupDependencies, StartDependencies, CcrRequestHandlerContext } from './types';
import { SetupDependencies, StartDependencies } from './types';
import { registerApiRoutes } from './routes';
import { elasticsearchJsPlugin } from './client/elasticsearch_ccr';
import { CrossClusterReplicationConfig } from './config';
import { License, isEsError } from './shared_imports';
import { formatEsError } from './lib/format_es_error';

async function getCustomEsClient(getStartServices: CoreSetup['getStartServices']) {
const [core] = await getStartServices();
// Extend the elasticsearchJs client with additional endpoints.
const esClientConfig = { plugins: [elasticsearchJsPlugin] };
return core.elasticsearch.legacy.createClient('crossClusterReplication', esClientConfig);
}
import { License, handleEsError } from './shared_imports';

// TODO replace deprecated ES client after Index Management is updated
const ccrDataEnricher = async (indicesList: Index[], callWithRequest: LegacyAPICaller) => {
if (!indicesList?.length) {
return indicesList;
Expand Down Expand Up @@ -66,7 +57,6 @@ export class CrossClusterReplicationServerPlugin implements Plugin<void, void, a
private readonly config$: Observable<CrossClusterReplicationConfig>;
private readonly license: License;
private readonly logger: Logger;
private ccrEsClient?: ILegacyCustomClusterClient;

constructor(initializerContext: PluginInitializerContext) {
this.logger = initializerContext.logger.get();
Expand Down Expand Up @@ -114,22 +104,11 @@ export class CrossClusterReplicationServerPlugin implements Plugin<void, void, a
],
});

http.registerRouteHandlerContext<CcrRequestHandlerContext, 'crossClusterReplication'>(
'crossClusterReplication',
async (ctx, request) => {
this.ccrEsClient = this.ccrEsClient ?? (await getCustomEsClient(getStartServices));
return {
client: this.ccrEsClient.asScoped(request),
};
}
);

registerApiRoutes({
router: http.createRouter(),
license: this.license,
lib: {
isEsError,
formatEsError,
handleEsError,
},
});
}
Expand All @@ -142,9 +121,5 @@ export class CrossClusterReplicationServerPlugin implements Plugin<void, void, a
});
}

stop() {
if (this.ccrEsClient) {
this.ccrEsClient.close();
}
}
stop() {}
}
Loading

0 comments on commit 78d822b

Please sign in to comment.