Skip to content

Commit

Permalink
Merge branch 'main' into apm/general-settings/add-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ElenaStoeva authored Feb 1, 2024
2 parents 57ebb14 + 2258b7e commit 3e9445f
Show file tree
Hide file tree
Showing 283 changed files with 7,288 additions and 2,865 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ xs=("$@")

# TODO: Safe to remove this after 2024-03-01 (https://github.com/elastic/kibana/issues/175904) - also clean up usages
uploadPrefix_old="gs://elastic-bekitzur-kibana-coverage-live/"
uploadPrefixWithTimeStamp_old="${uploadPrefix}${TIME_STAMP}/"
uploadPrefixWithTimeStamp_old="${uploadPrefix_old}${TIME_STAMP}/"

uploadPrefix="gs://elastic-kibana-coverage-live/"
uploadPrefixWithTimeStamp="${uploadPrefix}${TIME_STAMP}/"
Expand Down
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ packages/kbn-eslint-plugin-imports @elastic/kibana-operations
packages/kbn-eslint-plugin-telemetry @elastic/obs-knowledge-team
examples/eso_model_version_example @elastic/kibana-security
x-pack/test/encrypted_saved_objects_api_integration/plugins/api_consumer_plugin @elastic/kibana-security
packages/kbn-esql-utils @elastic/kibana-visualizations
packages/kbn-event-annotation-common @elastic/kibana-visualizations
packages/kbn-event-annotation-components @elastic/kibana-visualizations
src/plugins/event_annotation_listing @elastic/kibana-visualizations
Expand Down Expand Up @@ -529,6 +530,7 @@ x-pack/packages/maps/vector_tile_utils @elastic/kibana-gis
x-pack/plugins/metrics_data_access @elastic/obs-knowledge-team
x-pack/packages/ml/agg_utils @elastic/ml-ui
x-pack/packages/ml/anomaly_utils @elastic/ml-ui
x-pack/packages/ml/cancellable_search @elastic/ml-ui
x-pack/packages/ml/category_validator @elastic/ml-ui
x-pack/packages/ml/chi2test @elastic/ml-ui
x-pack/packages/ml/creation_wizard_utils @elastic/ml-ui
Expand Down
183 changes: 183 additions & 0 deletions docs/maps/clean-data.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
[role="xpack"]
[[maps-clean-your-data]]
=== Clean your data

// https://github.com/elastic/kibana/issues/135319

Geospatial fields in {es} have certain restrictions that need to be addressed before upload. On this section a few recipes will be presented to help troubleshooting common issues on this type of data.

[float]
==== Convert to GeoJSON or Shapefile

Use https://gdal.org/programs/ogr2ogr.html[ogr2ogr] (part of the https://gdal.org[GDAL/OGR] suite) to convert datasets into a GeoJSON or Esri Shapefile. For example, use the following commands to convert a GPX file into JSON:

[source,sh]
----
# Example GPX file from https://www.topografix.com/gpx_sample_files.asp
#
# Convert the GPX waypoints layer into a GeoJSON file
$ ogr2ogr \
-f GeoJSON "waypoints.geo.json" \ # Output format and file name
"fells_loop.gpx" \ # Input File Name
"waypoints" # Input Layer (usually same as file name)
# Extract the routes layer into a GeoJSON file
$ ogr2ogr -f "GeoJSON" "routes.geo.json" "fells_loop.gpx" "routes"
----

[float]
==== Convert to WGS84 Coordinate Reference System

{es} only supports WGS84 Coordinate Reference System. Use `ogr2ogr` to convert from other coordinate systems to WGS84.

On the following example, `ogr2ogr` transforms a shapefile from https://epsg.org/crs_4269/NAD83.html[NAD83] to https://epsg.org/crs_4326/WGS-84.html[WGS84]. The input CRS is detected automatically thanks to the `.prj` sidecar file in the source dataset.

[source,sh]
----
# Example NAD83 file from https://www2.census.gov/geo/tiger/GENZ2018/shp/cb_2018_us_county_5m.zip
#
# Convert the Census Counties shapefile to WGS84 (EPSG:4326)
$ ogr2ogr -f "Esri Shapefile" \
"cb_2018_us_county_5m.4326.shp" \ # Output file
-t_srs "EPSG:4326" \ # EPSG:4326 is the code for WGS84
"cb_2018_us_county_5m.shp" \ # Input file
"cb_2018_us_county_5m" # Input layer
----

[float]
==== Improve performance by breaking out complex geometries into one geometry per document

Sometimes geospatial datasets are composed by a small amount of geometries that contain a very large amount of individual part geometries. A good example of this situation is on detailed world country boundaries datasets where records for countries like Canada or Philippines have hundreds of small island geometries. Depending on the final usage of a dataset, you may want to break out this type of dataset to keep one geometry per document, considerably increasing the performance of your index.

[source,sh]
----
# Example NAD83 file from www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/2016/ler_000b16a_e.zip
#
# Check the number of input features
$ ogrinfo -summary ler_000b16a_e.shp ler_000b16a_e \
| grep "Feature Count"
Feature Count: 76
# Convert to WGS84 exploding the multiple geometries
$ ogr2ogr \
-f "Esri Shapefile" \
"ler_000b16a_e.4326-parts.shp" \ # Output file
-explodecollections \ # Convert multiparts into single records
-t_srs "EPSG:4326" \ # Transform to WGS84
"ler_000b16a_e.shp" \ # Input file
"ler_000b16a_e" # Input layer
# Check the number of geometries in the output file
# to confirm the 76 records are exploded into 27 thousand rows
$ ogrinfo -summary ler_000b16a_e.4326-parts.shp ler_000b16a_e.4326 \
| grep "Feature Count"
Feature Count: 27059
----

[WARNING]
====
A dataset containing records with a very large amount of parts as the one from the example above may even hang in {kib} Maps file uploader.
====

[float]
==== Reduce the precision

Some machine generated datasets are stored with more decimals than are strictly necessary. For reference, the GeoJSON RFC 7946 https://datatracker.ietf.org/doc/html/rfc7946#section-11.2[coordinate precision section] specifies six digits to be a common default to around 10 centimeters on the ground. The file uploader in the Maps application will automatically reduce the precision to 6 decimals but for big datasets it is better to do this before uploading.

`ogr2ogr` generates GeoJSON files with 7 decimal degrees when requesting `RFC7946` compliant files but using the `COORDINATE_PRECISION` https://gdal.org/drivers/vector/geojson.html#layer-creation-options[GeoJSON layer creation option] it can be downsized even more if that is OK for the usage of the data.

[source,sh]
----
# Example NAD83 file from https://www2.census.gov/geo/tiger/GENZ2018/shp/cb_2018_us_county_5m.zip
#
# Generate a 2008 GeoJSON file
$ ogr2ogr \
-f GeoJSON \
"cb_2018_us_county_5m.4326.geo.json" \ # Output file
-t_srs "EPSG:4326" \ # Convert to WGS84
-lco "RFC7946=NO" \ # Request a 2008 GeoJSON file
"cb_2018_us_county_5m.shp" \
"cb_2018_us_county_5m"
# Generate a RFC7946 GeoJSON file
$ ogr2ogr \
-f GeoJSON \
"cb_2018_us_county_5m.4326.RFC7946.geo.json" \ # Output file
-t_srs "EPSG:4326" \ # Convert to WGS84
-lco "RFC7946=YES" \ # Request a RFC7946 GeoJSON file
"cb_2018_us_county_5m.shp" \
"cb_2018_us_county_5m"
# Generate a RFC7946 GeoJSON file with just 5 decimal figures
$ ogr2ogr \
-f GeoJSON \
"cb_2018_us_county_5m.4326.RFC7946_mini.geo.json" \ # Output file
-t_srs "EPSG:4326" \ # Convert to WGS84
-lco "RFC7946=YES" \ # Request a RFC7946 GeoJSON file
-lco "COORDINATE_PRECISION=5" \ # Downsize to just 5 decimal positions
"cb_2018_us_county_5m.shp" \
"cb_2018_us_county_5m"
# Compare the disk size of the three output files
$ du -h cb_2018_us_county_5m.4326*.geo.json
7,4M cb_2018_us_county_5m.4326.geo.json
6,7M cb_2018_us_county_5m.4326.RFC7946.geo.json
6,1M cb_2018_us_county_5m.4326.RFC7946_mini.geo.json
----


[float]
==== Simplifying region datasets

Region datasets are polygon datasets where the boundaries of the documents don't overlap. This is common for administrative boundaries, land usage, and other continuous datasets. This type of datasets has the special feature that any geospatial operation modifying the lines of the polygons needs to be applied in the same way to the common sides of the polygons to avoid the generation of thin gap and overlap artifacts.

https://github.com/mbloch/mapshaper[`mapshaper`] is an excellent tool to work with this type of datasets as it understands datasets of this nature and works with them accordingly.

Depending on the usage of a region dataset, different geospatial precisions may be adequate. A world countries dataset that is displayed for the entire planet does not need the same precision as a map of the countries in the South Asian continent.

`mapshaper` offers a https://github.com/mbloch/mapshaper/wiki/Command-Reference#-simplify[`simplify`] command that accepts percentages, resolutions, and different simplification algorithms.

[source,sh]
----
# Example NAD83 file from https://www2.census.gov/geo/tiger/GENZ2018/shp/cb_2018_us_county_5m.zip
#
# Generate a baseline GeoJSON file from OGR
$ ogr2ogr \
-f GeoJSON "cb_2018_us_county_5m.ogr.geo.json" \
-t_srs "EPSG:4326" \
-lco RFC7946=YES \
"cb_2018_us_county_5m.shp" \
"cb_2018_us_county_5m"
# Simplify at different percentages with mapshaper
$ for pct in 10 50 75 99; do \
mapshaper \
-i "cb_2018_us_county_5m.shp" \ # Input file
-proj "EPSG:4326" \ # Output projection
-simplify "${pct}%" \ # Simplification
-o cb_2018_us_county_5m.mapshaper_${pct}.geo.json; \ # Output file
done
# Compare the size of the output files
$ du -h cb_2018_us_county_5m*.geo.json
2,0M cb_2018_us_county_5m.mapshaper_10.geo.json
4,1M cb_2018_us_county_5m.mapshaper_50.geo.json
5,3M cb_2018_us_county_5m.mapshaper_75.geo.json
6,7M cb_2018_us_county_5m.mapshaper_99.geo.json
6,7M cb_2018_us_county_5m.ogr.geo.json
----


[float]
==== Fixing incorrect geometries

The Maps application expects valid GeoJSON or Shapefile datasets. Apart from the mentioned CRS requirement, geometries need to be valid. Both `ogr2ogr` and `mapshaper` have options to try to fix invalid geometries:

* OGR https://gdal.org/programs/ogr2ogr.html#cmdoption-ogr2ogr-makevalid[`-makevalid`] option
* Mapshaper https://github.com/mbloch/mapshaper/wiki/Command-Reference#-clean[`-clean`] command


[float]
==== And so much more

`ogr2ogr` and `mapshaper` are excellent geospatial ETL (Extract Transform and Load) utilities that can do much more than viewed here. Reading the documentation in detail is worth investment to improve the quality of the datasets by removing unwanted fields, refining data types, validating value domains, etc. Finally, being command line utilities, both can be automated and added to QA pipelines.
1 change: 1 addition & 0 deletions docs/maps/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,6 @@ include::search.asciidoc[]
include::map-settings.asciidoc[]
include::connect-to-ems.asciidoc[]
include::import-geospatial-data.asciidoc[]
include::clean-data.asciidoc[]
include::indexing-geojson-data-tutorial.asciidoc[]
include::trouble-shooting.asciidoc[]
2 changes: 1 addition & 1 deletion docs/maps/trouble-shooting.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ Increase <<settings, `server.maxPayload`>> for large data views.
[float]
==== Custom tiles are not displayed
* When using a custom tile service, ensure your tile server has configured https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS[Cross-Origin Resource Sharing (CORS)] so tile requests from your {kib} domain have permission to access your tile server domain.
* Ensure custom vector and tile services have the required coordinate system. Vector data must use EPSG:4326 and tiles must use EPSG:3857.
* Ensure custom vector and tile services have the required coordinate system. Vector data must use EPSG:4326 and tiles must use EPSG:3857.
20 changes: 11 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@
"@kbn/es-ui-shared-plugin": "link:src/plugins/es_ui_shared",
"@kbn/eso-model-version-example": "link:examples/eso_model_version_example",
"@kbn/eso-plugin": "link:x-pack/test/encrypted_saved_objects_api_integration/plugins/api_consumer_plugin",
"@kbn/esql-utils": "link:packages/kbn-esql-utils",
"@kbn/event-annotation-common": "link:packages/kbn-event-annotation-common",
"@kbn/event-annotation-components": "link:packages/kbn-event-annotation-components",
"@kbn/event-annotation-listing-plugin": "link:src/plugins/event_annotation_listing",
Expand Down Expand Up @@ -549,6 +550,7 @@
"@kbn/metrics-data-access-plugin": "link:x-pack/plugins/metrics_data_access",
"@kbn/ml-agg-utils": "link:x-pack/packages/ml/agg_utils",
"@kbn/ml-anomaly-utils": "link:x-pack/packages/ml/anomaly_utils",
"@kbn/ml-cancellable-search": "link:x-pack/packages/ml/cancellable_search",
"@kbn/ml-category-validator": "link:x-pack/packages/ml/category_validator",
"@kbn/ml-chi2test": "link:x-pack/packages/ml/chi2test",
"@kbn/ml-creation-wizard-utils": "link:x-pack/packages/ml/creation_wizard_utils",
Expand Down Expand Up @@ -925,7 +927,7 @@
"css-box-model": "^1.2.1",
"css.escape": "^1.5.1",
"cuid": "^2.1.8",
"cypress-data-session": "^2.7.0",
"cypress-data-session": "^2.8.0",
"cytoscape": "^3.10.0",
"cytoscape-dagre": "^2.2.2",
"d3": "3.5.17",
Expand Down Expand Up @@ -1157,10 +1159,10 @@
"@babel/types": "^7.21.2",
"@bazel/ibazel": "^0.16.2",
"@bazel/typescript": "4.6.2",
"@cypress/code-coverage": "^3.10.0",
"@cypress/grep": "^3.1.5",
"@cypress/code-coverage": "^3.12.18",
"@cypress/grep": "^4.0.1",
"@cypress/snapshot": "^2.1.7",
"@cypress/webpack-preprocessor": "^5.12.2",
"@cypress/webpack-preprocessor": "^6.0.1",
"@elastic/eslint-plugin-eui": "0.0.2",
"@elastic/makelogs": "^6.1.1",
"@elastic/synthetics": "^1.5.0",
Expand Down Expand Up @@ -1528,11 +1530,11 @@
"cssnano": "^5.1.12",
"cssnano-preset-default": "^5.2.12",
"csstype": "^3.0.2",
"cypress": "^13.3.0",
"cypress": "^13.6.3",
"cypress-axe": "^1.5.0",
"cypress-file-upload": "^5.0.8",
"cypress-multi-reporters": "^1.6.3",
"cypress-real-events": "^1.10.3",
"cypress-multi-reporters": "^1.6.4",
"cypress-real-events": "^1.11.0",
"cypress-recurse": "^1.35.2",
"date-fns": "^2.29.3",
"debug": "^2.6.9",
Expand All @@ -1546,7 +1548,7 @@
"eslint-config-prettier": "^9.0.0",
"eslint-module-utils": "^2.8.0",
"eslint-plugin-ban": "^1.6.0",
"eslint-plugin-cypress": "^2.14.0",
"eslint-plugin-cypress": "^2.15.1",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.28.0",
"eslint-plugin-jest": "^27.2.3",
Expand All @@ -1565,7 +1567,7 @@
"faker": "^5.1.0",
"fetch-mock": "^7.3.9",
"file-loader": "^4.2.0",
"find-cypress-specs": "^1.35.1",
"find-cypress-specs": "^1.41.4",
"form-data": "^4.0.0",
"geckodriver": "^4.3.0",
"gulp-brotli": "^3.0.0",
Expand Down
1 change: 1 addition & 0 deletions packages/deeplinks/ml/deep_links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type LinkId =
| 'nodesOverview'
| 'nodes'
| 'memoryUsage'
| 'esqlDataVisualizer'
| 'dataVisualizer'
| 'fileUpload'
| 'indexDataVisualizer'
Expand Down
9 changes: 9 additions & 0 deletions packages/default-nav/ml/default_navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ export const defaultNavigation: MlNodeDefinition = {
);
},
},
{
title: i18n.translate('defaultNavigation.ml.esqlDataVisualizer', {
defaultMessage: 'ES|QL',
}),
link: 'ml:esqlDataVisualizer',
getIsActive: ({ pathNameSerialized, prepend }) => {
return pathNameSerialized.includes(prepend('/app/ml/datavisualizer/esql'));
},
},
{
title: i18n.translate('defaultNavigation.ml.dataComparison', {
defaultMessage: 'Data drift',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ const SecurityAlertOptional = rt.partial({
'ecs.version': schemaString,
'event.action': schemaString,
'event.kind': schemaString,
'host.asset.criticality': schemaString,
'kibana.alert.action_group': schemaString,
'kibana.alert.ancestors.rule': schemaString,
'kibana.alert.building_block_type': schemaString,
Expand Down Expand Up @@ -204,6 +205,7 @@ const SecurityAlertOptional = rt.partial({
'kibana.alert.workflow_user': schemaString,
'kibana.version': schemaString,
tags: schemaStringArray,
'user.asset.criticality': schemaString,
});

// prettier-ignore
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-es-query/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"kbn_references": [
"@kbn/utility-types",
"@kbn/i18n",
"@kbn/safer-lodash-set",
"@kbn/safer-lodash-set"
],
"exclude": [
"target/**/*",
Expand Down
4 changes: 4 additions & 0 deletions packages/kbn-esql-utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# @kbn/esql-utils

This package contains utilities for ES|QL.

9 changes: 9 additions & 0 deletions packages/kbn-esql-utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export { getESQLAdHocDataview } from './src';
13 changes: 13 additions & 0 deletions packages/kbn-esql-utils/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

module.exports = {
preset: '@kbn/test',
rootDir: '../..',
roots: ['<rootDir>/packages/kbn-esql-utils'],
};
5 changes: 5 additions & 0 deletions packages/kbn-esql-utils/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/esql-utils",
"owner": "@elastic/kibana-visualizations"
}
7 changes: 7 additions & 0 deletions packages/kbn-esql-utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@kbn/esql-utils",
"private": true,
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0",
"sideEffects": false
}
9 changes: 9 additions & 0 deletions packages/kbn-esql-utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export * from './utils';
Loading

0 comments on commit 3e9445f

Please sign in to comment.