Skip to content

Commit

Permalink
Merge branch 'master' into ftr/remove-retry-usage-in-testSubjects
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored May 14, 2020
2 parents ca671f2 + 02a2d07 commit fcb66fd
Show file tree
Hide file tree
Showing 64 changed files with 847 additions and 388 deletions.
1 change: 0 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@

# Pulse
/packages/kbn-analytics/ @elastic/pulse
/src/legacy/core_plugins/ui_metric/ @elastic/pulse
/src/plugins/kibana_usage_collection/ @elastic/pulse
/src/plugins/newsfeed/ @elastic/pulse
/src/plugins/telemetry/ @elastic/pulse
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
7 changes: 5 additions & 2 deletions x-pack/plugins/apm/public/application/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { UpdateBreadcrumbs } from '../components/app/Main/UpdateBreadcrumbs';
import { APMIndicesPermission } from '../components/app/APMIndicesPermission';
import { ScrollToTopOnPathChange } from '../components/app/Main/ScrollToTopOnPathChange';
import { routes } from '../components/app/Main/route_config';
import { history } from '../utils/history';
import { history, resetHistory } from '../utils/history';
import { ConfigSchema } from '..';
import 'react-vis/dist/style.css';

Expand Down Expand Up @@ -111,6 +111,7 @@ export const renderApp = (
{ element }: AppMountParameters,
config: ConfigSchema
) => {
resetHistory();
ReactDOM.render(
<ApmAppRoot
core={core}
Expand All @@ -120,5 +121,7 @@ export const renderApp = (
/>,
element
);
return () => ReactDOM.unmountComponentAtNode(element);
return () => {
ReactDOM.unmountComponentAtNode(element);
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ import {
AGENT,
URL,
USER,
CUSTOM_ERROR
CUSTOM_ERROR,
TRACE,
TRANSACTION
} from '../sections';

export const ERROR_METADATA_SECTIONS: Section[] = [
{ ...LABELS, required: true },
TRACE,
TRANSACTION,
ERROR,
HTTP,
HOST,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import {

export const SPAN_METADATA_SECTIONS: Section[] = [
LABELS,
SPAN,
TRANSACTION,
TRACE,
TRANSACTION,
SPAN,
SERVICE,
MESSAGE_SPAN,
AGENT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ import {
USER,
USER_AGENT,
CUSTOM_TRANSACTION,
MESSAGE_TRANSACTION
MESSAGE_TRANSACTION,
TRACE
} from '../sections';

export const TRANSACTION_METADATA_SECTIONS: Section[] = [
{ ...LABELS, required: true },
TRACE,
TRANSACTION,
HTTP,
HOST,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ export const TRACE: Section = {
key: 'trace',
label: i18n.translate('xpack.apm.metadataTable.section.traceLabel', {
defaultMessage: 'Trace'
})
}),
properties: ['id']
};

export const ERROR: Section = {
Expand Down
6 changes: 5 additions & 1 deletion x-pack/plugins/apm/public/utils/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import { createHashHistory } from 'history';

// Make history singleton available across APM project
// TODO: Explore using React context or hook instead?
const history = createHashHistory();
let history = createHashHistory();

export const resetHistory = () => {
history = createHashHistory();
};

export { history };
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
3 changes: 3 additions & 0 deletions x-pack/plugins/ingest_manager/common/types/models/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ export interface IndexTemplate {
mappings: object;
aliases: object;
};
data_stream: {
timestamp_field: string;
};
}

export interface TemplateRef {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ function getBaseTemplate(
// To be filled with the aliases that we need
aliases: {},
},
data_stream: {
timestamp_field: '@timestamp',
},
};
}

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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import { APICaller, Logger } from 'kibana/server';
import * as t from 'io-ts';
import { Client } from 'elasticsearch';
import Boom from 'boom';
import { ILicense } from '../../../../licensing/server';
import {
createAnnotationRt,
deleteAnnotationRt,
Expand Down Expand Up @@ -40,8 +42,9 @@ export function createAnnotationsClient(params: {
index: string;
apiCaller: APICaller;
logger: Logger;
license?: ILicense;
}) {
const { index, apiCaller, logger } = params;
const { index, apiCaller, logger, license } = params;

const initIndex = () =>
createOrUpdateIndex({
Expand All @@ -51,48 +54,59 @@ export function createAnnotationsClient(params: {
logger,
});

function ensureGoldLicense<T extends (...args: any[]) => any>(fn: T): T {
return ((...args) => {
if (!license?.hasAtLeast('gold')) {
throw Boom.forbidden('Annotations require at least a gold license or a trial license.');
}
return fn(...args);
}) as T;
}

return {
get index() {
return index;
},
create: async (
createParams: CreateParams
): Promise<{ _id: string; _index: string; _source: Annotation }> => {
const indexExists = await apiCaller('indices.exists', {
index,
});
create: ensureGoldLicense(
async (
createParams: CreateParams
): Promise<{ _id: string; _index: string; _source: Annotation }> => {
const indexExists = await apiCaller('indices.exists', {
index,
});

if (!indexExists) {
await initIndex();
}
if (!indexExists) {
await initIndex();
}

const annotation = {
...createParams,
event: {
created: new Date().toISOString(),
},
};
const annotation = {
...createParams,
event: {
created: new Date().toISOString(),
},
};

const response = (await apiCaller('index', {
index,
body: annotation,
refresh: 'wait_for',
})) as IndexDocumentResponse;
const response = (await apiCaller('index', {
index,
body: annotation,
refresh: 'wait_for',
})) as IndexDocumentResponse;

return apiCaller('get', {
index,
id: response._id,
});
},
getById: async (getByIdParams: GetByIdParams) => {
return apiCaller('get', {
index,
id: response._id,
});
}
),
getById: ensureGoldLicense(async (getByIdParams: GetByIdParams) => {
const { id } = getByIdParams;

return apiCaller('get', {
id,
index,
});
},
delete: async (deleteParams: DeleteParams) => {
}),
delete: ensureGoldLicense(async (deleteParams: DeleteParams) => {
const { id } = deleteParams;

const response = (await apiCaller('delete', {
Expand All @@ -101,6 +115,6 @@ export function createAnnotationsClient(params: {
refresh: 'wait_for',
})) as PromiseReturnType<Client['delete']>;
return response;
},
}),
};
}
Loading

0 comments on commit fcb66fd

Please sign in to comment.