Skip to content

Commit

Permalink
Merge branch 'main' into 193320-advance-setting-to-show-logs-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyghiani authored Oct 4, 2024
2 parents e413fbb + 47d01c3 commit 6f73452
Show file tree
Hide file tree
Showing 37 changed files with 315 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,23 +155,19 @@ export const RuleTypeList: React.FC<RuleTypeListProps> = ({
hasBorder
title={rule.name}
onClick={() => onSelectRuleType(rule.id)}
description={
<>
{rule.description}
{rule.description && <EuiSpacer size="s" />}
<EuiText
color="subdued"
size="xs"
style={{ textTransform: 'uppercase', fontWeight: euiTheme.font.weight.bold }}
>
{producerToDisplayName(rule.producer)}
</EuiText>
</>
}
description={rule.description}
style={{ marginRight: '8px', flexGrow: 0 }}
data-test-subj={`${rule.id}-SelectOption`}
isDisabled={rule.enabledInLicense === false}
/>
>
<EuiText
color="subdued"
size="xs"
style={{ textTransform: 'uppercase', fontWeight: euiTheme.font.weight.bold }}
>
{producerToDisplayName(rule.producer)}
</EuiText>
</EuiCard>
<EuiSpacer size="s" />
</React.Fragment>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const RuleTypeModal: React.FC<RuleTypeModalProps & RuleTypeModalState> =
<EuiFlexItem
style={{
overflow: 'hidden',
marginTop: -euiTheme.size.base /* Offset extra padding for card hover drop shadow */,
marginTop: `-${euiTheme.size.base}`,
}}
>
{ruleTypesLoading ? (
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-eslint-plugin-eslint/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ module.exports = {
no_this_in_property_initializers: require('./rules/no_this_in_property_initializers'),
no_unsafe_console: require('./rules/no_unsafe_console'),
no_unsafe_hash: require('./rules/no_unsafe_hash'),
no_deprecated_authz_config: require('./rules/no_deprecated_authz_config'),
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ const ACCESS_TAG_PREFIX = 'access:';

const isStringLiteral = (el) => el.type === 'Literal' && typeof el.value === 'string';
const isLiteralAccessTag = (el) => isStringLiteral(el) && el.value.startsWith(ACCESS_TAG_PREFIX);
const isLiteralNonAccessTag = (el) =>
isStringLiteral(el) && !el.value.startsWith(ACCESS_TAG_PREFIX);

const isTemplateLiteralAccessTag = (el) =>
el.type === 'TemplateLiteral' && el.quasis[0].value.raw.startsWith(ACCESS_TAG_PREFIX);
const isTemplateLiteralNonAccessTag = (el) =>
el.type === 'TemplateLiteral' && !el.quasis[0].value.raw.startsWith(ACCESS_TAG_PREFIX);

const maybeReportDisabledSecurityConfig = (node, context, isVersionedRoute = false) => {
// Allow disabling migration for routes that are opted out from authorization
if (process.env.MIGRATE_DISABLED_AUTHZ === 'false') {
return;
}

const callee = node.callee;
const isAddVersionCall =
callee.type === 'MemberExpression' && callee.property.name === 'addVersion';
Expand Down Expand Up @@ -166,11 +167,11 @@ const handleRouteConfig = (node, context, isVersionedRoute = false) => {

const accessTagsFilter = (el) => isLiteralAccessTag(el) || isTemplateLiteralAccessTag(el);
const nonAccessTagsFilter = (el) =>
isLiteralNonAccessTag(el) || isTemplateLiteralNonAccessTag(el);
!isLiteralAccessTag(el) && !isTemplateLiteralAccessTag(el);

const getAccessPrivilege = (el) => {
if (el.type === 'Literal') {
return `'${el.value.split(':')[1]}'`;
return `'${el.value.split(ACCESS_TAG_PREFIX)[1]}'`;
}

if (el.type === 'TemplateLiteral') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,28 @@ ruleTester.run('no_deprecated_authz_config', rule, {
`,
name: 'invalid: access tags are string literals, move to security.authz.requiredPrivileges',
},
{
code: `
router.get({
path: '/some/path',
options: {
tags: ['access:ml:someTag', 'access:prefix:someTag'],
},
});
`,
errors: [{ message: "Move 'access' tags to security.authz.requiredPrivileges." }],
output: `
router.get({
path: '/some/path',
security: {
authz: {
requiredPrivileges: ['ml:someTag', 'prefix:someTag'],
},
},
});
`,
name: 'invalid: access tags have multiple prefixes, move to security.authz.requiredPrivileges',
},
{
code: `
router.get({
Expand All @@ -180,6 +202,30 @@ ruleTester.run('no_deprecated_authz_config', rule, {
`,
name: 'invalid: access tags are template literals, move to security.authz.requiredPrivileges',
},
{
code: `
router.get({
path: '/some/path',
options: {
tags: ['access:securitySolution', routeTagHelper('someTag')],
},
});
`,
errors: [{ message: "Move 'access' tags to security.authz.requiredPrivileges." }],
output: `
router.get({
path: '/some/path',
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},options: {
tags: [routeTagHelper('someTag')],
},
});
`,
name: 'invalid: access tags and tags made with helper function, only access tags are moved to security.authz.requiredPrivileges',
},
{
code: `
router.get({
Expand Down
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
Loading

0 comments on commit 6f73452

Please sign in to comment.