Skip to content

Commit

Permalink
Merge branch 'main' into fleet/191719-allow-exclamation-mark-in-enrol…
Browse files Browse the repository at this point in the history
…lment-token-name
  • Loading branch information
elasticmachine authored Aug 30, 2024
2 parents 729aa9a + 74a551e commit 2a55742
Show file tree
Hide file tree
Showing 95 changed files with 2,117 additions and 215 deletions.
59 changes: 45 additions & 14 deletions src/dev/run_quick_checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
* Side Public License, v 1.
*/

import { exec } from 'child_process';
import { execFile } from 'child_process';
import { availableParallelism } from 'os';
import { join, isAbsolute } from 'path';
import { readdirSync, readFileSync } from 'fs';
import { isAbsolute, join } from 'path';
import { existsSync, readdirSync, readFileSync } from 'fs';

import { run, RunOptions } from '@kbn/dev-cli-runner';
import { REPO_ROOT } from '@kbn/repo-info';
Expand Down Expand Up @@ -54,7 +54,7 @@ void run(async ({ log, flagsReader }) => {
targetFile: flagsReader.string('file'),
targetDir: flagsReader.string('dir'),
checks: flagsReader.string('checks'),
});
}).map((script) => (isAbsolute(script) ? script : join(REPO_ROOT, script)));

logger.write(
`--- Running ${scriptsToRun.length} checks, with parallelism ${MAX_PARALLELISM}...`,
Expand Down Expand Up @@ -108,7 +108,7 @@ function collectScriptsToRun(inputOptions: {
}
}

async function runAllChecks(scriptsToRun: string[]) {
async function runAllChecks(scriptsToRun: string[]): Promise<CheckResult[]> {
const checksRunning: Array<Promise<any>> = [];
const checksFinished: CheckResult[] = [];

Expand All @@ -121,10 +121,20 @@ async function runAllChecks(scriptsToRun: string[]) {

const check = runCheckAsync(script);
checksRunning.push(check);
check.then((result) => {
checksRunning.splice(checksRunning.indexOf(check), 1);
checksFinished.push(result);
});
check
.then((result) => {
checksRunning.splice(checksRunning.indexOf(check), 1);
checksFinished.push(result);
})
.catch((error) => {
checksRunning.splice(checksRunning.indexOf(check), 1);
checksFinished.push({
success: false,
script,
output: error.message,
durationMs: 0,
});
});
}

await sleep(1000);
Expand All @@ -138,9 +148,10 @@ async function runCheckAsync(script: string): Promise<CheckResult> {
const startTime = Date.now();

return new Promise((resolve) => {
const scriptProcess = exec(script);
validateScriptPath(script);
const scriptProcess = execFile('bash', [script]);
let output = '';
const appendToOutput = (data: string | Buffer) => (output += data);
const appendToOutput = (data: string | Buffer) => (output += data.toString());

scriptProcess.stdout?.on('data', appendToOutput);
scriptProcess.stderr?.on('data', appendToOutput);
Expand Down Expand Up @@ -170,9 +181,10 @@ function printResults(startTimestamp: number, results: CheckResult[]) {
logger.info(`- Total time: ${total}, effective: ${effective}`);

results.forEach((result) => {
logger.write(
`--- ${result.success ? '✅' : '❌'} ${result.script}: ${humanizeTime(result.durationMs)}`
);
const resultLabel = result.success ? '✅' : '❌';
const scriptPath = stripRoot(result.script);
const runtime = humanizeTime(result.durationMs);
logger.write(`--- ${resultLabel} ${scriptPath}: ${runtime}`);
if (result.success) {
logger.debug(result.output);
} else {
Expand All @@ -194,3 +206,22 @@ function humanizeTime(ms: number) {
return `${minutes}m ${seconds}s`;
}
}

function validateScriptPath(scriptPath: string) {
if (!isAbsolute(scriptPath)) {
logger.error(`Invalid script path: ${scriptPath}`);
throw new Error('Invalid script path');
} else if (!scriptPath.endsWith('.sh')) {
logger.error(`Invalid script extension: ${scriptPath}`);
throw new Error('Invalid script extension');
} else if (!existsSync(scriptPath)) {
logger.error(`Script not found: ${scriptPath}`);
throw new Error('Script not found');
} else {
return;
}
}

function stripRoot(script: string) {
return script.replace(REPO_ROOT, '');
}
2 changes: 1 addition & 1 deletion src/plugins/data/config.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import moment from 'moment/moment';
import { SearchConfigSchema, SearchSessionsConfigSchema } from './config';
import type { SearchConfigSchema, SearchSessionsConfigSchema } from './server/config';

export const getMockSearchConfig = ({
sessions: { enabled = true, defaultExpiration = moment.duration(7, 'd') } = {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { PluginInitializerContext } from '@kbn/core/public';
import { ConfigSchema } from '../config';
import type { ConfigSchema } from '../server/config';

/*
* Filters:
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
IStorageWrapper,
createStartServicesGetter,
} from '@kbn/kibana-utils-plugin/public';
import { ConfigSchema } from '../config';
import type { ConfigSchema } from '../server/config';
import type {
DataPublicPluginSetup,
DataPublicPluginStart,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import { toPartialResponseAfterTimeout } from './to_partial_response';
import { ISessionService, SearchSessionState } from '../session';
import { SearchResponseCache } from './search_response_cache';
import { SearchAbortController } from './search_abort_controller';
import { SearchConfigSchema } from '../../../config';
import type { SearchConfigSchema } from '../../../server/config';
import type { SearchServiceStartDependencies } from '../search_service';
import { createRequestHash } from './create_request_hash';

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/public/search/search_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import {
SHARD_DELAY_AGG_NAME,
} from '../../common/search/aggs/buckets/shard_delay';
import { aggShardDelay } from '../../common/search/aggs/buckets/shard_delay_fn';
import { ConfigSchema } from '../../config';
import type { ConfigSchema } from '../../server/config';
import { NowProviderInternalContract } from '../now_provider';
import { DataPublicPluginStart, DataStartDependencies } from '../types';
import { AggsService } from './aggs';
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/public/search/session/session_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { i18n } from '@kbn/i18n';
import moment from 'moment';
import { ISearchOptions } from '@kbn/search-types';
import { SearchUsageCollector } from '../..';
import { ConfigSchema } from '../../../config';
import type { ConfigSchema } from '../../../server/config';
import type {
SessionMeta,
SessionStateContainer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { APP } from '..';
import { SearchSessionsMgmtAPI } from '../lib/api';
import { AsyncSearchIntroDocumentation } from '../lib/documentation';
import { renderApp } from './render';
import { SearchSessionsConfigSchema } from '../../../../../config';
import type { SearchSessionsConfigSchema } from '../../../../../server/config';

export class SearchSessionsMgmtApp {
constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { LocaleWrapper } from '../__mocks__';
import { SearchSessionsMgmtMain } from './main';
import { SharePluginStart } from '@kbn/share-plugin/public';
import { sharePluginMock } from '@kbn/share-plugin/public/mocks';
import { SearchSessionsConfigSchema } from '../../../../../config';
import type { SearchSessionsConfigSchema } from '../../../../../server/config';
import { createSearchUsageCollectorMock } from '../../../collectors/mocks';

let mockCoreSetup: MockedKeys<CoreSetup>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { SearchSessionsMgmtAPI } from '../lib/api';
import type { AsyncSearchIntroDocumentation } from '../lib/documentation';
import { SearchSessionsMgmtTable } from './table';
import { SearchSessionsDeprecatedWarning } from '../../search_sessions_deprecation_message';
import { SearchSessionsConfigSchema } from '../../../../../config';
import type { SearchSessionsConfigSchema } from '../../../../../server/config';
import { SearchUsageCollector } from '../../../collectors';

interface Props {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { LocaleWrapper } from '../../__mocks__';
import { SearchSessionsMgmtTable } from './table';
import { SharePluginStart } from '@kbn/share-plugin/public';
import { sharePluginMock } from '@kbn/share-plugin/public/mocks';
import { SearchSessionsConfigSchema } from '../../../../../../config';
import type { SearchSessionsConfigSchema } from '../../../../../../server/config';
import { createSearchUsageCollectorMock } from '../../../../collectors/mocks';

let mockCoreSetup: MockedKeys<CoreSetup>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { OnActionComplete } from '../actions';
import { getAppFilter } from './app_filter';
import { getStatusFilter } from './status_filter';
import { SearchUsageCollector } from '../../../../collectors';
import { SearchSessionsConfigSchema } from '../../../../../../config';
import type { SearchSessionsConfigSchema } from '../../../../../../server/config';

interface Props {
core: CoreStart;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type { ISessionsClient, SearchUsageCollector } from '../../..';
import { SEARCH_SESSIONS_MANAGEMENT_ID } from '../constants';
import type { SearchSessionsMgmtAPI } from './lib/api';
import type { AsyncSearchIntroDocumentation } from './lib/documentation';
import { SearchSessionsConfigSchema } from '../../../../config';
import type { SearchSessionsConfigSchema } from '../../../../server/config';

export interface IManagementSectionsPluginsSetup {
management: ManagementSetup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { SearchSessionStatus } from '../../../../../common';
import { sharePluginMock } from '@kbn/share-plugin/public/mocks';
import { SharePluginStart } from '@kbn/share-plugin/public';
import { SearchSessionsMgmtAPI } from './api';
import { SearchSessionsConfigSchema } from '../../../../../config';
import type { SearchSessionsConfigSchema } from '../../../../../server/config';

let mockCoreSetup: MockedKeys<CoreSetup>;
let mockCoreStart: MockedKeys<CoreStart>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
import { ISessionsClient } from '../../sessions_client';
import { SearchUsageCollector } from '../../../collectors';
import { SearchSessionsFindResponse, SearchSessionStatus } from '../../../../../common';
import { SearchSessionsConfigSchema } from '../../../../../config';
import type { SearchSessionsConfigSchema } from '../../../../../server/config';

type LocatorsStart = SharePluginStart['url']['locators'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { SearchSessionsMgmtAPI } from './api';
import { getColumns } from './get_columns';
import { SharePluginStart } from '@kbn/share-plugin/public';
import { sharePluginMock } from '@kbn/share-plugin/public/mocks';
import { SearchSessionsConfigSchema } from '../../../../../config';
import type { SearchSessionsConfigSchema } from '../../../../../server/config';
import { createSearchUsageCollectorMock } from '../../../collectors/mocks';

let mockCoreSetup: MockedKeys<CoreSetup>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { SearchSessionsMgmtAPI } from './api';
import { getExpirationStatus } from './get_expiration_status';
import { UISession } from '../types';
import { SearchUsageCollector } from '../../../collectors';
import { SearchSessionsConfigSchema } from '../../../../../config';
import type { SearchSessionsConfigSchema } from '../../../../../server/config';

// Helper function: translate an app string to EuiIcon-friendly string
const appToIcon = (app: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { i18n } from '@kbn/i18n';
import moment from 'moment';
import { SearchSessionsConfigSchema } from '../../../../../config';
import type { SearchSessionsConfigSchema } from '../../../../../server/config';

export const getExpirationStatus = (config: SearchSessionsConfigSchema, expires: string | null) => {
const tNow = moment.utc().valueOf();
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/plugins/data/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/
import { PluginConfigDescriptor, PluginInitializerContext } from '@kbn/core/server';
import { ConfigSchema, configSchema } from '../config';
import { ConfigSchema, configSchema } from './config';
import type { DataServerPlugin, DataPluginSetup, DataPluginStart } from './plugin';

export { getEsQueryConfig, DEFAULT_QUERY_LANGUAGE } from '../common';
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { BfetchServerSetup } from '@kbn/bfetch-plugin/server';
import { PluginStart as DataViewsServerPluginStart } from '@kbn/data-views-plugin/server';
import { UsageCollectionSetup } from '@kbn/usage-collection-plugin/server';
import { FieldFormatsSetup, FieldFormatsStart } from '@kbn/field-formats-plugin/server';
import { ConfigSchema } from '../config';
import { ConfigSchema } from './config';
import type { ISearchSetup, ISearchStart } from './search';
import { DatatableUtilitiesService } from './datatable_utilities';
import { SearchService } from './search/search_service';
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/server/search/search_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ import {
SHARD_DELAY_AGG_NAME,
} from '../../common/search/aggs/buckets/shard_delay';
import { aggShardDelay } from '../../common/search/aggs/buckets/shard_delay_fn';
import { ConfigSchema } from '../../config';
import { ConfigSchema } from '../config';
import { SearchSessionService } from './session';
import { registerBsearchRoute } from './routes/bsearch';
import { enhancedEsSearchStrategyProvider } from './strategies/ese_search';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { elasticsearchServiceMock } from '@kbn/core/server/mocks';
import { getSessionStatus } from './get_session_status';
import { SearchSessionSavedObjectAttributes, SearchSessionStatus } from '../../../common';
import moment from 'moment';
import { SearchSessionsConfigSchema } from '../../../config';
import { SearchSessionsConfigSchema } from '../../config';

const mockInProgressSearchResponse = {
body: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import moment from 'moment';
import { ElasticsearchClient } from '@kbn/core/server';
import { SearchSessionSavedObjectAttributes, SearchSessionStatus } from '../../../common';
import { SearchStatus } from './types';
import { SearchSessionsConfigSchema } from '../../../config';
import { SearchSessionsConfigSchema } from '../../config';
import { getSearchStatus } from './get_search_status';

export async function getSessionStatus(
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/server/search/session/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import moment from 'moment';
import type { IScopedSearchSessionsClient } from './types';
import { SearchSessionsConfigSchema } from '../../../config';
import { SearchSessionsConfigSchema } from '../../config';

export function createSearchSessionsClientMock(): jest.Mocked<IScopedSearchSessionsClient> {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { SearchSessionService } from './session_service';
import { createRequestHash } from './utils';
import moment from 'moment';
import { coreMock } from '@kbn/core/server/mocks';
import { ConfigSchema } from '../../../config';
import { ConfigSchema } from '../../config';
import type { AuthenticatedUser } from '@kbn/core/server';
import { SEARCH_SESSION_TYPE, SearchSessionStatus } from '../../../common';
import { elasticsearchServiceMock } from '@kbn/core/server/mocks';
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/server/search/session/session_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
} from '../../../common';
import { ISearchSessionService, NoSearchIdInSessionError } from '../..';
import { createRequestHash } from './utils';
import { ConfigSchema, SearchSessionsConfigSchema } from '../../../config';
import { ConfigSchema, SearchSessionsConfigSchema } from '../../config';
import { getSessionStatus } from './get_session_status';

export interface SearchSessionDependencies {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/server/search/session/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
SearchSessionSavedObjectAttributes,
SearchSessionStatusResponse,
} from '../../../common/search';
import { SearchSessionsConfigSchema } from '../../../config';
import { SearchSessionsConfigSchema } from '../../config';

export { SearchStatus } from '../../../common/search';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
AsyncSearchGetRequest,
} from '@elastic/elasticsearch/lib/api/types';
import { ISearchOptions } from '@kbn/search-types';
import { SearchConfigSchema } from '../../../../config';
import { SearchConfigSchema } from '../../../config';

/**
@internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { TransportResult } from '@elastic/elasticsearch';
import { tap } from 'rxjs';
import type { IScopedClusterClient, Logger } from '@kbn/core/server';
import { getKbnServerError } from '@kbn/kibana-utils-plugin/server';
import { SearchConfigSchema } from '../../../../config';
import { SearchConfigSchema } from '../../../config';
import {
EqlSearchStrategyRequest,
EqlSearchStrategyResponse,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
getTotalLoaded,
shimHitsTotal,
} from '../es_search';
import { SearchConfigSchema } from '../../../../config';
import { SearchConfigSchema } from '../../../config';
import { sanitizeRequestParams } from '../../sanitize_request_params';

export const enhancedEsSearchStrategyProvider = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { AsyncSearchSubmitRequest } from '@elastic/elasticsearch/lib/api/types';
import { ISearchOptions } from '@kbn/search-types';
import { UI_SETTINGS } from '../../../../common';
import { getDefaultSearchParams } from '../es_search';
import { SearchConfigSchema } from '../../../../config';
import { SearchConfigSchema } from '../../../config';
import {
getCommonDefaultAsyncGetParams,
getCommonDefaultAsyncSubmitParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { getKbnSearchError } from '../../report_search_error';
import type { ISearchStrategy, SearchStrategyDependencies } from '../../types';
import type { IAsyncSearchOptions } from '../../../../common';
import { toAsyncKibanaSearchResponse } from './response_utils';
import { SearchConfigSchema } from '../../../../config';
import { SearchConfigSchema } from '../../../config';

// `drop_null_columns` is going to change the response
// now we get `all_columns` and `columns`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { SqlGetAsyncRequest, SqlQueryRequest } from '@elastic/elasticsearch/lib/api/types';
import { ISearchOptions } from '@kbn/search-types';
import { SearchConfigSchema } from '../../../../config';
import { SearchConfigSchema } from '../../../config';
import {
getCommonDefaultAsyncGetParams,
getCommonDefaultAsyncSubmitParams,
Expand Down
Loading

0 comments on commit 2a55742

Please sign in to comment.