kibana/packages/kbn-mapbox-gl/index.ts
Nathan Reese 30c17e0222
[maps] fix layer shows no data instead of error (#170084)
Closes https://github.com/elastic/kibana/issues/169545
Closes https://github.com/elastic/kibana/issues/170657

While investigating https://github.com/elastic/kibana/issues/169545, it
was determined that Maps current error handling leaves a lot to be
desired. This PR cleans up several problems at once since they are all
intertwined.

#### Problem 1 - layer error removed when another data request finished
Redux store contains error state in a single location, `__errorMessage`
key in `LayerDescriptor`. This resulted in other operations, like
"fitting to bounds", "fetching supports feature state", or "fetching
style meta" clearing layer error state.

#### Solution to problem 1
Redux store updated to contain isolated error state
1) `error` key added `DataRequestDescriptor`, allowing each data request
to store independent error state. This will capture data fetching errors
when fetching features and join metrics.
2) `error` key added to `JoinDescriptor`, allowing each join to store
independent error state. This will capture join errors like mismatched
join keys
3) `__tileErrors` added to `LayerDescriptor`, allowing each tile error
to be stored independently. This will capture tile fetch errors.

#### Problem 2 - tile status tracker clears error cache when map center
tile changes
This resulted in removing tile errors that may still be relevant if
tiles have not been refetched.

#### Solution to problem 2
Updated tile status tracker to only clear a tile error when the tile is
reloaded.

#### Problem 3 - Tile Errors do not surface elasticsearch ErrorCause
This results in useless error messages like in the screen shot below
<img width="300" alt="Screenshot 2023-11-01 at 2 39 01 PM"
src="75546228-24c6-4855-bea7-39ed421ee3f4">

#### Solution to problem 3
Updated tile status tracker to read and persist elasticsearch ErrorCause
from tile error. Now tile error messages contain more relevant
information about the problem.
<img width="200" alt="Screenshot 2023-11-03 at 9 56 41 AM"
src="b9ddff98-049e-4f22-8249-3f5988fa93a5">

#### Problem 4 - error UI is not interactive when layer editor is not
available, in dashboards or read only user

#### Solution to problem 4
* Updated layer tooltip to only display error title
<img width="200" alt="Screenshot 2023-11-03 at 11 22 50 AM"
src="6943aead-a7d6-4da3-8ecc-bb6065e0406a">
* Moved error callout from editor to legend so its visible when map is
in dashboard and by readonly users.
<img width="200" alt="Screenshot 2023-11-03 at 11 23 45 AM"
src="358fe133-4c5a-4f06-a03e-e96a16b7afb6">

Moving error details from tooltip to legend allowed error details to
contain interactive elements. For example, display a tile picker so that
users can see each tile's error. This will be useful in the future where
search source requests can display "view details" button that opens
request in inspector.

#### Problem 5 - error UI displayed as warning
This results in inconsistent view between kibana applications

#### Solution to problem 5
Updated error UI to use danger callout and error icon

### test instructions
1) install sample web logs
2) create map
3) add documents layer with vector tiles scaling
4) add documents layer with geojson scaling
5) add join layer
6) add filter
    ```
    {
      "error_query": {
        "indices": [
          {
            "error_type": "exception",
            "message": "local shard failure message 123",
            "name": "kibana_sample_data_logs"
          }
        ]
      }
    }
    ```

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2023-11-06 17:00:15 -07:00

69 lines
1.6 KiB
TypeScript

/*
* 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.
*/
import type {
AJAXError,
Map,
LayerSpecification,
Source,
GeoJSONSource,
VectorTileSource,
RasterTileSource,
SourceSpecification,
StyleSpecification,
MapEvent,
MapOptions,
MapMouseEvent,
MapSourceDataEvent,
LngLat,
LngLatBounds,
Point2D,
PointLike,
MapGeoJSONFeature,
CustomLayerInterface,
FilterSpecification,
FeatureIdentifier,
} from 'maplibre-gl';
// @ts-expect-error
import maplibreglDist from 'maplibre-gl/dist/maplibre-gl-csp';
// @ts-expect-error
import mbRtlPlugin from '!!file-loader!@mapbox/mapbox-gl-rtl-text/mapbox-gl-rtl-text.min.js';
// @ts-expect-error
import mbWorkerUrl from '!!file-loader!maplibre-gl/dist/maplibre-gl-csp-worker';
import 'maplibre-gl/dist/maplibre-gl.css';
const maplibregl: any = maplibreglDist;
maplibregl.workerUrl = mbWorkerUrl;
maplibregl.setRTLTextPlugin(mbRtlPlugin);
export { maplibregl };
export type {
AJAXError,
Map,
LayerSpecification,
SourceSpecification,
StyleSpecification,
Source,
GeoJSONSource,
VectorTileSource,
RasterTileSource,
MapEvent,
MapOptions,
MapMouseEvent,
MapSourceDataEvent,
LngLat,
LngLatBounds,
Point2D,
PointLike,
MapGeoJSONFeature,
CustomLayerInterface,
FilterSpecification,
FeatureIdentifier,
};