Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/elastic/kibana into actio…
Browse files Browse the repository at this point in the history
…ns/placeholders
  • Loading branch information
ymao1 committed Nov 9, 2020
2 parents dea3c34 + c78cf35 commit 1e24dbf
Show file tree
Hide file tree
Showing 73 changed files with 1,717 additions and 2,070 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ export const PeopleinSpaceExpression: React.FunctionComponent<PeopleinSpaceParam
});

const errorsCallout = flatten(
Object.entries(errors).map(([field, errs]: [string, string[]]) =>
errs.map((e) => (
<p>
Object.entries(errors).map(([field, errs]: [string, string[]], fieldIndex) =>
errs.map((e, index) => (
<p key={`astros-error-${fieldIndex}-${index}`}>
<EuiTextColor color="accent">{field}:</EuiTextColor>`: ${errs}`
</p>
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,31 @@
*/

import uuid from 'uuid';
import { range } from 'lodash';
import { range, random } from 'lodash';
import { AlertType } from '../../../../plugins/alerts/server';
import { DEFAULT_INSTANCES_TO_GENERATE, ALERTING_EXAMPLE_APP_ID } from '../../common/constants';

const ACTION_GROUPS = [
{ id: 'small', name: 'small' },
{ id: 'medium', name: 'medium' },
{ id: 'large', name: 'large' },
];

export const alertType: AlertType = {
id: 'example.always-firing',
name: 'Always firing',
actionGroups: [{ id: 'default', name: 'default' }],
defaultActionGroupId: 'default',
actionGroups: ACTION_GROUPS,
defaultActionGroupId: 'small',
async executor({ services, params: { instances = DEFAULT_INSTANCES_TO_GENERATE }, state }) {
const count = (state.count ?? 0) + 1;

range(instances)
.map(() => ({ id: uuid.v4() }))
.forEach((instance: { id: string }) => {
.map(() => ({ id: uuid.v4(), tshirtSize: ACTION_GROUPS[random(0, 2)].id! }))
.forEach((instance: { id: string; tshirtSize: string }) => {
services
.alertInstanceFactory(instance.id)
.replaceState({ triggerdOnCycle: count })
.scheduleActions('default');
.scheduleActions(instance.tshirtSize);
});

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
import { ValuesType } from 'utility-types';
import { APMBaseDoc } from '../../../../../typings/es_schemas/raw/apm_base_doc';
import { APMError } from '../../../../../typings/es_schemas/ui/apm_error';
import { KibanaRequest } from '../../../../../../../../src/core/server';
import {
KibanaRequest,
LegacyScopedClusterClient,
} from '../../../../../../../../src/core/server';
import { ProcessorEvent } from '../../../../../common/processor_event';
import {
ESSearchRequest,
ESSearchResponse,
} from '../../../../../typings/elasticsearch';
import { ApmIndicesConfig } from '../../../settings/apm_indices/get_apm_indices';
import { APMRequestHandlerContext } from '../../../../routes/typings';
import { addFilterToExcludeLegacyData } from './add_filter_to_exclude_legacy_data';
import { callClientWithDebug } from '../call_client_with_debug';
import { Transaction } from '../../../../../typings/es_schemas/ui/transaction';
Expand Down Expand Up @@ -51,20 +53,23 @@ type TypedSearchResponse<
export type APMEventClient = ReturnType<typeof createApmEventClient>;

export function createApmEventClient({
context,
esClient,
debug,
request,
indices,
options: { includeFrozen } = { includeFrozen: false },
}: {
context: APMRequestHandlerContext;
esClient: Pick<
LegacyScopedClusterClient,
'callAsInternalUser' | 'callAsCurrentUser'
>;
debug: boolean;
request: KibanaRequest;
indices: ApmIndicesConfig;
options: {
includeFrozen: boolean;
};
}) {
const client = context.core.elasticsearch.legacy.client;

return {
search<TParams extends APMEventESSearchRequest>(
params: TParams,
Expand All @@ -77,14 +82,14 @@ export function createApmEventClient({
: withProcessorEventFilter;

return callClientWithDebug({
apiCaller: client.callAsCurrentUser,
apiCaller: esClient.callAsCurrentUser,
operationName: 'search',
params: {
...withPossibleLegacyDataFilter,
ignore_throttled: !includeFrozen,
},
request,
debug: context.params.query._debug,
debug,
});
},
};
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/apm/server/lib/helpers/setup_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ export async function setupRequest<TParams extends SetupRequestParams>(
const coreSetupRequest = {
indices,
apmEventClient: createApmEventClient({
context,
esClient: context.core.elasticsearch.legacy.client,
debug: context.params.query._debug,
request,
indices,
options: { includeFrozen },
Expand Down
47 changes: 42 additions & 5 deletions x-pack/plugins/apm/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ import { map, take } from 'rxjs/operators';
import {
CoreSetup,
CoreStart,
KibanaRequest,
Logger,
Plugin,
PluginInitializerContext,
RequestHandlerContext,
} from 'src/core/server';
import { APMConfig, APMXPackConfig, mergeConfigs } from '.';
import { APMOSSPluginSetup } from '../../../../src/plugins/apm_oss/server';
import { HomeServerPluginSetup } from '../../../../src/plugins/home/server';
import { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/server';
import { UI_SETTINGS } from '../../../../src/plugins/data/common';
import { ActionsPlugin } from '../../actions/server';
import { AlertingPlugin } from '../../alerts/server';
import { CloudSetup } from '../../cloud/server';
Expand All @@ -30,6 +33,7 @@ import { TaskManagerSetupContract } from '../../task_manager/server';
import { APM_FEATURE, registerFeaturesUsage } from './feature';
import { registerApmAlerts } from './lib/alerts/register_apm_alerts';
import { createApmTelemetry } from './lib/apm_telemetry';
import { createApmEventClient } from './lib/helpers/create_es_client/create_apm_event_client';
import { getInternalSavedObjectsClient } from './lib/helpers/get_internal_saved_objects_client';
import { createApmAgentConfigurationIndex } from './lib/settings/agent_configuration/create_agent_config_index';
import { getApmIndices } from './lib/settings/apm_indices/get_apm_indices';
Expand All @@ -42,6 +46,11 @@ import { uiSettings } from './ui_settings';
export interface APMPluginSetup {
config$: Observable<APMConfig>;
getApmIndices: () => ReturnType<typeof getApmIndices>;
createApmEventClient: (params: {
debug?: boolean;
request: KibanaRequest;
context: RequestHandlerContext;
}) => Promise<ReturnType<typeof createApmEventClient>>;
}

export class APMPlugin implements Plugin<APMPluginSetup> {
Expand Down Expand Up @@ -141,13 +150,41 @@ export class APMPlugin implements Plugin<APMPluginSetup> {
},
});

const boundGetApmIndices = async () =>
getApmIndices({
savedObjectsClient: await getInternalSavedObjectsClient(core),
config: await mergedConfig$.pipe(take(1)).toPromise(),
});

return {
config$: mergedConfig$,
getApmIndices: async () =>
getApmIndices({
savedObjectsClient: await getInternalSavedObjectsClient(core),
config: await mergedConfig$.pipe(take(1)).toPromise(),
}),
getApmIndices: boundGetApmIndices,
createApmEventClient: async ({
request,
context,
debug,
}: {
debug?: boolean;
request: KibanaRequest;
context: RequestHandlerContext;
}) => {
const [indices, includeFrozen] = await Promise.all([
boundGetApmIndices(),
context.core.uiSettings.client.get(UI_SETTINGS.SEARCH_INCLUDE_FROZEN),
]);

const esClient = context.core.elasticsearch.legacy.client;

return createApmEventClient({
debug: debug ?? false,
esClient,
request,
indices,
options: {
includeFrozen,
},
});
},
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ export const setup = async () => {
setFreeze,
setIndexPriority: setIndexPriority('cold'),
},
delete: {
enable: enable('delete'),
setMinAgeValue: setMinAgeValue('delete'),
setMinAgeUnits: setMinAgeUnits('delete'),
},
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ describe('<EditPolicy />', () => {
expect(testBed.find('snapshotPolicyCombobox').prop('data-currentvalue')).toEqual([
{
label: DELETE_PHASE_POLICY.policy.phases.delete?.actions.wait_for_snapshot?.policy,
value: DELETE_PHASE_POLICY.policy.phases.delete?.actions.wait_for_snapshot?.policy,
},
]);
});
Expand Down Expand Up @@ -412,7 +411,7 @@ describe('<EditPolicy />', () => {
test('wait for snapshot field should delete action if field is empty', async () => {
const { actions } = testBed;

actions.setWaitForSnapshotPolicy('');
await actions.setWaitForSnapshotPolicy('');
await actions.savePolicy();

const expected = {
Expand Down
Loading

0 comments on commit 1e24dbf

Please sign in to comment.