Skip to content

Commit

Permalink
Merge branch 'master' into capture-case-timeline-click
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored May 14, 2020
2 parents 19be127 + 8652bed commit 4ae1afd
Show file tree
Hide file tree
Showing 41 changed files with 530 additions and 148 deletions.
29 changes: 13 additions & 16 deletions packages/kbn-es/src/utils/native_realm.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ exports.NativeRealm = class NativeRealm {
}

const reservedUsers = await this.getReservedUsers();
if (!reservedUsers || reservedUsers.length < 1) {
throw new Error('no reserved users found, unable to set native realm passwords');
}

await Promise.all(
reservedUsers.map(async user => {
await this.setPassword(user, options[`password.${user}`]);
Expand All @@ -88,16 +84,18 @@ exports.NativeRealm = class NativeRealm {
}

async getReservedUsers() {
const users = await this._autoRetry(async () => {
return await this._client.security.getUser();
});
return await this._autoRetry(async () => {
const resp = await this._client.security.getUser();
const usernames = Object.keys(resp.body).filter(
user => resp.body[user].metadata._reserved === true
);

return Object.keys(users.body).reduce((acc, user) => {
if (users.body[user].metadata._reserved === true) {
acc.push(user);
if (!usernames?.length) {
throw new Error('no reserved users found, unable to set native realm passwords');
}
return acc;
}, []);

return usernames;
});
}

async isSecurityEnabled() {
Expand Down Expand Up @@ -125,10 +123,9 @@ exports.NativeRealm = class NativeRealm {
throw error;
}

this._log.warning(
'assuming [elastic] user not available yet, waiting 1.5 seconds and trying again'
);
await new Promise(resolve => setTimeout(resolve, 1500));
const sec = 1.5 * attempt;
this._log.warning(`assuming ES isn't initialized completely, trying again in ${sec} seconds`);
await new Promise(resolve => setTimeout(resolve, sec * 1000));
return await this._autoRetry(fn, attempt + 1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,13 @@ export class IndexPattern implements IIndexPattern {
}

async popularizeField(fieldName: string, unit = 1) {
/**
* This function is just used by Discover and it's high likely to be removed in the near future
* It doesn't use the save function to skip the error message that's displayed when
* a user adds several columns in a higher frequency that the changes can be persisted to ES
* resulting in 409 errors
*/
if (!this.id) return;
const field = this.fields.getByName(fieldName);
if (!field) {
return;
Expand All @@ -308,7 +315,15 @@ export class IndexPattern implements IIndexPattern {
return;
}
field.count = count;
await this.save();

try {
const res = await this.savedObjectsClient.update(type, this.id, this.prepBody(), {
version: this.version,
});
this.version = res._version;
} catch (e) {
// no need for an error message here
}
}

getNonScriptedFields() {
Expand Down
3 changes: 2 additions & 1 deletion test/functional/apps/visualize/_tsvb_chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export default function({ getService, getPageObjects }: FtrProviderContext) {
const security = getService('security');
const PageObjects = getPageObjects(['visualize', 'visualBuilder', 'timePicker', 'visChart']);

describe('visual builder', function describeIndexTests() {
// FLAKY: https://github.com/elastic/kibana/issues/43150
describe.skip('visual builder', function describeIndexTests() {
this.tags('includeFirefox');
beforeEach(async () => {
await security.testUser.setRoles(['kibana_admin', 'test_logstash_reader']);
Expand Down
13 changes: 5 additions & 8 deletions x-pack/plugins/apm/server/routes/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import * as t from 'io-ts';
import Boom from 'boom';
import { unique } from 'lodash';
import { ScopedAnnotationsClient } from '../../../observability/server';
import { setupRequest } from '../lib/helpers/setup_request';
import { getServiceAgentName } from '../lib/services/get_service_agent_name';
import { getServices } from '../lib/services/get_services';
Expand Down Expand Up @@ -95,13 +94,10 @@ export const serviceAnnotationsRoute = createRoute(() => ({
const { serviceName } = context.params.path;
const { environment } = context.params.query;

let annotationsClient: ScopedAnnotationsClient | undefined;

if (context.plugins.observability) {
annotationsClient = await context.plugins.observability.getScopedAnnotationsClient(
request
);
}
const annotationsClient = await context.plugins.observability?.getScopedAnnotationsClient(
context,
request
);

return getServiceAnnotations({
setup,
Expand Down Expand Up @@ -143,6 +139,7 @@ export const serviceAnnotationsCreateRoute = createRoute(() => ({
},
handler: async ({ request, context }) => {
const annotationsClient = await context.plugins.observability?.getScopedAnnotationsClient(
context,
request
);

Expand Down
43 changes: 35 additions & 8 deletions x-pack/plugins/lens/public/app_plugin/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ describe('Lens App', () => {
storage: Storage;
docId?: string;
docStorage: SavedObjectStore;
redirectTo: (id?: string, returnToOrigin?: boolean, newlyCreated?: boolean) => void;
redirectTo: (
id?: string,
returnToOrigin?: boolean,
originatingApp?: string | undefined,
newlyCreated?: boolean
) => void;
originatingApp: string | undefined;
}> {
return ({
Expand Down Expand Up @@ -140,7 +145,14 @@ describe('Lens App', () => {
load: jest.fn(),
save: jest.fn(),
},
redirectTo: jest.fn((id?: string, returnToOrigin?: boolean, newlyCreated?: boolean) => {}),
redirectTo: jest.fn(
(
id?: string,
returnToOrigin?: boolean,
originatingApp?: string | undefined,
newlyCreated?: boolean
) => {}
),
} as unknown) as jest.Mocked<{
navigation: typeof navigationStartMock;
editorFrame: EditorFrameInstance;
Expand All @@ -149,7 +161,12 @@ describe('Lens App', () => {
storage: Storage;
docId?: string;
docStorage: SavedObjectStore;
redirectTo: (id?: string, returnToOrigin?: boolean, newlyCreated?: boolean) => void;
redirectTo: (
id?: string,
returnToOrigin?: boolean,
originatingApp?: string | undefined,
newlyCreated?: boolean
) => void;
originatingApp: string | undefined;
}>;
}
Expand Down Expand Up @@ -348,7 +365,12 @@ describe('Lens App', () => {
storage: Storage;
docId?: string;
docStorage: SavedObjectStore;
redirectTo: (id?: string, returnToOrigin?: boolean, newlyCreated?: boolean) => void;
redirectTo: (
id?: string,
returnToOrigin?: boolean,
originatingApp?: string | undefined,
newlyCreated?: boolean
) => void;
originatingApp: string | undefined;
}>;

Expand Down Expand Up @@ -521,7 +543,7 @@ describe('Lens App', () => {
expression: 'kibana 3',
});

expect(args.redirectTo).toHaveBeenCalledWith('aaa', undefined, true);
expect(args.redirectTo).toHaveBeenCalledWith('aaa', undefined, undefined, true);

inst.setProps({ docId: 'aaa' });

Expand All @@ -541,7 +563,7 @@ describe('Lens App', () => {
expression: 'kibana 3',
});

expect(args.redirectTo).toHaveBeenCalledWith('aaa', undefined, true);
expect(args.redirectTo).toHaveBeenCalledWith('aaa', undefined, undefined, true);

inst.setProps({ docId: 'aaa' });

Expand Down Expand Up @@ -609,7 +631,7 @@ describe('Lens App', () => {
title: 'hello there',
});

expect(args.redirectTo).toHaveBeenCalledWith('aaa', true, true);
expect(args.redirectTo).toHaveBeenCalledWith('aaa', true, undefined, true);
});

it('saves app filters and does not save pinned filters', async () => {
Expand Down Expand Up @@ -677,7 +699,12 @@ describe('Lens App', () => {
storage: Storage;
docId?: string;
docStorage: SavedObjectStore;
redirectTo: (id?: string, returnToOrigin?: boolean, newlyCreated?: boolean) => void;
redirectTo: (
id?: string,
returnToOrigin?: boolean,
originatingApp?: string | undefined,
newlyCreated?: boolean
) => void;
}>;

beforeEach(() => {
Expand Down
23 changes: 15 additions & 8 deletions x-pack/plugins/lens/public/app_plugin/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ interface State {
isLoading: boolean;
isSaveModalVisible: boolean;
indexPatternsForTopNav: IndexPatternInstance[];
originatingApp: string | undefined;
persistedDoc?: Document;
lastKnownDoc?: Document;

Expand All @@ -54,7 +55,7 @@ export function App({
docId,
docStorage,
redirectTo,
originatingApp,
originatingAppFromUrl,
navigation,
}: {
editorFrame: EditorFrameInstance;
Expand All @@ -64,8 +65,13 @@ export function App({
storage: IStorageWrapper;
docId?: string;
docStorage: SavedObjectStore;
redirectTo: (id?: string, returnToOrigin?: boolean, newlyCreated?: boolean) => void;
originatingApp?: string | undefined;
redirectTo: (
id?: string,
returnToOrigin?: boolean,
originatingApp?: string | undefined,
newlyCreated?: boolean
) => void;
originatingAppFromUrl?: string | undefined;
}) {
const language =
storage.get('kibana.userQueryLanguage') || core.uiSettings.get('search:queryLanguage');
Expand All @@ -77,6 +83,7 @@ export function App({
isSaveModalVisible: false,
indexPatternsForTopNav: [],
query: { query: '', language },
originatingApp: originatingAppFromUrl,
dateRange: {
fromDate: currentRange.from,
toDate: currentRange.to,
Expand Down Expand Up @@ -229,7 +236,7 @@ export function App({
lastKnownDoc: newDoc,
}));
if (docId !== id || saveProps.returnToOrigin) {
redirectTo(id, saveProps.returnToOrigin, newlyCreated);
redirectTo(id, saveProps.returnToOrigin, state.originatingApp, newlyCreated);
}
})
.catch(e => {
Expand Down Expand Up @@ -269,7 +276,7 @@ export function App({
<div className="lnsApp__header">
<TopNavMenu
config={[
...(!!originatingApp && lastKnownDoc?.id
...(!!state.originatingApp && lastKnownDoc?.id
? [
{
label: i18n.translate('xpack.lens.app.saveAndReturn', {
Expand All @@ -294,14 +301,14 @@ export function App({
: []),
{
label:
lastKnownDoc?.id && !!originatingApp
lastKnownDoc?.id && !!state.originatingApp
? i18n.translate('xpack.lens.app.saveAs', {
defaultMessage: 'Save as',
})
: i18n.translate('xpack.lens.app.save', {
defaultMessage: 'Save',
}),
emphasize: !originatingApp || !lastKnownDoc?.id,
emphasize: !state.originatingApp || !lastKnownDoc?.id,
run: () => {
if (isSaveable && lastKnownDoc) {
setState(s => ({ ...s, isSaveModalVisible: true }));
Expand Down Expand Up @@ -422,7 +429,7 @@ export function App({
</div>
{lastKnownDoc && state.isSaveModalVisible && (
<SavedObjectSaveModalOrigin
originatingApp={originatingApp}
originatingApp={state.originatingApp}
onSave={props => runSave(props)}
onClose={() => setState(s => ({ ...s, isSaveModalVisible: false }))}
documentInfo={{
Expand Down
17 changes: 8 additions & 9 deletions x-pack/plugins/lens/public/app_plugin/mounter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,11 @@ export async function mountApp(
);
const redirectTo = (
routeProps: RouteComponentProps<{ id?: string }>,
originatingApp: string,
id?: string,
returnToOrigin?: boolean,
originatingApp?: string,
newlyCreated?: boolean
) => {
if (!!originatingApp && !returnToOrigin) {
removeQueryParam(routeProps.history, 'embeddableOriginatingApp');
}

if (!id) {
routeProps.history.push('/');
} else if (!originatingApp) {
Expand All @@ -78,7 +74,10 @@ export async function mountApp(
const renderEditor = (routeProps: RouteComponentProps<{ id?: string }>) => {
trackUiEvent('loaded');
const urlParams = parse(routeProps.location.search) as Record<string, string>;
const originatingApp = urlParams.embeddableOriginatingApp;
const originatingAppFromUrl = urlParams.embeddableOriginatingApp;
if (urlParams.embeddableOriginatingApp) {
removeQueryParam(routeProps.history, 'embeddableOriginatingApp');
}

return (
<App
Expand All @@ -89,10 +88,10 @@ export async function mountApp(
storage={new Storage(localStorage)}
docId={routeProps.match.params.id}
docStorage={new SavedObjectIndexStore(savedObjectsClient)}
redirectTo={(id, returnToOrigin, newlyCreated) =>
redirectTo(routeProps, originatingApp, id, returnToOrigin, newlyCreated)
redirectTo={(id, returnToOrigin, originatingApp, newlyCreated) =>
redirectTo(routeProps, id, returnToOrigin, originatingApp, newlyCreated)
}
originatingApp={originatingApp}
originatingAppFromUrl={originatingAppFromUrl}
/>
);
};
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/observability/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"xpack",
"observability"
],
"optionalPlugins": [
"licensing"
],
"ui": true,
"server": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { CoreSetup, PluginInitializerContext, KibanaRequest } from 'kibana/server';
import {
CoreSetup,
PluginInitializerContext,
KibanaRequest,
RequestHandlerContext,
} from 'kibana/server';
import { PromiseReturnType } from '../../../typings/common';
import { createAnnotationsClient } from './create_annotations_client';
import { registerAnnotationAPIs } from './register_annotation_apis';
Expand Down Expand Up @@ -31,11 +36,12 @@ export async function bootstrapAnnotations({ index, core, context }: Params) {
});

return {
getScopedAnnotationsClient: (request: KibanaRequest) => {
getScopedAnnotationsClient: (requestContext: RequestHandlerContext, request: KibanaRequest) => {
return createAnnotationsClient({
index,
apiCaller: core.elasticsearch.dataClient.asScoped(request).callAsCurrentUser,
logger,
license: requestContext.licensing?.license,
});
},
};
Expand Down
Loading

0 comments on commit 4ae1afd

Please sign in to comment.