Skip to content

Commit

Permalink
Merge branch 'main' into fix_conf_flaky_test_2
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Oct 13, 2023
2 parents e2146b1 + 3f061a5 commit 84b2dc8
Show file tree
Hide file tree
Showing 25 changed files with 541 additions and 205 deletions.
5 changes: 5 additions & 0 deletions packages/kbn-apm-synthtrace/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ export { InfraSynthtraceEsClient } from './src/lib/infra/infra_synthtrace_es_cli
export { AssetsSynthtraceEsClient } from './src/lib/assets/assets_synthtrace_es_client';

export { MonitoringSynthtraceEsClient } from './src/lib/monitoring/monitoring_synthtrace_es_client';

export {
addObserverVersionTransform,
deleteSummaryFieldTransform,
} from './src/lib/utils/transform_helpers';
17 changes: 15 additions & 2 deletions packages/kbn-apm-synthtrace/src/lib/shared/base_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
SynthtraceESAction,
SynthtraceGenerator,
} from '@kbn/apm-synthtrace-client';
import { castArray } from 'lodash';
import { castArray, isFunction } from 'lodash';
import { Readable, Transform } from 'stream';
import { isGeneratorObject } from 'util/types';
import { Logger } from '../utils/create_logger';
Expand Down Expand Up @@ -69,9 +69,17 @@ export class SynthtraceEsClient<TFields extends Fields> {
this.pipelineCallback = cb;
}

async index(streamOrGenerator: MaybeArray<Readable | SynthtraceGenerator<TFields>>) {
async index(
streamOrGenerator: MaybeArray<Readable | SynthtraceGenerator<TFields>>,
pipelineCallback?: (base: Readable) => NodeJS.WritableStream
) {
this.logger.debug(`Bulk indexing ${castArray(streamOrGenerator).length} stream(s)`);

const previousPipelineCallback = this.pipelineCallback;
if (isFunction(pipelineCallback)) {
this.pipeline(pipelineCallback);
}

const allStreams = castArray(streamOrGenerator).map((obj) => {
const base = isGeneratorObject(obj) ? Readable.from(obj) : obj;

Expand Down Expand Up @@ -121,6 +129,11 @@ export class SynthtraceEsClient<TFields extends Fields> {

this.logger.info(`Produced ${count} events`);

// restore pipeline callback
if (pipelineCallback) {
this.pipeline(previousPipelineCallback);
}

if (this.refreshAfterIndex) {
await this.refresh();
}
Expand Down
33 changes: 33 additions & 0 deletions packages/kbn-apm-synthtrace/src/lib/utils/transform_helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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 { Transform } from 'stream';

export function addObserverVersionTransform(observerVersion: string) {
return new Transform({
objectMode: true,
transform(chunk: { observer?: { version?: string } }, encoding, callback) {
if (chunk?.observer?.version) {
chunk.observer.version = observerVersion;
}
callback(null, chunk);
},
});
}

export function deleteSummaryFieldTransform() {
return new Transform({
objectMode: true,
transform(chunk: { transaction?: { duration?: { summary?: number } } }, encoding, callback) {
if (chunk?.transaction?.duration?.summary) {
delete chunk.transaction.duration.summary;
}
callback(null, chunk);
},
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ describe('#setupSavedObjects', () => {
type: 'known-type',
attributes: { attrOne: 'one', attrSecret: '*secret*' },
references: [],
namespaces: ['some-ns'],
};
mockSavedObjectsRepository.get.mockResolvedValue(mockSavedObject);
mockSavedObjectTypeRegistry.isSingleNamespace.mockReturnValue(true);
Expand Down Expand Up @@ -101,6 +102,7 @@ describe('#setupSavedObjects', () => {
type: 'known-type',
attributes: { attrOne: 'one', attrSecret: '*secret*' },
references: [],
namespaces: ['some-ns2', 'some-ns'],
};
mockSavedObjectsRepository.get.mockResolvedValue(mockSavedObject);
mockSavedObjectTypeRegistry.isSingleNamespace.mockReturnValue(false);
Expand Down Expand Up @@ -154,6 +156,7 @@ describe('#setupSavedObjects', () => {
type: 'known-type',
attributes: { attrOne: 'one', attrSecret: '*secret*' },
references: [],
namespaces: ['some-ns'],
};
mockSavedObjectsRepository.createPointInTimeFinder = jest.fn().mockReturnValue({
close: jest.fn(),
Expand Down Expand Up @@ -320,5 +323,51 @@ describe('#setupSavedObjects', () => {
await finder.close();
expect(mockClose).toHaveBeenCalledTimes(1);
});

it('includes `namespace` for * find option', async () => {
const mockSavedObject: SavedObject = {
id: 'some-id',
type: 'known-type',
attributes: { attrOne: 'one', attrSecret: '*secret*' },
references: [],
namespaces: ['some-ns'],
};
mockSavedObjectsRepository.createPointInTimeFinder = jest.fn().mockReturnValue({
close: jest.fn(),
find: function* asyncGenerator() {
yield { saved_objects: [mockSavedObject] };
},
});

mockSavedObjectTypeRegistry.isSingleNamespace.mockReturnValue(true);

const finder = await setupContract().createPointInTimeFinderDecryptedAsInternalUser({
type: 'known-type',
namespaces: ['*'],
});

for await (const res of finder.find()) {
expect(res).toEqual({
saved_objects: [
{
...mockSavedObject,
attributes: { attrOne: 'one', attrSecret: 'secret' },
},
],
});
}

expect(mockEncryptedSavedObjectsService.decryptAttributes).toHaveBeenCalledTimes(1);
expect(mockEncryptedSavedObjectsService.decryptAttributes).toHaveBeenCalledWith(
{ type: mockSavedObject.type, id: mockSavedObject.id, namespace: 'some-ns' },
mockSavedObject.attributes
);

expect(mockSavedObjectsRepository.createPointInTimeFinder).toHaveBeenCalledTimes(1);
expect(mockSavedObjectsRepository.createPointInTimeFinder).toHaveBeenCalledWith(
{ type: 'known-type', namespaces: ['*'] },
undefined
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export function setupSavedObjects({
{
type,
id,
namespace: getDescriptorNamespace(typeRegistry, type, options?.namespace),
namespace: getDescriptorNamespace(typeRegistry, type, savedObject.namespaces),
},
savedObject.attributes as Record<string, unknown>
)) as T,
Expand Down Expand Up @@ -148,7 +148,7 @@ export function setupSavedObjects({
namespace: getDescriptorNamespace(
typeRegistry,
savedObject.type,
findOptions.namespaces
savedObject.namespaces
),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,6 @@ export const ConnectorCheckable: React.FC<ConnectorCheckableProps> = ({
value={serviceType}
>
<EuiFlexGroup direction="column" gutterSize="xs">
{documentationUrl && (
<EuiFlexItem grow={false}>
<EuiLink target="_blank" href={documentationUrl}>
{i18n.translate(
'xpack.enterpriseSearch.content.indices.selectConnector.connectorCheckable.documentationLinkLabel',
{
defaultMessage: 'Documentation',
}
)}
</EuiLink>
</EuiFlexItem>
)}
<EuiFlexItem>
<EuiFlexGroup
direction="row"
Expand Down Expand Up @@ -152,6 +140,20 @@ export const ConnectorCheckable: React.FC<ConnectorCheckableProps> = ({
)}
</EuiFlexGroup>
</EuiFlexItem>
{documentationUrl && (
<EuiFlexItem grow={false}>
<EuiText size="xs">
<EuiLink target="_blank" href={documentationUrl}>
{i18n.translate(
'xpack.enterpriseSearch.content.indices.selectConnector.connectorCheckable.documentationLinkLabel',
{
defaultMessage: 'Documentation',
}
)}
</EuiLink>
</EuiText>
</EuiFlexItem>
)}
</EuiFlexGroup>
</EuiCheckableCard>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ class DocLinks {
this.connectorsMySQL = docLinks.links.enterpriseSearch.connectorsMySQL;
this.connectorsNative = docLinks.links.enterpriseSearch.connectorsNative;
this.connectorsNetworkDrive = docLinks.links.enterpriseSearch.connectorsNetworkDrive;
this.connectorsOneDrive = docLinks.links.enterpriseSearch.connectorsOneDrive;
this.connectorsOracle = docLinks.links.enterpriseSearch.connectorsOracle;
this.connectorsOutlook = docLinks.links.enterpriseSearch.connectorsOutlook;
this.connectorsPostgreSQL = docLinks.links.enterpriseSearch.connectorsPostgreSQL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@
* 2.0.
*/

import { ELASTIC_MODEL_DEFINITIONS } from '@kbn/ml-trained-models-utils';

import {
ElasticsearchResponseError,
isNotFoundException,
isResourceNotFoundException,
} from '../../utils/identify_exceptions';

export const acceptableModelNames = Object.keys(ELASTIC_MODEL_DEFINITIONS);

export function isNotFoundExceptionError(error: unknown): boolean {
return (
isResourceNotFoundException(error as ElasticsearchResponseError) ||
Expand All @@ -23,20 +19,3 @@ export function isNotFoundExceptionError(error: unknown): boolean {
error?.statusCode === 404
);
}

export function throwIfNotAcceptableModelName(modelName: string) {
if (!acceptableModelNames.includes(modelName)) {
const notFoundError: ElasticsearchResponseError = {
meta: {
body: {
error: {
type: 'resource_not_found_exception',
},
},
statusCode: 404,
},
name: 'ResponseError',
};
throw notFoundError;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ import { MlTrainedModels } from '@kbn/ml-plugin/server';
import { MlModelDeploymentStatus, MlModelDeploymentState } from '../../../common/types/ml';

import { getMlModelDeploymentStatus } from './get_ml_model_deployment_status';
import {
isNotFoundExceptionError,
throwIfNotAcceptableModelName,
} from './ml_model_deployment_common';
import { isNotFoundExceptionError } from './ml_model_deployment_common';

export const startMlModelDeployment = async (
modelName: string,
Expand All @@ -25,10 +22,6 @@ export const startMlModelDeployment = async (
throw new Error('Machine Learning is not enabled');
}

// before anything else, check our model name
// to ensure we only allow those names we want
throwIfNotAcceptableModelName(modelName);

try {
// try and get the deployment status of the model first
// and see if it's already deployed or deploying...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import { MlTrainedModels } from '@kbn/ml-plugin/server';
import { MlModelDeploymentState, MlModelDeploymentStatus } from '../../../common/types/ml';

import { getMlModelDeploymentStatus } from './get_ml_model_deployment_status';
import {
isNotFoundExceptionError,
throwIfNotAcceptableModelName,
} from './ml_model_deployment_common';
import { isNotFoundExceptionError } from './ml_model_deployment_common';

export const startMlModelDownload = async (
modelName: string,
Expand All @@ -24,10 +21,6 @@ export const startMlModelDownload = async (
throw new Error('Machine Learning is not enabled');
}

// before anything else, check our model name
// to ensure we only allow those names we want
throwIfNotAcceptableModelName(modelName);

try {
// try and get the deployment status of the model first
// and see if it's already deployed or deploying...
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/observability/public/application/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import { Router, Routes, Route } from '@kbn/shared-ux-router';
import { AppMountParameters, APP_WRAPPER_CLASS, CoreStart } from '@kbn/core/public';
import { EuiThemeProvider } from '@kbn/kibana-react-plugin/common';
import type { LazyObservabilityPageTemplateProps } from '@kbn/observability-shared-plugin/public';
import { KibanaContextProvider, RedirectAppLinks } from '@kbn/kibana-react-plugin/public';
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import { KibanaThemeProvider } from '@kbn/react-kibana-context-theme';
import { RedirectAppLinks } from '@kbn/shared-ux-link-redirect-app';
import { Storage } from '@kbn/kibana-utils-plugin/public';
import { UsageCollectionSetup } from '@kbn/usage-collection-plugin/public';
import { ObservabilityAIAssistantProvider } from '@kbn/observability-ai-assistant-plugin/public';
Expand Down Expand Up @@ -111,8 +112,7 @@ export const renderApp = ({
<EuiThemeProvider darkMode={isDarkMode}>
<i18nCore.Context>
<RedirectAppLinks
application={core.application}
className={APP_WRAPPER_CLASS}
coreStart={core}
data-test-subj="observabilityMainContainer"
>
<QueryClientProvider client={queryClient}>
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/observability/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@
"@kbn/deeplinks-observability",
"@kbn/core-application-common",
"@kbn/react-kibana-mount",
"@kbn/react-kibana-context-theme"
"@kbn/react-kibana-context-theme",
"@kbn/shared-ux-link-redirect-app"
],
"exclude": [
"target/**/*"
Expand Down
27 changes: 10 additions & 17 deletions x-pack/plugins/observability_onboarding/public/application/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { Router, Routes, Route } from '@kbn/shared-ux-router';
import { euiDarkVars, euiLightVars } from '@kbn/ui-theme';
import React from 'react';
import ReactDOM from 'react-dom';
import { RouteComponentProps, RouteProps } from 'react-router-dom';
import { ConfigSchema } from '..';
import { customLogsRoutes } from '../components/app/custom_logs';
import { systemLogsRoutes } from '../components/app/system_logs';
Expand All @@ -37,16 +36,6 @@ import { baseRoutes, routes } from '../routes';
import { CustomLogs } from '../routes/templates/custom_logs';
import { SystemLogs } from '../routes/templates/system_logs';

export type BreadcrumbTitle<
T extends { [K in keyof T]?: string | undefined } = {}
> = string | ((props: RouteComponentProps<T>) => string) | null;

export interface RouteDefinition<
T extends { [K in keyof T]?: string | undefined } = any
> extends RouteProps {
breadcrumb: BreadcrumbTitle<T>;
}

export const onBoardingTitle = i18n.translate(
'xpack.observability_onboarding.breadcrumbs.onboarding',
{
Expand Down Expand Up @@ -157,6 +146,8 @@ export function ObservabilityOnboardingAppRoot({
const i18nCore = core.i18n;
const plugins = { ...deps };

const renderFeedbackLinkAsPortal = !config.serverless.enabled;

return (
<RedirectAppLinks
className={APP_WRAPPER_CLASS}
Expand All @@ -183,12 +174,14 @@ export function ObservabilityOnboardingAppRoot({
<i18nCore.Context>
<Router history={history}>
<EuiErrorBoundary>
<HeaderMenuPortal
setHeaderActionMenu={setHeaderActionMenu}
theme$={theme$}
>
<ObservabilityOnboardingHeaderActionMenu />
</HeaderMenuPortal>
{renderFeedbackLinkAsPortal && (
<HeaderMenuPortal
setHeaderActionMenu={setHeaderActionMenu}
theme$={theme$}
>
<ObservabilityOnboardingHeaderActionMenu />
</HeaderMenuPortal>
)}
<ObservabilityOnboardingApp />
</EuiErrorBoundary>
</Router>
Expand Down
Loading

0 comments on commit 84b2dc8

Please sign in to comment.