Skip to content

Commit

Permalink
[Fleet] Remove deprecated APIs for agents endpoints (elastic#198313)
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet authored Nov 1, 2024
1 parent 34aab05 commit 115dbec
Show file tree
Hide file tree
Showing 27 changed files with 26 additions and 1,995 deletions.
540 changes: 0 additions & 540 deletions oas_docs/bundle.json

Large diffs are not rendered by default.

540 changes: 0 additions & 540 deletions oas_docs/bundle.serverless.json

Large diffs are not rendered by default.

379 changes: 0 additions & 379 deletions oas_docs/output/kibana.serverless.yaml

Large diffs are not rendered by default.

379 changes: 0 additions & 379 deletions oas_docs/output/kibana.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const createPolicies = (
const agentPolicyStatus = {
id: agentPolicy.id,
name: agentPolicy.name,
agents: agentStatusByAgentPolicyId[agentPolicy.id]?.total,
agents: agentStatusByAgentPolicyId[agentPolicy.id]?.active,
};
return {
package_policy: cloudDefendPackage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const getBenchmarksData = (
const agentPolicyStatus = {
id: agentPolicy.id,
name: agentPolicy.name,
agents: agentStatusByAgentPolicyId[agentPolicy.id]?.total,
agents: agentStatusByAgentPolicyId[agentPolicy.id]?.active,
};
return {
package_policy: cspPackage,
Expand Down
4 changes: 0 additions & 4 deletions x-pack/plugins/fleet/common/constants/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ export const APP_API_ROUTES = {
CHECK_PERMISSIONS_PATTERN: `${API_ROOT}/check-permissions`,
GENERATE_SERVICE_TOKEN_PATTERN: `${API_ROOT}/service_tokens`,
AGENT_POLICIES_SPACES: `${INTERNAL_ROOT}/agent_policies_spaces`,
// deprecated since 8.0
GENERATE_SERVICE_TOKEN_PATTERN_DEPRECATED: `${API_ROOT}/service-tokens`,
};

// Agent API routes
Expand All @@ -159,8 +157,6 @@ export const AGENT_API_ROUTES = {
AVAILABLE_VERSIONS_PATTERN: `${API_ROOT}/agents/available_versions`,
STATUS_PATTERN: `${API_ROOT}/agent_status`,
DATA_PATTERN: `${API_ROOT}/agent_status/data`,
// deprecated since 8.0
STATUS_PATTERN_DEPRECATED: `${API_ROOT}/agent-status`,
UPGRADE_PATTERN: `${API_ROOT}/agents/{agentId}/upgrade`,
BULK_UPGRADE_PATTERN: `${API_ROOT}/agents/bulk_upgrade`,
ACTION_STATUS_PATTERN: `${API_ROOT}/agents/action_status`,
Expand Down
16 changes: 1 addition & 15 deletions x-pack/plugins/fleet/common/types/rest_spec/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ import type { ListResult, ListWithKuery } from './common';

export interface GetAgentsRequest {
query: ListWithKuery & {
showInactive: boolean;
showInactive?: boolean;
showUpgradeable?: boolean;
withMetrics?: boolean;
};
}

export interface GetAgentsResponse extends ListResult<Agent> {
// deprecated in 8.x
list?: Agent[];
statusSummary?: Record<AgentStatus, number>;
}

Expand Down Expand Up @@ -128,16 +126,6 @@ export type PostBulkAgentUpgradeResponse = BulkAgentAction;
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface PostAgentUpgradeResponse {}

// deprecated
export interface PutAgentReassignRequest {
params: {
agentId: string;
};
body: { policy_id: string };
}
// deprecated
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface PutAgentReassignResponse {}
export interface PostAgentReassignRequest {
params: {
agentId: string;
Expand Down Expand Up @@ -217,8 +205,6 @@ export interface GetAgentStatusRequest {
export interface GetAgentStatusResponse {
results: {
events: number;
// deprecated
total: number;
online: number;
error: number;
offline: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ export const CreatePackagePolicySinglePage: CreatePackagePolicyParams = ({
let count = 0;
for (const policyId of agentPolicyIds) {
const { data } = await sendGetAgentStatus({ policyId });
if (data?.results.total) {
count += data.results.total;
if (data?.results.active) {
count += data.results.active;
}
}
setAgentCount(count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ export const SettingsView = memo<{ agentPolicy: AgentPolicy }>(
if (isFleetEnabled) {
setIsLoading(true);
const { data } = await sendGetAgentStatus({ policyId: agentPolicy.id });
if (data?.results.total) {
setAgentCount(data.results.total);
if (data?.results.active) {
setAgentCount(data.results.active);
} else {
await submitUpdateAgentPolicy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ export const EditPackagePolicyForm = memo<{
let count = 0;
for (const id of packagePolicy.policy_ids) {
const { data } = await sendGetAgentStatus({ policyId: id });
if (data?.results.total) {
count += data.results.total;
if (data?.results.active) {
count += data.results.active;
}
}
setAgentCount(count);
Expand Down
30 changes: 2 additions & 28 deletions x-pack/plugins/fleet/server/routes/agent/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
* 2.0.
*/

import { uniq } from 'lodash';
import { omit, uniq } from 'lodash';
import { type RequestHandler, SavedObjectsErrorHelpers } from '@kbn/core/server';
import type { TypeOf } from '@kbn/config-schema';

import type {
GetAgentsResponse,
GetOneAgentResponse,
GetAgentStatusResponse,
PutAgentReassignResponse,
GetAgentTagsResponse,
GetAvailableVersionsResponse,
GetActionStatusResponse,
Expand All @@ -30,7 +29,6 @@ import type {
DeleteAgentRequestSchema,
GetAgentStatusRequestSchema,
GetAgentDataRequestSchema,
PutAgentReassignRequestSchemaDeprecated,
PostAgentReassignRequestSchema,
PostBulkAgentReassignRequestSchema,
PostBulkUpdateAgentTagsRequestSchema,
Expand Down Expand Up @@ -207,7 +205,6 @@ export const getAgentsHandler: FleetRequestHandler<
}

const body: GetAgentsResponse = {
list: agents, // deprecated
items: agents,
total,
page,
Expand Down Expand Up @@ -243,29 +240,6 @@ export const getAgentTagsHandler: RequestHandler<
}
};

export const putAgentsReassignHandlerDeprecated: RequestHandler<
TypeOf<typeof PutAgentReassignRequestSchemaDeprecated.params>,
undefined,
TypeOf<typeof PutAgentReassignRequestSchemaDeprecated.body>
> = async (context, request, response) => {
const coreContext = await context.core;
const soClient = coreContext.savedObjects.client;
const esClient = coreContext.elasticsearch.client.asInternalUser;
try {
await AgentService.reassignAgent(
soClient,
esClient,
request.params.agentId,
request.body.policy_id
);

const body: PutAgentReassignResponse = {};
return response.ok({ body });
} catch (error) {
return defaultFleetErrorHandler({ error, response });
}
};

export const postAgentReassignHandler: RequestHandler<
TypeOf<typeof PostAgentReassignRequestSchema.params>,
undefined,
Expand Down Expand Up @@ -341,7 +315,7 @@ export const getAgentStatusForAgentPolicyHandler: FleetRequestHandler<
parsePolicyIds(request.query.policyIds)
);

const body: GetAgentStatusResponse = { results };
const body: GetAgentStatusResponse = { results: omit(results, 'total') };

return response.ok({ body });
} catch (error) {
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/fleet/server/routes/agent/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ describe('schema validation', () => {
it('list agents should return valid response', async () => {
const expectedResponse: GetAgentsResponse = {
items: [agent],
list: [agent],
total: 1,
page: 1,
perPage: 1,
Expand Down Expand Up @@ -366,7 +365,6 @@ describe('schema validation', () => {
const expectedResponse: GetAgentStatusResponse = {
results: {
events: 1,
total: 1,
online: 1,
error: 1,
offline: 1,
Expand Down
35 changes: 0 additions & 35 deletions x-pack/plugins/fleet/server/routes/agent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
GetAgentStatusRequestSchema,
GetAgentDataRequestSchema,
PostNewAgentActionRequestSchema,
PutAgentReassignRequestSchemaDeprecated,
PostAgentReassignRequestSchema,
PostBulkAgentReassignRequestSchema,
PostAgentUpgradeRequestSchema,
Expand Down Expand Up @@ -68,7 +67,6 @@ import {
updateAgentHandler,
deleteAgentHandler,
getAgentStatusForAgentPolicyHandler,
putAgentsReassignHandlerDeprecated,
postBulkAgentReassignHandler,
getAgentDataHandler,
bulkUpdateAgentTagsHandler,
Expand Down Expand Up @@ -391,23 +389,6 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT
postAgentUnenrollHandler
);

router.versioned
.put({
path: AGENT_API_ROUTES.REASSIGN_PATTERN,
fleetAuthz: {
fleet: { allAgents: true },
},
// @ts-expect-error TODO(https://github.com/elastic/kibana/issues/196095): Replace {RouteDeprecationInfo}
deprecated: true,
})
.addVersion(
{
version: API_VERSIONS.public.v1,
validate: { request: PutAgentReassignRequestSchemaDeprecated },
},
putAgentsReassignHandlerDeprecated
);

router.versioned
.post({
path: AGENT_API_ROUTES.REASSIGN_PATTERN,
Expand Down Expand Up @@ -613,22 +594,6 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT
},
getAgentStatusForAgentPolicyHandler
);
router.versioned
.get({
path: AGENT_API_ROUTES.STATUS_PATTERN_DEPRECATED,
fleetAuthz: {
fleet: { readAgents: true },
},
// @ts-expect-error TODO(https://github.com/elastic/kibana/issues/196095): Replace {RouteDeprecationInfo}
deprecated: true,
})
.addVersion(
{
version: API_VERSIONS.public.v1,
validate: { request: GetAgentStatusRequestSchema },
},
getAgentStatusForAgentPolicyHandler
);
// Agent data
router.versioned
.get({
Expand Down
18 changes: 0 additions & 18 deletions x-pack/plugins/fleet/server/routes/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,22 +285,4 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType
},
generateServiceTokenHandler
);

router.versioned
.post({
path: APP_API_ROUTES.GENERATE_SERVICE_TOKEN_PATTERN_DEPRECATED,
fleetAuthz: {
fleet: { allAgents: true },
},
description: `Create a service token`,
// @ts-expect-error TODO(https://github.com/elastic/kibana/issues/196095): Replace {RouteDeprecationInfo}
deprecated: true,
})
.addVersion(
{
version: API_VERSIONS.public.v1,
validate: {},
},
generateServiceTokenHandler
);
};
22 changes: 0 additions & 22 deletions x-pack/plugins/fleet/server/types/rest_spec/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,6 @@ export const AgentResponseSchema = schema.object({
});

export const GetAgentsResponseSchema = ListResponseSchema(AgentResponseSchema).extends({
list: schema.maybe(
schema.arrayOf(AgentResponseSchema, {
meta: { deprecated: true },
})
),
statusSummary: schema.maybe(schema.recordOf(AgentStatusSchema, schema.number())),
});

Expand Down Expand Up @@ -377,15 +372,6 @@ export const PostBulkAgentUpgradeRequestSchema = {
}),
};

export const PutAgentReassignRequestSchemaDeprecated = {
params: schema.object({
agentId: schema.string(),
}),
body: schema.object({
policy_id: schema.string(),
}),
};

export const PostAgentReassignRequestSchema = {
params: schema.object({
agentId: schema.string(),
Expand Down Expand Up @@ -518,9 +504,6 @@ export const GetAgentStatusRequestSchema = {
return validationObj?.error;
}
},
meta: {
deprecated: true,
},
})
),
}),
Expand All @@ -529,11 +512,6 @@ export const GetAgentStatusRequestSchema = {
export const GetAgentStatusResponseSchema = schema.object({
results: schema.object({
events: schema.number(),
total: schema.number({
meta: {
deprecated: true,
},
}),
online: schema.number(),
error: schema.number(),
offline: schema.number(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const getAgentPoliciesRoute = (router: IRouter, osqueryContext: OsqueryAp
(agentPolicy: GetAgentPoliciesResponseItem) =>
agentService?.asInternalUser
.getAgentStatusForAgentPolicy(agentPolicy.id)
.then(({ total: agentTotal }) => (agentPolicy.agents = agentTotal)),
.then(({ active: agentTotal }) => (agentPolicy.agents = agentTotal)),
{ concurrency: 10 }
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from '@kbn/fleet-plugin/common';
import type {
GetOneAgentResponse,
PutAgentReassignResponse,
PostAgentReassignResponse,
UpdateAgentPolicyResponse,
} from '@kbn/fleet-plugin/common/types';
import { uninstallTokensRouteService } from '@kbn/fleet-plugin/common/services/routes';
Expand Down Expand Up @@ -56,10 +56,10 @@ export const getAgentByHostName = (hostname: string): Cypress.Chainable<Agent> =
export const reassignAgentPolicy = (
agentId: string,
agentPolicyId: string
): Cypress.Chainable<Cypress.Response<PutAgentReassignResponse>> =>
request<PutAgentReassignResponse>({
): Cypress.Chainable<Cypress.Response<PostAgentReassignResponse>> =>
request<PostAgentReassignResponse>({
url: agentRouteService.getReassignPath(agentId),
method: 'PUT',
method: 'POST',
body: {
policy_id: agentPolicyId,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ describe('Policy Details', () => {
if (path === `${AGENT_API_ROUTES.STATUS_PATTERN}`) {
asyncActions = asyncActions.then(async () => sleep());
return Promise.resolve({
results: { events: 0, total: 5, online: 3, error: 1, offline: 1 },
results: { events: 0, active: 5, online: 3, error: 1, offline: 1 },
success: true,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const PolicyDetails = React.memo(() => {

const headerRightContent = (
<AgentsSummary
total={policyAgentStatusSummary?.total ?? 0}
total={policyAgentStatusSummary?.active ?? 0}
online={policyAgentStatusSummary?.online ?? 0}
offline={policyAgentStatusSummary?.offline ?? 0}
error={policyAgentStatusSummary?.error ?? 0}
Expand Down
Loading

0 comments on commit 115dbec

Please sign in to comment.