Skip to content

Commit

Permalink
Merge branch 'main' into 117686-replace-alert-workflow-status-in-aler…
Browse files Browse the repository at this point in the history
…ts-view
  • Loading branch information
kibanamachine authored Nov 29, 2021
2 parents 8ada6ae + a0650c7 commit 01caf34
Show file tree
Hide file tree
Showing 47 changed files with 307 additions and 37 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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ async function removeLogFile() {
await fs.unlink(logFilePath).catch(() => void 0);
}

describe('migration from 7.13 to 7.14+ with many failed action_tasks', () => {
// FLAKY: https://github.com/elastic/kibana/issues/118626
describe.skip('migration from 7.13 to 7.14+ with many failed action_tasks', () => {
let esServer: kbnTestServer.TestElasticsearchUtils;
let root: Root;
let startES: () => Promise<kbnTestServer.TestElasticsearchUtils>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import { applyCurrentSettings } from './apply_editor_settings';
const isJSONContentType = (contentType?: string) =>
Boolean(contentType && contentType.indexOf('application/json') >= 0);

const isMapboxVectorTile = (contentType?: string) =>
contentType?.includes('application/vnd.mapbox-vector-tile') ?? false;

/**
* Best effort expand literal strings
*/
Expand Down Expand Up @@ -85,6 +88,11 @@ function EditorOutputUI() {
if (readOnlySettings.tripleQuotes && isJSONContentType(contentType)) {
return safeExpandLiteralStrings(value as string);
}
if (isMapboxVectorTile(contentType)) {
return i18n.translate('console.outputCannotPreviewBinaryData', {
defaultMessage: 'Cannot preview binary data.',
});
}
return value;
})
.join('\n'),
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/console/public/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ export type BaseResponseType =
| 'text/tab-separated-values'
| 'text/plain'
| 'application/yaml'
| 'unknown';
| 'unknown'
| 'application/vnd.mapbox-vector-tile';
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ const SavedObjectsTablePage = ({
text: i18n.translate('savedObjectsManagement.breadcrumb.index', {
defaultMessage: 'Saved objects',
}),
href: '/',
},
]);
}, [setBreadcrumbs]);
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import React, { useEffect, useCallback, useRef } from 'react';
import { EuiResizeObserver } from '@elastic/eui';
import { throttle } from 'lodash';

import { IInterpreterRenderHandlers } from 'src/plugins/expressions';
import type { IInterpreterRenderHandlers, RenderMode } from 'src/plugins/expressions';
import { createVegaVisualization } from '../vega_visualization';
import { VegaVisualizationDependencies } from '../plugin';
import { VegaParser } from '../data_model/vega_parser';
Expand All @@ -21,26 +21,33 @@ interface VegaVisComponentProps {
deps: VegaVisualizationDependencies;
fireEvent: IInterpreterRenderHandlers['event'];
renderComplete: () => void;
renderMode: RenderMode;
visData: VegaParser;
}

type VegaVisController = InstanceType<ReturnType<typeof createVegaVisualization>>;

const VegaVisComponent = ({ visData, fireEvent, renderComplete, deps }: VegaVisComponentProps) => {
const VegaVisComponent = ({
visData,
fireEvent,
renderComplete,
deps,
renderMode,
}: VegaVisComponentProps) => {
const chartDiv = useRef<HTMLDivElement>(null);
const visController = useRef<VegaVisController | null>(null);

useEffect(() => {
if (chartDiv.current) {
const VegaVis = createVegaVisualization(deps);
const VegaVis = createVegaVisualization(deps, renderMode);
visController.current = new VegaVis(chartDiv.current, fireEvent);
}

return () => {
visController.current?.destroy();
visController.current = null;
};
}, [deps, fireEvent]);
}, [deps, fireEvent, renderMode]);

useEffect(() => {
if (visController.current) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export class VegaBaseView {
this._initialized = false;
this._externalUrl = opts.externalUrl;
this._enableExternalUrls = getEnableExternalUrls();
this._renderMode = opts.renderMode;
this._vegaStateRestorer = opts.vegaStateRestorer;
}

Expand Down Expand Up @@ -238,7 +239,7 @@ export class VegaBaseView {
}

onWarn() {
if (!this._parser || !this._parser.hideWarnings) {
if (this._renderMode !== 'view' && (!this._parser || !this._parser.hideWarnings)) {
this._addMessage('warn', Utils.formatWarningToStr(...arguments));
}
}
Expand Down
1 change: 1 addition & 0 deletions src/plugins/vis_types/vega/public/vega_vis_renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const getVegaVisRenderer: (
deps={deps}
fireEvent={handlers.event}
renderComplete={handlers.done}
renderMode={handlers.getRenderMode()}
visData={visData}
/>
</VisualizationContainer>
Expand Down
11 changes: 6 additions & 5 deletions src/plugins/vis_types/vega/public/vega_visualization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { i18n } from '@kbn/i18n';
import { IInterpreterRenderHandlers } from 'src/plugins/expressions';
import type { IInterpreterRenderHandlers, RenderMode } from 'src/plugins/expressions';
import { VegaParser } from './data_model/vega_parser';
import { VegaVisualizationDependencies } from './plugin';
import { getNotifications, getData } from './services';
Expand All @@ -19,10 +19,10 @@ type VegaVisType = new (el: HTMLDivElement, fireEvent: IInterpreterRenderHandler
destroy(): void;
};

export const createVegaVisualization = ({
core,
getServiceSettings,
}: VegaVisualizationDependencies): VegaVisType =>
export const createVegaVisualization = (
{ core, getServiceSettings }: VegaVisualizationDependencies,
renderMode: RenderMode
): VegaVisType =>
class VegaVisualization {
private readonly dataPlugin = getData();
private vegaView: InstanceType<typeof VegaView> | null = null;
Expand Down Expand Up @@ -82,6 +82,7 @@ export const createVegaVisualization = ({
serviceSettings,
filterManager,
timefilter,
renderMode,
};

if (vegaParser.useMap) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { SavedObjectAttributes } from '../../../../core/types';
import { getSavedVisualization } from '../utils/saved_visualize_utils';
import { VisSavedObject } from '../types';
import { toExpressionAst } from './to_ast';
import type { RenderMode } from '../../../expressions';

const getKeys = <T extends {}>(o: T): Array<keyof T> => Object.keys(o) as Array<keyof T>;

Expand All @@ -63,6 +64,7 @@ export interface VisualizeInput extends EmbeddableInput {
colors?: { [key: string]: string };
};
savedVis?: SerializedVis;
renderMode?: RenderMode;
table?: unknown;
query?: Query;
filters?: Filter[];
Expand Down Expand Up @@ -314,6 +316,7 @@ export class VisualizeEmbeddable

const expressions = getExpressions();
this.handler = await expressions.loader(this.domNode, undefined, {
renderMode: this.input.renderMode || 'view',
onRenderError: (element: HTMLElement, error: ExpressionRenderError) => {
this.onContainerError(error);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ describe('getVisualizationInstance', () => {
serializedVisMock
);
expect(mockServices.createVisEmbeddableFromObject).toHaveBeenCalledWith(visMock, {
searchSessionId: undefined,
timeRange: undefined,
filters: undefined,
renderMode: 'edit',
id: '',
});

Expand Down Expand Up @@ -203,8 +205,10 @@ describe('getVisualizationInstanceInput', () => {
input.savedVis
);
expect(mockServices.createVisEmbeddableFromObject).toHaveBeenCalledWith(visMock, {
searchSessionId: undefined,
timeRange: undefined,
filters: undefined,
renderMode: 'edit',
id: '',
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const createVisualizeEmbeddableAndLinkSavedSearch = async (
timeRange: data.query.timefilter.timefilter.getTime(),
filters: data.query.filterManager.getFilters(),
searchSessionId: data.search.session.getSessionId(),
renderMode: 'edit',
})) as VisualizeEmbeddableContract;

embeddableHandler.getOutput$().subscribe((output) => {
Expand Down
3 changes: 2 additions & 1 deletion test/functional/apps/management/_scripted_fields_preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export default function ({ getService, getPageObjects }) {
const PageObjects = getPageObjects(['settings']);
const SCRIPTED_FIELD_NAME = 'myScriptedField';

describe('scripted fields preview', () => {
// FLAKY: https://github.com/elastic/kibana/issues/118981
describe.skip('scripted fields preview', () => {
before(async function () {
await browser.setWindowSize(1200, 800);
await PageObjects.settings.navigateTo();
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
1 change: 1 addition & 0 deletions x-pack/plugins/monitoring/public/alerts/badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export const AlertsBadge: React.FC<Props> = (props: Props) => {
<EuiBadge
iconType="bell"
color={inSetupMode ? 'default' : 'danger'}
data-test-subj="alertsBadge"
onClickAriaLabel={
inSetupMode ? numberOfRulesLabel(alertCount) : numberOfAlertsLabel(alertCount)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const showDisabledWatcherClusterAlertsError = () => {
})}
</p>
),
'data-test-subj': 'alertsCreatedToast',
});
};

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 @@ -162,6 +162,7 @@ export class WrappedSetupModeRenderer extends React.Component {
iconSide="right"
size="s"
onClick={() => toggleSetupMode(false)}
data-test-subj="exitSetupModeBtn"
>
{i18n.translate('xpack.monitoring.setupMode.exit', {
defaultMessage: `Exit setup mode`,
Expand Down
Loading

0 comments on commit 01caf34

Please sign in to comment.