Skip to content

Commit

Permalink
Merge branch 'main' into canvas_filters_panel_update_group
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Nov 29, 2021
2 parents 3d21e99 + a0650c7 commit 9bceb67
Show file tree
Hide file tree
Showing 18 changed files with 148 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
"deep-freeze-strict": "^1.1.1",
"deepmerge": "^4.2.2",
"del": "^5.1.0",
"elastic-apm-node": "^3.24.0",
"elastic-apm-node": "^3.25.0",
"execa": "^4.0.2",
"exit-hook": "^2.2.0",
"expiry-js": "0.1.7",
Expand Down
1 change: 1 addition & 0 deletions src/plugins/vis_types/timelion/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface TimelionFunctionArgs {
multi?: boolean;
types: TimelionFunctionArgsTypes[];
suggestions?: TimelionFunctionArgsSuggestion[];
hidden?: boolean;
}

export interface ITimelionFunction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function getArgumentsHelp(

// ignore arguments that are already provided in function declaration
const functionArgNames = functionArgs.map((arg) => arg.name);
return argsHelp.filter((arg) => !functionArgNames.includes(arg.name));
return argsHelp.filter((arg) => !arg.hidden && !functionArgNames.includes(arg.name));
}

async function extractSuggestionsFromParsedResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default class Datasource extends TimelionFunction {
fitFunctions: _.keys(fitFunctions).join(', '),
},
}),
hidden: Boolean(config.hideFitArg),
});

// Wrap the original function so we can modify inputs/outputs with offset & fit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import buildRequest from './lib/build_request';
import toSeriesList from './lib/agg_response_to_series_list';

export default new Datasource('es', {
hideFitArg: true,
args: [
{
name: 'q',
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/actions/server/lib/action_executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class ActionExecutor {
name: `execute_action`,
type: 'actions',
labels: {
actionId,
actions_connector_id: actionId,
},
},
async (span) => {
Expand Down Expand Up @@ -135,7 +135,7 @@ export class ActionExecutor {
if (span) {
span.name = `execute_action ${actionTypeId}`;
span.addLabels({
actionTypeId,
actions_connector_type_id: actionTypeId,
});
}

Expand Down
42 changes: 41 additions & 1 deletion x-pack/plugins/alerting/server/task_runner/task_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import apm from 'elastic-apm-node';
import type { PublicMethodsOf } from '@kbn/utility-types';
import { Dictionary, pickBy, mapValues, without, cloneDeep } from 'lodash';
import type { Request } from '@hapi/hapi';
Expand Down Expand Up @@ -529,6 +529,17 @@ export class TaskRunner<
// Ensure API key is still valid and user has access
try {
alert = await rulesClient.get({ id: alertId });

if (apm.currentTransaction) {
apm.currentTransaction.name = `Execute Alerting Rule: "${alert.name}"`;
apm.currentTransaction.addLabels({
alerting_rule_consumer: alert.consumer,
alerting_rule_name: alert.name,
alerting_rule_tags: alert.tags.join(', '),
alerting_rule_type_id: alert.alertTypeId,
alerting_rule_params: JSON.stringify(alert.params),
});
}
} catch (err) {
throw new ErrorWithReason(AlertExecutionStatusErrorReasons.Read, err);
}
Expand Down Expand Up @@ -560,6 +571,13 @@ export class TaskRunner<
schedule: taskSchedule,
} = this.taskInstance;

if (apm.currentTransaction) {
apm.currentTransaction.name = `Execute Alerting Rule`;
apm.currentTransaction.addLabels({
alerting_rule_id: alertId,
});
}

const runDate = new Date();
const runDateString = runDate.toISOString();
this.logger.debug(`executing alert ${this.alertType.id}:${alertId} at ${runDateString}`);
Expand Down Expand Up @@ -615,6 +633,14 @@ export class TaskRunner<
executionStatus.lastExecutionDate = new Date(event.event.start);
}

if (apm.currentTransaction) {
if (executionStatus.status === 'ok' || executionStatus.status === 'active') {
apm.currentTransaction.setOutcome('success');
} else if (executionStatus.status === 'error' || executionStatus.status === 'unknown') {
apm.currentTransaction.setOutcome('failure');
}
}

this.logger.debug(
`alertExecutionStatus for ${this.alertType.id}:${alertId}: ${JSON.stringify(executionStatus)}`
);
Expand Down Expand Up @@ -855,6 +881,12 @@ function generateNewAndRecoveredInstanceEvents<
const recoveredAlertInstanceIds = Object.keys(recoveredAlertInstances);
const newIds = without(currentAlertInstanceIds, ...originalAlertInstanceIds);

if (apm.currentTransaction) {
apm.currentTransaction.addLabels({
alerting_new_alerts: newIds.length,
});
}

for (const id of recoveredAlertInstanceIds) {
const { group: actionGroup, subgroup: actionSubgroup } =
recoveredAlertInstances[id].getLastScheduledActions() ?? {};
Expand Down Expand Up @@ -1035,6 +1067,14 @@ function logActiveAndRecoveredInstances<
const { logger, activeAlertInstances, recoveredAlertInstances, alertLabel } = params;
const activeInstanceIds = Object.keys(activeAlertInstances);
const recoveredInstanceIds = Object.keys(recoveredAlertInstances);

if (apm.currentTransaction) {
apm.currentTransaction.addLabels({
alerting_active_alerts: activeInstanceIds.length,
alerting_recovered_alerts: recoveredInstanceIds.length,
});
}

if (activeInstanceIds.length > 0) {
logger.debug(
`alert ${alertLabel} has ${activeInstanceIds.length} active alert instances: ${JSON.stringify(
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/task_manager/server/task_scheduling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ jest.mock('uuid', () => ({

jest.mock('elastic-apm-node', () => ({
currentTraceparent: 'parent',
currentTransaction: {
type: 'taskManager run',
},
}));

describe('TaskScheduling', () => {
Expand Down
8 changes: 7 additions & 1 deletion x-pack/plugins/task_manager/server/task_scheduling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,15 @@ export class TaskScheduling {
...options,
taskInstance: ensureDeprecatedFieldsAreCorrected(taskInstance, this.logger),
});

const traceparent =
agent.currentTransaction && agent.currentTransaction.type !== 'request'
? agent.currentTraceparent
: '';

return await this.store.schedule({
...modifiedTask,
traceparent: agent.currentTraceparent ?? '',
traceparent: traceparent || '',
});
}

Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/uptime/common/constants/rest_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ export enum API_URLS {
DELETE_RULE = '/api/alerting/rule/',
RULES_FIND = '/api/alerting/rules/_find',
CONNECTOR_TYPES = '/api/actions/connector_types',

// Service end points
INDEX_TEMPLATES = '/api/uptime/service/index_templates',
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { UptimeESClient } from '../../lib';
import type { UptimeRouter } from '../../../types';
import { SecurityPluginStart } from '../../../../../security/server';
import { CloudSetup } from '../../../../../cloud/server';
import { FleetStartContract } from '../../../../../fleet/server';
import { UptimeConfig } from '../../../../common/config';

export type UMElasticsearchQueryFn<P, R = any> = (
Expand All @@ -41,7 +42,8 @@ export type UMSavedObjectsQueryFn<T = any, P = undefined> = (
export interface UptimeCoreSetup {
router: UptimeRouter;
config: UptimeConfig;
cloud: CloudSetup;
cloud?: CloudSetup;
fleet: FleetStartContract;
security: SecurityPluginStart;
encryptedSavedObjects: EncryptedSavedObjectsPluginStart;
}
Expand All @@ -59,6 +61,7 @@ export interface UptimeCorePluginsSetup {

export interface UptimeCorePluginsStart {
security: SecurityPluginStart;
fleet: FleetStartContract;
encryptedSavedObjects: EncryptedSavedObjectsPluginStart;
}

Expand Down
32 changes: 28 additions & 4 deletions x-pack/plugins/uptime/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Plugin as PluginType,
ISavedObjectsRepository,
Logger,
SavedObjectsClient,
} from '../../../../src/core/server';
import { uptimeRuleFieldMap } from '../common/rules/uptime_rule_field_map';
import { initServerWithKibana } from './kibana.index';
Expand All @@ -25,17 +26,19 @@ import { registerUptimeSavedObjects, savedObjectsAdapter } from './lib/saved_obj
import { mappingFromFieldMap } from '../../rule_registry/common/mapping_from_field_map';
import { Dataset } from '../../rule_registry/server';
import { UptimeConfig } from '../common/config';
import { installSyntheticsIndexTemplates } from './rest_api/synthetics_service/install_index_templates';

export type UptimeRuleRegistry = ReturnType<Plugin['setup']>['ruleRegistry'];

export class Plugin implements PluginType {
private savedObjectsClient?: ISavedObjectsRepository;
private initContext: PluginInitializerContext;
private logger?: Logger;
private logger: Logger;
private server?: UptimeCoreSetup;

constructor(_initializerContext: PluginInitializerContext<UptimeConfig>) {
this.initContext = _initializerContext;
constructor(initializerContext: PluginInitializerContext<UptimeConfig>) {
this.initContext = initializerContext;
this.logger = initializerContext.logger.get();
}

public setup(core: CoreSetup, plugins: UptimeCorePluginsSetup) {
Expand All @@ -60,8 +63,8 @@ export class Plugin implements PluginType {
});

this.server = {
router: core.http.createRouter(),
config,
router: core.http.createRouter(),
cloud: plugins.cloud,
} as UptimeCoreSetup;

Expand All @@ -83,8 +86,29 @@ export class Plugin implements PluginType {
this.savedObjectsClient = core.savedObjects.createInternalRepository();
if (this.server) {
this.server.security = plugins.security;
this.server.fleet = plugins.fleet;
this.server.encryptedSavedObjects = plugins.encryptedSavedObjects;
}

if (this.server?.config?.unsafe?.service.enabled) {
const esClient = core.elasticsearch.client.asInternalUser;
installSyntheticsIndexTemplates({
esClient,
server: this.server,
savedObjectsClient: new SavedObjectsClient(core.savedObjects.createInternalRepository()),
}).then(
(result) => {
if (result.name === 'synthetics' && result.install_status === 'installed') {
this.logger.info('Installed synthetics index templates');
} else if (result.name === 'synthetics' && result.install_status === 'install_failed') {
this.logger.warn('Failed to install synthetics index templates');
}
},
() => {
this.logger.warn('Failed to install synthetics index templates');
}
);
}
}

public stop() {}
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/uptime/server/rest_api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { createGetIndexStatusRoute } from './index_state';
import { createNetworkEventsRoute } from './network_events';
import { createJourneyFailedStepsRoute } from './pings/journeys';
import { createLastSuccessfulStepRoute } from './synthetics/last_successful_step';
import { installIndexTemplatesRoute } from './synthetics_service/install_index_templates';

export * from './types';
export { createRouteWithAuth } from './create_route_with_auth';
Expand All @@ -51,4 +52,5 @@ export const restApiRoutes: UMRestApiRouteFactory[] = [
createJourneyFailedStepsRoute,
createLastSuccessfulStepRoute,
createJourneyScreenshotBlocksRoute,
installIndexTemplatesRoute,
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { ElasticsearchClient, SavedObjectsClientContract } from 'kibana/server';
import { UMRestApiRouteFactory } from '../types';
import { API_URLS } from '../../../common/constants';
import { UptimeCoreSetup } from '../../lib/adapters';

export const installIndexTemplatesRoute: UMRestApiRouteFactory = () => ({
method: 'GET',
path: API_URLS.INDEX_TEMPLATES,
validate: {},
handler: async ({ server, request, savedObjectsClient, uptimeEsClient }): Promise<any> => {
return installSyntheticsIndexTemplates({
server,
savedObjectsClient,
esClient: uptimeEsClient.baseESClient,
});
},
});

export async function installSyntheticsIndexTemplates({
esClient,
server,
savedObjectsClient,
}: {
server: UptimeCoreSetup;
esClient: ElasticsearchClient;
savedObjectsClient: SavedObjectsClientContract;
}) {
// no need to add error handling here since fleetSetupCompleted is already wrapped in try/catch and will log
// warning if setup fails to complete
await server.fleet.fleetSetupCompleted();

return await server.fleet.packageService.ensureInstalledPackage({
esClient,
savedObjectsClient,
pkgName: 'synthetics',
});
}
3 changes: 2 additions & 1 deletion x-pack/test/api_integration/apis/search/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ export default function ({ getService }: FtrProviderContext) {
});
});

describe('delete', () => {
// FLAKY: https://github.com/elastic/kibana/issues/119272
describe.skip('delete', () => {
it('should return 404 when no search id provided', async () => {
await supertest.delete(`/internal/search/ese`).set('kbn-xsrf', 'foo').send().expect(404);
});
Expand Down
3 changes: 2 additions & 1 deletion x-pack/test/functional/apps/infra/home_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
});
});

describe('with metrics present', () => {
// FLAKY: https://github.com/elastic/kibana/issues/119763
describe.skip('with metrics present', () => {
before(async () => {
await esArchiver.load('x-pack/test/functional/es_archives/infra/metrics_and_logs');
await pageObjects.common.navigateToApp('infraOps');
Expand Down
3 changes: 2 additions & 1 deletion x-pack/test/functional/apps/uptime/synthetics_integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
});
});

describe('create new policy', () => {
// FLAKY: https://github.com/elastic/kibana/issues/103390
describe.skip('create new policy', () => {
let version: string;

beforeEach(async () => {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12407,10 +12407,10 @@ elastic-apm-http-client@^10.3.0:
readable-stream "^3.4.0"
stream-chopper "^3.0.1"

elastic-apm-node@^3.24.0:
version "3.24.0"
resolved "https://registry.yarnpkg.com/elastic-apm-node/-/elastic-apm-node-3.24.0.tgz#d7acb3352f928a23c28ebabab2bd30098562814e"
integrity sha512-Fmj/W2chWQa2zb1FfMYK2ypLB4TcnKNX+1klaJFbytRYDLgeSfo0EC7egvI3a+bLPZSRL5053PXOp7slVTPO6Q==
elastic-apm-node@^3.25.0:
version "3.25.0"
resolved "https://registry.yarnpkg.com/elastic-apm-node/-/elastic-apm-node-3.25.0.tgz#3207c936429739cd07f64cbf76d7b5b4b8e0da3e"
integrity sha512-3K+uUQkKeaJarjPb/pDY3fldP7QeppgPPx8nJOkOrW+BvQK5YBMiWbf4S9fdx0yUUkWsVX6K+CAc401+Y1COkg==
dependencies:
"@elastic/ecs-pino-format" "^1.2.0"
after-all-results "^2.0.0"
Expand Down

0 comments on commit 9bceb67

Please sign in to comment.