Skip to content

Custom elasticsearch configuration for custom clients #58132

@mshustov

Description

@mshustov

copied from #57655

Plugins are allowed to create a custom elasticsearch config that will be used for custom elasticsearch clients. Although I only found that monitoring allows to re-define elasticsearch config values.

// monitoring_config
import { elasticsearchSchema } from 'src/core/server';
const schema = elasticsearchSchema;
// monitoring_plugin
const config$ = config.create().pipe(map(rawConfig => new ElasticsearchConfig(rawConfig)));
// note all this logic belongs to elasticsearch service so far
const client$ = config$.pipe(map(config => elasticsearch.createClient('monitoring', config));

The current implementation is the most straightforward and there are several things that I don't like:

  • exporting elasticsearch schema and ElasticsearchConfig class increases API surface
  • elasticsearch schema and ElasticsearchConfig are tightly coupled and could not be used separately, which is not obvious.
  • it's easy to misuse config$ and ignore config updates.
  • @kbn/config-schema doesn't allow to re-write validation rules locally. YAGNI, but I can imagine such a requirement in the future.

I think we can live with it for some time, but I assume we may want to refactor this part. To get rid of ElasticsearchConfig class to move elasticsearch config validation to the platform, for example.

// elasticsearch config
const elasticsearchSchema = schema.object({
   //...
  clients: schema.recordOf(schema.string(), elasticsearchSchema);
});
// kibana.yml
elasticsearch.clients.monitoring.requestTimeout: 30000
// monitoring_plugin
const client$ = elasticsearch.getClient('monitoring'));

@joshdover suggested to refactor createClusterClient to consume config$:

// on ElasticsearchSetup
// This would automatically swap out client instances under-the-hood just like
// dataClient
createClusterClient(config$: Observable<ElasticsearchConfigType>): ClusterClient;

// in plugin code

export const config = {
  schema: schema.object({
    monitoringCluster: coreConfig.elasticsearch.schema
  })
}

class Plugin {a
  setup(core) {
    const monitoringCluster = core.elasticsearch.createClusterClient$(
      this.config$.pipe(map(c => c.monitoringCluster))
    );
  }
}

However, it still requires exporting elasticsearch config schema & ElasticsearchConfigClass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Feature:New PlatformTeam:CorePlatform Core services: plugins, logging, config, saved objects, http, ES client, i18n, etc t//discuss

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions