Skip to content

Commit

Permalink
Merge branch 'master' of github.com:elastic/kibana into detections-fi…
Browse files Browse the repository at this point in the history
…x-import-rules
  • Loading branch information
XavierM committed Jan 31, 2020
2 parents a1b8c3e + 31fae25 commit 712a223
Show file tree
Hide file tree
Showing 72 changed files with 1,785 additions and 1,048 deletions.
14 changes: 7 additions & 7 deletions docs/visualize/timelion.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ image::images/timelion-create01.png[]
[[time-series-compare-data]]
==== Compare the data

To compare the two data sets, add another series with data from the previous hour, separated by a comma:
To compare the two data sets, add another series with data from the previous hour, separated by a comma:

[source,text]
----------------------------------
Expand Down Expand Up @@ -81,7 +81,7 @@ image::images/timelion-create03.png[]

[float]
[[time-series-title]]
==== Add a title
==== Add a title

Add a meaningful title:

Expand Down Expand Up @@ -169,7 +169,7 @@ Change the position and style of the legend:

[source,text]
----------------------------------
.es(offset=-1h,index=metricbeat-*, timefield='@timestamp', metric='avg:system.cpu.user.pct').label('last hour').lines(fill=1,width=0.5).color(gray), .es(index=metricbeat-*, timefield='@timestamp', metric='avg:system.cpu.user.pct').label('current hour').title('CPU usage over time').color(#1E90FF).legend(columns=2, position=nw) <1>
.es(offset=-1h,index=metricbeat-*, timefield='@timestamp', metric='avg:system.cpu.user.pct').label('last hour').lines(fill=1,width=0.5).color(gray), .es(index=metricbeat-*, timefield='@timestamp', metric='avg:system.cpu.user.pct').label('current hour').title('CPU usage over time').color(#1E90FF).legend(columns=2, position=nw) <1>
----------------------------------

<1> `.legend()` sets the position and style of the legend. In this example, `.legend(columns=2, position=nw)` places the legend in the north west position of the visualization with two columns.
Expand Down Expand Up @@ -210,7 +210,7 @@ Change how the data is displayed so that you can easily monitor the inbound traf
.es(index=metricbeat*, timefield=@timestamp, metric=max:system.network.in.bytes).derivative() <1>
----------------------------------

<1> `.derivative` plots the change in values over time.
<1> `.derivative` plots the change in values over time.

[role="screenshot"]
image::images/timelion-math02.png[]
Expand Down Expand Up @@ -240,7 +240,7 @@ To make the visualization easier to analyze, change the data metric from bytes t
.es(index=metricbeat*, timefield=@timestamp, metric=max:system.network.in.bytes).derivative().divide(1048576), .es(index=metricbeat*, timefield=@timestamp, metric=max:system.network.out.bytes).derivative().multiply(-1).divide(1048576) <1>
----------------------------------

<1> `.divide()` accepts the same input as `.multiply()`, then divides the data series by the defined divisor.
<1> `.divide()` accepts the same input as `.multiply()`, then divides the data series by the defined divisor.

[role="screenshot"]
image::images/timelion-math04.png[]
Expand All @@ -256,7 +256,7 @@ Customize and format the visualization using functions:
----------------------------------
.es(index=metricbeat*,
timefield=@timestamp,
metric=max:system.network.in.byte)
metric=max:system.network.in.bytes)
.derivative()
.divide(1048576)
.lines(fill=2, width=1)
Expand All @@ -270,7 +270,7 @@ Customize and format the visualization using functions:
.multiply(-1)
.divide(1048576)
.lines(fill=2, width=1) <3>
.color(blue) < <4>
.color(blue) <4>
.label("Outbound traffic")
.legend(columns=2, position=nw) <5>
----------------------------------
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"clean": {
"extraPatterns": [
"build",
"optimize",
"data/optimize",
"built_assets",
".eslintcache",
".node_binaries"
Expand Down
137 changes: 137 additions & 0 deletions src/core/MIGRATION_EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ APIs to their New Platform equivalents.
- [3. New Platform shim using New Platform router](#3-new-platform-shim-using-new-platform-router)
- [4. New Platform plugin](#4-new-platform-plugin)
- [Accessing Services](#accessing-services)
- [Migrating Hapi "pre" handlers](#migrating-hapi-pre-handlers)
- [Chrome](#chrome)
- [Updating an application navlink](#updating-application-navlink)
- [Chromeless Applications](#chromeless-applications)
Expand Down Expand Up @@ -450,6 +451,142 @@ class Plugin {
}
```
### Migrating Hapi "pre" handlers
In the Legacy Platform, routes could provide a "pre" option in their config to
register a function that should be run prior to the route handler. These
"pre" handlers allow routes to share some business logic that may do some
pre-work or validation. In Kibana, these are often used for license checks.
The Kibana Platform's HTTP interface does not provide this functionality,
however it is simple enough to port over using a higher-order function that can
wrap the route handler.
#### Simple example
In this simple example, a pre-handler is used to either abort the request with
an error or continue as normal. This is a simple "gate-keeping" pattern.
```ts
// Legacy pre-handler
const licensePreRouting = (request) => {
const licenseInfo = getMyPluginLicenseInfo(request.server.plugins.xpack_main);
if (!licenseInfo.isOneOf(['gold', 'platinum', 'trial'])) {
throw Boom.forbidden(`You don't have the right license for MyPlugin!`);
}
}

server.route({
method: 'GET',
path: '/api/my-plugin/do-something',
config: {
pre: [{ method: licensePreRouting }]
},
handler: (req) => {
return doSomethingInteresting();
}
})
```
In the Kibana Platform, the same functionality can be acheived by creating a
function that takes a route handler (or factory for a route handler) as an
argument and either invokes it in the successful case or returns an error
response in the failure case.
We'll call this a "high-order handler" similar to the "high-order component"
pattern common in the React ecosystem.
```ts
// New Platform high-order handler
const checkLicense = <P, Q, B>(
handler: RequestHandler<P, Q, B, RouteMethod>
): RequestHandler<P, Q, B, RouteMethod> => {
return (context, req, res) => {
const licenseInfo = getMyPluginLicenseInfo(context.licensing.license);

if (licenseInfo.hasAtLeast('gold')) {
return handler(context, req, res);
} else {
return res.forbidden({ body: `You don't have the right license for MyPlugin!` });
}
}
}

router.get(
{ path: '/api/my-plugin/do-something', validate: false },
checkLicense(async (context, req, res) => {
const results = doSomethingInteresting();
return res.ok({ body: results });
}),
)
```
#### Full Example
In some cases, the route handler may need access to data that the pre-handler
retrieves. In this case, you can utilize a handler _factory_ rather than a raw
handler.
```ts
// Legacy pre-handler
const licensePreRouting = (request) => {
const licenseInfo = getMyPluginLicenseInfo(request.server.plugins.xpack_main);
if (licenseInfo.isOneOf(['gold', 'platinum', 'trial'])) {
// In this case, the return value of the pre-handler is made available on
// whatever the 'assign' option is in the route config.
return licenseInfo;
} else {
// In this case, the route handler is never called and the user gets this
// error message
throw Boom.forbidden(`You don't have the right license for MyPlugin!`);
}
}

server.route({
method: 'GET',
path: '/api/my-plugin/do-something',
config: {
pre: [{ method: licensePreRouting, assign: 'licenseInfo' }]
},
handler: (req) => {
const licenseInfo = req.pre.licenseInfo;
return doSomethingInteresting(licenseInfo);
}
})
```
In many cases, it may be simpler to duplicate the function call
to retrieve the data again in the main handler. In this other cases, you can
utilize a handler _factory_ rather than a raw handler as the argument to your
high-order handler. This way the high-order handler can pass arbitrary arguments
to the route handler.
```ts
// New Platform high-order handler
const checkLicense = <P, Q, B>(
handlerFactory: (licenseInfo: MyPluginLicenseInfo) => RequestHandler<P, Q, B, RouteMethod>
): RequestHandler<P, Q, B, RouteMethod> => {
return (context, req, res) => {
const licenseInfo = getMyPluginLicenseInfo(context.licensing.license);

if (licenseInfo.hasAtLeast('gold')) {
const handler = handlerFactory(licenseInfo);
return handler(context, req, res);
} else {
return res.forbidden({ body: `You don't have the right license for MyPlugin!` });
}
}
}

router.get(
{ path: '/api/my-plugin/do-something', validate: false },
checkLicense(licenseInfo => async (context, req, res) => {
const results = doSomethingInteresting(licenseInfo);
return res.ok({ body: results });
}),
)
```
## Chrome
In the Legacy Platform, the `ui/chrome` import contained APIs for a very wide
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ kibana_vars=(
console.enabled
console.proxyConfig
console.proxyFilter
cpu.cgroup.path.override
cpuacct.cgroup.path.override
csp.rules
csp.strict
csp.warnLegacyBrowsers
elasticsearch.customHeaders
elasticsearch.hosts
elasticsearch.logQueries
Expand All @@ -30,6 +35,7 @@ kibana_vars=(
elasticsearch.sniffInterval
elasticsearch.sniffOnConnectionFault
elasticsearch.sniffOnStart
elasticsearch.ssl.alwaysPresentCertificate
elasticsearch.ssl.certificate
elasticsearch.ssl.certificateAuthorities
elasticsearch.ssl.key
Expand All @@ -42,9 +48,13 @@ kibana_vars=(
elasticsearch.startupTimeout
elasticsearch.username
i18n.locale
interpreter.enableInVisualize
kibana.autocompleteTerminateAfter
kibana.autocompleteTimeout
kibana.defaultAppId
kibana.index
logging.dest
logging.json
logging.quiet
logging.rotate.enabled
logging.rotate.everyBytes
Expand All @@ -55,18 +65,32 @@ kibana_vars=(
logging.useUTC
logging.verbose
map.includeElasticMapsService
map.proxyElasticMapsServiceInMaps
map.regionmap
map.tilemap.options.attribution
map.tilemap.options.maxZoom
map.tilemap.options.minZoom
map.tilemap.options.subdomains
map.tilemap.url
newsfeed.enabled
ops.interval
path.data
pid.file
regionmap
server.basePath
server.customResponseHeaders
server.compression.enabled
server.compression.referrerWhitelist
server.cors
server.cors.origin
server.defaultRoute
server.host
server.keepAliveTimeout
server.maxPayloadBytes
server.name
server.port
server.rewriteBasePath
server.socketTimeout
server.ssl.cert
server.ssl.certificate
server.ssl.certificateAuthorities
Expand All @@ -82,6 +106,7 @@ kibana_vars=(
server.ssl.truststore.password
server.ssl.redirectHttpFromPort
server.ssl.supportedProtocols
server.xsrf.disableProtection
server.xsrf.whitelist
status.allowAnonymous
status.v6ApiFormat
Expand All @@ -96,11 +121,13 @@ kibana_vars=(
xpack.apm.serviceMapEnabled
xpack.apm.ui.enabled
xpack.apm.ui.maxTraceItems
xpack.apm.ui.transactionGroupBucketSize
apm_oss.apmAgentConfigurationIndex
apm_oss.indexPattern
apm_oss.errorIndices
apm_oss.onboardingIndices
apm_oss.spanIndices
apm_oss.sourcemapIndices
apm_oss.transactionIndices
apm_oss.metricsIndices
xpack.canvas.enabled
Expand All @@ -116,6 +143,8 @@ kibana_vars=(
xpack.code.security.gitHostWhitelist
xpack.code.security.gitProtocolWhitelist
xpack.graph.enabled
xpack.graph.canEditDrillDownUrls
xpack.graph.savePolicy
xpack.grokdebugger.enabled
xpack.infra.enabled
xpack.infra.query.partitionFactor
Expand All @@ -128,11 +157,14 @@ kibana_vars=(
xpack.infra.sources.default.fields.timestamp
xpack.infra.sources.default.logAlias
xpack.infra.sources.default.metricAlias
xpack.license_management.enabled
xpack.ml.enabled
xpack.monitoring.cluster_alerts.email_notifications.email_address
xpack.monitoring.elasticsearch.password
xpack.monitoring.elasticsearch.pingTimeout
xpack.monitoring.elasticsearch.hosts
xpack.monitoring.elasticsearch.username
xpack.monitoring.elasticsearch.logFetchCount
xpack.monitoring.elasticsearch.ssl.certificateAuthorities
xpack.monitoring.elasticsearch.ssl.verificationMode
xpack.monitoring.enabled
Expand Down Expand Up @@ -166,6 +198,7 @@ kibana_vars=(
xpack.reporting.csv.maxSizeBytes
xpack.reporting.csv.scroll.duration
xpack.reporting.csv.scroll.size
xpack.reporting.capture.maxAttempts
xpack.reporting.enabled
xpack.reporting.encryptionKey
xpack.reporting.index
Expand All @@ -183,6 +216,8 @@ kibana_vars=(
xpack.reporting.queue.pollIntervalErrorMultiplier
xpack.reporting.queue.timeout
xpack.reporting.roles.allow
xpack.rollup.enabled
xpack.security.audit.enabled
xpack.searchprofiler.enabled
xpack.security.authc.providers
xpack.security.authc.oidc.realm
Expand All @@ -196,7 +231,10 @@ kibana_vars=(
xpack.security.session.idleTimeout
xpack.security.session.lifespan
xpack.security.loginAssistanceMessage
telemetry.allowChangingOptInStatus
telemetry.enabled
telemetry.optIn
telemetry.optInStatusUrl
telemetry.sendUsageFrom
)

Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data/common/es_query/kuery/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export interface KueryParseOptions {
startRule: string;
allowLeadingWildcards: boolean;
errorOnLuceneSyntax: boolean;
cursorSymbol?: string;
parseCursor?: boolean;
}

export { nodeTypes } from './node_types';
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/data/public/autocomplete/autocomplete_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,9 @@ export class AutocompleteService {
this.querySuggestionProviders.clear();
}
}

/** @public **/
export type AutocompleteSetup = ReturnType<AutocompleteService['setup']>;

/** @public **/
export type AutocompleteStart = ReturnType<AutocompleteService['start']>;
5 changes: 3 additions & 2 deletions src/plugins/data/public/autocomplete/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import * as autocomplete from './static';
export { AutocompleteService, AutocompleteSetup, AutocompleteStart } from './autocomplete_service';

export { AutocompleteService } from './autocomplete_service';
export { QuerySuggestion, QuerySuggestionType, QuerySuggestionsGetFn } from './types';
export { autocomplete };
Loading

0 comments on commit 712a223

Please sign in to comment.