Skip to content

Commit

Permalink
Merge branch 'main' into asset-criticality-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
tiansivive authored Dec 18, 2023
2 parents 1532e07 + cd02fbd commit a27e3b3
Show file tree
Hide file tree
Showing 82 changed files with 1,503 additions and 600 deletions.
32 changes: 32 additions & 0 deletions packages/kbn-apm-synthtrace-client/src/lib/apm/apm_fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,35 @@ export interface GeoLocation {
type: string;
}

export interface APMStacktrace {
abs_path?: string;
classname?: string;
context?: {
post?: string[];
pre?: string[];
};
exclude_from_grouping?: boolean;
filename?: string;
function?: string;
module?: string;
library_frame?: boolean;
line?:
| {
column?: number;
number: number;
}
| {
context?: string;
};
sourcemap?: {
error?: string;
updated?: boolean;
};
vars?: {
[key: string]: unknown;
};
}

type ExperimentalFields = Partial<{
'metricset.interval': string;
'transaction.duration.summary': string;
Expand Down Expand Up @@ -80,6 +109,8 @@ export type ApmFields = Fields<{
'cloud.provider': string;
'cloud.region': string;
'cloud.service.name': string;
// otel
'code.stacktrace': string;
'container.id': string;
'destination.address': string;
'destination.port': number;
Expand Down Expand Up @@ -169,6 +200,7 @@ export type ApmFields = Fields<{
'span.duration.us': number;
'span.id': string;
'span.name': string;
'span.stacktrace': APMStacktrace[];
'span.self_time.count': number;
'span.self_time.sum.us': number;
'span.subtype': string;
Expand Down
3 changes: 3 additions & 0 deletions packages/kbn-check-mappings-update-cli/current_fields.json
Original file line number Diff line number Diff line change
Expand Up @@ -968,5 +968,8 @@
"kuery",
"serviceEnvironmentFilterEnabled",
"serviceNameFilterEnabled"
],
"cloud-security-posture-settings": [
"rules"
]
}
4 changes: 4 additions & 0 deletions packages/kbn-check-mappings-update-cli/current_mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2349,6 +2349,10 @@
}
}
},
"cloud-security-posture-settings": {
"dynamic": false,
"properties": {}
},
"slo": {
"dynamic": false,
"properties": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"cases-connector-mappings": "f9d1ac57e484e69506c36a8051e4d61f4a8cfd25",
"cases-telemetry": "f219eb7e26772884342487fc9602cfea07b3cedc",
"cases-user-actions": "483f10db9b3bd1617948d7032a98b7791bf87414",
"cloud-security-posture-settings": "675e47dd958fbce6c70a20baac12af3145e7c0ef",
"config": "179b3e2bc672626aafce3cf92093a113f456af38",
"config-global": "8e8a134a2952df700d7d4ec51abb794bbd4cf6da",
"connector_token": "5a9ac29fe9c740eb114e9c40517245c71706b005",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const previouslyRegisteredTypes = [
'canvas-element',
'canvas-workpad',
'canvas-workpad-template',
'cloud-security-posture-settings',
'cases',
'cases-comments',
'cases-configure',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ describe('split .kibana index into multiple system indices', () => {
"cases-connector-mappings",
"cases-telemetry",
"cases-user-actions",
"cloud-security-posture-settings",
"config",
"config-global",
"connector_token",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { apm, timerange } from '@kbn/apm-synthtrace-client';
import { synthtrace } from '../../../synthtrace';

function getAPMGeneratedStacktrace() {
const apmGeneratedStacktrace = apm
.service({
name: 'apm-generated',
environment: 'production',
agentName: 'java',
})
.instance('instance a');

return Array.from(
timerange(
new Date('2022-01-01T00:00:00.000Z'),
new Date('2022-01-01T00:01:00.000Z')
)
.interval('1m')
.rate(1)
.generator((timestamp) => {
return apmGeneratedStacktrace
.transaction({ transactionName: `Transaction A` })
.defaults({
'service.language.name': 'java',
})
.timestamp(timestamp)
.duration(1000)
.success()
.children(
apmGeneratedStacktrace
.span({
spanName: `Span A`,
spanType: 'internal',
'span.stacktrace': [
{
library_frame: false,
exclude_from_grouping: false,
filename: 'OutputBuffer.java',
classname: 'org.apache.catalina.connector.OutputBuffer',
line: { number: 825 },
module: 'org.apache.catalina.connector',
function: 'flushByteBuffer',
},
],
})
.timestamp(timestamp + 50)
.duration(100)
.failure()
);
})
);
}

function getOtelGeneratedStacktrace() {
const apmGeneratedStacktrace = apm
.service({
name: 'otel-generated',
environment: 'production',
agentName: 'java',
})
.instance('instance a');

return Array.from(
timerange(
new Date('2022-01-01T00:00:00.000Z'),
new Date('2022-01-01T00:01:00.000Z')
)
.interval('1m')
.rate(1)
.generator((timestamp) => {
return apmGeneratedStacktrace
.transaction({ transactionName: `Transaction A` })
.timestamp(timestamp)
.duration(1000)
.defaults({
'service.language.name': 'java',
})
.success()
.children(
apmGeneratedStacktrace
.span({
spanName: `Span A`,
spanType: 'internal',
'code.stacktrace':
'java.lang.Throwable\n\tat co.elastic.otel.ElasticSpanProcessor.captureStackTrace(ElasticSpanProcessor.java:81)',
})
.timestamp(timestamp + 50)
.duration(100)
.failure()
);
})
);
}

export function generateSpanStacktraceData() {
const apmGeneratedStacktrace = getAPMGeneratedStacktrace();
const otelGeneratedStacktrace = getOtelGeneratedStacktrace();

synthtrace.index([...apmGeneratedStacktrace, ...otelGeneratedStacktrace]);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import url from 'url';
import { synthtrace } from '../../../synthtrace';
import { generateSpanStacktraceData } from './generate_span_stacktrace_data';

const start = '2022-01-01T00:00:00.000Z';
const end = '2022-01-01T00:15:00.000Z';

function getServiceInventoryUrl({ serviceName }: { serviceName: string }) {
return url.format({
pathname: `/app/apm/services/${serviceName}`,
query: {
rangeFrom: start,
rangeTo: end,
environment: 'ENVIRONMENT_ALL',
kuery: '',
serviceGroup: '',
transactionType: 'request',
comparisonEnabled: true,
offset: '1d',
},
});
}

describe('Span stacktrace', () => {
beforeEach(() => {
cy.loginAsViewerUser();
});
describe('span flyout', () => {
before(() => {
generateSpanStacktraceData();
});

after(() => {
synthtrace.clean();
});
it('Shows APM agent generated stacktrace', () => {
cy.visitKibana(getServiceInventoryUrl({ serviceName: 'apm-generated' }));
cy.contains('Transaction A').click();
cy.contains('Span A').click();
cy.getByTestSubj('spanStacktraceTab').click();
cy.contains(
'at org.apache.catalina.connector.OutputBuffer.flushByteBuffer(OutputBuffer.java:825)'
);
});

it('Shows Otel generated stacktrace', () => {
cy.visitKibana(getServiceInventoryUrl({ serviceName: 'otel-generated' }));
cy.contains('Transaction A').click();
cy.contains('Span A').click();
cy.getByTestSubj('spanStacktraceTab').click();
cy.contains(
`java.lang.Throwable at co.elastic.otel.ElasticSpanProcessor.captureStackTrace(ElasticSpanProcessor.java:81)`
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { euiStyled } from '@kbn/kibana-react-plugin/common';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import { isEmpty } from 'lodash';
import React, { Fragment } from 'react';
import { PlaintextStacktrace } from '../../../../../error_group_details/error_sampler/plaintext_stacktrace';
import { Span } from '../../../../../../../../typings/es_schemas/ui/span';
import { Transaction } from '../../../../../../../../typings/es_schemas/ui/transaction';
import { useFetcher, isPending } from '../../../../../../../hooks/use_fetcher';
Expand Down Expand Up @@ -204,6 +205,7 @@ function SpanFlyoutBody({
flyoutDetailTab?: string;
}) {
const stackframes = span.span.stacktrace;
const plaintextStacktrace = span.code?.stacktrace;
const codeLanguage = parentTransaction?.service.language?.name;
const spanDb = span.span.db;
const spanTypes = getSpanTypes(span);
Expand Down Expand Up @@ -232,10 +234,11 @@ function SpanFlyoutBody({
</Fragment>
),
},
...(!isEmpty(stackframes)
...(!isEmpty(stackframes) || !isEmpty(plaintextStacktrace)
? [
{
id: 'stack-trace',
'data-test-subj': 'spanStacktraceTab',
name: i18n.translate(
'xpack.apm.transactionDetails.spanFlyout.stackTraceTabLabel',
{
Expand All @@ -245,10 +248,17 @@ function SpanFlyoutBody({
content: (
<Fragment>
<EuiSpacer size="l" />
<Stacktrace
stackframes={stackframes}
codeLanguage={codeLanguage}
/>
{stackframes ? (
<Stacktrace
stackframes={stackframes}
codeLanguage={codeLanguage}
/>
) : (
<PlaintextStacktrace
stacktrace={plaintextStacktrace}
codeLanguage={codeLanguage}
/>
)}
</Fragment>
),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Stackframe as StackframeComponent } from './stackframe';
interface Props {
stackframes?: Stackframe[];
codeLanguage?: string;
stackTrace?: string;
}

export function Stacktrace({ stackframes = [], codeLanguage }: Props) {
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/apm/typings/es_schemas/raw/span_raw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ export interface SpanRaw extends APMBaseDoc {
id: string;
};
child?: { id: string[] };
code?: {
stacktrace?: string;
};
http?: Http;
url?: Url;
}
9 changes: 7 additions & 2 deletions x-pack/plugins/cloud_security_posture/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ export const BENCHMARKS_API_CURRENT_VERSION = '1';
export const FIND_CSP_BENCHMARK_RULE_ROUTE_PATH = '/internal/cloud_security_posture/rules/_find';
export const FIND_CSP_BENCHMARK_RULE_API_CURRENT_VERSION = '1';

export const DETECTION_RULE_ALERTS_STATUS_API_CURRENT_VERSION = '1';
export const DETECTION_RULE_RULES_API_CURRENT_VERSION = '2023-10-31';
export const CSP_BENCHMARK_RULES_BULK_ACTION_ROUTE_PATH =
'/internal/cloud_security_posture/rules/_bulk_action';
export const CSP_BENCHMARK_RULES_BULK_ACTION_API_CURRENT_VERSION = '1';

export const GET_DETECTION_RULE_ALERTS_STATUS_PATH =
'/internal/cloud_security_posture/detection_engine_rules/alerts/_status';
export const DETECTION_RULE_ALERTS_STATUS_API_CURRENT_VERSION = '1';
export const DETECTION_RULE_RULES_API_CURRENT_VERSION = '2023-10-31';

export const CLOUD_SECURITY_POSTURE_PACKAGE_NAME = 'cloud_security_posture';
// TODO: REMOVE CSP_LATEST_FINDINGS_DATA_VIEW and replace it with LATEST_FINDINGS_INDEX_PATTERN
Expand Down Expand Up @@ -88,6 +91,8 @@ export const INTERNAL_FEATURE_FLAGS = {
} as const;

export const CSP_BENCHMARK_RULE_SAVED_OBJECT_TYPE = 'csp-rule-template';
export const INTERNAL_CSP_SETTINGS_SAVED_OBJECT_TYPE = 'cloud-security-posture-settings';
export const INTERNAL_CSP_SETTINGS_SAVED_OBJECT_ID = 'csp-internal-settings';

export const CLOUDBEAT_VANILLA = 'cloudbeat/cis_k8s';
export const CLOUDBEAT_EKS = 'cloudbeat/cis_eks';
Expand Down
33 changes: 33 additions & 0 deletions x-pack/plugins/cloud_security_posture/common/types/rules/v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,36 @@ export interface FindCspBenchmarkRuleResponse {
page: number;
perPage: number;
}

export const cspBenchmarkRules = schema.arrayOf(
schema.object({
benchmark_id: schema.string(),
benchmark_version: schema.string(),
rule_number: schema.string(),
})
);

export const cspBenchmarkRulesBulkActionRequestSchema = schema.object({
action: schema.oneOf([schema.literal('mute'), schema.literal('unmute')]),
rules: cspBenchmarkRules,
});

export type CspBenchmarkRules = TypeOf<typeof cspBenchmarkRules>;

export type CspBenchmarkRulesBulkActionRequestSchema = TypeOf<
typeof cspBenchmarkRulesBulkActionRequestSchema
>;

const rulesStates = schema.recordOf(
schema.string(),
schema.object({
muted: schema.boolean(),
})
);

export const cspSettingsSchema = schema.object({
rules: rulesStates,
});

export type CspBenchmarkRulesStates = TypeOf<typeof rulesStates>;
export type CspSettings = TypeOf<typeof cspSettingsSchema>;
Loading

0 comments on commit a27e3b3

Please sign in to comment.