-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tim Roes
committed
May 9, 2018
1 parent
c8b8027
commit 52fcd66
Showing
56 changed files
with
2,264 additions
and
90 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* This function collects statistics from a SearchSource and a response | ||
* for the usage in the inspector stats panel. Pass in a searchSource and a response | ||
* and the returned object can be passed to the `stats` method of the request | ||
* logger. | ||
*/ | ||
function getRequestInspectorStats(searchSource) { | ||
const stats = {}; | ||
const index = searchSource.get('index'); | ||
|
||
if (index) { | ||
stats['Index Pattern Title'] = { | ||
value: index.title, | ||
description: 'The index pattern against which this query was executed.', | ||
}; | ||
stats ['Index Pattern ID'] = { | ||
value: index.id, | ||
description: 'The ID of the saved index pattern object in the .kibana index.', | ||
}; | ||
} | ||
|
||
return stats; | ||
} | ||
|
||
function getResponseInspectorStats(searchSource, resp) { | ||
const lastRequest = searchSource.history && searchSource.history[searchSource.history.length - 1]; | ||
const stats = {}; | ||
|
||
if (resp && resp.took) { | ||
stats['Query Time'] = { | ||
value: `${resp.took}ms`, | ||
description: `The time it took Elasticsearch to process the query. | ||
This does not include the time it takes to send the request to Elasticsearch | ||
or parse it in the browser.`, | ||
}; | ||
} | ||
|
||
if (resp && resp.hits) { | ||
stats.Hits = { | ||
value: `${resp.hits.total}`, | ||
description: 'The total number of documents that matched the query.', | ||
}; | ||
} | ||
|
||
if (lastRequest && (lastRequest.ms === 0 || lastRequest.ms)) { | ||
stats['Request time'] = { | ||
value: `${lastRequest.ms}ms`, | ||
}; | ||
} | ||
|
||
return stats; | ||
} | ||
|
||
export { getRequestInspectorStats, getResponseInspectorStats }; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
# Inspector | ||
|
||
The inspector is a contextual tool to gain insights into different elements | ||
in Kibana, e.g. visualizations. It has the form of a flyout panel. | ||
|
||
## Inspector Views | ||
|
||
The "Inspector Panel" can have multiple so called "Inspector Views" inside of it. | ||
These views are used to gain different information into the element you are inspecting. | ||
There is a request inspector view to gain information in the requests done for this | ||
element or a data inspector view to inspect the underlying data. Whether or not | ||
a specific view is available depends on the used adapters. | ||
|
||
## Inspector Adapters | ||
|
||
Since the Inspector panel itself is not tight to a specific type of elements (visualizations, | ||
saved searches, etc.), everything you need to open the inspector is a collection | ||
of so called inspector adapters. A single adapter can be any type of JavaScript class. | ||
|
||
Most likely an adapter offers some kind of logging capabilities for the element, that | ||
uses it e.g. the request adapter allows element (like visualizations) to log requests | ||
they make. | ||
|
||
The corresponding inspector view will then use the information inside the adapter | ||
to present the data in the panel. That concept allows different types of elements | ||
to use the Inspector panel, while they can use completely or partial different adapters | ||
and inspector views than other elements. | ||
|
||
For example a visualization could provide the request and data adapter while a saved | ||
search could only provide the request adapter and a Vega visualization could additionally | ||
provide a Vega adapter. | ||
|
||
There is no 1 to 1 relationship between adapters and views. An adapter could be used | ||
by multiple views and a view can use data from multiple adapters. It's up to the | ||
view to decide whether or not it wants to be shown for a given adapters list. | ||
|
||
## Develop custom inspectors | ||
|
||
You can extend the inspector panel by adding custom inspector views and inspector | ||
adapters via a plugin. | ||
|
||
### Develop inspector views | ||
|
||
To develop custom inspector views you should first register your file via `uiExports` | ||
in your plugin config: | ||
|
||
```js | ||
export default (kibana) => { | ||
return new kibana.Plugin({ | ||
uiExports: { | ||
inspectorViews: [ 'plugins/your_plugin/custom_view' ], | ||
} | ||
}); | ||
}; | ||
``` | ||
|
||
Within the `custom_view.js` file in your `public` folder, you can define your | ||
inspector view as follows: | ||
|
||
```js | ||
import React from 'react'; | ||
import { InspectorView, viewRegistry } from 'ui/inspector'; | ||
|
||
function MyInspectorComponent(props) { | ||
// props.adapters is the object of all adapters and may vary depending | ||
// on who and where this inspector was opened. You should check for all | ||
// adapters you need, in the below shouldShow method, before accessing | ||
// them here. | ||
return ( | ||
<InspectorView> | ||
{ /* Always use InspectorView as the wrapping element! */ } | ||
</InspectorView> | ||
); | ||
} | ||
|
||
const MyLittleInspectorView = { | ||
// Title shown to select this view | ||
title: 'Display Name', | ||
// An icon id from the EUI icon list | ||
icon: 'iconName', | ||
// An order to sort the views (lower means first) | ||
order: 10, | ||
// An additional helptext, that wil | ||
help: `And additional help text, that will be shown in the inspector help.`, | ||
shouldShow(adapters) { | ||
// Only show if `someAdapter` is available. Make sure to check for | ||
// all adapters that you want to access in your view later on and | ||
// any additional condition you want to be true to be shown. | ||
return adapters.someAdapter; | ||
}, | ||
// A React component, that will be used for rendering | ||
component: MyInspectorComponent | ||
}; | ||
|
||
viewRegistry.register(MyLittleInspectorView); | ||
``` | ||
|
||
### Develop custom adapters | ||
|
||
An inspector adapter is just a plain JavaScript class, that can e.g. be attached | ||
to custom visualization types, so an inspector view can show additional information for this | ||
visualization. | ||
|
||
To add additional adapters to your visualization type, use the `inspectorAdapters.custom` | ||
object when defining the visualization type: | ||
|
||
```js | ||
class MyCustomInspectorAdapter { | ||
// .... | ||
} | ||
|
||
// inside your visualization type description (usually passed to VisFactory.create...Type) | ||
{ | ||
// ... | ||
inspectorAdapters: { | ||
custom: { | ||
someAdaoter: MyCustomInspectorAdapter | ||
} | ||
} | ||
} | ||
``` | ||
|
||
An instance of MyCustomInspectorAdapter will now be available on each visualization | ||
of that type and can be accessed via `vis.API.inspectorAdapters.someInspector`. | ||
|
||
Custom inspector views can now check for the presence of `adapters.someAdapter` | ||
in their `shouldShow` method and use this adapter in their component. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import EventEmitter from 'events'; | ||
|
||
class DataAdapter extends EventEmitter { | ||
|
||
setTabularLoader(callback) { | ||
this._tabular = callback; | ||
this.emit('change', 'tabular'); | ||
} | ||
|
||
getTabular() { | ||
return Promise.resolve(this._tabular ? this._tabular() : null); | ||
} | ||
|
||
} | ||
|
||
export { DataAdapter }; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { DataAdapter } from './data_adapter'; | ||
export { RequestAdapter, RequestStatus } from './request_adapter'; |
Oops, something went wrong.