Skip to content

Commit

Permalink
Merge branch 'main' into grouped-alert-table
Browse files Browse the repository at this point in the history
  • Loading branch information
maryam-saeidi authored Aug 21, 2024
2 parents 4e354b2 + bc8cb00 commit fd2d043
Show file tree
Hide file tree
Showing 563 changed files with 6,879 additions and 5,460 deletions.
2 changes: 1 addition & 1 deletion .buildkite/ftr_oblt_serverless_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ enabled:
- x-pack/test_serverless/functional/test_suites/observability/common_configs/config.group6.ts
- x-pack/test_serverless/functional/test_suites/observability/config.screenshots.ts
# serverless config files that run deployment-agnostic tests
- x-pack/test/api_integration/deployment_agnostic/oblt.serverless.config.ts
- x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.serverless.config.ts
2 changes: 2 additions & 0 deletions .buildkite/ftr_oblt_stateful_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ enabled:
- x-pack/test/observability_ai_assistant_functional/enterprise/config.ts
- x-pack/test/profiling_api_integration/cloud/config.ts
- x-pack/test/functional/apps/apm/config.ts
# stateful config files that run deployment-agnostic tests
- x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.stateful.config.ts
2 changes: 1 addition & 1 deletion .buildkite/ftr_platform_stateful_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,4 @@ enabled:
- x-pack/performance/journeys_e2e/infra_hosts_view.ts
- x-pack/test/custom_branding/config.ts
# stateful config files that run deployment-agnostic tests
- x-pack/test/api_integration/deployment_agnostic/stateful.config.ts
- x-pack/test/api_integration/deployment_agnostic/configs/stateful/platform.stateful.config.ts
2 changes: 1 addition & 1 deletion .buildkite/ftr_search_serverless_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ enabled:
- x-pack/test_serverless/functional/test_suites/search/common_configs/config.group5.ts
- x-pack/test_serverless/functional/test_suites/search/common_configs/config.group6.ts
# serverless config files that run deployment-agnostic tests
- x-pack/test/api_integration/deployment_agnostic/search.serverless.config.ts
- x-pack/test/api_integration/deployment_agnostic/configs/serverless/search.serverless.config.ts
2 changes: 1 addition & 1 deletion .buildkite/ftr_security_serverless_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@ enabled:
- x-pack/test/security_solution_endpoint/configs/serverless.endpoint.config.ts
- x-pack/test/security_solution_endpoint/configs/serverless.integrations.config.ts
# serverless config files that run deployment-agnostic tests
- x-pack/test/api_integration/deployment_agnostic/security.serverless.config.ts
- x-pack/test/api_integration/deployment_agnostic/configs/serverless/security.serverless.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ async function main() {

const preamble = locationFileLines.slice(0, 1);

// eslint-disable-next-line @kbn/eslint/no_unsafe_js_yaml
const locationObj = jsYaml.load(
locationFileLines.slice(1).join('\n')
) as BackstageLocationResource;
locationObj.spec.targets = pipelines.map(
(fileName) => `${resourceDefinitionsBaseUrl}/${fileName}`
);

// eslint-disable-next-line @kbn/eslint/no_unsafe_js_yaml
const locationYaml = jsYaml.dump(locationObj, { lineWidth: 400 });

fs.writeFileSync(locationFile, `${preamble.join('\n')}\n${locationYaml}`);
Expand Down
1 change: 1 addition & 0 deletions .buildkite/pipeline-utils/agent_images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Side Public License, v 1.
*/

// eslint-disable-next-line @kbn/eslint/no_unsafe_js_yaml
import { dump } from 'js-yaml';
import { BuildkiteClient, BuildkiteCommandStep } from './buildkite';

Expand Down
3 changes: 3 additions & 0 deletions .buildkite/pipeline-utils/buildkite/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

import axios, { AxiosInstance } from 'axios';
import { execSync, ExecSyncOptions } from 'child_process';

// eslint-disable-next-line @kbn/eslint/no_unsafe_js_yaml
import { dump } from 'js-yaml';

import { parseLinkHeader } from './parse_link_header';
import { Artifact } from './types/artifact';
import { Build, BuildStatus } from './types/build';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import * as Fs from 'fs';

import * as globby from 'globby';
import minimatch from 'minimatch';

// eslint-disable-next-line @kbn/eslint/no_unsafe_js_yaml
import { load as loadYaml } from 'js-yaml';

import { BuildkiteClient, BuildkiteStep } from '../buildkite';
Expand Down
1 change: 0 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,6 @@ x-pack/test/observability_ai_assistant_functional @elastic/obs-ai-assistant
/x-pack/test/api_integration/apis/monitoring_collection @elastic/stack-monitoring

# Fleet
/fleet_packages.json @elastic/fleet
/x-pack/test/fleet_api_integration @elastic/fleet
/x-pack/test/fleet_cypress @elastic/fleet
/x-pack/test/fleet_functional @elastic/fleet
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@
"@langchain/langgraph": "^0.0.31",
"@langchain/openai": "^0.1.3",
"@langtrase/trace-attributes": "^3.0.8",
"@launchdarkly/node-server-sdk": "^9.5.0",
"@launchdarkly/node-server-sdk": "^9.5.1",
"@loaders.gl/core": "^3.4.7",
"@loaders.gl/json": "^3.4.7",
"@loaders.gl/shapefile": "^3.4.7",
Expand Down Expand Up @@ -1016,7 +1016,7 @@
"archiver": "^5.3.1",
"async": "^3.2.3",
"aws4": "^1.12.0",
"axios": "^1.6.8",
"axios": "^1.7.4",
"base64-js": "^1.3.1",
"bitmap-sdf": "^1.0.3",
"blurhash": "^2.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,30 @@
*/

import { generateShortId } from '@kbn/apm-synthtrace-client';
import { faker } from '@faker-js/faker';
import { randomInt } from 'crypto';
import moment from 'moment';

const {
internet: { ipv4, userAgent, httpMethod, httpStatusCode },
word: { noun, verb },
} = faker;

// Utility function to get a random element from an array
const getAtIndexOrRandom = <T>(values: T[], index?: number) =>
values[index ?? randomInt(values.length)];

// Arrays for data
const LOG_LEVELS: string[] = ['FATAL', 'ERROR', 'WARN', 'INFO', 'DEBUG', 'TRACE'];

const JAVA_LOG_MESSAGES = [
'[main] com.example1.core.ApplicationCore - Critical failure: NullPointerException encountered during startup',
'[main] com.example.service.UserService - User registration completed for userId: 12345',
'[main] com.example3.util.JsonParser - Parsing JSON response from external API',
'[main] com.example4.security.AuthManager - Unauthorized access attempt detected for userId: 67890',
'[main] com.example5.dao.UserDao - Database query failed: java.sql.SQLException: Timeout expired',
];

const IP_ADDRESSES = [
'223.72.43.22',
'20.24.184.101',
Expand Down Expand Up @@ -50,3 +67,14 @@ export const getGeoCoordinate = (index?: number) => getAtIndexOrRandom(GEO_COORD
export const getCloudProvider = (index?: number) => getAtIndexOrRandom(CLOUD_PROVIDERS, index);
export const getCloudRegion = (index?: number) => getAtIndexOrRandom(CLOUD_REGION, index);
export const getServiceName = (index?: number) => getAtIndexOrRandom(SERVICE_NAMES, index);
export const getJavaLog = () =>
`${moment().format('YYYY-MM-DD HH:mm:ss,SSS')} ${getAtIndexOrRandom(
LOG_LEVELS
)} ${getAtIndexOrRandom(JAVA_LOG_MESSAGES)}`;

export const getWebLog = () => {
const path = `/api/${noun()}/${verb()}`;
const bytes = randomInt(100, 4000);

return `${ipv4()} - - [${moment().toISOString()}] "${httpMethod()} ${path} HTTP/1.1" ${httpStatusCode()} ${bytes} "-" "${userAgent()}"`;
};
47 changes: 47 additions & 0 deletions packages/kbn-apm-synthtrace/src/scenarios/unstructured_logs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { LogDocument, log } from '@kbn/apm-synthtrace-client';
import { Scenario } from '../cli/scenario';
import { IndexTemplateName } from '../lib/logs/custom_logsdb_index_templates';
import { withClient } from '../lib/utils/with_client';
import { parseLogsScenarioOpts } from './helpers/logs_scenario_opts_parser';
import { getJavaLog, getWebLog } from './helpers/logs_mock_data';

const scenario: Scenario<LogDocument> = async (runOptions) => {
const { isLogsDb } = parseLogsScenarioOpts(runOptions.scenarioOpts);
return {
bootstrap: async ({ logsEsClient }) => {
if (isLogsDb) await logsEsClient.createIndexTemplate(IndexTemplateName.LogsDb);
},
generate: ({ range, clients: { logsEsClient } }) => {
const { logger } = runOptions;

const datasetJavaLogs = (timestamp: number) =>
log.create({ isLogsDb }).dataset('java').message(getJavaLog()).timestamp(timestamp);

const datasetWebLogs = (timestamp: number) =>
log.create({ isLogsDb }).dataset('web').message(getWebLog()).timestamp(timestamp);

const logs = range
.interval('1m')
.rate(1)
.generator((timestamp) => {
return Array(200)
.fill(0)
.flatMap((_, index) => [datasetJavaLogs(timestamp), datasetWebLogs(timestamp)]);
});

return withClient(
logsEsClient,
logger.perf('generating_logs', () => logs)
);
},
};
};

export default scenario;
2 changes: 1 addition & 1 deletion packages/kbn-es/src/utils/read_roles_from_resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
import fs from 'fs';
import { extname } from 'path';
import { load as loadYaml } from 'js-yaml';
import { safeLoad as loadYaml } from 'js-yaml';

export const readRolesFromResource = (resourcePath: string) => {
if (!fs.existsSync(resourcePath) || extname(resourcePath) !== '.yml') {
Expand Down
7 changes: 7 additions & 0 deletions packages/kbn-eslint-config/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ module.exports = {
disallowedMessage: `import from @kbn/i18n-react instead`,
exclude: [/packages[\/\\]kbn-i18n-react[\/\\]/],
},
{
from: 'zod',
to: '@kbn/zod',
disallowedMessage: `import from @kbn/zod instead`,
exclude: [/packages[\/\\]kbn-zod[\/\\]/],
},
{
from: 'styled-components',
to: false,
Expand Down Expand Up @@ -308,6 +314,7 @@ module.exports = {
'@kbn/eslint/no_constructor_args_in_property_initializers': 'error',
'@kbn/eslint/no_this_in_property_initializers': 'error',
'@kbn/eslint/no_unsafe_console': 'error',
'@kbn/eslint/no_unsafe_js_yaml': 'error',
'@kbn/imports/no_unresolvable_imports': 'error',
'@kbn/imports/uniform_imports': 'error',
'@kbn/imports/no_unused_imports': 'error',
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 @@ -18,5 +18,6 @@ module.exports = {
no_constructor_args_in_property_initializers: require('./rules/no_constructor_args_in_property_initializers'),
no_this_in_property_initializers: require('./rules/no_this_in_property_initializers'),
no_unsafe_console: require('./rules/no_unsafe_console'),
no_unsafe_js_yaml: require('./rules/no_unsafe_js_yaml'),
},
};
90 changes: 90 additions & 0 deletions packages/kbn-eslint-plugin-eslint/rules/no_unsafe_js_yaml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

module.exports = {
meta: {
fixable: 'code',
schema: [],
},
create(context) {
const sourceCode = context.getSourceCode();
const jsYamlIdentifiers = new Set();
const isUnsafeMethod = (node) => node.name === 'load' || node.name === 'dump';

return {
ImportDeclaration(node) {
if (node.source.value === 'js-yaml') {
node.specifiers.forEach((specifier) => {
jsYamlIdentifiers.add(specifier.local.name);

if (specifier.imported && isUnsafeMethod(specifier.imported)) {
context.report({
node: specifier,
message:
'Use `safeLoad` instead of `load` and `safeDump` instead of `dump` from `js-yaml`.',
fix(fixer) {
const replacement =
specifier.imported.name === 'load'
? fixer.replaceText(specifier.imported, 'safeLoad')
: fixer.replaceText(specifier.imported, 'safeDump');
return replacement;
},
});
}
});
}
},
CallExpression(node) {
const callee = node.callee;

if (isUnsafeMethod(callee)) {
const scope = sourceCode.getScope(node);
const variable = scope.variables.find((v) => v.name === callee.name);

if (variable && variable.defs.length) {
const [def] = variable.defs;

if (def?.parent?.source?.value === 'js-yaml') {
context.report({
node: callee,
message:
'Use `safeLoad` instead of `load` and `safeDump` instead of `dump` from `js-yaml`.',
fix(fixer) {
const replacement =
callee.name === 'load'
? fixer.replaceText(callee, 'safeLoad')
: fixer.replaceText(callee, 'safeDump');
return replacement;
},
});
}
}
}

if (
callee.type === 'MemberExpression' &&
isUnsafeMethod(callee.property) &&
jsYamlIdentifiers.has(callee.object.name)
) {
context.report({
node: callee.property,
message:
'Use `safeLoad` instead of `load` and `safeDump` instead of `dump` from `js-yaml`.',
fix(fixer) {
const replacement =
callee.property.name === 'load'
? fixer.replaceText(callee.property, 'safeLoad')
: fixer.replaceText(callee.property, 'safeDump');
return replacement;
},
});
}
},
};
},
};
Loading

0 comments on commit fd2d043

Please sign in to comment.