Skip to content

Commit

Permalink
Merge branch 'main' into 157721-hosts-view-flaky-test-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored May 16, 2023
2 parents d83ee12 + 7cab4ed commit ed59bee
Show file tree
Hide file tree
Showing 56 changed files with 1,182 additions and 214 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ packages/kbn-mapbox-gl @elastic/kibana-gis
x-pack/examples/third_party_maps_source_example @elastic/kibana-gis
src/plugins/maps_ems @elastic/kibana-gis
x-pack/plugins/maps @elastic/kibana-gis
x-pack/packages/maps/vector_tile_utils @elastic/kibana-gis
x-pack/packages/ml/agg_utils @elastic/ml-ui
x-pack/packages/ml/anomaly_utils @elastic/ml-ui
x-pack/packages/ml/date_picker @elastic/ml-ui
Expand Down
3 changes: 2 additions & 1 deletion docs/concepts/data-views.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ image::images/discover-data-view.png[How to set the {data-source} in Discover, w
. Give your {data-source} a name.

. Start typing in the *Index pattern* field, and {kib} looks for the names of
indices, data streams, and aliases that match your input.
indices, data streams, and aliases that match your input. You can
view all available sources or only the sources that the data view targets.
+
[role="screenshot"]
image:management/index-patterns/images/create-data-view.png["Create data view"]
Expand Down
2 changes: 1 addition & 1 deletion docs/discover/document-explorer.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Fine tune your explorations by customizing *Discover* to bring out the the best
Adjust the chart height, modify the document table, and look inside a document.

[role="screenshot"]
image:images/discover.png[A view of the Discover app]
image::images/hello-field.png[A view of the Discover app]


[float]
Expand Down
Binary file modified docs/discover/images/customer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/discover/images/discover-add-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/discover/images/discover-context.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/discover/images/discover-day-of-week.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/discover/images/discover-from-visualize.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/discover/images/discover-search-for-relevance.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/discover/images/discover-sidebar-available-fields.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/discover/images/document-explorer-compare-data.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/discover/images/document-explorer-row-height.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/discover/images/document-table-expanded.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/discover/images/document-table.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/discover/images/hello-field.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/management/index-patterns/images/create-data-view.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 15 additions & 5 deletions docs/user/discover.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,23 @@ that shows all the documents that match your search.
By default, the document table includes a column for the time field and a column that lists all other fields in the document.
You’ll modify the document table to display your fields of interest.

. In the sidebar, enter `ma` to in the search field to find the `manufacturer` field.
. In the sidebar, enter `ma` in the search field to find the `manufacturer` field.
+
[role="screenshot"]
image:images/discover-sidebar-available-fields.png[Fields list that displays the top five search results, width=50%]
+
NOTE: You can use wildcards in field searches. For example, `goe*dest` finds `geo.dest` and `geo.src.dest`.

. In the *Available fields* list, click `manufacturer` to view its most popular values.
+
**Discover** shows the top 10 values and the number of records used to calculate those values.

. Click image:images/add-icon.png[Add icon] to toggle the field into the document table.
You can also drag the field from the *Available fields* list into the document table.
+
[role="screenshot"]
image::images/discover-add-icon.png[How to add a field as a column in the table, width="50%"]


. Find the `customer_first_name` and `customer_last_name` fields and add
them to the document table. Your table should look similar to this:
+
Expand All @@ -111,15 +113,19 @@ column header, and then select *Move left* or *Move right*.
+
* To copy the name or values in a column to the clipboard, click the column header and select the desired **Copy** option.
+
* For keyboard shortcuts on the document table, click
image:images/keyboard-shortcut-icon.png[icon button for opening list of keyboard shortcuts, width=24px].
+
* To view more of the document table,
click
image:images/chart-icon.png[icon button for opening Show/Hide chart menu, width=24px]
to open the *Chart options* menu,
and then select *Hide chart*.
+
* For keyboard shortcuts on the document table, click
image:images/keyboard-shortcut-icon.png[icon button for opening list of keyboard shortcuts, width=24px].
+
* To set the row height to one or more lines, or automatically
adjust the height to fit the contents, click
image:images/row-height-icon.png[icon to open the Row height pop-up, width=24px].
+
* To toggle the table in and out of fullscreen mode, click the fullscreen icon
image:images/fullscreen-icon.png[icon to display the document table in fullscreen mode].

Expand Down Expand Up @@ -270,6 +276,10 @@ If a field can be {ref}/search-aggregations.html[aggregated], you can quickly
visualize it from **Discover**.

. In the sidebar, find and then click `day_of_week`.
+
[role="screenshot"]
image:images/discover-day-of-week.png[Top values for the day_of_week field, plus Visualize button, width=50%]


. In the popup, click **Visualize**.
+
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@
"@kbn/maps-custom-raster-source-plugin": "link:x-pack/examples/third_party_maps_source_example",
"@kbn/maps-ems-plugin": "link:src/plugins/maps_ems",
"@kbn/maps-plugin": "link:x-pack/plugins/maps",
"@kbn/maps-vector-tile-utils": "link:x-pack/packages/maps/vector_tile_utils",
"@kbn/ml-agg-utils": "link:x-pack/packages/ml/agg_utils",
"@kbn/ml-anomaly-utils": "link:x-pack/packages/ml/anomaly_utils",
"@kbn/ml-date-picker": "link:x-pack/packages/ml/date_picker",
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,8 @@
"@kbn/maps-ems-plugin/*": ["src/plugins/maps_ems/*"],
"@kbn/maps-plugin": ["x-pack/plugins/maps"],
"@kbn/maps-plugin/*": ["x-pack/plugins/maps/*"],
"@kbn/maps-vector-tile-utils": ["x-pack/packages/maps/vector_tile_utils"],
"@kbn/maps-vector-tile-utils/*": ["x-pack/packages/maps/vector_tile_utils/*"],
"@kbn/ml-agg-utils": ["x-pack/packages/ml/agg_utils"],
"@kbn/ml-agg-utils/*": ["x-pack/packages/ml/agg_utils/*"],
"@kbn/ml-anomaly-utils": ["x-pack/packages/ml/anomaly_utils"],
Expand Down
3 changes: 3 additions & 0 deletions x-pack/packages/maps/vector_tile_utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @kbn/maps-vector-tile-utils

Utility functions for vector tile API
8 changes: 8 additions & 0 deletions x-pack/packages/maps/vector_tile_utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export { getTileUrlParams } from './src/get_tile_url_params';
12 changes: 12 additions & 0 deletions x-pack/packages/maps/vector_tile_utils/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

module.exports = {
preset: '@kbn/test',
rootDir: '../../../..',
roots: ['<rootDir>/x-pack/packages/maps/vector_tile_utils'],
};
5 changes: 5 additions & 0 deletions x-pack/packages/maps/vector_tile_utils/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/maps-vector-tile-utils",
"owner": "@elastic/kibana-gis"
}
6 changes: 6 additions & 0 deletions x-pack/packages/maps/vector_tile_utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@kbn/maps-vector-tile-utils",
"private": true,
"version": "1.0.0",
"license": "Elastic License 2.0"
}
33 changes: 33 additions & 0 deletions x-pack/packages/maps/vector_tile_utils/src/get_tile_url_params.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import rison from '@kbn/rison';

export function getTileUrlParams(
params: Record<string, boolean | number | object | string | null | undefined>
) {
const urlSearchParams = new URLSearchParams();
Object.keys(params).forEach((key) => {
const value = params[key];
if (value === null || value === undefined) {
return;
}

if (typeof value === 'object') {
urlSearchParams.set(key, rison.encode(value));
return;
}

if (typeof value === 'number' || typeof value === 'boolean') {
urlSearchParams.set(key, value.toString());
}

urlSearchParams.set(key, value as string);
});

return urlSearchParams.toString();
}
21 changes: 21 additions & 0 deletions x-pack/packages/maps/vector_tile_utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": "../../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node",
"react"
]
},
"include": [
"**/*.ts",
"**/*.tsx",
],
"exclude": [
"target/**/*"
],
"kbn_references": [
"@kbn/rison",
]
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
# Query Debugging
# Elasticsearch query debugging (AKA Inspector)

When debugging an issue with the APM UI it can be very helpful to see the exact Elasticsearch queries and responses that was made for a given API request.
To enable debugging of Elasticsearch queries in APM UI do the following:
When debugging an issue within APM UI it can be very helpful to see the exact Elasticsearch queries and responses that was made for a specific page. This can be achieved by enabling the Inspector:

1. Go to "Stack Management"
2. Under "Kibana" on the left-hand side, select "Advanced Settings"
3. Search for "Observability"
4. Enable "Inspect ES queries" setting
5. Click "Save"
1. Open APM UI
2. Click "Settings" (top right corner)
3. Click "General Settings" tab
4. Enable "Inspect ES queries" and click "Save"

When you navigate back to APM UI you can now inspect Elasticsearch queries by opening your browser's Developer Tools and selecting an api request to APM's api.
There will be an `_inspect` key containing every Elasticsearch query made during that request including both requests and responses to and from Elasticsearch.
You will now be able to navigate to any page in APM UI, and see a new button in the top-right corner called "Inspect". Clicking this will open a fly-out listing all the requests made to Elasticsearch.

![apm-inspect2](https://github.com/elastic/kibana/assets/209966/ba5ebad9-cecc-4ed8-b6c6-9ffc0ce14c6d)

## Inspecting specific http endpoints

It is also possible to see the Elasticsearch queries made for a specific http endpoint. Again, navigate to the page making the request, then open your browser's Developer Tools and select the http request of interest. There will be an `_inspect` key in the response containing every Elasticsearch query made during that request including both requests and responses to and from Elasticsearch.

![image](https://user-images.githubusercontent.com/209966/140500012-b075adf0-8401-40fd-99f8-85b68711de17.png)

## Example

When "Inspect ES queries" are enabed all API calls to the APM API will be include the query param `_inspect=true`. For the environments API the request / response will be:




<details>
<summary>See example</summary>

```
GET /internal/apm/environments?start=<start>&end=<end>&_inspect=true
```
Expand Down Expand Up @@ -143,3 +150,6 @@ GET /internal/apm/environments?start=<start>&end=<end>&_inspect=true
]
}
```

</details>

Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React from 'react';

import { waitFor, fireEvent, act } from '@testing-library/react';
import type { RenderResult } from '@testing-library/react';

import { createFleetTestRendererMock } from '../../../../../../mock';
import type { TestRenderer } from '../../../../../../mock';

import { allowedExperimentalValues } from '../../../../../../../common/experimental_features';

import { ExperimentalFeaturesService } from '../../../../../../services/experimental_features';

import type { NewAgentPolicy, AgentPolicy } from '../../../../../../../common/types';

import { useLicense } from '../../../../../../hooks/use_license';

import type { LicenseService } from '../../../../../../../common/services';

import type { ValidationResults } from '../agent_policy_validation';

import { AgentPolicyAdvancedOptionsContent } from '.';

jest.mock('../../../../../../hooks/use_license');

const mockedUseLicence = useLicense as jest.MockedFunction<typeof useLicense>;

describe('Agent policy advanced options content', () => {
let testRender: TestRenderer;
let renderResult: RenderResult;

const mockAgentPolicy: Partial<NewAgentPolicy | AgentPolicy> = {
id: 'agent-policy-1',
name: 'some-agent-policy',
is_managed: false,
is_protected: false,
};

const mockUpdateAgentPolicy = jest.fn();
const mockValidation = jest.fn() as unknown as ValidationResults;
const usePlatinumLicense = () =>
mockedUseLicence.mockReturnValue({
hasAtLeast: () => true,
isPlatinum: () => true,
} as unknown as LicenseService);

const render = () => {
// remove when feature flag is removed
ExperimentalFeaturesService.init({
...allowedExperimentalValues,
agentTamperProtectionEnabled: true,
});

renderResult = testRender.render(
<AgentPolicyAdvancedOptionsContent
agentPolicy={mockAgentPolicy}
updateAgentPolicy={mockUpdateAgentPolicy}
validation={mockValidation}
/>
);
};

beforeEach(() => {
testRender = createFleetTestRendererMock();
});
afterEach(() => {
jest.resetAllMocks();
});

describe('Agent tamper protection toggle', () => {
it('should be visible if license is at least platinum', () => {
usePlatinumLicense();
render();
expect(renderResult.queryByTestId('tamperProtectionSwitch')).toBeInTheDocument();
});

it('should not be visible if license is below platinum', () => {
mockedUseLicence.mockReturnValueOnce({
isPlatinum: () => false,
hasAtLeast: () => false,
} as unknown as LicenseService);
render();
expect(renderResult.queryByTestId('tamperProtectionSwitch')).not.toBeInTheDocument();
});
it('switched to true enables the uninstall command link', async () => {
usePlatinumLicense();
render();
await act(async () => {
fireEvent.click(renderResult.getByTestId('tamperProtectionSwitch'));
});
waitFor(() => {
expect(renderResult.getByTestId('tamperProtectionSwitch')).toBeChecked();
expect(renderResult.getByTestId('uninstallCommandLink')).toBeEnabled();
});
});
it('switched to false disables the uninstall command link', () => {
usePlatinumLicense();
render();
expect(renderResult.getByTestId('tamperProtectionSwitch')).not.toBeChecked();
expect(renderResult.getByTestId('uninstallCommandLink')).toBeDisabled();
});
it('should update agent policy when switched on', async () => {
usePlatinumLicense();
render();
await act(async () => {
(await renderResult.findByTestId('tamperProtectionSwitch')).click();
});
expect(mockUpdateAgentPolicy).toHaveBeenCalledWith({ is_protected: true });
});
});
});
Loading

0 comments on commit ed59bee

Please sign in to comment.