Skip to content

Kibana client support#1243

Closed
delvedor wants to merge 5 commits intomasterfrom
kibana-client
Closed

Kibana client support#1243
delvedor wants to merge 5 commits intomasterfrom
kibana-client

Conversation

@delvedor
Copy link
Copy Markdown
Member

@delvedor delvedor commented Jul 2, 2020

Proposal for offering first-class support to Kibana.

Requirements

  • Avoid the creation of a wrapper
  • Some properties and methods of the client should not be accessed by mistake
    • transport
    • connectionPool
    • serializer
    • close
    • child
    • extend
    • on
    • once
    • emit
  • Simplified type definition (the work done in Export a kibana restricted type definition #1239 will merged here)
  • Ship the kibana type definition with the client
  • The chosen solution will be part of the testing suite of the client
  • Support of jest mocks

Implementation

Currently, the idea is that the Kibana client will extend the base Client and hide the properties that should not be accessed by plugin users.
The main counterargument of this approach is that if Kibana core needs to access these methods, we'll need to re-expose them via symbols, for example:

const kClose = Symbol('kibana-client-close')
class KibanaClient extends Client {
  get [kClose] () {
    return super.close
  }
}

const client = new KibanaClient()
client[kClose]()

A different solution is to exclude the properties we don't want to be accessed with a builder function.

const client = new Client(opts)
function buildKibanaClient () {
  return {
    ...client,
    transport: {
      request: client.transport.request.bind(client.transport)
    },
    connectionPool: undefined,
    serializer: undefined,
    close () {
      throw new errors.ElasticsearchClientError('Cannot access close method')
    }
  }
}

const kclient = buildKibanaClient()

In my opinion, the first method is more elegant, as it uses idiomatic JavaScript to solve the issue, but will require you to use symbols for accessing "private" APIs. The second method feels hackier, as we'll need to bind the client in some places, but it removes the need to use Symbols at all.

@elastic/kibana-platform what do you think?

* pros:
* - no need to use symbols in kibana core for accesssing properties
* cons:
* - hackier solution, it requires a lot of small adjustments for binding the client instance
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah. that looks rather fragile.

}

get transport () {
return this[kTransport]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it can be as simple as _transport instead of using Symbol. not 100% safe, but Symbol doesn't provide full safety either.

@delvedor
Copy link
Copy Markdown
Member Author

delvedor commented Jul 3, 2020

Closing in favor of #1239 for now as we decided to start simple and only ship a restricted type definition file.

@delvedor delvedor closed this Jul 3, 2020
@delvedor delvedor deleted the kibana-client branch October 21, 2020 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants