Skip to content

Commit b25e364

Browse files
authored
Merge branch 'main' into bug/trusted-apps-wildcard-warning-with-field-supports-matches-only
2 parents 5e257c1 + e364fee commit b25e364

72 files changed

Lines changed: 377 additions & 409 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/developer/architecture/development/csv-integration.asciidoc

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,43 @@
22
=== CSV
33

44
[float]
5-
==== Job parameters
6-
If integrating with Reporting via a custom UI, the following job parameters must be Rison encoded and posted to
7-
the aforementioned generate job url:
5+
==== Job parameters of CsvSearchSource
6+
The export type to generate CSV reports and is available in Discover uses "search source" objects. This export type is called
7+
`csv_searchsource` in the code. A configuration for a CSV report job is represented with an interface that includes the
8+
`BaseParams` and the following fields. To create a request for a CSV report, these required job parameters are Rison encoded into
9+
a query string variable of the report generation URL:
810

911
----
10-
interface jobParameters {
11-
type: string;
12-
title: string;
13-
searchRequest: {
14-
index: string;
15-
body: object;
16-
};
17-
fields: string[];
18-
metaFields: string[];
19-
conflictedTypesFields: string[];
20-
indexPatternId: string;
21-
}
12+
interface JobParamsCSV {
13+
searchSource: SerializedSearchSourceFields; <1>
14+
columns?: string[]; <2>
15+
};
2216
----
23-
24-
The `searchRequest.body` should abide by the {ref}/search-search.html[Elasticsearch Search Request Body] syntax
17+
<1> An object of serialized data that internally represents a search object in Kibana. It will contain a reference to a DataView
18+
saved object.
19+
<2> An array of field names to include as columns in the CSV report.
2520

2621
[float]
27-
==== `export-config` Directive
28-
If integrating with Reporting via the `export-config` directive, the AngularJS controller that contains the directive should expose
29-
the following methods and the `export-config` directive will POST them to the reporting API:
22+
==== Job parameters of CsvFromSavedObject
23+
A newer export type to generate CSV reports is available, currently only by API. This export type is called `csv_v2` in the code.
3024

3125
----
32-
interface sharingData {
33-
searchRequest: {
34-
index: string;
35-
body: object;
36-
};
37-
fields: string[];
38-
metaFields: string[];
39-
conflictedTypesFields: string[];
40-
indexPatternId: string;
41-
}
42-
43-
function getSharingData(): sharingData;
44-
45-
function getSharingType(): string;
26+
interface JobParamsCsvFromSavedObject {
27+
locatorParams: LocatorParams[]; <1>
28+
};
29+
----
30+
<1> The `locatorParams` value is controlled by the Discover application and identifies a search loaded in Discover, including the
31+
selection of DataView, columns and filters. Only a single value in the array is permitted in the `createJob` method.
4632

47-
function getSharingTitle() string;
33+
[float]
34+
==== Job payload
35+
After the job parameters are received by the route handler for the report generation URL, an additional field is automatically
36+
added to the fields from job parameters:
4837

4938
----
50-
51-
The `sharingData.searchRequest.body` should abide by the {ref}/search-search.html[{es} Search Request Body] syntax
39+
interface TaskPayloadCSV {
40+
pagingStrategy: 'scan' | 'pit' <1>
41+
}
42+
----
43+
<1> The `pagingStrategy` value is taken from the value of the `xpack.reporting.csv.scroll.strategy` setting in kibana.yml and used
44+
to control how the `runTask` method pages through all of the data.
Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
[role="xpack"]
22
[[reporting-integration]]
33
== Reporting integration
4-
Integrating a {kib} application with the {report-features} requires a minimum
5-
amount of code, and the goal is to not have to modify the reporting code as we
6-
add additional applications. Instead, applications abide by a contract that
7-
{report-features} use to determine the information that is required to export
8-
CSVs and PDFs.
4+
Applications abide by a contract that {report-features} use to determine the information that is required to request exports of
5+
data from {kib}, and how to generate and store the reports.
96

107
[IMPORTANT]
118
==============================================
@@ -14,16 +11,56 @@ However, these docs will be kept up-to-date to reflect the current implementatio
1411
==============================================
1512

1613
[float]
17-
[[reporting-nav-bar-extensions]]
14+
=== Reporting Export Types
15+
"Export Types" are pieces of code that plug into the {kib} Reporting framework, and are responsible for exporting data on behalf
16+
of a {kib} application. These pieces of code are implemented as TypeScript classes that extend an abstract base class, and
17+
implement methods for controlling the creation of report jobs, and asynchronously generating report contents. Their `createJob`
18+
methods handle requests to create report jobs, by accepting jobParams objects and returning "task payload" objects. Their
19+
`runTask` methods generate the report contents by accepting the task payload object created from the `createJob` function, which
20+
is then stored in a system index in Elasticsearch.
21+
22+
[float]
23+
[[reporting-share-service-registrations]]
1824
=== Share menu extensions
19-
X-Pack uses the `share` plugin of the Kibana platform to register actions in the share menu.
25+
X-Pack services, such as the {report-features}, register with the `share` plugin of the Kibana platform to register additional
26+
actions available to make content shareable.
27+
28+
[float]
29+
=== Generate a report job URL
30+
To generate a new reporting job, different export types require different `jobParams` objects, which are Rison-encoded and used as
31+
a `jobParams` query string variable in the Reporting generation endpoint URL. If you use the aforementioned
32+
<<reporting-share-service-registrations, Sharing plugin registrations>> then this detail will be abstracted away. If your
33+
application does not use the Share menu extensions, you will have to generate the URL and create a POST request to the URL.
2034

2135
[float]
22-
=== Generate job URL
23-
To generate a new reporting job, different export types require different `jobParams` that are Rison encoded into a URL
24-
that abide by the following convention: `/api/reporting/generate?jobParams=${rison.encode(jobParams)}`. If you use the
25-
aforementioned <<reporting-nav-bar-extensions, nav bar extensions>> then this detail will be abstracted away, but if you
26-
provide a custom UI for generating the report, you will have to generate the URL and create a POST request to the URL.
36+
=== Basic job parameters
37+
Certain fields of Reporting job parameters are required for every type of export.
38+
39+
----
40+
interface BaseParams {
41+
title: string; <1>
42+
objectType: string; <2>
43+
browserTimezone: string; <3>
44+
version: string; <4>
45+
};
46+
----
47+
<1> The `title` for the report. This is shown in the listing of reports in **Stack Management > Alerts and
48+
Insights > Reporting** and used as the filename when the report is downloaded.
49+
<2> The `objectType` field is automatically added when using internal Reporting APIs. This value used for choosing an icon for the
50+
report job in the listing of reports in {kib}.
51+
<3> The `browserTimezone` field is automatically added when using internal Reporting APIs to craft the job parameters. This is
52+
used to correctly format time-based data in the user's desired timezone.
53+
<4> The `version` field is automatically added when using internal Reporting APIs. This is used in cases where job parameters are
54+
reused after an upgrade of Kibana, and a migration may be needed.
2755

2856
include::csv-integration.asciidoc[]
2957
include::pdf-integration.asciidoc[]
58+
59+
=== Using POST URLs for debugging
60+
Developers can capture a POST URL from a reporting-capable application to access the `jobParams` query string variable in the
61+
public API report generation endpoint. The query string variable can be passed through a URL de-encoder and then passed through a
62+
Rison-to-JSON converter to make the job parameters human-readable.
63+
64+
If attempting to send requests to the POST URL to test generating a report, use a shell script containing the curl command that
65+
POSTs the request. This will avoid any unintentional character escaping that can happen if running the curl command in an
66+
interactive shell.
Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,47 @@
11
[float]
2-
=== PDF
2+
=== PDF and PNG
33

44
[float]
55
==== Job parameters
6-
If integrating with Reporting via a custom UI, the following job parameters must be Rison encoded and posted to
7-
the aforementioned generate job url:
6+
A configuration for a PDF or PNG report job is represented with an interface that includes the `BaseParams` and the following
7+
fields. To create a request for one of these report types, these required job parameters are encoded into a query string variable
8+
of the report generation URL:
89

910
----
10-
interface jobParameters {
11-
objectType: string;
12-
title: string;
13-
browserTimezone: string;
14-
relativeUrls: string[];
11+
interface BaseParamsPDFV2 {
1512
layout: {
16-
id: string;
13+
id: string; <1>
1714
dimensions: {
1815
height: number;
1916
width: number;
2017
};
2118
};
19+
locatorParams: LocatorParams[]; <2>
2220
}
23-
----
24-
25-
`jobParameters.browserTimezone` is a string that appears in the tz database
26-
`jobParameters.layout.id` presently only accepts "print" and "preserve_layout"
27-
`jobParameters.layout.dimensions` is only currently used by "preserve_layout"
28-
29-
[float]
30-
==== `export-config` directive
31-
If integrating with Reporting via the `export-config` directive, the AngularJS controller that contains
32-
the directive should expose the following methods and the `export-config` directive will POST them to the
33-
reporting API:
34-
35-
----
36-
37-
function getSharingType(): string;
38-
39-
function getSharingTitle(): string;
4021
22+
interface BaseParamsPNGV2 {
23+
layout: {
24+
id: string; <3>
25+
dimensions: {
26+
height: number;
27+
width: number;
28+
};
29+
};
30+
locatorParams: LocatorParams; <4>
31+
}
4132
----
42-
43-
The `export-config` directive will use the browser's current URL and timezone when generating the job
44-
parameters automatically. The `export-config` directive will also grab the height/width of the element
45-
with the `data-shared-items-container` attribute and use this as the dimensions.
33+
<1> The available `layout.id` options for PDF exports are `preserve_layout`, `print`, and `canvas`. These control how dashboard
34+
panels are captured and positioned into pages in the PDF file.
35+
<2> The `locatorParams` value is controlled by the application loaded in the browser for which a screenshot will be captured. The
36+
parameters to generate a PDF report allow an array of `locatorParams` to support multi-page PDF reports.
37+
<3> The only available `layout.id` option for PNG exports is `preserve_layout`.
38+
<4> The parameters to generate a PNG report allow a single value for `locatorParams`.
4639

4740
[float]
48-
==== Screenshot capturing attributes
49-
When generating the PDF, reporting looks for a number of attributes in the DOM to determine which elements
50-
should have their screenshot taken and when the Visualizations are done rendering.
41+
==== How applications make themselves screenshot-capable
42+
When generating the PDF, the headless browser launched by the Reporting export type runs a script that looks for a number of
43+
attributes in the DOM to determine which elements should have their screenshot taken and when the Visualizations are done
44+
rendering.
5145

5246
The print layout takes a screenshot of every element with the `data-shared-item` attribute and includes the
5347
individual screenshots in the PDF. The print layout also uses the `data-title` and `data-description`
@@ -58,10 +52,12 @@ reporting will resize the element with the `data-shared-items-container` to be t
5852
The preserve layout also uses the `data-title` and `data-description` attributes on the HTMLElement with the
5953
`data-shared-items-container` attribute to specify the title/description for the entire PDF.
6054

61-
Reporting needs to determine when all of the visualizations have completed rendering, so that it can begin taking screenshots.
62-
If there are multiple visualizations, the `data-shared-items-count` attribute should be specified to let Reporting know how
63-
many Visualizations to look for. Reporting will look at every element with the `data-shared-item` attribute and use the corresponding
64-
`data-render-complete` attribute and `renderComplete` events to listen for rendering to complete. When rendering is complete for a visualization
65-
the `data-render-complete` attribute should be set to "true" and it should dispatch a custom DOM `renderComplete` event.
55+
Reporting needs to determine when all of the visualizations have completed rendering, so that it can begin taking screenshots. If
56+
there are multiple visualizations, the `data-shared-items-count` attribute should be specified to let Reporting know how many
57+
Visualizations to look for. Reporting will look at every element with the `data-shared-item` attribute and use the corresponding
58+
`data-render-complete` attribute and `renderComplete` events to listen for rendering to complete. When rendering is complete for a
59+
visualization the `data-render-complete` attribute should be set to "true" and it should dispatch a custom DOM `renderComplete`
60+
event.
6661

67-
If the reporting job uses multiple URLs, before looking for any of the `data-shared-item` or `data-shared-items-count` attributes, it waits for a `data-shared-page` attribute that specifies which page is being loaded.
62+
If the reporting job uses multiple URLs, before looking for any of the `data-shared-item` or `data-shared-items-count` attributes,
63+
it waits for a `data-shared-page` attribute that specifies which page is being loaded.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
"@elastic/ecs": "^8.11.1",
107107
"@elastic/elasticsearch": "^8.12.2",
108108
"@elastic/ems-client": "8.5.1",
109-
"@elastic/eui": "93.5.1",
109+
"@elastic/eui": "93.5.2",
110110
"@elastic/filesaver": "1.1.2",
111111
"@elastic/node-crypto": "1.2.1",
112112
"@elastic/numeral": "^2.5.1",
@@ -1103,7 +1103,7 @@
11031103
"react-syntax-highlighter": "^15.3.1",
11041104
"react-use": "^15.3.8",
11051105
"react-virtualized": "^9.22.5",
1106-
"react-window": "^1.8.9",
1106+
"react-window": "^1.8.10",
11071107
"reduce-reducers": "^1.0.4",
11081108
"redux": "^4.2.1",
11091109
"redux-actions": "^2.6.5",
@@ -1490,7 +1490,7 @@
14901490
"@types/react-syntax-highlighter": "^15.4.0",
14911491
"@types/react-test-renderer": "^17.0.2",
14921492
"@types/react-virtualized": "^9.21.22",
1493-
"@types/react-window": "^1.8.5",
1493+
"@types/react-window": "^1.8.8",
14941494
"@types/redux-actions": "^2.6.1",
14951495
"@types/resolve": "^1.20.1",
14961496
"@types/seedrandom": ">=2.0.0 <4.0.0",

packages/shared-ux/router/impl/routes.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ import { Switch, useRouteMatch } from 'react-router-dom';
1313
import { Routes as ReactRouterRoutes, Route } from 'react-router-dom-v5-compat';
1414
import { Route as LegacyRoute, MatchPropagator } from './route';
1515

16+
type RouterElementChildren = Array<
17+
React.ReactElement<
18+
{
19+
path: string;
20+
render: Function;
21+
children: RouterElementChildren;
22+
component: Function;
23+
},
24+
string | React.JSXElementConstructor<unknown>
25+
>
26+
>;
27+
1628
export const Routes = ({
1729
legacySwitch = true,
1830
children,
@@ -26,24 +38,20 @@ export const Routes = ({
2638
<Switch>{children}</Switch>
2739
) : (
2840
<ReactRouterRoutes>
29-
{Children.map(children, (child) => {
41+
{Children.map(children as RouterElementChildren, (child) => {
3042
if (React.isValidElement(child) && child.type === LegacyRoute) {
3143
const path = replace(child?.props.path, match.url + '/', '');
3244
const renderFunction =
33-
// @ts-expect-error upgrade typescript v4.9.5
3445
typeof child?.props.children === 'function'
35-
? // @ts-expect-error upgrade typescript v4.9.5
36-
child?.props.children
37-
: // @ts-expect-error upgrade typescript v4.9.5
38-
child?.props.render;
46+
? child?.props.children
47+
: child?.props.render;
3948

4049
return (
4150
<Route
4251
path={path}
4352
element={
4453
<>
4554
<MatchPropagator />
46-
{/* @ts-expect-error upgrade typescript v4.9.5*/}
4755
{(child?.props?.component && <child.props.component />) ||
4856
(renderFunction && renderFunction()) ||
4957
children}

src/dev/license_checker/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export const LICENSE_OVERRIDES = {
8686
'jsts@1.6.2': ['Eclipse Distribution License - v 1.0'], // cf. https://github.com/bjornharrtell/jsts
8787
'@mapbox/jsonlint-lines-primitives@2.0.2': ['MIT'], // license in readme https://github.com/tmcw/jsonlint
8888
'@elastic/ems-client@8.5.1': ['Elastic License 2.0'],
89-
'@elastic/eui@93.5.1': ['SSPL-1.0 OR Elastic License 2.0'],
89+
'@elastic/eui@93.5.2': ['SSPL-1.0 OR Elastic License 2.0'],
9090
'language-subtag-registry@0.3.21': ['CC-BY-4.0'], // retired ODC‑By license https://github.com/mattcg/language-subtag-registry
9191
'buffers@0.1.1': ['MIT'], // license in importing module https://www.npmjs.com/package/binary
9292
'@bufbuild/protobuf@1.2.1': ['Apache-2.0'], // license (Apache-2.0 AND BSD-3-Clause)

src/plugins/files/server/routes/file_kind/enhance_router.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ export function enhanceRouter({ router, fileKind }: Args): FileKindRouter {
2626
const handlerWrapper: (handler: FileKindHandler) => FileKindHandler =
2727
(handler) => async (ctx, req, res) => {
2828
return handler(
29-
// @ts-expect-error upgrade typescript v4.9.5
30-
Object.create(ctx, { fileKind: { value: fileKind, enumerable: true, writeable: false } }),
29+
Object.create(ctx, { fileKind: { value: fileKind, enumerable: true, writable: false } }),
3130
req,
3231
res
3332
);

src/plugins/files/server/routes/types.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
*/
88

99
import type {
10-
RequestHandlerContext,
10+
HttpResponsePayload,
11+
IKibanaResponse,
1112
IRouter,
12-
RequestHandler,
13-
RouteMethod,
1413
KibanaResponseFactory,
15-
IKibanaResponse,
1614
Logger,
15+
RequestHandler,
16+
RequestHandlerContext,
17+
ResponseError,
18+
RouteMethod,
1719
} from '@kbn/core/server';
1820
import type { SecurityPluginStart } from '@kbn/security-plugin/server';
1921
import type { FileServiceStart } from '../file_service';
@@ -41,8 +43,9 @@ export type FilesRequestHandler<
4143
Method extends RouteMethod = any
4244
> = RequestHandler<P, Q, B, FilesRequestHandlerContext, Method, KibanaResponseFactory>;
4345

44-
// @ts-expect-error upgrade typescript v4.9.5
45-
export type AsyncResponse<T> = Promise<IKibanaResponse<T>>;
46+
export type AsyncResponse<T extends HttpResponsePayload | ResponseError = any> = Promise<
47+
IKibanaResponse<T>
48+
>;
4649

4750
export type CreateHandler<E extends AnyEndpoint> = FilesRequestHandler<
4851
E['inputs']['params'],

0 commit comments

Comments
 (0)