Skip to content

Commit

Permalink
[7.x] [Ingest Manager] Rename API /api/ingest_manager => /api/fleet (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet authored Oct 6, 2020
1 parent 3498d12 commit 644047f
Show file tree
Hide file tree
Showing 58 changed files with 517 additions and 323 deletions.
60 changes: 33 additions & 27 deletions x-pack/plugins/ingest_manager/common/constants/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
* you may not use this file except in compliance with the Elastic License.
*/
// Base API paths
export const API_ROOT = `/api/ingest_manager`;

export const API_ROOT = `/api/fleet`;
export const EPM_API_ROOT = `${API_ROOT}/epm`;
export const DATA_STREAM_API_ROOT = `${API_ROOT}/data_streams`;
export const PACKAGE_POLICY_API_ROOT = `${API_ROOT}/package_policies`;
export const AGENT_POLICY_API_ROOT = `${API_ROOT}/agent_policies`;
export const FLEET_API_ROOT = `${API_ROOT}/fleet`;
export const FLEET_API_ROOT_7_9 = `/api/ingest_manager/fleet`;

export const LIMITED_CONCURRENCY_ROUTE_TAG = 'ingest:limited-concurrency';

Expand Down Expand Up @@ -76,37 +77,42 @@ export const APP_API_ROUTES = {

// Agent API routes
export const AGENT_API_ROUTES = {
LIST_PATTERN: `${FLEET_API_ROOT}/agents`,
INFO_PATTERN: `${FLEET_API_ROOT}/agents/{agentId}`,
UPDATE_PATTERN: `${FLEET_API_ROOT}/agents/{agentId}`,
DELETE_PATTERN: `${FLEET_API_ROOT}/agents/{agentId}`,
EVENTS_PATTERN: `${FLEET_API_ROOT}/agents/{agentId}/events`,
CHECKIN_PATTERN: `${FLEET_API_ROOT}/agents/{agentId}/checkin`,
ACKS_PATTERN: `${FLEET_API_ROOT}/agents/{agentId}/acks`,
ACTIONS_PATTERN: `${FLEET_API_ROOT}/agents/{agentId}/actions`,
ENROLL_PATTERN: `${FLEET_API_ROOT}/agents/enroll`,
UNENROLL_PATTERN: `${FLEET_API_ROOT}/agents/{agentId}/unenroll`,
BULK_UNENROLL_PATTERN: `${FLEET_API_ROOT}/agents/bulk_unenroll`,
REASSIGN_PATTERN: `${FLEET_API_ROOT}/agents/{agentId}/reassign`,
BULK_REASSIGN_PATTERN: `${FLEET_API_ROOT}/agents/bulk_reassign`,
STATUS_PATTERN: `${FLEET_API_ROOT}/agent-status`,
UPGRADE_PATTERN: `${FLEET_API_ROOT}/agents/{agentId}/upgrade`,
BULK_UPGRADE_PATTERN: `${FLEET_API_ROOT}/agents/bulk_upgrade`,
LIST_PATTERN: `${API_ROOT}/agents`,
INFO_PATTERN: `${API_ROOT}/agents/{agentId}`,
UPDATE_PATTERN: `${API_ROOT}/agents/{agentId}`,
DELETE_PATTERN: `${API_ROOT}/agents/{agentId}`,
EVENTS_PATTERN: `${API_ROOT}/agents/{agentId}/events`,
CHECKIN_PATTERN: `${API_ROOT}/agents/{agentId}/checkin`,
ACKS_PATTERN: `${API_ROOT}/agents/{agentId}/acks`,
ACTIONS_PATTERN: `${API_ROOT}/agents/{agentId}/actions`,
ENROLL_PATTERN: `${API_ROOT}/agents/enroll`,
UNENROLL_PATTERN: `${API_ROOT}/agents/{agentId}/unenroll`,
BULK_UNENROLL_PATTERN: `${API_ROOT}/agents/bulk_unenroll`,
REASSIGN_PATTERN: `${API_ROOT}/agents/{agentId}/reassign`,
BULK_REASSIGN_PATTERN: `${API_ROOT}/agents/bulk_reassign`,
STATUS_PATTERN: `${API_ROOT}/agent-status`,
UPGRADE_PATTERN: `${API_ROOT}/agents/{agentId}/upgrade`,
BULK_UPGRADE_PATTERN: `${API_ROOT}/agents/bulk_upgrade`,
};
export const AGENT_API_ROUTES_7_9 = {
CHECKIN_PATTERN: `${FLEET_API_ROOT_7_9}/agents/{agentId}/checkin`,
ACKS_PATTERN: `${FLEET_API_ROOT_7_9}/agents/{agentId}/acks`,
ENROLL_PATTERN: `${FLEET_API_ROOT_7_9}/agents/enroll`,
};

export const ENROLLMENT_API_KEY_ROUTES = {
CREATE_PATTERN: `${FLEET_API_ROOT}/enrollment-api-keys`,
LIST_PATTERN: `${FLEET_API_ROOT}/enrollment-api-keys`,
INFO_PATTERN: `${FLEET_API_ROOT}/enrollment-api-keys/{keyId}`,
DELETE_PATTERN: `${FLEET_API_ROOT}/enrollment-api-keys/{keyId}`,
CREATE_PATTERN: `${API_ROOT}/enrollment-api-keys`,
LIST_PATTERN: `${API_ROOT}/enrollment-api-keys`,
INFO_PATTERN: `${API_ROOT}/enrollment-api-keys/{keyId}`,
DELETE_PATTERN: `${API_ROOT}/enrollment-api-keys/{keyId}`,
};

// Fleet setup API routes
export const FLEET_SETUP_API_ROUTES = {
INFO_PATTERN: `${FLEET_API_ROOT}/setup`,
CREATE_PATTERN: `${FLEET_API_ROOT}/setup`,
// Agents setup API routes
export const AGENTS_SETUP_API_ROUTES = {
INFO_PATTERN: `${API_ROOT}/agents/setup`,
CREATE_PATTERN: `${API_ROOT}/agents/setup`,
};

export const SETUP_API_ROUTE = `${API_ROOT}/setup`;

export const INSTALL_SCRIPT_API_ROUTES = `${FLEET_API_ROOT}/install/{osType}`;
export const INSTALL_SCRIPT_API_ROUTES = `${API_ROOT}/install/{osType}`;
12 changes: 6 additions & 6 deletions x-pack/plugins/ingest_manager/common/openapi/spec_oas3.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"servers": [
{
"url": "http://localhost:5601/api/ingest_manager",
"url": "http://localhost:5601/api/fleet",
"description": "local"
}
],
Expand Down Expand Up @@ -1280,9 +1280,9 @@
]
}
},
"/fleet/setup": {
"/agents/setup": {
"get": {
"summary": "Fleet setup - Info",
"summary": "Agents setup - Info",
"tags": [],
"responses": {
"200": {
Expand Down Expand Up @@ -1314,16 +1314,16 @@
}
}
},
"operationId": "get-fleet-setup",
"operationId": "get-agents-setup",
"security": [
{
"basicAuth": []
}
]
},
"post": {
"summary": "Fleet setup - Create",
"operationId": "post-fleet-setup",
"summary": "Agents setup - Create",
"operationId": "post-agents-setup",
"responses": {
"200": {
"description": "OK",
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/ingest_manager/common/services/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
PACKAGE_POLICY_API_ROUTES,
AGENT_POLICY_API_ROUTES,
DATA_STREAM_API_ROUTES,
FLEET_SETUP_API_ROUTES,
AGENTS_SETUP_API_ROUTES,
AGENT_API_ROUTES,
ENROLLMENT_API_KEY_ROUTES,
SETUP_API_ROUTE,
Expand Down Expand Up @@ -121,8 +121,8 @@ export const dataStreamRouteService = {
};

export const fleetSetupRouteService = {
getFleetSetupPath: () => FLEET_SETUP_API_ROUTES.INFO_PATTERN,
postFleetSetupPath: () => FLEET_SETUP_API_ROUTES.CREATE_PATTERN,
getFleetSetupPath: () => AGENTS_SETUP_API_ROUTES.INFO_PATTERN,
postFleetSetupPath: () => AGENTS_SETUP_API_ROUTES.CREATE_PATTERN,
};

export const agentRouteService = {
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/ingest_manager/dev_docs/api/agents_acks.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Acknowledge actions received during checkin

## Request

`POST /api/ingest_manager/fleet/agents/{agentId}/acks`
`POST /api/fleet/agents/{agentId}/acks`

## Headers

Expand All @@ -22,7 +22,7 @@ Acknowledge actions received during checkin
## Example

```js
POST /api/ingest_manager/fleet/agents/a4937110-e53e-11e9-934f-47a8e38a522c/acks
POST /api/fleet/agents/a4937110-e53e-11e9-934f-47a8e38a522c/acks
Authorization: ApiKey VALID_ACCESS_API_KEY
{
"action_ids": ["action-1", "action-2"]
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/ingest_manager/dev_docs/api/agents_checkin.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Report current state of a Fleet agent.

## Request

`POST /api/ingest_manager/fleet/agents/{agentId}/checkin`
`POST /api/fleet/agents/{agentId}/checkin`

## Headers

Expand All @@ -24,7 +24,7 @@ Report current state of a Fleet agent.
## Example

```js
POST /api/ingest_manager/fleet/agents/a4937110-e53e-11e9-934f-47a8e38a522c/checkin
POST /api/fleet/agents/a4937110-e53e-11e9-934f-47a8e38a522c/checkin
Authorization: ApiKey VALID_ACCESS_API_KEY
{
"events": [{
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/ingest_manager/dev_docs/api/agents_enroll.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Enroll agent

## Request

`POST /api/ingest_manager/fleet/agents/enroll`
`POST /api/fleet/agents/enroll`

## Headers

Expand All @@ -25,7 +25,7 @@ Enroll agent
## Example

```js
POST /api/ingest_manager/fleet/agents/enroll
POST /api/fleet/agents/enroll
Authorization: ApiKey VALID_API_KEY
{
"type": "PERMANENT",
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/ingest_manager/dev_docs/api/agents_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Request

`GET /api/ingest_manager/fleet/agents`
`GET /api/fleet/agents`

## Query

Expand All @@ -18,5 +18,5 @@
## Example

```js
GET /api/ingest_manager/fleet/agents?kuery=fleet-agents.last_checkin:2019-10-01T13:42:54.323Z
GET /api/fleet/agents?kuery=fleet-agents.last_checkin:2019-10-01T13:42:54.323Z
```
4 changes: 2 additions & 2 deletions x-pack/plugins/ingest_manager/dev_docs/api/agents_unenroll.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Unenroll an agent

## Request

`POST /api/ingest_manager/fleet/agents/unenroll`
`POST /api/fleet/agents/unenroll`

## Request body

Expand All @@ -20,7 +20,7 @@ Unenroll an agent
## Example

```js
POST /api/ingest_manager/fleet/agents/enroll
POST /api/fleet/agents/enroll
{
"ids": ['agent1'],
}
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/ingest_manager/dev_docs/api/epm.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ The Package Manager offers an API. Here an example on how they can be used.
List installed packages:

```
curl localhost:5601/api/ingest_manager/epm/packages
curl localhost:5601/api/fleet/epm/packages
```

Install a package:

```
curl -X POST localhost:5601/api/ingest_manager/epm/packages/iptables-1.0.4
curl -X POST localhost:5601/api/fleet/epm/packages/iptables-1.0.4
```

Delete a package:

```
curl -X DELETE localhost:5601/api/ingest_manager/epm/packages/iptables-1.0.4
curl -X DELETE localhost:5601/api/fleet/epm/packages/iptables-1.0.4
```
18 changes: 11 additions & 7 deletions x-pack/plugins/ingest_manager/dev_docs/api_integration_tests.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
# API integration tests

Many API integration tests for Ingest Manager trigger at some point a connection to the package registry, and retrieval of some packages. If these connections are made to a package registry deployment outside of Kibana CI, these tests can fail at any time for two reasons:
* the deployed registry is temporarily unavailable
* the packages served by the registry do not match the expectation of the code under test

- the deployed registry is temporarily unavailable
- the packages served by the registry do not match the expectation of the code under test

For that reason, we run a dockerized version of the package registry in Kibana CI. For this to work, our tests must run against a custom test configuration and be kept in a custom directory, `x-pack/test/ingest_manager_api_integration`.

## How to run the tests locally

Usually, having the test server and the test runner in two different shells is most efficient, as it is possible to keep the server running and only rerun the test runner as often as needed. To do so, in one shell in the main `kibana` directory, run:

```
$ export INGEST_MANAGEMENT_PACKAGE_REGISTRY_PORT=12345
$ yarn test:ftr:server --config x-pack/test/ingest_manager_api_integration/config.ts
```

In another shell in the same directory, run

```
$ export INGEST_MANAGEMENT_PACKAGE_REGISTRY_PORT=12345
$ yarn test:ftr:runner --config x-pack/test/ingest_manager_api_integration/config.ts
```

However, it is also possible to **alternatively** run everything in one go, again from the main `kibana` directory:

```
$ export INGEST_MANAGEMENT_PACKAGE_REGISTRY_PORT=12345
$ yarn test:ftr --config x-pack/test/ingest_manager_api_integration/config.ts
```
Port `12345` is used as an example here, it can be anything, but the environment variable has to be present for the tests to run at all.

Port `12345` is used as an example here, it can be anything, but the environment variable has to be present for the tests to run at all.

## DockerServers service setup

Expand All @@ -50,9 +54,9 @@ The main configuration for the `DockerServers` service for our tests can be foun
'./apis/fixtures/test_packages'
)}:/registry/packages/test-packages`,
];
```
```

`-v` mounts local paths into the docker image. The first one puts a custom configuration file into the correct place in the docker container, the second one mounts a directory containing additional packages.
`-v` mounts local paths into the docker image. The first one puts a custom configuration file into the correct place in the docker container, the second one mounts a directory containing additional packages.

### Specify the docker image to use

Expand Down Expand Up @@ -82,7 +86,7 @@ Also, not every developer has `docker` installed on their workstation, so it mus
it('fetches a .json search file', async function () {
if (server.enabled) {
await supertest
.get('/api/ingest_manager/epm/packages/filetest/0.1.0/kibana/search/sample_search.json')
.get('/api/fleet/epm/packages/filetest/0.1.0/kibana/search/sample_search.json')
.set('kbn-xsrf', 'xxx')
.expect('Content-Type', 'application/json; charset=utf-8')
.expect(200);
Expand All @@ -104,7 +108,7 @@ If the tests are skipped in this way, they are marked in the test summary as `pe
│ warn disabling tests because DockerServers service is not enabled, set INGEST_MANAGEMENT_PACKAGE_REGISTRY_PORT to run them
└-> lists all packages from the registry
└-> "after all" hook
[...]
[...]
│1 passing (233ms)
│6 pending
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ When an agent checkin fleet:

This is really similar to the checkin (same auth mecanism) and it's used for agent to acknowlege action received during checkin.

An agent can acknowledge one or multiple actions by calling `POST /api/ingest_manager/fleet/agents/{agentId}/acks`
An agent can acknowledge one or multiple actions by calling `POST /api/fleet/agents/{agentId}/acks`

## Other interactions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const AgentPolicyDeleteProvider: React.FunctionComponent<Props> = ({ chil
}
setIsLoadingAgentsCount(true);
const { data } = await sendRequest<{ total: number }>({
path: `/api/ingest_manager/fleet/agents`,
path: `/api/fleet/agents`,
method: 'get',
query: {
kuery: `${AGENT_SAVED_OBJECT_TYPE}.policy_id : ${agentPolicyToCheck}`,
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/ingest_manager/scripts/dev_agent/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ async function checkin(kibanaURL: string, agent: Agent, log: ToolingLog) {
},
],
};
const res = await fetch(`${kibanaURL}/api/ingest_manager/fleet/agents/${agent.id}/checkin`, {
const res = await fetch(`${kibanaURL}/api/fleet/agents/${agent.id}/checkin`, {
method: 'POST',
body: JSON.stringify(body),
headers: {
Expand Down Expand Up @@ -116,7 +116,7 @@ async function enroll(kibanaURL: string, apiKey: string, log: ToolingLog): Promi
},
},
};
const res = await fetch(`${kibanaURL}/api/ingest_manager/fleet/agents/enroll`, {
const res = await fetch(`${kibanaURL}/api/fleet/agents/enroll`, {
method: 'POST',
body: JSON.stringify(body),
headers: {
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/ingest_manager/server/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ export {
DATA_STREAM_API_ROUTES,
PACKAGE_POLICY_API_ROUTES,
AGENT_API_ROUTES,
AGENT_API_ROUTES_7_9,
AGENT_POLICY_API_ROUTES,
FLEET_SETUP_API_ROUTES,
AGENTS_SETUP_API_ROUTES,
ENROLLMENT_API_KEY_ROUTES,
INSTALL_SCRIPT_API_ROUTES,
OUTPUT_API_ROUTES,
Expand Down
Loading

0 comments on commit 644047f

Please sign in to comment.