Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Infra][ECO] Adding summary API #194612

Merged
merged 12 commits into from
Oct 4, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const serviceTransactionFilter = (additionalFilters: string[] = []) => {

export const builtInServicesFromEcsEntityDefinition: EntityDefinition =
entityDefinitionSchema.parse({
version: '0.2.0',
version: '0.3.0',
id: `${BUILT_IN_ID_PREFIX}services_from_ecs_data`,
name: 'Services from ECS data',
description:
Expand All @@ -46,8 +46,15 @@ export const builtInServicesFromEcsEntityDefinition: EntityDefinition =
displayNameTemplate: '{{service.name}}',
metadata: [
{ source: '_index', destination: 'sourceIndex' },
{
source: 'data_stream.type',
destination: 'source_data_stream.type',
},
{
source: 'data_stream.dataset',
destination: 'source_data_stream.dataset',
},
{ source: 'agent.name', aggregation: { type: 'terms', limit: 100 } },
'data_stream.type',
'service.environment',
'service.name',
'service.namespace',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export async function findEntityDefinitions({
page = 1,
perPage = 10,
includeState = false,
type,
}: {
soClient: SavedObjectsClientContract;
esClient: ElasticsearchClient;
Expand All @@ -39,12 +40,14 @@ export async function findEntityDefinitions({
page?: number;
perPage?: number;
includeState?: boolean;
type?: string;
}): Promise<EntityDefinition[] | EntityDefinitionWithState[]> {
const filter = compact([
typeof builtIn === 'boolean'
? `${SO_ENTITY_DEFINITION_TYPE}.attributes.id:(${BUILT_IN_ID_PREFIX}*)`
: undefined,
id ? `${SO_ENTITY_DEFINITION_TYPE}.attributes.id:(${id})` : undefined,
type ? `${SO_ENTITY_DEFINITION_TYPE}.attributes.type:(${type})` : undefined,
]).join(' AND ');
const response = await soClient.find<EntityDefinition>({
type: SO_ENTITY_DEFINITION_TYPE,
Expand Down
6 changes: 6 additions & 0 deletions x-pack/plugins/entity_manager/server/lib/entity_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,15 @@ export class EntityClient {
page = 1,
perPage = 10,
includeState = false,
type,
builtIn,
}: {
id?: string;
page?: number;
perPage?: number;
includeState?: boolean;
type?: string;
builtIn?: boolean;
}) {
const definitions = await findEntityDefinitions({
esClient: this.options.esClient,
Expand All @@ -88,6 +92,8 @@ export class EntityClient {
perPage,
id,
includeState,
type,
builtIn,
});

return { definitions };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@
* 2.0.
*/

export const ENTITY = 'entity';
export const LAST_SEEN = 'entity.lastSeenTimestamp';
export const FIRST_SEEN = 'entity.firstSeenTimestamp';
export const ENTITY_ID = 'entity.id';
export const ENTITY_METRICS_LATENCY = 'entity.metrics.latency';
export const ENTITY_METRICS_LOG_ERROR_RATE = 'entity.metrics.logErrorRate';
export const ENTITY_METRICS_LOG_RATE = 'entity.metrics.logRate';
export const ENTITY_METRICS_THROUGHPUT = 'entity.metrics.throughput';
export const ENTITY_METRICS_FAILED_TRANSACTION_RATE = 'entity.metrics.failedTransactionRate';
export const ENTITY_TYPE = 'entity.type';
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
* 2.0.
*/
import type { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { FIRST_SEEN, LAST_SEEN } from '../../../common/es_fields/entities';
import {
ENTITY_FIRST_SEEN,
ENTITY_LAST_SEEN,
} from '@kbn/observability-shared-plugin/common/field_names/elasticsearch';
import type { EntitiesESClient } from '../../lib/helpers/create_es_client/create_entities_es_client/create_entities_es_client';
import { getEntityLatestServices } from './get_entity_latest_services';
import type { EntityLatestServiceRaw } from './types';
Expand All @@ -19,14 +22,14 @@ export function entitiesRangeQuery(start?: number, end?: number): QueryDslQueryC
return [
{
range: {
[LAST_SEEN]: {
[ENTITY_LAST_SEEN]: {
gte: start,
},
},
},
{
range: {
[FIRST_SEEN]: {
[ENTITY_FIRST_SEEN]: {
lte: end,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
* 2.0.
*/

import { termsQuery, rangeQuery } from '@kbn/observability-plugin/server';
import { EntityMetrics } from '../../../common/entities/types';
import { rangeQuery, termsQuery } from '@kbn/observability-plugin/server';
import {
ENTITY_ID,
ENTITY_LAST_SEEN,
} from '@kbn/observability-shared-plugin/common/field_names/elasticsearch';
import { EntityMetrics } from '../../../common/entities/types';
import {
ENTITY_METRICS_FAILED_TRANSACTION_RATE,
ENTITY_METRICS_LATENCY,
ENTITY_METRICS_LOG_ERROR_RATE,
ENTITY_METRICS_LOG_RATE,
ENTITY_METRICS_THROUGHPUT,
LAST_SEEN,
} from '../../../common/es_fields/entities';
import { EntitiesESClient } from '../../lib/helpers/create_es_client/create_entities_es_client/create_entities_es_client';

Expand All @@ -39,7 +41,10 @@ export async function getEntityHistoryServicesMetrics({
track_total_hits: false,
query: {
bool: {
filter: [...rangeQuery(start, end, LAST_SEEN), ...termsQuery(ENTITY_ID, ...entityIds)],
filter: [
...rangeQuery(start, end, ENTITY_LAST_SEEN),
...termsQuery(ENTITY_ID, ...entityIds),
],
},
},
aggs: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
* 2.0.
*/

import { termsQuery, rangeQuery } from '@kbn/observability-plugin/server';
import { getBucketSize } from '@kbn/apm-data-access-plugin/common';
import { rangeQuery, termsQuery } from '@kbn/observability-plugin/server';
import { ENTITY_LAST_SEEN } from '@kbn/observability-shared-plugin/common/field_names/elasticsearch';
import { keyBy } from 'lodash';
import { SERVICE_NAME } from '../../../common/es_fields/apm';
import {
ENTITY_METRICS_FAILED_TRANSACTION_RATE,
ENTITY_METRICS_LATENCY,
ENTITY_METRICS_LOG_ERROR_RATE,
ENTITY_METRICS_LOG_RATE,
ENTITY_METRICS_THROUGHPUT,
LAST_SEEN,
} from '../../../common/es_fields/entities';
import { SERVICE_NAME } from '../../../common/es_fields/apm';
import { EntitiesESClient } from '../../lib/helpers/create_es_client/create_entities_es_client/create_entities_es_client';
import { environmentQuery } from '../../../common/utils/environment_query';
import { EntitiesESClient } from '../../lib/helpers/create_es_client/create_entities_es_client/create_entities_es_client';

interface Params {
entitiesESClient: EntitiesESClient;
Expand Down Expand Up @@ -48,7 +48,7 @@ export async function getEntityHistoryServicesTimeseries({
query: {
bool: {
filter: [
...rangeQuery(start, end, LAST_SEEN),
...rangeQuery(start, end, ENTITY_LAST_SEEN),
...termsQuery(SERVICE_NAME, ...serviceNames),
...environmentQuery(environment),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

import { kqlQuery, termQuery } from '@kbn/observability-plugin/server';
import {
AGENT_NAME,
DATA_STEAM_TYPE,
SERVICE_ENVIRONMENT,
SERVICE_NAME,
} from '../../../common/es_fields/apm';
import { ENTITY, ENTITY_TYPE } from '../../../common/es_fields/entities';
ENTITY,
ENTITY_TYPE,
SOURCE_DATA_STREAM_TYPE,
} from '@kbn/observability-shared-plugin/common/field_names/elasticsearch';
import { AGENT_NAME, SERVICE_ENVIRONMENT, SERVICE_NAME } from '../../../common/es_fields/apm';
import { environmentQuery } from '../../../common/utils/environment_query';
import { EntitiesESClient } from '../../lib/helpers/create_es_client/create_entities_es_client/create_entities_es_client';
import { entitiesRangeQuery } from './get_entities';
Expand Down Expand Up @@ -40,7 +39,7 @@ export async function getEntityLatestServices({
body: {
size,
track_total_hits: false,
_source: [AGENT_NAME, ENTITY, DATA_STEAM_TYPE, SERVICE_NAME, SERVICE_ENVIRONMENT],
_source: [AGENT_NAME, ENTITY, SOURCE_DATA_STREAM_TYPE, SERVICE_NAME, SERVICE_ENVIRONMENT],
query: {
bool: {
filter: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface EntityLatestServiceRaw {
agent: {
name: AgentName[];
};
data_stream: {
source_data_stream: {
type: string[];
};
service: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('mergeEntities', () => {
environment: 'test',
},
agent: { name: ['nodejs'] },
data_stream: { type: ['metrics', 'logs'] },
source_data_stream: { type: ['metrics', 'logs'] },
entity: {
firstSeenTimestamp: '2024-06-05T10:34:40.810Z',
lastSeenTimestamp: '2024-06-05T10:34:40.810Z',
Expand Down Expand Up @@ -64,7 +64,7 @@ describe('mergeEntities', () => {
environment: 'env-service-1',
},
agent: { name: ['nodejs'] },
data_stream: { type: ['foo'] },
source_data_stream: { type: ['foo'] },
entity: {
firstSeenTimestamp: '2024-03-05T10:34:40.810Z',
lastSeenTimestamp: '2024-03-05T10:34:40.810Z',
Expand All @@ -85,7 +85,7 @@ describe('mergeEntities', () => {
environment: 'env-service-2',
},
agent: { name: ['nodejs'] },
data_stream: { type: ['bar'] },
source_data_stream: { type: ['bar'] },
entity: {
firstSeenTimestamp: '2024-03-05T10:34:40.810Z',
lastSeenTimestamp: '2024-03-05T10:34:40.810Z',
Expand All @@ -106,7 +106,7 @@ describe('mergeEntities', () => {
environment: 'env-service-3',
},
agent: { name: ['java'] },
data_stream: { type: ['baz'] },
source_data_stream: { type: ['baz'] },
entity: {
firstSeenTimestamp: '2024-06-05T10:34:40.810Z',
lastSeenTimestamp: '2024-06-05T10:34:40.810Z',
Expand All @@ -127,7 +127,7 @@ describe('mergeEntities', () => {
environment: 'env-service-4',
},
agent: { name: ['java'] },
data_stream: { type: ['baz'] },
source_data_stream: { type: ['baz'] },
entity: {
firstSeenTimestamp: '2024-06-05T10:34:40.810Z',
lastSeenTimestamp: '2024-06-05T10:34:40.810Z',
Expand Down Expand Up @@ -204,7 +204,7 @@ describe('mergeEntities', () => {
environment: 'test',
},
agent: { name: ['nodejs'] },
data_stream: { type: ['metrics', 'logs'] },
source_data_stream: { type: ['metrics', 'logs'] },
entity: {
firstSeenTimestamp: '2024-06-05T10:34:40.810Z',
lastSeenTimestamp: '2024-06-05T10:34:40.810Z',
Expand All @@ -225,7 +225,7 @@ describe('mergeEntities', () => {
environment: 'test',
},
agent: { name: ['nodejs'] },
data_stream: { type: ['metrics', 'logs'] },
source_data_stream: { type: ['metrics', 'logs'] },
entity: {
firstSeenTimestamp: '2024-06-05T10:34:40.810Z',
lastSeenTimestamp: '2024-06-05T10:34:40.810Z',
Expand All @@ -246,7 +246,7 @@ describe('mergeEntities', () => {
environment: 'prod',
},
agent: { name: ['nodejs'] },
data_stream: { type: ['foo'] },
source_data_stream: { type: ['foo'] },
entity: {
firstSeenTimestamp: '2024-23-05T10:34:40.810Z',
lastSeenTimestamp: '2024-23-05T10:34:40.810Z',
Expand Down Expand Up @@ -305,7 +305,7 @@ describe('mergeEntities', () => {
environment: undefined,
},
agent: { name: ['nodejs'] },
data_stream: { type: [] },
source_data_stream: { type: [] },
entity: {
firstSeenTimestamp: '2024-06-05T10:34:40.810Z',
lastSeenTimestamp: '2024-06-05T10:34:40.810Z',
Expand Down Expand Up @@ -348,7 +348,7 @@ describe('mergeEntities', () => {
name: 'service-1',
},
agent: { name: ['nodejs'] },
data_stream: { type: [] },
source_data_stream: { type: [] },
entity: {
firstSeenTimestamp: '2024-06-05T10:34:40.810Z',
lastSeenTimestamp: '2024-06-05T10:34:40.810Z',
Expand All @@ -368,7 +368,7 @@ describe('mergeEntities', () => {
name: 'service-1',
},
agent: { name: ['nodejs'] },
data_stream: { type: [] },
source_data_stream: { type: [] },
entity: {
firstSeenTimestamp: '2024-06-05T10:34:40.810Z',
lastSeenTimestamp: '2024-06-05T10:34:40.810Z',
Expand Down Expand Up @@ -420,7 +420,7 @@ describe('mergeEntities', () => {
name: 'service-1',
},
agent: { name: ['nodejs'] },
data_stream: { type: [] },
source_data_stream: { type: [] },
entity: {
firstSeenTimestamp: '2024-06-05T10:34:40.810Z',
lastSeenTimestamp: '2024-06-05T10:34:40.810Z',
Expand Down Expand Up @@ -463,7 +463,7 @@ describe('mergeEntities', () => {
name: 'service-1',
},
agent: { name: ['nodejs'] },
data_stream: { type: [] },
source_data_stream: { type: [] },
entity: {
firstSeenTimestamp: '2024-06-05T10:34:40.810Z',
lastSeenTimestamp: '2024-06-05T10:34:40.810Z',
Expand All @@ -483,7 +483,7 @@ describe('mergeEntities', () => {
name: 'service-1',
},
agent: { name: ['nodejs'] },
data_stream: { type: [] },
source_data_stream: { type: [] },
entity: {
firstSeenTimestamp: '2024-06-05T10:34:40.810Z',
lastSeenTimestamp: '2024-06-05T10:34:40.810Z',
Expand Down Expand Up @@ -536,7 +536,7 @@ describe('mergeEntities', () => {
environment: 'test',
},
agent: { name: ['nodejs'] },
data_stream: { type: ['metrics'] },
source_data_stream: { type: ['metrics'] },
entity: {
firstSeenTimestamp: '2024-06-05T10:34:40.810Z',
lastSeenTimestamp: '2024-06-05T10:34:40.810Z',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function mergeFunc(entity: EntityLatestServiceRaw, existingEntity?: MergedServic
if (!existingEntity) {
return {
...commonEntityFields,
dataStreamTypes: entity.data_stream.type,
dataStreamTypes: entity.source_data_stream.type,
environments: compact([entity?.service.environment]),
metrics: [entity.entity.metrics],
hasLogMetrics,
Expand All @@ -62,7 +62,7 @@ function mergeFunc(entity: EntityLatestServiceRaw, existingEntity?: MergedServic
return {
...commonEntityFields,
dataStreamTypes: uniq(
compact([...(existingEntity?.dataStreamTypes ?? []), ...entity.data_stream.type])
compact([...(existingEntity?.dataStreamTypes ?? []), ...entity.source_data_stream.type])
),
environments: uniq(compact([...existingEntity?.environments, entity?.service.environment])),
metrics: [...existingEntity?.metrics, entity.entity.metrics],
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/observability_solution/infra/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"usageCollection",
"visTypeTimeseries",
"apmDataAccess",
"logsDataAccess"
"logsDataAccess",
"entityManager"
],
"optionalPlugins": [
"spaces",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { initProfilingRoutes } from './routes/profiling';
import { initServicesRoute } from './routes/services';
import { initCustomDashboardsRoutes } from './routes/custom_dashboards/custom_dashboards';
import { InfraBackendLibs } from './lib/infra_types';
import { initEntitiesConfigurationRoutes } from './routes/entities';

export const registerRoutes = (libs: InfraBackendLibs) => {
initIpToHostName(libs);
Expand Down Expand Up @@ -63,4 +64,5 @@ export const registerRoutes = (libs: InfraBackendLibs) => {
initProfilingRoutes(libs);
initServicesRoute(libs);
initCustomDashboardsRoutes(libs.framework);
initEntitiesConfigurationRoutes(libs);
};
Loading
Loading