Skip to content

Commit

Permalink
[8.x] [ECO][Inventory v2] APM changes (#202497) (#204524)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.x`:
- [[ECO][Inventory v2] APM changes
(#202497)](#202497)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Cauê
Marcondes","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-17T09:24:33Z","message":"[ECO][Inventory
v2] APM changes (#202497)\n\nCloses
[202299](https://github.com/elastic/kibana/issues/202299)\r\n\r\n##
Summary\r\n\r\nThis PR replaces the query in `getServiceEntitySummary`
with the v2\r\nfunction
(`entityManagerClient.v2.searchEntities`)\r\n\r\n## Testing\r\n- Verify
the response of the summary endpoint in the
UI:\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/ba895f7d-57c8-492b-81dd-cf7869ffbc86\r\n\r\n\r\n\r\n-
Dev tools query\r\n - APM service\r\n #### Request:\r\n
```\r\nGET\r\nkbn:/internal/apm/entities/services/synth-node-0/summary?environment=ENVIRONMENT_ALL\r\n
```\r\n #### Response\r\n ```\r\n {\r\n \"serviceName\":
\"synth-node-0\",\r\n \"agentName\": \"nodejs\",\r\n
\"lastSeenTimestamp\": \"2024-12-13T16:29:19.868Z\",\r\n
\"dataStreamTypes\": [\r\n \"logs\",\r\n \"traces\"\r\n ],\r\n
\"environments\": [\r\n \"Synthtrace: simple_trace\"\r\n ]\r\n }\r\n
```\r\n\r\n - Service from logs\r\n #### Request:\r\n
```\r\nGET\r\nkbn:/internal/apm/entities/services/synth-node/summary?environment=ENVIRONMENT_ALL\r\n
```\r\n #### Response: \r\n ```\r\n {\r\n \"serviceName\":
\"synth-node\",\r\n \"agentName\": \"go\",\r\n \"lastSeenTimestamp\":
\"2024-12-13T16:27:43.461Z\",\r\n \"dataStreamTypes\": [\r\n
\"logs\",\r\n \"traces\"\r\n ],\r\n \"environments\": [\r\n
\"Synthtrace: logs_traces_hosts\"\r\n ]\r\n }\r\n
```\r\n\r\n---------\r\n\r\nCo-authored-by: Jenny
<[email protected]>\r\nCo-authored-by: kibanamachine
<[email protected]>","sha":"a66c1399e60b184c338fc99c9550539bd2ecf68b","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:prev-minor","ci:project-deploy-observability","Team:obs-ux-infra_services"],"title":"[ECO][Inventory
v2] APM
changes","number":202497,"url":"https://github.com/elastic/kibana/pull/202497","mergeCommit":{"message":"[ECO][Inventory
v2] APM changes (#202497)\n\nCloses
[202299](https://github.com/elastic/kibana/issues/202299)\r\n\r\n##
Summary\r\n\r\nThis PR replaces the query in `getServiceEntitySummary`
with the v2\r\nfunction
(`entityManagerClient.v2.searchEntities`)\r\n\r\n## Testing\r\n- Verify
the response of the summary endpoint in the
UI:\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/ba895f7d-57c8-492b-81dd-cf7869ffbc86\r\n\r\n\r\n\r\n-
Dev tools query\r\n - APM service\r\n #### Request:\r\n
```\r\nGET\r\nkbn:/internal/apm/entities/services/synth-node-0/summary?environment=ENVIRONMENT_ALL\r\n
```\r\n #### Response\r\n ```\r\n {\r\n \"serviceName\":
\"synth-node-0\",\r\n \"agentName\": \"nodejs\",\r\n
\"lastSeenTimestamp\": \"2024-12-13T16:29:19.868Z\",\r\n
\"dataStreamTypes\": [\r\n \"logs\",\r\n \"traces\"\r\n ],\r\n
\"environments\": [\r\n \"Synthtrace: simple_trace\"\r\n ]\r\n }\r\n
```\r\n\r\n - Service from logs\r\n #### Request:\r\n
```\r\nGET\r\nkbn:/internal/apm/entities/services/synth-node/summary?environment=ENVIRONMENT_ALL\r\n
```\r\n #### Response: \r\n ```\r\n {\r\n \"serviceName\":
\"synth-node\",\r\n \"agentName\": \"go\",\r\n \"lastSeenTimestamp\":
\"2024-12-13T16:27:43.461Z\",\r\n \"dataStreamTypes\": [\r\n
\"logs\",\r\n \"traces\"\r\n ],\r\n \"environments\": [\r\n
\"Synthtrace: logs_traces_hosts\"\r\n ]\r\n }\r\n
```\r\n\r\n---------\r\n\r\nCo-authored-by: Jenny
<[email protected]>\r\nCo-authored-by: kibanamachine
<[email protected]>","sha":"a66c1399e60b184c338fc99c9550539bd2ecf68b"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/202497","number":202497,"mergeCommit":{"message":"[ECO][Inventory
v2] APM changes (#202497)\n\nCloses
[202299](https://github.com/elastic/kibana/issues/202299)\r\n\r\n##
Summary\r\n\r\nThis PR replaces the query in `getServiceEntitySummary`
with the v2\r\nfunction
(`entityManagerClient.v2.searchEntities`)\r\n\r\n## Testing\r\n- Verify
the response of the summary endpoint in the
UI:\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/ba895f7d-57c8-492b-81dd-cf7869ffbc86\r\n\r\n\r\n\r\n-
Dev tools query\r\n - APM service\r\n #### Request:\r\n
```\r\nGET\r\nkbn:/internal/apm/entities/services/synth-node-0/summary?environment=ENVIRONMENT_ALL\r\n
```\r\n #### Response\r\n ```\r\n {\r\n \"serviceName\":
\"synth-node-0\",\r\n \"agentName\": \"nodejs\",\r\n
\"lastSeenTimestamp\": \"2024-12-13T16:29:19.868Z\",\r\n
\"dataStreamTypes\": [\r\n \"logs\",\r\n \"traces\"\r\n ],\r\n
\"environments\": [\r\n \"Synthtrace: simple_trace\"\r\n ]\r\n }\r\n
```\r\n\r\n - Service from logs\r\n #### Request:\r\n
```\r\nGET\r\nkbn:/internal/apm/entities/services/synth-node/summary?environment=ENVIRONMENT_ALL\r\n
```\r\n #### Response: \r\n ```\r\n {\r\n \"serviceName\":
\"synth-node\",\r\n \"agentName\": \"go\",\r\n \"lastSeenTimestamp\":
\"2024-12-13T16:27:43.461Z\",\r\n \"dataStreamTypes\": [\r\n
\"logs\",\r\n \"traces\"\r\n ],\r\n \"environments\": [\r\n
\"Synthtrace: logs_traces_hosts\"\r\n ]\r\n }\r\n
```\r\n\r\n---------\r\n\r\nCo-authored-by: Jenny
<[email protected]>\r\nCo-authored-by: kibanamachine
<[email protected]>","sha":"a66c1399e60b184c338fc99c9550539bd2ecf68b"}}]}]
BACKPORT-->

Co-authored-by: Cauê Marcondes <[email protected]>
  • Loading branch information
kibanamachine and cauemarcondes authored Dec 17, 2024
1 parent 4e7bca8 commit ab308aa
Show file tree
Hide file tree
Showing 16 changed files with 249 additions and 488 deletions.
1 change: 1 addition & 0 deletions x-pack/plugins/observability_solution/apm/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"uiActions",
"logsDataAccess",
"savedSearch",
"entityManager"
],
"optionalPlugins": [
"actions",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ describe('Entity link', () => {
renderEntityLink({
isEntityCentricExperienceEnabled: true,
serviceEntitySummaryMockReturnValue: {
serviceEntitySummary: { dataStreamTypes: ['metrics'] } as unknown as ServiceEntitySummary,
serviceEntitySummary: {
['data_stream.type']: ['metrics'],
} as unknown as ServiceEntitySummary,
serviceEntitySummaryStatus: FETCH_STATUS.SUCCESS,
},
hasApmDataFetcherMockReturnValue: {
Expand All @@ -200,7 +202,9 @@ describe('Entity link', () => {
renderEntityLink({
isEntityCentricExperienceEnabled: true,
serviceEntitySummaryMockReturnValue: {
serviceEntitySummary: { dataStreamTypes: ['metrics'] } as unknown as ServiceEntitySummary,
serviceEntitySummary: {
['data_stream.type']: ['metrics'],
} as unknown as ServiceEntitySummary,
serviceEntitySummaryStatus: FETCH_STATUS.SUCCESS,
},
hasApmDataFetcherMockReturnValue: {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,31 @@
* 2.0.
*/

import type { EntitiesESClient } from '../../../lib/helpers/create_es_client/create_entities_es_client/create_entities_es_client';
import { SERVICE_NAME, AGENT_NAME, SERVICE_ENVIRONMENT } from '@kbn/apm-types';
import { BUILT_IN_ENTITY_TYPES, DATA_STREAM_TYPE } from '@kbn/observability-shared-plugin/common';
import moment from 'moment';
import type { EntityClient } from '@kbn/entityManager-plugin/server/lib/entity_client';
import { withApmSpan } from '../../../utils/with_apm_span';
import { getEntityLatestServices } from '../get_entity_latest_services';
import { mergeEntities } from '../utils/merge_entities';
import { MAX_NUMBER_OF_SERVICES } from './get_service_entities';

interface Params {
entitiesESClient: EntitiesESClient;
entityManagerClient: EntityClient;
serviceName: string;
environment: string;
}

export function getServiceEntitySummary({ entitiesESClient, environment, serviceName }: Params) {
export function getServiceEntitySummary({ entityManagerClient, environment, serviceName }: Params) {
return withApmSpan('get_service_entity_summary', async () => {
const entityLatestServices = await getEntityLatestServices({
entitiesESClient,
environment,
size: MAX_NUMBER_OF_SERVICES,
serviceName,
const serviceEntitySummary = await entityManagerClient.v2.searchEntities({
start: moment().subtract(15, 'm').toISOString(),
end: moment().toISOString(),
type: BUILT_IN_ENTITY_TYPES.SERVICE_V2,
filters: [`${SERVICE_NAME}: "${serviceName}"`],
limit: 1,
metadata_fields: [DATA_STREAM_TYPE, AGENT_NAME, SERVICE_ENVIRONMENT],
});

const serviceEntity = mergeEntities({ entities: entityLatestServices });
const serviceEntity = mergeEntities({ entities: serviceEntitySummary?.entities });
return serviceEntity[0];
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
*/
import * as t from 'io-ts';
import { environmentQuery } from '../../../../common/utils/environment_query';
import { createEntitiesESClient } from '../../../lib/helpers/create_es_client/create_entities_es_client/create_entities_es_client';
import { createApmServerRoute } from '../../apm_routes/create_apm_server_route';
import { environmentRt, kueryRt, rangeRt } from '../../default_api_types';
import { getServiceEntities } from './get_service_entities';
import { getServiceEntitySummary } from './get_service_entity_summary';

const serviceEntitiesSummaryRoute = createApmServerRoute({
Expand All @@ -20,52 +18,20 @@ const serviceEntitiesSummaryRoute = createApmServerRoute({
}),
security: { authz: { requiredPrivileges: ['apm'] } },
async handler(resources) {
const { context, params, request } = resources;
const coreContext = await context.core;

const entitiesESClient = await createEntitiesESClient({
request,
esClient: coreContext.elasticsearch.client.asCurrentUser,
});
const { params, request, plugins } = resources;
const entityManagerStart = await plugins.entityManager.start();

const entityManagerClient = await entityManagerStart.getScopedClient({ request });
const { serviceName } = params.path;
const { environment } = params.query;

return getServiceEntitySummary({
entitiesESClient,
const serviceEntitySummary = await getServiceEntitySummary({
entityManagerClient,
serviceName,
environment,
});
},
});

const servicesEntitiesRoute = createApmServerRoute({
endpoint: 'GET /internal/apm/entities/services',
params: t.type({
query: t.intersection([environmentRt, kueryRt, rangeRt]),
}),
security: { authz: { requiredPrivileges: ['apm'] } },
async handler(resources) {
const { context, params, request } = resources;
const coreContext = await context.core;

const entitiesESClient = await createEntitiesESClient({
request,
esClient: coreContext.elasticsearch.client.asCurrentUser,
});

const { start, end, kuery, environment } = params.query;

const services = await getServiceEntities({
entitiesESClient,
start,
end,
kuery,
environment,
logger: resources.logger,
});

return { services };
return serviceEntitySummary;
},
});

Expand Down Expand Up @@ -137,7 +103,6 @@ const serviceLogErrorRateTimeseriesRoute = createApmServerRoute({
});

export const servicesEntitiesRoutesRepository = {
...servicesEntitiesRoute,
...serviceLogRateTimeseriesRoute,
...serviceLogErrorRateTimeseriesRoute,
...serviceEntitiesSummaryRoute,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,10 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { AgentName } from '../../../typings/es_schemas/ui/fields/agent';
import type { EntityMetadata, EntityV2 } from '@kbn/entities-schema';

export enum EntityType {
SERVICE = 'service',
}

export interface EntityLatestServiceRaw {
agent: {
name: AgentName[];
};
source_data_stream: {
type: string[];
};
service: {
name: string;
environment?: string;
};
entity: Entity;
}

interface Entity {
id: string;
last_seen_timestamp: string;
identity_fields: string[];
}
export type EntityLatestServiceRaw = EntityV2 & EntityMetadata;
Loading

0 comments on commit ab308aa

Please sign in to comment.