Reporting integration

edit

Applications abide by a contract that reporting features use to determine the information that is required to request exports of data from Kibana, and how to generate and store the reports.

These pages document internal APIs and are not guaranteed to be supported across future versions of Kibana. However, these docs will be kept up-to-date to reflect the current implementation of Reporting integration in Kibana.

Reporting Export Types

edit

"Export Types" are pieces of code that plug into the Kibana Reporting framework, and are responsible for exporting data on behalf of a Kibana application. These pieces of code are implemented as TypeScript classes that extend an abstract base class, and implement methods for controlling the creation of report jobs, and asynchronously generating report contents. Their createJob methods handle requests to create report jobs, by accepting jobParams objects and returning "task payload" objects. Their runTask methods generate the report contents by accepting the task payload object created from the createJob function, which is then stored in a system index in Elasticsearch.

Share menu extensions

edit

X-Pack services, such as the reporting features, register with the share plugin of the Kibana platform to register additional actions available to make content shareable.

Generate a report job URL

edit

To generate a new reporting job, different export types require different jobParams objects, which are Rison-encoded and used as a jobParams query string variable in the Reporting generation endpoint URL. If you use the aforementioned Sharing plugin registrations then this detail will be abstracted away. If your application does not use the Share menu extensions, you will have to generate the URL and create a POST request to the URL.

Basic job parameters

edit

Certain fields of Reporting job parameters are required for every type of export.

interface BaseParams {
  title: string; 
  objectType: string; 
  browserTimezone: string; 
  version: string; 
};

The title for the report. This is shown in the listing of reports in Stack Management > Alerts and Insights > Reporting and used as the filename when the report is downloaded.

The objectType field is automatically added when using internal Reporting APIs. This value used for choosing an icon for the report job in the listing of reports in Kibana.

The browserTimezone field is automatically added when using internal Reporting APIs to craft the job parameters. This is used to correctly format time-based data in the user’s desired timezone.

The version field is automatically added when using internal Reporting APIs. This is used in cases where job parameters are reused after an upgrade of Kibana, and a migration may be needed.

CSV

edit
Job parameters of CsvSearchSource
edit

The export type to generate CSV reports and is available in Discover uses "search source" objects. This export type is called csv_searchsource in the code. A configuration for a CSV report job is represented with an interface that includes the BaseParams and the following fields. To create a request for a CSV report, these required job parameters are Rison encoded into a query string variable of the report generation URL:

interface JobParamsCSV {
  searchSource: SerializedSearchSourceFields; 
  columns?: string[]; 
};

An object of serialized data that internally represents a search object in Kibana. It will contain a reference to a DataView saved object.

An array of field names to include as columns in the CSV report.

Job parameters of CsvFromSavedObject
edit

A newer export type to generate CSV reports is available, currently only by API. This export type is called csv_v2 in the code.

interface JobParamsCsvFromSavedObject {
  locatorParams: LocatorParams[]; 
};

The locatorParams value is controlled by the Discover application and identifies a search loaded in Discover, including the selection of DataView, columns and filters. Only a single value in the array is permitted in the createJob method.

Job payload
edit

After the job parameters are received by the route handler for the report generation URL, an additional field is automatically added to the fields from job parameters:

interface TaskPayloadCSV {
  pagingStrategy: 'scan' | 'pit' 
}

The pagingStrategy value is taken from the value of the xpack.reporting.csv.scroll.strategy setting in kibana.yml and used to control how the runTask method pages through all of the data.

PDF and PNG

edit
Job parameters
edit

A configuration for a PDF or PNG report job is represented with an interface that includes the BaseParams and the following fields. To create a request for one of these report types, these required job parameters are encoded into a query string variable of the report generation URL:

interface BaseParamsPDFV2 {
  layout: {
    id: string; 
    dimensions: {
      height: number;
      width: number;
    };
  };
  locatorParams: LocatorParams[]; 
}

interface BaseParamsPNGV2 {
  layout: {
    id: string; 
    dimensions: {
      height: number;
      width: number;
    };
  };
  locatorParams: LocatorParams; 
}

The available layout.id options for PDF exports are preserve_layout, print, and canvas. These control how dashboard panels are captured and positioned into pages in the PDF file.

The locatorParams value is controlled by the application loaded in the browser for which a screenshot will be captured. The parameters to generate a PDF report allow an array of locatorParams to support multi-page PDF reports.

The only available layout.id option for PNG exports is preserve_layout.

The parameters to generate a PNG report allow a single value for locatorParams.

How applications make themselves screenshot-capable
edit

When generating the PDF, the headless browser launched by the Reporting export type runs a script that looks for a number of attributes in the DOM to determine which elements should have their screenshot taken and when the Visualizations are done rendering.

The print layout takes a screenshot of every element with the data-shared-item attribute and includes the individual screenshots in the PDF. The print layout also uses the data-title and data-description attributes on the same HTMLElement as the data-shared-item to specify the title and description.

The preserve layout takes a screenshot of the element with the data-shared-items-container attribute. Additionally, reporting will resize the element with the data-shared-items-container to be the size specified in the layout dimensions. The preserve layout also uses the data-title and data-description attributes on the HTMLElement with the data-shared-items-container attribute to specify the title/description for the entire PDF.

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

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.

Using POST URLs for debugging

edit

Developers can capture a POST URL from a reporting-capable application to access the jobParams query string variable in the public API report generation endpoint. The query string variable can be passed through a URL de-encoder and then passed through a Rison-to-JSON converter to make the job parameters human-readable.

If attempting to send requests to the POST URL to test generating a report, use a shell script containing the curl command that POSTs the request. This will avoid any unintentional character escaping that can happen if running the curl command in an interactive shell.