Skip to content

Commit

Permalink
Merge branch 'main' of github.com:elastic/kibana into remove-unrefere…
Browse files Browse the repository at this point in the history
…nced-apis/SavedObjectsImportFailure.title
  • Loading branch information
afharo committed Mar 7, 2022
2 parents 7b100ae + a24b1fc commit b59fff2
Show file tree
Hide file tree
Showing 60 changed files with 781 additions and 265 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ Client used to query the elasticsearch cluster.
<b>Signature:</b>

```typescript
export declare type ElasticsearchClient = Omit<Client, 'connectionPool' | 'serializer' | 'extend' | 'child' | 'close' | 'diagnostic'>;
export declare type ElasticsearchClient = Omit<Client, 'connectionPool' | 'serializer' | 'extend' | 'close' | 'diagnostic'>;
```
20 changes: 12 additions & 8 deletions packages/kbn-type-summarizer/src/lib/source_mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,25 @@ import { tryReadFile } from './helpers/fs';
import { parseJson } from './helpers/json';
import { isNodeModule } from './is_node_module';

type SourceMapConsumerEntry = [ts.SourceFile, BasicSourceMapConsumer | undefined];

export class SourceMapper {
static async forSourceFiles(
log: Logger,
dtsDir: string,
repoRelativePackageDir: string,
sourceFiles: readonly ts.SourceFile[]
) {
const consumers = new Map<ts.SourceFile, BasicSourceMapConsumer | undefined>();

await Promise.all(
sourceFiles.map(async (sourceFile) => {
const entries = await Promise.all(
sourceFiles.map(async (sourceFile): Promise<undefined | SourceMapConsumerEntry> => {
if (isNodeModule(dtsDir, sourceFile.fileName)) {
return;
}

const text = sourceFile.getText();
const match = text.match(/^\/\/#\s*sourceMappingURL=(.*)/im);
if (!match) {
consumers.set(sourceFile, undefined);
return;
return [sourceFile, undefined];
}

const relSourceFile = Path.relative(process.cwd(), sourceFile.fileName);
Expand All @@ -50,11 +49,16 @@ export class SourceMapper {
}

const json = parseJson(sourceJson, `source map at [${relSourceMapPath}]`);
consumers.set(sourceFile, await new SourceMapConsumer(json));
log.debug('loaded sourcemap for', relSourceFile);
return [sourceFile, await new SourceMapConsumer(json)];
})
);

const consumers = new Map(entries.filter((e): e is SourceMapConsumerEntry => !!e));
log.debug(
'loaded sourcemaps for',
Array.from(consumers.keys()).map((s) => Path.relative(process.cwd(), s.fileName))
);

return new SourceMapper(consumers, repoRelativePackageDir);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ it('prints basic class correctly', async () => {
}
`);
expect(output.logs).toMatchInlineSnapshot(`
"debug loaded sourcemap for packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts
"debug loaded sourcemaps for [ 'packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts' ]
debug Ignoring 1 global declarations for \\"Record\\"
debug Ignoring 5 global declarations for \\"Promise\\"
"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ it('prints the function declaration, including comments', async () => {
}
`);
expect(result.logs).toMatchInlineSnapshot(`
"debug loaded sourcemap for packages/kbn-type-summarizer/tests/__tmp__/dist_dts/bar.d.ts
debug loaded sourcemap for packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts
"debug loaded sourcemaps for [
'packages/kbn-type-summarizer/tests/__tmp__/dist_dts/bar.d.ts',
'packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts'
]
"
`);
});
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ it('output type links to named import from node modules', async () => {
}
`);
expect(output.logs).toMatchInlineSnapshot(`
"debug loaded sourcemap for packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts
"debug loaded sourcemaps for [ 'packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts' ]
"
`);
});
Expand Down Expand Up @@ -84,7 +84,7 @@ it('output type links to default import from node modules', async () => {
}
`);
expect(output.logs).toMatchInlineSnapshot(`
"debug loaded sourcemap for packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts
"debug loaded sourcemaps for [ 'packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts' ]
"
`);
});
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ it('prints the whole interface, including comments', async () => {
}
`);
expect(result.logs).toMatchInlineSnapshot(`
"debug loaded sourcemap for packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts
"debug loaded sourcemaps for [ 'packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts' ]
debug Ignoring 5 global declarations for \\"Promise\\"
"
`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ it('collects references from source files which contribute to result', async ()
}
`);
expect(result.logs).toMatchInlineSnapshot(`
"debug loaded sourcemap for packages/kbn-type-summarizer/tests/__tmp__/dist_dts/files/foo.d.ts
debug loaded sourcemap for packages/kbn-type-summarizer/tests/__tmp__/dist_dts/files/index.d.ts
debug loaded sourcemap for packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts
"debug loaded sourcemaps for [
'packages/kbn-type-summarizer/tests/__tmp__/dist_dts/files/foo.d.ts',
'packages/kbn-type-summarizer/tests/__tmp__/dist_dts/files/index.d.ts',
'packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts'
]
debug Ignoring 5 global declarations for \\"Promise\\"
debug Ignoring 4 global declarations for \\"Symbol\\"
debug Ignoring 2 global declarations for \\"Component\\"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ it('prints basic type alias', async () => {
}
`);
expect(output.logs).toMatchInlineSnapshot(`
"debug loaded sourcemap for packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts
"debug loaded sourcemaps for [ 'packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts' ]
"
`);
});
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ it('prints basic variable exports with sourcemaps', async () => {
}
`);
expect(output.logs).toMatchInlineSnapshot(`
"debug loaded sourcemap for packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts
"debug loaded sourcemaps for [ 'packages/kbn-type-summarizer/tests/__tmp__/dist_dts/index.d.ts' ]
"
`);
});
2 changes: 1 addition & 1 deletion src/core/server/elasticsearch/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type { Client } from '@elastic/elasticsearch';
*/
export type ElasticsearchClient = Omit<
Client,
'connectionPool' | 'serializer' | 'extend' | 'child' | 'close' | 'diagnostic'
'connectionPool' | 'serializer' | 'extend' | 'close' | 'diagnostic'
>;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ export { EcsEventOutcome }
export { EcsEventType }

// @public
export type ElasticsearchClient = Omit<Client, 'connectionPool' | 'serializer' | 'extend' | 'child' | 'close' | 'diagnostic'>;
export type ElasticsearchClient = Omit<Client, 'connectionPool' | 'serializer' | 'extend' | 'close' | 'diagnostic'>;

// @public
export type ElasticsearchClientConfig = Pick<ElasticsearchConfig, 'customHeaders' | 'compression' | 'sniffOnStart' | 'sniffOnConnectionFault' | 'requestHeadersWhitelist' | 'sniffInterval' | 'hosts' | 'username' | 'password' | 'serviceAccountToken'> & {
Expand Down
3 changes: 2 additions & 1 deletion test/functional/apps/management/_scripted_fields_filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
const PageObjects = getPageObjects(['settings']);

describe('filter scripted fields', function describeIndexTests() {
// FLAKY: https://github.com/elastic/kibana/issues/126027
describe.skip('filter scripted fields', function describeIndexTests() {
before(async function () {
// delete .kibana index and then wait for Kibana to re-create it
await browser.setWindowSize(1200, 800);
Expand Down
3 changes: 2 additions & 1 deletion test/functional_ccs/apps/discover/_data_view_ccs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await testSubjects.click('saveIndexPatternButton');
};

describe('discover integration with data view editor', function describeIndexTests() {
// FLAKY: https://github.com/elastic/kibana/issues/126658
describe.skip('discover integration with data view editor', function describeIndexTests() {
before(async function () {
await security.testUser.setRoles(['kibana_admin', 'test_logstash_reader']);
await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/logstash_functional');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { Client } from '@elastic/elasticsearch';
import { loggingSystemMock } from 'src/core/server/mocks';
import { elasticsearchServiceMock } from '../../../../../src/core/server/mocks';
import { createWrappedScopedClusterClientFactory } from './wrap_scoped_cluster_client';
import { ElasticsearchClientWithChild } from '../types';

const esQuery = {
body: { query: { bool: { filter: { range: { '@timestamp': { gte: 0 } } } } } },
Expand Down Expand Up @@ -41,9 +40,7 @@ describe('wrapScopedClusterClient', () => {
const scopedClusterClient = elasticsearchServiceMock.createScopedClusterClient();
const childClient = elasticsearchServiceMock.createElasticsearchClient();

(
scopedClusterClient.asInternalUser as unknown as jest.Mocked<ElasticsearchClientWithChild>
).child.mockReturnValue(childClient as unknown as Client);
scopedClusterClient.asInternalUser.child.mockReturnValue(childClient as unknown as Client);
const asInternalUserWrappedSearchFn = childClient.search;

const wrappedSearchClient = createWrappedScopedClusterClientFactory({
Expand All @@ -62,9 +59,7 @@ describe('wrapScopedClusterClient', () => {
const scopedClusterClient = elasticsearchServiceMock.createScopedClusterClient();
const childClient = elasticsearchServiceMock.createElasticsearchClient();

(
scopedClusterClient.asCurrentUser as unknown as jest.Mocked<ElasticsearchClientWithChild>
).child.mockReturnValue(childClient as unknown as Client);
scopedClusterClient.asCurrentUser.child.mockReturnValue(childClient as unknown as Client);
const asCurrentUserWrappedSearchFn = childClient.search;

const wrappedSearchClient = createWrappedScopedClusterClientFactory({
Expand All @@ -83,9 +78,7 @@ describe('wrapScopedClusterClient', () => {
const scopedClusterClient = elasticsearchServiceMock.createScopedClusterClient();
const childClient = elasticsearchServiceMock.createElasticsearchClient();

(
scopedClusterClient.asInternalUser as unknown as jest.Mocked<ElasticsearchClientWithChild>
).child.mockReturnValue(childClient as unknown as Client);
scopedClusterClient.asInternalUser.child.mockReturnValue(childClient as unknown as Client);
const asInternalUserWrappedSearchFn = childClient.search;

const wrappedSearchClient = createWrappedScopedClusterClientFactory({
Expand All @@ -106,9 +99,7 @@ describe('wrapScopedClusterClient', () => {
const scopedClusterClient = elasticsearchServiceMock.createScopedClusterClient();
const childClient = elasticsearchServiceMock.createElasticsearchClient();

(
scopedClusterClient.asInternalUser as unknown as jest.Mocked<ElasticsearchClientWithChild>
).child.mockReturnValue(childClient as unknown as Client);
scopedClusterClient.asInternalUser.child.mockReturnValue(childClient as unknown as Client);
const asInternalUserWrappedSearchFn = childClient.search;

asInternalUserWrappedSearchFn.mockRejectedValueOnce(new Error('something went wrong!'));
Expand All @@ -127,9 +118,7 @@ describe('wrapScopedClusterClient', () => {
const scopedClusterClient = elasticsearchServiceMock.createScopedClusterClient();
const childClient = elasticsearchServiceMock.createElasticsearchClient();

(
scopedClusterClient.asInternalUser as unknown as jest.Mocked<ElasticsearchClientWithChild>
).child.mockReturnValue(childClient as unknown as Client);
scopedClusterClient.asInternalUser.child.mockReturnValue(childClient as unknown as Client);
const asInternalUserWrappedSearchFn = childClient.search;
// @ts-ignore incomplete return type
asInternalUserWrappedSearchFn.mockResolvedValue({});
Expand All @@ -156,9 +145,7 @@ describe('wrapScopedClusterClient', () => {
const scopedClusterClient = elasticsearchServiceMock.createScopedClusterClient();
const childClient = elasticsearchServiceMock.createElasticsearchClient();

(
scopedClusterClient.asInternalUser as unknown as jest.Mocked<ElasticsearchClientWithChild>
).child.mockReturnValue(childClient as unknown as Client);
scopedClusterClient.asInternalUser.child.mockReturnValue(childClient as unknown as Client);
const asInternalUserWrappedSearchFn = childClient.search;
// @ts-ignore incomplete return type
asInternalUserWrappedSearchFn.mockResolvedValue({ took: 333 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type {
AggregationsAggregate,
} from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { IScopedClusterClient, ElasticsearchClient, Logger } from 'src/core/server';
import { ElasticsearchClientWithChild, RuleExecutionMetrics } from '../types';
import { RuleExecutionMetrics } from '../types';
import { Alert as Rule } from '../types';

type RuleInfo = Pick<Rule, 'name' | 'alertTypeId' | 'id'> & { spaceId: string };
Expand Down Expand Up @@ -87,8 +87,7 @@ function wrapScopedClusterClient(opts: WrapScopedClusterClientOpts): IScopedClus
function wrapEsClient(opts: WrapEsClientOpts): ElasticsearchClient {
const { esClient, ...rest } = opts;

// Core hides access to .child via TS
const wrappedClient = (esClient as ElasticsearchClientWithChild).child({});
const wrappedClient = esClient.child({});

// Mutating the functions we want to wrap
wrappedClient.search = getWrappedSearchFn({ esClient: wrappedClient, ...rest });
Expand Down
12 changes: 7 additions & 5 deletions x-pack/plugins/alerting/server/task_runner/task_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class TaskRunner<
this.executionId = uuid.v4();
}

async getDecryptedAttributes(
private async getDecryptedAttributes(
ruleId: string,
spaceId: string
): Promise<{ apiKey: string | null; enabled: boolean }> {
Expand Down Expand Up @@ -267,7 +267,7 @@ export class TaskRunner<
}
}

async executeAlert(
private async executeAlert(
alertId: string,
alert: CreatedAlert<InstanceState, InstanceContext>,
executionHandler: ExecutionHandler<ActionGroupIds | RecoveryActionGroupId>
Expand All @@ -283,7 +283,7 @@ export class TaskRunner<
return executionHandler({ actionGroup, actionSubgroup, context, state, alertId });
}

async executeAlerts(
private async executeAlerts(
fakeRequest: KibanaRequest,
rule: SanitizedAlert<Params>,
params: Params,
Expand Down Expand Up @@ -548,7 +548,7 @@ export class TaskRunner<
};
}

async validateAndExecuteRule(
private async validateAndExecuteRule(
fakeRequest: KibanaRequest,
apiKey: RawRule['apiKey'],
rule: SanitizedAlert<Params>,
Expand All @@ -574,7 +574,9 @@ export class TaskRunner<
return this.executeAlerts(fakeRequest, rule, validatedParams, executionHandler, spaceId, event);
}

async loadRuleAttributesAndRun(event: Event): Promise<Resultable<RuleExecutionRunResult, Error>> {
private async loadRuleAttributesAndRun(
event: Event
): Promise<Resultable<RuleExecutionRunResult, Error>> {
const {
params: { alertId: ruleId, spaceId },
} = this.taskInstance;
Expand Down
6 changes: 0 additions & 6 deletions x-pack/plugins/alerting/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
* 2.0.
*/

import { Client } from '@elastic/elasticsearch';
import type {
IRouter,
RequestHandlerContext,
SavedObjectReference,
ElasticsearchClient,
IUiSettingsClient,
} from 'src/core/server';
import type { PublicMethodsOf } from '@kbn/utility-types';
Expand Down Expand Up @@ -48,10 +46,6 @@ import { IAbortableClusterClient } from './lib/create_abortable_es_client_factor
export type WithoutQueryAndParams<T> = Pick<T, Exclude<keyof T, 'query' | 'params'>>;
export type SpaceIdToNamespaceFunction = (spaceId?: string) => string | undefined;

export interface ElasticsearchClientWithChild extends ElasticsearchClient {
child: Client['child'];
}

/**
* @public
*/
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/cloud/public/fullstory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ export interface FullStoryDeps {
}

export type FullstoryUserVars = Record<string, any>;
export type FullstoryVars = Record<string, any>;

export interface FullStoryApi {
identify(userId: string, userVars?: FullstoryUserVars): void;
setVars(pageName: string, vars?: FullstoryVars): void;
setUserVars(userVars?: FullstoryUserVars): void;
event(eventName: string, eventProperties: Record<string, any>): void;
}
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/cloud/public/plugin.test.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { FullStoryDeps, FullStoryApi, FullStoryService } from './fullstory'
export const fullStoryApiMock: jest.Mocked<FullStoryApi> = {
event: jest.fn(),
setUserVars: jest.fn(),
setVars: jest.fn(),
identify: jest.fn(),
};
export const initializeFullStoryMock = jest.fn<FullStoryService, [FullStoryDeps]>(() => ({
Expand Down
Loading

0 comments on commit b59fff2

Please sign in to comment.