Commit graph

450 commits

Author SHA1 Message Date
Christos Nasikas
56d8eb179d
[8.11] [Cases] Unskip MKI tests (#168924) (#169616)
# Backport

This will backport the following commits from `main` to `8.11`:
- [[Cases] Unskip MKI tests
(#168924)](https://github.com/elastic/kibana/pull/168924)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Christos
Nasikas","email":"christos.nasikas@elastic.co"},"sourceCommit":{"committedDate":"2023-10-23T09:21:25Z","message":"[Cases]
Unskip MKI tests (#168924)\n\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"2146a7ef1634a06cf6b4b70edc55dd22fd5b6a4c","branchLabelMapping":{"^v8.12.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:skip","Team:ResponseOps","Feature:Cases","ci:skip-cypress-osquery","v8.11.0","v8.12.0"],"number":168924,"url":"https://github.com/elastic/kibana/pull/168924","mergeCommit":{"message":"[Cases]
Unskip MKI tests (#168924)\n\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"2146a7ef1634a06cf6b4b70edc55dd22fd5b6a4c"}},"sourceBranch":"main","suggestedTargetBranches":["8.11"],"targetPullRequestStates":[{"branch":"8.11","label":"v8.11.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.12.0","labelRegex":"^v8.12.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/168924","number":168924,"mergeCommit":{"message":"[Cases]
Unskip MKI tests (#168924)\n\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"2146a7ef1634a06cf6b4b70edc55dd22fd5b6a4c"}}]}]
BACKPORT-->
2023-10-24 05:32:10 -07:00
Kibana Machine
f7b1c0f7d8
[8.11] [OpenAI Connector] Track token count for streaming responses (#168440) (#169228)
# Backport

This will backport the following commits from `main` to `8.11`:
- [[OpenAI Connector] Track token count for streaming responses
(#168440)](https://github.com/elastic/kibana/pull/168440)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Dario
Gieselaar","email":"dario.gieselaar@elastic.co"},"sourceCommit":{"committedDate":"2023-10-18T12:04:21Z","message":"[OpenAI
Connector] Track token count for streaming responses
(#168440)\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"980e0cc70452897f6271288bdd0ba7b0085731c3","branchLabelMapping":{"^v8.12.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:enhancement","v8.11.0","v8.12.0","v8.11.1"],"number":168440,"url":"https://github.com/elastic/kibana/pull/168440","mergeCommit":{"message":"[OpenAI
Connector] Track token count for streaming responses
(#168440)\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"980e0cc70452897f6271288bdd0ba7b0085731c3"}},"sourceBranch":"main","suggestedTargetBranches":["8.11"],"targetPullRequestStates":[{"branch":"8.11","label":"v8.11.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.12.0","labelRegex":"^v8.12.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/168440","number":168440,"mergeCommit":{"message":"[OpenAI
Connector] Track token count for streaming responses
(#168440)\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"980e0cc70452897f6271288bdd0ba7b0085731c3"}}]}]
BACKPORT-->

Co-authored-by: Dario Gieselaar <dario.gieselaar@elastic.co>
2023-10-18 06:22:00 -07:00
Patryk Kopyciński
5fb9a3889e
Setup E2E against Serverless ES, Kibana, Fleet server standalone and Elastic endpoint agent in VM (#167720)
## Summary

Run Defend Workflows Cypress E2E against Serverless stack, similar to
https://github.com/elastic/kibana/pull/165415

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Gloria Hornero <gloria.hornero@elastic.co>
2023-10-04 11:56:08 +02:00
Hannah Mudge
9e8312f2e4
[Dashboard Navigation] Make links panel available under technical preview (#166896)
## Summary
This PR wraps up the work the @elastic/kibana-presentation team has done
to finish the MVP of [Phase
1](https://github.com/elastic/kibana/issues/154354) of the `Link`
embeddable, which enables users to add panels to their dashboard that
contain links to other dashboards + external links - with respect to
dashboard links, we give the author control over which pieces of context
should be kept across dashboards so that things like filter pills,
queries, and time ranges are not lost. This marks a huge improvement in
dashboard navigation overall, which was previously only available via a
variety of different workarounds including (but not limited to):
- Creating (essentially) a `noop` dashboard-to-dashboard drilldown 
- Using markdown panels with hard Dashboard links, which are prone to
break across updates
- Avoiding navigation all together, which resulted in large,
slow-to-load dashboards.

As an added benefit, because these panels contain **references** to each
dashboard rather than hard links, (1) unlike markdown links, they should
not break after updates and (2) if a links panel is exported and
imported into another space or instance, all of the dashboards it links
to will also be imported.



1a86b713-47e7-4db9-8a04-29d41b13681a

> **Note**
> 🔉 The above video has audio! Turn on your sound for the best
experience.

### Note about this PR
- A majority of this work was done on a feature branch, with thorough
reviews from @andreadelrio on behalf of @elastic/kibana-design along the
way. Therefore, while feedback on the design is encouraged, any large
concerns brought up in this PR should be filed as separate issues and
addressed in follow-up PRs.
- This PR contains work for giving embeddables control over their own
panel size / default positioning on the dashboard. This was especially
important for the links panel, since we assume that (a) most links
panels would be located somewhere near the top of the dashboard and (b)
the horizontal links panel should have a different default "shape"
(longer than it is tall) than the vertical panel (taller than it is
long).
- This PR also contains work for caching dashboard saved objects, which
makes navigation much more seamless.

### Flaky Test Runner
-
https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/3251


![image](7616443e-0cb0-43ce-a1d0-41f8bee6cbfc)


### Checklist

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
~[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials~ This will
be addressed in a follow up:
https://github.com/elastic/kibana/issues/166750
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios - ~Units tests
are added, functional tests are forthcoming~ Edit: All tests are in.
- [x] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [x] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [x] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [x] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)

### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

---------

Co-authored-by: Nick Peihl <nick.peihl@elastic.co>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com>
Co-authored-by: Devon Thomson <devon.thomson@elastic.co>
Co-authored-by: Nick Peihl <nickpeihl@gmail.com>
Co-authored-by: Gerard Soldevila <gerard.soldevila@elastic.co>
2023-09-29 08:25:51 -06:00
Alex Szabo
7f82102d72
[Ops] ES Serverless image verification pipeline (#166054)
## Summary
Prepares the serverless FTR tests to be runnable with a custom ES image.
(`--esServerlessImage` cli arg)
Creates a pipeline for testing and promoting ES Serverless docker
releases.

The job can be triggered here:
https://buildkite.com/elastic/kibana-elasticsearch-serverless-verify-and-promote
The three main env variables it takes:
- BUILDKITE_BRANCH: the kibana branch to test with (maybe not as
important)
 - BUILDKITE_COMMIT: the kibana commit to test with
- ES_SERVERLESS_IMAGE: the elasticsearch serverless image, or tag to use
from this repo:
`docker.elastic.co/elasticsearch-ci/elasticsearch-serverless`

## TODOS:
 - [x] set `latest_verified` with full img path as default
- [x] ~~find other CLIs that might need the `esServerlessImage` argument
(if the docker runner has multiple usages)~~ | I confused the `yarn es
docker` with this, because I thought we only run ES serverless in a
docker container, but `elasticsearch` can also be run in docker.
- [x] set `latest-compatible` or similar flag in a manifest in gcs for
Elastic's use-case
- [ ] ensure we can only verify "forward" (ie.: to avoid a
parameterization on old versions to set our pointers back) [on a second
thought, this might be kept as a feature to roll back (if we should ever
need that)]


There are two confusing things I couldn't sort out just yet:
#### Ambiguity in --esServerlessImage 
We can either have 2 CLI args: one for an image tag, one for an image
repo/image url, or we can have one (like I have it now) and interpret
that in the code, it can be either the image url, or the tag. It's more
flexible, but it's two things in one. Is it ok this way, or is it too
confusing?
e.g.:
```
node scripts/functional_tests --esFrom serverless --esServerlessImage docker.elastic.co/elasticsearch-ci/elasticsearch-serverless:git-8fc8f941bd4d --bail --config x-pack/test_serverless/functional/test_suites/security/config.ts

# or
node scripts/functional_tests  --esFrom serverless --esServerlessImage latest --bail --config x-pack/test_serverless/functional/test_suites/security/config.ts
```

#### Ambiguity in the default image path
The published ES Serverless images will sit on this image path:
`docker.elastic.co/elasticsearch-ci/elasticsearch-serverless`, however,
our one exception is the `latest-verified` which we will be tagging
under a different path, where we have write rights:
`docker.elastic.co/kibana-ci/elasticsearch-serverless:latest-verified`.

Is it okay, that by default, we're searching in the `elasticsearch-ci`
images for any tags as parameters (after all, all the new images will be
published there), however our grand default will ultimately be
`docker.elastic.co/kibana-ci/elasticsearch-serverless:latest-verified`.


## Links
Buildkite:
https://buildkite.com/elastic/kibana-elasticsearch-serverless-verify-and-promote
eg.:
https://buildkite.com/elastic/kibana-elasticsearch-serverless-verify-and-promote/builds/24
Closes: https://github.com/elastic/kibana/issues/162931

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2023-09-25 09:49:20 -07:00
Brad White
8ddad927fe
[kbn/es serverless] invert teardown logic to always kill cluster (#166546)
## Summary

Closes #166543 

- It is counterintuitive to `CTRL + C` from the `yarn es serverless`
process and the cluster is still running. This has caused issues when
switching between stateful and serverless work flows for some
developers. This PR inverts the logic to always teardown the cluster
unless a flag is passed.
- Small docs update for changing ES memory allocation on all operation
systems.
- Fixes bug were cluster status would continue looping after `SIGINT`.
- Bind to `SIGINT` earlier so nodes are always killed
2023-09-21 09:10:21 -07:00
Kurt
70c7fc571b
Upgrade openpgp 5.3.0 to 5.10.1 (#165526)
## Summary

Upgrade `openpgp` from `5.3.0` to `5.10.1`

Commit log:
https://github.com/openpgpjs/openpgpjs/compare/v5.3.0...v5.10.1

There is an incompatibility of `Uint8Array` when using Jest/JSDom with
the TextEncoder/TextDecoder from node `util`.

`https://github.com/kayahr/text-encoding` has been added as a
`devDependency` so it can be used in the polyfill. It provides a working
TextEncoder/Decoder for our Jest tests.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2023-09-18 08:31:16 -04:00
Kevin Lacabane
d78ecfea34
[Metrics] metrics_data_access plugin (#164094)
## Summary

Closes https://github.com/elastic/kibana/issues/161876

Creates a plugin providing utilities to access metrics data. The plugin
only exposes a server API which includes a client with two methods:
- `getMetricIndices` to retrieve the user-defined indices where metrics
are located
- `updateMetricIndices` to update the indices

The client is now used where we previously relied on infra plugin to
provide the configuration, in APM and Infra.

The plugin persists the configuration in a new saved object
`metrics-data-source`. Because this configuration was previously stored
in the `infrastructure-ui-source`, the plugin relies on a fallback to
reuse any existing value (see additional context
https://github.com/elastic/kibana/issues/161876#issuecomment-1673537400).

### Reviewers
There are no functional changes outside of Infra Monitoring UI and APM
UI, other codeowners are involved because this introduces a new saved
object
- APM - the change introduces a drop-in replacement of the
`infra.getMetricIndices` call. The ui code still relies on infra plugin
for a couple of components so we can't drop the dependency yet, those
we'll need to be moved to a tier 2 plugin (more details in
https://github.com/elastic/observability-dev/discussions/2787
(internal)) in a separate issue

### Testing
You'll need metrics data to verify data fetching works (I've used an
edge-oblt cluster)

1. Navigate to Infrastructure Settings and verify metric indices are
configured with the default value of `infrastructure-ui-source`
2. Update metric indices settings (if connected to oblt cluster add
`remote_cluster:..` indices)
3. Verify `metrics-data-source` saved object is persisted with correct
attributes
4. Verify Infrastructure Inventory is pulling data from the newly
configured indices
5. Go to APM services, verify service Infrastructure pulls data from
newly configured indices

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Jason Rhodes <jason.rhodes@elastic.co>
2023-09-14 12:55:13 +02:00
David Luna
9a798c7969
chore: update elastic-agent-nodejs to v4 (#165483)
## Summary

Draft PR to see the impact of the new major version of
`elastic-apm-node` dependency. Please do not review yet.

- elastic-apm-node@4 changelog:
https://www.elastic.co/guide/en/apm/agent/nodejs/current/release-notes-4.x.html#release-notes-4.0.0
- elastic-apm-node@4 upgrade guide:
https://www.elastic.co/guide/en/apm/agent/nodejs/current/upgrade-to-v4.html


### Checklist

Delete any items that are not applicable to this PR.

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
2023-09-13 12:56:39 +02:00
Dzmitry Lemechko
b340c27a74
[kbn-es] convert cluster.js to typescript (#165676)
## Summary

Converting cluster.js to typescript with small logic adjustment. It
should improve readability and simplify maintenance:
keep the following cluster properties solely for stateful
source/snapshot ES instance:
- process
- outcome
- setupPromise
- stdioTarget

Use `serverlessNodes` prop to check if serverless ES was started in
`runServerless/stop/kill`

Remove return statement for `runDocker` & `runDockerContainer` as the
result (e.g. pid) is not used anyways, but assigning to `process` prop
lead to confusion (more in comments)



Adding more tests to increase cluster functionality coverage.
2023-09-12 18:00:25 +02:00
Brad White
d7573c77a3
[kbn/es serverless] Enable security and transport ssl by default (#166023)
## Summary

Due to most users needing security plugin enabled by default, this
adjusts to that. Which requires transport SSL to be enabled as well. The
`--ssl` flag now will enable HTTP SSL only.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Aleh Zasypkin <aleh.zasypkin@gmail.com>
2023-09-11 17:01:55 -07:00
Brad White
68f2adf1b1
Add waitForReady to base config for FTR serverless (#165522)
## Summary

`waitForReady` was added in #165467. This PR utilizes it so that FTR
doesn't continue with starting Kibana until ES has reported its ready.
We get quite a few of [these
errors](https://buildkite.com/elastic/kibana-pull-request/builds/155832#018a5223-a3f7-4a43-990d-004ca465ab84/2350-2452)
every time, and it could be misleading. It adds 20-30s to startup time.

---------

Co-authored-by: Tiago Costa <tiago.costa@elastic.co>
2023-09-05 14:36:35 -07:00
Brad White
06ebc3120c
ESS support for FTR serverless tests. SSL support in kbn/es. kbn/es DX improvements. (#162673)
Closes #162593
Closes #163939 
Closes #162625

The original intention of this PR was to add FTR support for ESS.
However the scope increased as that also required adding SSL support due
to tests failing from disabled `security` and no authentication.
Additionally, after using serverless in `kbn/es` extensively for this,
there was a bit of friction in regards to DX.

## Summary
- Switch `x-pack/test_serverless` FTR to use ES serverless instead of
(stateful) snapshot
- Adds SSL support to Docker and Serverless in `kbn/es`
- Adds `port` option override
- Adds `teardown` option to kill running nodes if the process exits
without shutdown
- Adds `kill` option to kill running nodes on startup if detected
- Adds `--esFrom serverless` to FTR CLI
- Adds `files` option to mount extra files into containers
- For serverless, automatically attach to first node with `docker logs
-f es01` on startup for better DX.
- Added `background` flag to not attach `logs`.
- Adds graceful shutdown for ESS cluster
- Separate `docker pull` from `run` for better logging, ensures latest
image and stops multiple pulls of the same image occurring in parallel
- Align (most) default settings for ES serverless with `gradlew`
[settings](https://github.com/elastic/elasticsearch-serverless/blob/main/serverless-build-tools/src/main/kotlin/elasticsearch.serverless-run.gradle.kts#L8)
- Fixes Docker bind mount permissions in CI
- Fixes issue where `esFrom` would default to `snapshot` and override
FTR config settings.

### Checklist

- [x]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

## Related Issues for Skipped Tests
Security Threat Hunting: #165135
Observability: #165138
Response Ops: #165145

---------

Co-authored-by: Dzmitry Lemechko <dzmitry.lemechko@elastic.co>
Co-authored-by: Tiago Costa <tiago.costa@elastic.co>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Patryk Kopycinski <contact@patrykkopycinski.com>
2023-08-30 13:28:29 -07:00
Dario Gieselaar
c5c6574592
[Observability AI Assistant] More specific error handling (#165068)
Implements more specific error handling, in addition to a bug fix w/ the
Lens function where it was not rendering outside of the Observability AI
Assistant plugin's context, and validation of the parameters before
executing the function.

Additionally:
- improves recall function
- filter alerts and services by alert/health status

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2023-08-30 09:34:02 +02:00
Andrew Macri
3935548f36
[Security Solution] [Elastic AI Assistant] LangChain integration (experimental) (#164908)
## [Security Solution] [Elastic AI Assistant] LangChain integration (experimental)

This PR integrates [LangChain](https://www.langchain.com/) with the [Elastic AI Assistant](https://www.elastic.co/blog/introducing-elastic-ai-assistant) as an experimental, alternative execution path.

### How it works

- There are virtually no client side changes to the assistant, apart from a new branch in `x-pack/packages/kbn-elastic-assistant/impl/assistant/api.tsx` that chooses a path based on the value of the `assistantLangChain` flag:

```typescript
    const path = assistantLangChain
      ? `/internal/elastic_assistant/actions/connector/${apiConfig?.connectorId}/_execute`
      : `/api/actions/connector/${apiConfig?.connectorId}/_execute`;
```

Execution of the LangChain chain happens server-side. The new route still executes the request via the `connectorId` in the route, but the connector won't execute the request exactly as it was sent by the client. Instead, the connector will execute one (or more) prompts that are generated by LangChain.

Requests routed to `/internal/elastic_assistant/actions/connector/${apiConfig?.connectorId}/_execute` will be processed by a new Kibana plugin located in:

```
x-pack/plugins/elastic_assistant
```

- Requests are processed in the `postActionsConnectorExecuteRoute` handler in `x-pack/plugins/elastic_assistant/server/routes/post_actions_connector_execute.ts`.

The `postActionsConnectorExecuteRoute` route handler:

1. Extracts the chat messages sent by the assistant
2. Converts the extracted messages to the format expected by LangChain
3. Passes the converted messages to `executeCustomLlmChain`

- The `executeCustomLlmChain` function in `x-pack/plugins/elastic_assistant/server/lib/langchain/execute_custom_llm_chain/index.ts`:

1. Splits the messages into `pastMessages` and `latestMessage`, where the latter contains only the last message sent by the user
2. Wraps the conversation history in the `BufferMemory` LangChain abstraction
3. Executes the chain, kicking it off with `latestMessage`

```typescript
  const llm = new ActionsClientLlm({ actions, connectorId, request });

  const pastMessages = langchainMessages.slice(0, -1); // all but the last message
  const latestMessage = langchainMessages.slice(-1); // the last message

  const memory = new BufferMemory({
    chatHistory: new ChatMessageHistory(pastMessages),
  });

  const chain = new ConversationChain({ llm, memory });

  await chain.call({ input: latestMessage[0].content }); // kick off the chain with the last message
};
```

- When LangChain executes the chain, it will invoke `ActionsClientLlm`'s `_call` function in `x-pack/plugins/elastic_assistant/server/lib/langchain/llm/actions_client_llm.ts` one or more times.

The `_call` function's signature is defined by LangChain:

```
async _call(prompt: string): Promise<string>
```

- The contents of `prompt` are completely determined by LangChain.
- The string returned by the promise is the "answer" from the LLM

The `ActionsClientLlm` extends LangChain's LLM interface:

```typescript
export class ActionsClientLlm extends LLM
```

This let's us do additional "work" in the `_call` function:

1. Create a new assistant message using the contents of the `prompt` (`string`) argument to `_call`
2. Create a request body in the format expected by the connector
3. Create an actions client from the authenticated request context
4. Execute the actions client with the request body
5. Save the raw response from the connector, because that's what the assistant expects
6. Return the result as a plain string, as per the contact of `_call`

## Desk testing

This experimental LangChain integration may NOT be enabled via a feature flag (yet).

Set

```typescript
assistantLangChain={true}
```

in `x-pack/plugins/security_solution/public/app/app.tsx` to enable this experimental feature in development environments.
2023-08-28 10:30:05 -06:00
Alex Szabo
9d2696b5c5
[Ops] Upgrade to axios 1.4 (#163732)
## Summary
upgrade `axios` to 1.4

- adjust to header usage, and config optionality
- Axios' adapters are now resolved from a string key by axios, no need
to import/instantiate adapters
- most of the changed code stems from changes in Axios' types
  - `response.config` is now optional
- there was a change in the type of AxiosHeaders <->
InternalAxiosHeaders

Closes: #162661 
Closes: #162414

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2023-08-22 11:47:48 +02:00
Khristinin Nikita
2bd52fc421
Risk engine initialisation, update from legacy risk engine workflow and status change (#162400)
## Risk engine initialisation, update from legacy risk engine workflow
and status change



dfb75d4a-f447-4346-9760-d0e9685cce39


Green areas it is what was implemented
<img width="1449" alt="Screenshot 2023-08-01 at 15 07 01"
src="4d87887f-1163-45eb-a4e9-a77a685f6565">


This pr has:
- Upgrade workflow. If the user has a risk host or user transforms, we
will show the panel with a call to action for the upgrade.
- Introduce new Saved object to save the configuration of risk engine
- API which is described bellow

It required experiment enabled - **riskScoringRoutesEnabled**
## New API

### /engine/status

#### GET
Get the status of the Risk Engine

##### Description:
Returns the status of both the legacy transform-based risk engine, as
well as the new risk engine

##### Responses

```json
{
  "legacy_risk_engine_status": "NOT_INSTALLED" , "ENABLED"
  ,
  "risk_engine_status": "NOT_INSTALLED" , "ENABLED" , "DISABLED"
}
```

### /engine/init

#### POST
Initialize the Risk Engine

##### Description:
Initializes the Risk Engine by creating the necessary indices and
mappings, removing old transforms, creating saved object configuration

##### Responses

```json
{
  "result": {
    "risk_engine_enabled": true,
    "risk_engine_resources_installed": true,
    "risk_engine_configuration_created": true,
    "legacy_risk_engine_disabled": true,
    "errors": [
      "string"
    ]
  }
}
```

### /engine/enable

#### POST
Enable the Risk Engine
##### Description:
Change saved object configuration and in the future here we will start
task

### /engine/disable

#### POST
Disable the Risk Engine
Change saved object configuration and in the future here we will stop
task

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Ryland Herrick <ryalnd@gmail.com>
2023-08-04 09:03:46 -07:00
Jean-Louis Leysens
87ff936b34
Turn on internal API restriction for serverless tests (#162636)
## Summary

Since we already have some E2E tests running for serverless, this PR
turns on the internal API restriction flag to test whether our UI
functions _as such_ under these tests.

An alternative could be to have a specific smoke test for this, but it
seems this is thoroughly covered by piggy-backing off the existing set
of tests.

Blocks: https://github.com/elastic/kibana/pull/162149
2023-08-01 10:19:57 +02:00
Clint Andrew Hall
477505a2dd
[context] Unify Contexts, deprecate others (#161914)
> Pre-req for https://github.com/elastic/kibana/issues/56406

## Summary

We've had a long-standing problem in Kibana around our use of React
context, particularly with EUI and i18n. There hasn't existed an
idempotent context structure, and that has lead to a lot of unexpected
results, (e.g. missing translations, inconsistent dark mode, excess
context providers, etc).

The biggest change coming from this PR is knowing exactly which provider
to use in a particular use case. This means, for example,
`ReactDOM.render` calls won't be missing `i18n` or `theme` due to a
missing context. It also allows consumers to use `darkMode` without
having to read the `uiSetting` themselves, instead allowing the context
to do it for them.

We also haven't been honoring the intended [`EuiProvider`
API](https://eui.elastic.co/#/utilities/provider#theming-and-global-styles)...
in some cases we've been creating and re-creating the Emotion caches,
often by copy/paste of the cache code. We've also been nesting
`EuiThemeProvider` contexts unnecessarily-- thinking we need to render a
theme provider in an isolated component-- which renders an additional
`span` element into the DOM.

This PR attempts to address this inconsistency by creating a set of
context providers divided by use case:


![diagram](e01c6296-1b7a-4639-ae96-946866950efe)

### `KibanaRootContextProvider`
A root context provider for Kibana. This is the top level context
provider that wraps the entire application. It is responsible for
initializing all of the other contexts and providing them to the
application. It's provided as a package for specific use cases, (e.g.
the `RenderingService`, cases where we replace the entire page content,
Storybook, testing, etc), but not intended for plugins.

### `KibanaRenderContextProvider`
A render context provider for Kibana. This context is designed to be
used with ad-hoc renders of React components, (usually with
`ReactDOM.render`).

### `KibanaThemeContextProvider`
A theme context provider for Kibana. A corollary to EUI's
`EuiThemeProvider`, it uses Kibana services to ensure the EUI Theme is
customized correctly.

### (deprecated) `KibanaStyledComponentsThemeProvider`
A styled components theme provider for Kibana. This package is supplied
for compatibility with legacy code, but should not be used in new code.

## Deprecation strategy
This PR does *not* change any use of context by consumers. It maps the
existing contexts in `kibanaReact` to the new contexts, (along with the
loose API). This means that we won't have completely fixed all of our
dark mode issues yet. But this is necessary to keep this PR focused on
the change, rather than drawing in a lot of teams to review individual
uses.

We should, however, see an immediate performance improvement in the UI
from the reduction in `EuiProvider` calls.

## Open questions
- [ ] Does it make sense to expose a `useTheme` hook from
`@kbn/react-kibana-context-theme` to replace `useEuiTheme`?

## Next steps
- [ ] Update deprecated uses to new contexts.
- [ ] Audit and update calls to `ReactDOM.render`.
- [ ] Add ESLint rule to warn for use of EUI contexts.
- [ ] Delete code from `kibanaReact`.
2023-07-28 09:30:08 -07:00
Tiago Costa
e9a6519337
chore(NA): add Blob polyfill on jest env (#162197)
This PR adds the `Blob` polyfill into the jest jsdom env which is
currently not supported as mentioned in
https://github.com/jsdom/jsdom/issues/2555

---------

Co-authored-by: Thomas Watson <w@tson.dk>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2023-07-20 18:30:43 +01:00
Elena Stoeva
41056193d9
[Serverless] Add internal uiSettings routes and expose public routes in self-managed only (#160499)
Partially addresses https://github.com/elastic/kibana/issues/159590

## Summary

This PR adds an an internal uiSettings API that is a duplicate of the
public API and is intended for use by the browser-side uiSettings
client.

The PR also adds a config settings that is configured in serverless
context only and exposes the public uiSettings routes based on the value
of this setting (it defaults to false since we don't want to expose the
public routes in serverless).

**How to test:**

I. Verify that in serverless the internal routes are exposed but the
public ones aren't:
1. Start Es with `yarn es snapshot` and Kibana with `yarn
serverless-{mode}` where `{mode}` can be `es`, `oblt`, or `security`
(the public routes should be disabled for all projects).
2. Verify that the public endpoints are not accessible. For example,
`curl --user elastic:changeme
'http://localhost:5601/zhb/api/kibana/settings' -X 'GET'` should return
`{"statusCode":404,"error":"Not Found","message":"Not Found"}`.
3. Verify that the internal endpoints are accessible. For example, `curl
--user elastic:changeme
'http://localhost:5601/zhb/internal/kibana/settings' -X 'GET'` should
return
`{"settings":{"buildNum":{"userValue":9007199254740991},"isDefaultIndexMigrated":{"userValue":true},"defaultRoute":{"isOverridden":true,"userValue":"/app/elasticsearch"}}}`


II. Verify that the both public and internal routes are exposed in
self-managed:
1. Start Es with `yarn es snapshot` and Kibana with `yarn start`
2. Verify that the public endpoints are accessible. For example, `curl
--user elastic:changeme 'http://localhost:5601/zhb/api/kibana/settings'
-X 'GET'` should return
`{"settings":{"buildNum":{"userValue":9007199254740991},"isDefaultIndexMigrated":{"userValue":true}}}`
3. Verify that the internal endpoints are accessible. For example, `curl
--user elastic:changeme
'http://localhost:5601/zhb/internal/kibana/settings' -X 'GET'` should
return
`{"settings":{"buildNum":{"userValue":9007199254740991},"isDefaultIndexMigrated":{"userValue":true}}}`

III. Verify that the plugins/services that consume the internal
uiSettings endpoints work as expected in both self-managed and
serverless environment.

### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2023-07-14 15:53:17 +01:00
Jean-Louis Leysens
bda0195982
[http] Fix running FTR tests locally (#161336)
## Summary

Running FTR tests locally (not on CI) that make API requests to public
versioned Kibana endpoints is currently broken. This is because:

* we require version headers to be set for both internal and **public**
endpoints in **dev** by way of a runtime check (ensures our code is
locked to a version)
* the vast majority of FTR tests do not set these headers for talking to
public endpoints
* on CI, this is different as we run these tests against a distributable
build (i.e., non-dev)

This manifests locally as a 400 response. E.g. the current
api_integration tests for data views by running:

```
node scripts/functional_test_runner.js --config ./test/api_integration/config.js --grep 'index_pattern_crud'
```

---

There are a few ways to resolve this, this PR proposes that we:

* Keep FTR tests as they are (i.e., don't update all of them to set
headers when making requests to public versioned endpoints), this is a
useful way to exercise our intended end-user behaviour
* Make the version resolution behaviour not depend on `--dev`: rather
set the default resolution to `none` (new setting) when we run in
`--dev` so that it can be configured to behave as we want for tests.

In this way we keep the runtime check for its intended purpose and can
run our FTR tests "as end users" of our endpoints.

---

Close https://github.com/elastic/kibana/issues/161435
2023-07-11 11:51:05 +02:00
Dzmitry Lemechko
ac8d73ac6d
[ftr] fix test users for serverless (#161280)
## Summary

This PR fixes few issues occurring while running FTR API tests against
actual serverless project.

How to run:
```
TEST_CLOUD=1 ES_SECURITY_ENABLED=1 NODE_TLS_REJECT_UNAUTHORIZED=0 TEST_ES_URL=<your_es_url_with_credentials> TEST_KIBANA_URL=<your_es_url_with_credentials> node  --no-warnings scripts/functional_test_runner --es-version=8.9.0 --config x-pack/test_serverless/api_integration/test_suites/search/config.ts --bail
```

The first error is faced during Elasticsearch version validation

```
ERROR Error: attempted to use the "es" service to fetch Elasticsearch version info but the request failed: ResponseError: {"ok":false,"message":"Unknown resource."}
          at SniffingTransport.request (/Users/dmle/github/kibana/node_modules/@elastic/transport/src/Transport.ts:535:17)
          at processTicksAndRejections (node:internal/process/task_queues:96:5)
          at Client.InfoApi [as info] (/Users/dmle/github/kibana/node_modules/@elastic/elasticsearch/src/api/api/info.ts:60:10)
          at FunctionalTestRunner.validateEsVersion (functional_test_runner.ts:129:16)
          at functional_test_runner.ts:64:11
          at FunctionalTestRunner.runHarness (functional_test_runner.ts:251:14)
          at FunctionalTestRunner.run (functional_test_runner.ts:48:12)
          at log.defaultLevel (cli.ts:112:32)
          at run.ts:70:7
          at withProcRunner (with_proc_runner.ts:29:5)
          at run (run.ts:69:5)
          at FunctionalTestRunner.validateEsVersion (functional_test_runner.ts:131:13)
          at processTicksAndRejections (node:internal/process/task_queues:96:5)
          at functional_test_runner.ts:64:11
          at FunctionalTestRunner.runHarness (functional_test_runner.ts:251:14)
          at FunctionalTestRunner.run (functional_test_runner.ts:48:12)
          at log.defaultLevel (cli.ts:112:32)
          at run.ts:70:7
          at withProcRunner (with_proc_runner.ts:29:5)
          at run (run.ts:69:5)
```

Since there is no version term in case of serverless, we can skip
version check by using newly added to FTR schema `serverless` property
(`false` by default). It is set to `true` in root FTR config
`/shared/config.base`.

The next error is related to ESArchiver relying on `ES` FTR service to
provide ESClient.

```
ResponseError: security_exception
   │ 	Root causes:
   │ 		security_exception: unable to authenticate user [system_indices_superuser] for REST request [/kibana_sample_data_flights]
```

It is fixed by using the default user (from host url) instead of
`system_indices_superuser` we use in stateful run.
2023-07-10 10:09:07 +02:00
Gergő Ábrahám
c9b6054cbe
[Fleet][Agent tamper protection ] Split GET /uninstall_tokens API (#159944)
## Summary

> **Note**
> For testing: enable the `agentTamperProtectionEnabled` feature flag.

This PR modifies the quite new `GET /api/fleet/uninstall_tokens` API:
- `GET /api/fleet/uninstall_tokens`, returns token 'metadata' (i.e.
**uninstall token id**, policy ID and creation date) for the latest
token for every policy, without the token itself.
  - it is paginated (query params `page`, `perPage`),
  - and can be searched by partial policy ID (query param `policyId`).
  - this route is not used at the moment, will be used very soon
- `GET /api/fleet/uninstall_tokens/{id}` returns one decrypted token
identified by its ID
- ~`GET /api/fleet/agent_policies/{policyId}/uninstall_tokens`, returns
the decrypted token history for one policy~
  - ~this route is used by the `UninstallCommandFlyout`~
- this was added and then removed, because not a necessity at the
moment, and let's keep open all doors for agent tampering v2

### Todo - done  
`created_at` field was removed from the uninstall token saved object
mapping (21855ce37b320e1864c5b9db647ac2355158f91d), because it was
unused and messed up ordering by the saved object's own `created_at`
field.

This removal is not allowed, though, so this issue needs to be fixed.

**Update:** after a discussion with Kibana Core team, the `created_at`
field was removed in a separate PR which is merged in v8.9.0. Reason:
it's okay to use the SO's internal `created_at` field for sorting. Also,
the mapping will be released in v8.9.0 first, so it's okay to modify it
this time. The PR: https://github.com/elastic/kibana/pull/159985

### Checklist

Delete any items that are not applicable to this PR.

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2023-06-30 10:56:26 +02:00
Shahzad
e5cb4f3e68
[Synthetics] Fix and updated alert flaky tests (#160870) 2023-06-30 10:14:32 +02:00
renovate[bot]
1b1be4795d
Update dependency elastic-apm-node to ^3.47.0 (main) (#160223)
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [elastic-apm-node](https://togithub.com/elastic/apm-agent-nodejs) |
[`^3.46.0` ->
`^3.47.0`](https://renovatebot.com/diffs/npm/elastic-apm-node/3.46.0/3.47.0)
|
[![age](https://badges.renovateapi.com/packages/npm/elastic-apm-node/3.47.0/age-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://badges.renovateapi.com/packages/npm/elastic-apm-node/3.47.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://badges.renovateapi.com/packages/npm/elastic-apm-node/3.47.0/compatibility-slim/3.46.0)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://badges.renovateapi.com/packages/npm/elastic-apm-node/3.47.0/confidence-slim/3.46.0)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>elastic/apm-agent-nodejs</summary>

###
[`v3.47.0`](https://togithub.com/elastic/apm-agent-nodejs/releases/tag/v3.47.0)

[Compare
Source](https://togithub.com/elastic/apm-agent-nodejs/compare/v3.46.0...v3.47.0)

For more information, please see the
[changelog](https://www.elastic.co/guide/en/apm/agent/nodejs/current/release-notes-3.x.html#release-notes-3.47.0).

##### Elastic APM Node.js agent layer ARNs

|Region|ARN|
|------|---|

|af-south-1|arn:aws:lambda:af-south-1:267093732750:layer:elastic-apm-node-ver-3-47-0:1|

|ap-east-1|arn:aws:lambda:ap-east-1:267093732750:layer:elastic-apm-node-ver-3-47-0:1|

|ap-northeast-1|arn:aws:lambda:ap-northeast-1:267093732750:layer:elastic-apm-node-ver-3-47-0:1|

|ap-northeast-2|arn:aws:lambda:ap-northeast-2:267093732750:layer:elastic-apm-node-ver-3-47-0:1|

|ap-northeast-3|arn:aws:lambda:ap-northeast-3:267093732750:layer:elastic-apm-node-ver-3-47-0:1|

|ap-south-1|arn:aws:lambda:ap-south-1:267093732750:layer:elastic-apm-node-ver-3-47-0:1|

|ap-southeast-1|arn:aws:lambda:ap-southeast-1:267093732750:layer:elastic-apm-node-ver-3-47-0:1|

|ap-southeast-2|arn:aws:lambda:ap-southeast-2:267093732750:layer:elastic-apm-node-ver-3-47-0:1|

|ap-southeast-3|arn:aws:lambda:ap-southeast-3:267093732750:layer:elastic-apm-node-ver-3-47-0:1|

|ca-central-1|arn:aws:lambda:ca-central-1:267093732750:layer:elastic-apm-node-ver-3-47-0:1|

|eu-central-1|arn:aws:lambda:eu-central-1:267093732750:layer:elastic-apm-node-ver-3-47-0:1|

|eu-north-1|arn:aws:lambda:eu-north-1:267093732750:layer:elastic-apm-node-ver-3-47-0:1|

|eu-south-1|arn:aws:lambda:eu-south-1:267093732750:layer:elastic-apm-node-ver-3-47-0:1|

|eu-west-1|arn:aws:lambda:eu-west-1:267093732750:layer:elastic-apm-node-ver-3-47-0:1|

|eu-west-2|arn:aws:lambda:eu-west-2:267093732750:layer:elastic-apm-node-ver-3-47-0:1|

|eu-west-3|arn:aws:lambda:eu-west-3:267093732750:layer:elastic-apm-node-ver-3-47-0:1|

|me-south-1|arn:aws:lambda:me-south-1:267093732750:layer:elastic-apm-node-ver-3-47-0:1|

|sa-east-1|arn:aws:lambda:sa-east-1:267093732750:layer:elastic-apm-node-ver-3-47-0:1|

|us-east-1|arn:aws:lambda:us-east-1:267093732750:layer:elastic-apm-node-ver-3-47-0:1|

|us-east-2|arn:aws:lambda:us-east-2:267093732750:layer:elastic-apm-node-ver-3-47-0:1|

|us-west-1|arn:aws:lambda:us-west-1:267093732750:layer:elastic-apm-node-ver-3-47-0:1|

|us-west-2|arn:aws:lambda:us-west-2:267093732750:layer:elastic-apm-node-ver-3-47-0:1|

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/elastic/kibana).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4xMzEuMCIsInVwZGF0ZWRJblZlciI6IjM1LjEzMS4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: pgayvallet <pierre.gayvallet@elastic.co>
2023-06-23 10:15:38 +02:00
Konrad Szwarc
c9658bf238
[Security Solution] ~200 ways to decrease flakiness in Cypress (#157387)
This PR addresses Cypress parallelisation in Security Solution scope. It
is a first step in improving e2e tests reliability and gives us a solid
foundation for further work on flakiness and run times. With this PR
each CI job starts 3 instances of ES, kibana and Cypress runner in
isolation.

Other issues addressed in this PR: 
- Use click() instead of trigger('click') in all Cypress tests.
- Use testIsolation in all Cypress tests.
- login before each test to ensure that the correct user is always
logged in. Also, with test isolation enabled, login should be required
before each test.
- use visit() instead of cy.visit() in some cases so that tests wait for
the page to fully load before executing.
- Cypress e2e tests are no longer compatible with Firefox (or any
non-Chromium based browser) due to using cypress-real-events
- Removes uses of cypress-pipe. Tests that used cypress-pipe in order to
retry click events will no longer retry click events.
- Fixes an error related to test files being overwritten by Webpack file
processing

---------

Co-authored-by: Patryk Kopycinski <contact@patrykkopycinski.com>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2023-05-30 17:40:18 +02:00
Dzmitry Lemechko
7bbdab0653
[codeowners] add appex-qa for ftr-related packages (#155230)
## Summary

While elastic/appex-qa is in process to take ownership over FTR related
code, from elastic/kibana-operations it will be good to keep track on
any changes happening and participate in the review process.
2023-05-24 08:53:09 +02:00
Alejandro Fernández Haro
ff6943376d
[Config Service] Expose serverless contextRef (#156837) 2023-05-08 17:39:12 +02:00
Dzmitry Lemechko
4211e03a5f
[ftr] fix scripts/functional_tests to respect cli flags (#155734)
## Summary

This
[failure](https://buildkite.com/elastic/kibana-on-merge/builds/29091#01879988-ecd2-4e4f-bfb4-108939f145a1)
clearly shows that `--bail` flag is ignored when passed to
`scripts/functional_tests.js` script, and since
`scripts/functional_tests.js --help` list these flags I think we need to
fix it:

```
    --include-tag        Tags that suites must include to be run, can be included multiple times
    --exclude-tag        Tags that suites must NOT include to be run, can be included multiple times
    --include            Files that must included to be run, can be included multiple times
    --exclude            Files that must NOT be included to be run, can be included multiple times
    --grep               Pattern to select which tests to run
    --bail               Stop the test run at the first failure
    --dry-run            Report tests without executing them
    --updateBaselines    Replace baseline screenshots with whatever is generated from the test
    --updateSnapshots    Replace inline and file snapshots with whatever is generated from the test
```

I was able to reproduce it locally:
1. Break
[test/functional/apps/console/_console.ts](test/functional/apps/console/_console.ts)
by adding `expect(1).to.be(2);` in the first `it` function
2. Run `node scripts/functional_tests.js --bail --config
test/functional/apps/console/config.ts`
Actual: Tests continue to run after failure
Expected: Stop tests after first failure

It turned out `scripts/functional_test_runner.js` respects the flags so
I just copied the logic from
[packages/kbn-test/src/functional_test_runner/cli.ts](https://github.com/elastic/kibana/blob/main/packages/kbn-test/src/functional_test_runner/cli.ts#L41-L63)

Let me know if you think we need to add jest tests.


Tested:

```
node scripts/functional_tests.js --bail --config test/functional/apps/console/config.ts --grep "multiple requests output"
```
2023-04-26 18:33:54 +02:00
Spencer
1b85815402
[packages] migrate all plugins to packages (#148130)
Fixes https://github.com/elastic/kibana/issues/149344

This PR migrates all plugins to packages automatically. It does this
using `node scripts/lint_packages` to automatically migrate
`kibana.json` files to `kibana.jsonc` files. By doing this automatically
we can simplify many build and testing procedures to only support
packages, and not both "packages" and "synthetic packages" (basically
pointers to plugins).

The majority of changes are in operations related code, so we'll be
having operations review this before marking it ready for review. The
vast majority of the code owners are simply pinged because we deleted
all `kibana.json` files and replaced them with `kibana.jsonc` files, so
we plan on leaving the PR ready-for-review for about 24 hours before
merging (after feature freeze), assuming we don't have any blockers
(especially from @elastic/kibana-core since there are a few core
specific changes, though the majority were handled in #149370).

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2023-02-08 21:06:50 -06:00
Pierre Gayvallet
e70fceaf9d
[FTR] KbnClientSavedObjects improvements (#149582)
## Summary

Follow-up of https://github.com/elastic/kibana/pull/149188


- Use the bulkDelete API for `KbnClientSavedObjects.bulkDelete`
- Create a dedicated `/_clean` endpoint for
`KbnClientSavedObjects.clean` and
`KbnClientSavedObjects.cleanStandardList`

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2023-01-30 09:05:53 -07:00
Pierre Gayvallet
cd9a53f284
Create the ftrSoApis FTR plugin (#149188)
## Summary

Fix https://github.com/elastic/kibana/issues/148412

More and more SO types will not be accessible from the HTTP APIs (either
`hidden:true` or `hiddenFromHTTPApis: true`).

However, the FTR SO client (`KbnClientSavedObjects`) still needs to be
able to access and manipulate all SO types.

This PR introduces a `ftrSoApis` plugin that is loaded for all FTR
suites. This plugin exposes SO APIs that are used by the FTR client
instead of the public SO HTTP APIs. These APIs are configured to know
about all types, even hidden ones.

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2023-01-26 01:47:29 -07:00
Tiago Costa
e38350f7f9
chore(NA): upgrades uuid to v9.0.0 (#149135)
This PR upgrades uuid into its latest version `9.0.0`.
The previous default used version `v4` was kept where it was previously
used and places using `v1` or `v5` are still using it.

In this latest version they removed the deep import feature and as we
are not using tree shaking it increased our bundles by a significant
size. As such, I've moved this dependency into the `ui-shared-deps-npm`
bundle.

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2023-01-19 19:48:07 +00:00
Spencer
d6be4a4b06
Implement package linter (#148496)
This PR implements a linter like the TS Project linter, except for
packages in the repo. It does this by extracting the reusable bits from
the TS Project linter and reusing them for the project linter. The only
rule that exists for packages right now is that the "name" in the
package.json file matches the "id" in Kibana.jsonc. The goal is to use a
rule to migrate kibana.json files on the future.

Additionally, a new rule for validating the indentation of tsconfig.json
files was added.

Validating and fixing violations is what has triggered review by so many
teams, but we plan to treat those review requests as notifications of
the changes and not as blockers for merging.

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2023-01-09 16:49:29 -07:00
Spencer
afb09ccf8a
Transpile packages on demand, validate all TS projects (#146212)
## Dearest Reviewers 👋 

I've been working on this branch with @mistic and @tylersmalley and
we're really confident in these changes. Additionally, this changes code
in nearly every package in the repo so we don't plan to wait for reviews
to get in before merging this. If you'd like to have a concern
addressed, please feel free to leave a review, but assuming that nobody
raises a blocker in the next 24 hours we plan to merge this EOD pacific
tomorrow, 12/22.

We'll be paying close attention to any issues this causes after merging
and work on getting those fixed ASAP. 🚀

---

The operations team is not confident that we'll have the time to achieve
what we originally set out to accomplish by moving to Bazel with the
time and resources we have available. We have also bought ourselves some
headroom with improvements to babel-register, optimizer caching, and
typescript project structure.

In order to make sure we deliver packages as quickly as possible (many
teams really want them), with a usable and familiar developer
experience, this PR removes Bazel for building packages in favor of
using the same JIT transpilation we use for plugins.

Additionally, packages now use `kbn_references` (again, just copying the
dx from plugins to packages).

Because of the complex relationships between packages/plugins and in
order to prepare ourselves for automatic dependency detection tools we
plan to use in the future, this PR also introduces a "TS Project Linter"
which will validate that every tsconfig.json file meets a few
requirements:

1. the chain of base config files extended by each config includes
`tsconfig.base.json` and not `tsconfig.json`
1. the `include` config is used, and not `files`
2. the `exclude` config includes `target/**/*`
3. the `outDir` compiler option is specified as `target/types`
1. none of these compiler options are specified: `declaration`,
`declarationMap`, `emitDeclarationOnly`, `skipLibCheck`, `target`,
`paths`

4. all references to other packages/plugins use their pkg id, ie:
	
	```js
    // valid
    {
      "kbn_references": ["@kbn/core"]
    }
    // not valid
    {
      "kbn_references": [{ "path": "../../../src/core/tsconfig.json" }]
    }
    ```

5. only packages/plugins which are imported somewhere in the ts code are
listed in `kbn_references`

This linter is not only validating all of the tsconfig.json files, but
it also will fix these config files to deal with just about any
violation that can be produced. Just run `node scripts/ts_project_linter
--fix` locally to apply these fixes, or let CI take care of
automatically fixing things and pushing the changes to your PR.

> **Example:** [`64e93e5`
(#146212)](64e93e5806)
When I merged main into my PR it included a change which removed the
`@kbn/core-injected-metadata-browser` package. After resolving the
conflicts I missed a few tsconfig files which included references to the
now removed package. The TS Project Linter identified that these
references were removed from the code and pushed a change to the PR to
remove them from the tsconfig.json files.

## No bazel? Does that mean no packages??
Nope! We're still doing packages but we're pretty sure now that we won't
be using Bazel to accomplish the 'distributed caching' and 'change-based
tasks' portions of the packages project.

This PR actually makes packages much easier to work with and will be
followed up with the bundling benefits described by the original
packages RFC. Then we'll work on documentation and advocacy for using
packages for any and all new code.

We're pretty confident that implementing distributed caching and
change-based tasks will be necessary in the future, but because of
recent improvements in the repo we think we can live without them for
**at least** a year.

## Wait, there are still BUILD.bazel files in the repo
Yes, there are still three webpack bundles which are built by Bazel: the
`@kbn/ui-shared-deps-npm` DLL, `@kbn/ui-shared-deps-src` externals, and
the `@kbn/monaco` workers. These three webpack bundles are still created
during bootstrap and remotely cached using bazel. The next phase of this
project is to figure out how to get the package bundling features
described in the RFC with the current optimizer, and we expect these
bundles to go away then. Until then any package that is used in those
three bundles still needs to have a BUILD.bazel file so that they can be
referenced by the remaining webpack builds.

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2022-12-22 19:00:29 -06:00
Karl Godard
0b19cfafa3
Custom fleet policy UX for new integration (cloud defend v1) (#147300)
## Summary

New Kibana plugin created for an integration called "Cloud defend for
containers" which will have a corresponding agent service which can
proactively block and alert on executable creation or modification in a
running container.

This plugin is purely in place to configure the fleet policy UX around
this new integration. For now we have added a yaml editor as a custom
input to our integration. The monaco-yaml libary was added to allow
support for JSON schema validation support for yaml.

Integration PR is up, and a work in progress: (waiting on some content
for the doc page)
https://github.com/elastic/integrations/pull/4680

### Screenshot


![image](https://user-images.githubusercontent.com/16198204/207160791-73e11e05-953b-42ba-b4dd-a4904bd95451.png)

### Checklist

Delete any items that are not applicable to this PR.

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [ ] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [x] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [x] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)

Co-authored-by: Karl Godard <karlgodard@elastic.co>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2022-12-19 17:37:39 -07:00
Spencer
2763af3a4e
[ftr] remove @types/mocha, define custom ambient-ftr-types (#147284)
After moving away from composite projects in the IDE we now have an
issue where projects like security solutions are getting `@types/jest`
and `@types/mocha` loaded up, even though the "types" compiler option in
security solutions focuses on jest. To fix this I've removed the
`@types/mocha` package, implemented/copied a portion of the mocha types
into a new `@kbn/ambient-ftr-types` package which can be used in ftr
packages to define the describe/it/etc. globals.

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2022-12-19 10:42:12 -07:00
Spencer
c107f8a73a
[jest/ci] disable console methods (#146910)
Removes all the noise from poorly written React tests and includes a
warning to explain the situation to folks

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2022-12-02 15:28:55 -07:00
Spencer
c38315f91c
[jest] parse CLI flags correctly (#146844)
Fixes https://github.com/elastic/kibana/issues/144051

Rather than just parsing process.argv with the default config of
getopts, which treats flags like `-u` into a "value collecting" flag,
this updates the way we call getopts so that all known jest CLI flags
are properly handled. This is accomplished by parsing the output of
`yarn jest --help` and then using that information to power `node
scripts/jest`.

To update the known CLI flags we just need to run `yarn jest --help |
node scripts/read_jest_help.mjs` (for some reason I don't understand,
Jest does not produce it's entire `--help` output when called from node,
only when called from a terminal).
2022-12-02 10:04:15 -07:00
Spencer
cfdb8553ba
[pkgs/peggy] automatically transform peggy files with babel-register and webpack (#145615)
In order to get us closer to the developer experience we want for
packages, we are trying to move package builds out of bazel and instead
we want to build files on demand. In the case of .peggy files this means
importing them directly and teaching babel/jest/webpack how to handle
these imports by automatically transpiling and caching the results.

This change does just that, adding a `@kbn/peggy` package which wraps
peggy for types, and also adds support for defining peggy config
adjacent to a peggy grammar file in a `${basename}.config.json` file.
This file will be parsed and used to configure things like
`allowedStartRules` as described in [the peggy
docs](https://peggyjs.org/documentation.html#generating-a-parser-javascript-api).

This PR also implements `@kbn/peggy-loader` which uses `@kbn/peggy` to
transpile peggy files in webpack, and a peggy transform for both Jest
and our custom babel register hook.

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2022-11-22 11:25:50 -07:00
Jonathan Budzenski
2ac7ebe3bf
Upgrade to Jest 29 (#143319)
https://jestjs.io/blog/2022/04/25/jest-28
https://jestjs.io/blog/2022/08/25/jest-29

- jest.useFakeTimers('legacy') -> jest.useFakeTimers({ legacyFakeTimers:
true });
- jest.useFakeTimers('modern'); -> jest.useFakeTimers();
- tests can either use promises or callbacks, but not both
- test runner jasmine is no longer included, switch all suites to
jest-circus

Co-authored-by: Andrew Tate <andrew.tate@elastic.co>
2022-11-18 09:40:16 -06:00
Thomas Watson
b02d976a3b
Remove dependencies for empty @types/* packages (#144324)
The removed packages were empty becuase the packages for which they provide
types now ship with their own types. So they are no longer needed.

The following command was run to find them:

    find node_modules/@types \
      -mindepth 1 \
      -maxdepth 1 \
      -type d '!' \
      -exec test -e "{}/index.d.ts" ';' \
      -print

In this case that produced the following output:

    node_modules/@types/moment-timezone
    node_modules/@types/strip-ansi
    node_modules/@types/joi
    node_modules/@types/rrule
    node_modules/@types/vfile-message
    node_modules/@types/reduce-reducers
    node_modules/@types/react-resize-detector
    node_modules/@types/pretty-ms

Except for `vfile-message` all of these were direct dependencies and could be
removed.
2022-11-07 04:37:43 -07:00
Tiago Costa
e41569b4a6
fix(NA): wrongly spread stripInternal and rootDir configs across packages (#144463)
* chore(NA): remove overrides for rootDir on packages

* chore(NA): replace './target_types' with 'target_types' on packages

* chore(NA): removes stripInternal false configs

* chore(NA): remove unused strip internals
2022-11-03 01:04:55 +00:00
Spencer
7d77d39e1f
[ts] set allowJs to true by default (#144281)
* [ts] set allowJs to true by default

* fix scripts/check_ts_projects, original implementation is now wildly inefficient

* produce stats in check_ts_projects to make sure it's actually working

* fix imports
2022-11-01 15:26:44 -07:00
spalger
52f2b33a07
[auto] migrate existing plugin/package configs 2022-10-28 14:06:46 -05:00
spalger
42879f7656
[bazel] fix some BUILD.bazel file inconsistencies 2022-10-26 11:07:55 -05:00
Jonathan Budzenski
7a056a84d9
fix flaky test 'produces a valid junit report for failures' (#143995)
* fix flaky test 'produces a valid junit report for failures'

After the upgrading to Jest 27, it appears the runtime of this test is
occasionally reported as 0.  0 is evaluated to false and time is left
out of the junit report.  This updates the conditional to check for type
number.

Closes #143993

* unskip
2022-10-26 10:49:00 -05:00
Jonathan Budzenski
2d1cdfdc28 skip flaky test. #143993 2022-10-25 19:31:24 -05:00
Jonathan Budzenski
be432c0d89
Upgrade to Jest 27 (#139335)
* Upgrade to Jest 27

* fix test
2022-10-25 14:38:38 -05:00