Skip to content

Commit

Permalink
Merge branch 'main' into feature/eui-75.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Feb 13, 2023
2 parents 9746566 + 2bfbddb commit a13a495
Show file tree
Hide file tree
Showing 74 changed files with 1,554 additions and 578 deletions.
5 changes: 4 additions & 1 deletion .buildkite/scripts/steps/artifacts/docker_image_trigger.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@

set -euo pipefail

ts-node .buildkite/scripts/steps/trigger_pipeline.ts kibana-artifacts-container-image "$BUILDKITE_BRANCH" "$BUILDKITE_COMMIT"
if [[ "$BUILDKITE_BRANCH" == "main" ]]; then
echo "--- Trigger artifacts container image pipeline"
ts-node .buildkite/scripts/steps/trigger_pipeline.ts kibana-artifacts-container-image "$BUILDKITE_BRANCH" "$BUILDKITE_COMMIT"
fi
18 changes: 14 additions & 4 deletions packages/kbn-apm-synthtrace-client/src/lib/timerange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import datemath from '@kbn/datemath';
import type { Moment } from 'moment';
import { Interval } from './interval';

Expand All @@ -23,12 +23,22 @@ export class Timerange {

type DateLike = Date | number | Moment | string;

function getDateFrom(date: DateLike): Date {
function getDateFrom(date: DateLike, now: Date): Date {
if (date instanceof Date) return date;

if (typeof date === 'string') {
const parsed = datemath.parse(date, { forceNow: now });
if (parsed && parsed.isValid()) {
return parsed.toDate();
}
}

if (typeof date === 'number' || typeof date === 'string') return new Date(date);

return date.toDate();
}

export function timerange(from: Date | number | Moment, to: Date | number | Moment) {
return new Timerange(getDateFrom(from), getDateFrom(to));
export function timerange(from: DateLike, to: DateLike) {
const now = new Date();
return new Timerange(getDateFrom(from, now), getDateFrom(to, now));
}
3 changes: 3 additions & 0 deletions packages/kbn-apm-synthtrace-client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
"include": ["**/*.ts"],
"exclude": [
"target/**/*",
],
"kbn_references": [
"@kbn/datemath",
]
}
18 changes: 16 additions & 2 deletions src/dev/build/lib/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ const versionInfo = jest.requireMock('./version_info').getVersionInfo();

expect.addSnapshotSerializer(createAbsolutePathSerializer());

const setup = async ({ targetAllPlatforms = true }: { targetAllPlatforms?: boolean } = {}) => {
const setup = async ({
targetAllPlatforms = true,
isRelease = true,
}: { targetAllPlatforms?: boolean; isRelease?: boolean } = {}) => {
return await Config.create({
isRelease: true,
isRelease,
targetAllPlatforms,
dockerContextUseLocalArtifact: false,
dockerCrossCompile: false,
Expand Down Expand Up @@ -192,6 +195,17 @@ describe('#getBuildSha()', () => {
});
});

describe('#isRelease()', () => {
it('returns true when marked as a release', async () => {
const config = await setup({ isRelease: true });
expect(config.isRelease).toBe(true);
});
it('returns false when not marked as a release', async () => {
const config = await setup({ isRelease: false });
expect(config.isRelease).toBe(false);
});
});

describe('#resolveFromTarget()', () => {
it('resolves a relative path, from the target directory', async () => {
const config = await setup();
Expand Down
2 changes: 1 addition & 1 deletion src/dev/build/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ export class Config {
private readonly dockerTag: string | null,
private readonly dockerTagQualifier: string | null,
private readonly dockerPush: boolean,
public readonly downloadFreshNode: boolean,
public readonly isRelease: boolean,
public readonly downloadFreshNode: boolean,
public readonly pluginSelector: PluginSelector
) {
this.pluginFilter = getPluginPackagesFilter(this.pluginSelector);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ describe('getFlappingSettingsRoute', () => {
await handler(context, req, res);

expect(rulesSettingsClient.flapping().get).toHaveBeenCalledTimes(1);
expect(res.ok).toHaveBeenCalled();
expect(res.ok).toHaveBeenCalledWith({
body: expect.objectContaining({
enabled: true,
look_back_window: 10,
status_change_threshold: 10,
created_by: 'test name',
updated_by: 'test name',
created_at: expect.any(String),
updated_at: expect.any(String),
}),
});
});
});
24 changes: 21 additions & 3 deletions x-pack/plugins/alerting/server/routes/get_flapping_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,26 @@
import { IRouter } from '@kbn/core/server';
import { ILicenseState } from '../lib';
import { AlertingRequestHandlerContext, INTERNAL_BASE_ALERTING_API_PATH } from '../types';
import { verifyAccessAndContext } from './lib';
import { API_PRIVILEGES } from '../../common';
import { verifyAccessAndContext, RewriteResponseCase } from './lib';
import { API_PRIVILEGES, RulesSettingsFlapping } from '../../common';

const rewriteBodyRes: RewriteResponseCase<RulesSettingsFlapping> = ({
lookBackWindow,
statusChangeThreshold,
createdBy,
updatedBy,
createdAt,
updatedAt,
...rest
}) => ({
...rest,
look_back_window: lookBackWindow,
status_change_threshold: statusChangeThreshold,
created_by: createdBy,
updated_by: updatedBy,
created_at: createdAt,
updated_at: updatedAt,
});

export const getFlappingSettingsRoute = (
router: IRouter<AlertingRequestHandlerContext>,
Expand All @@ -27,7 +45,7 @@ export const getFlappingSettingsRoute = (
verifyAccessAndContext(licenseState, async function (context, req, res) {
const rulesSettingsClient = (await context.alerting).getRulesSettingsClient();
const flappingSettings = await rulesSettingsClient.flapping().get();
return res.ok({ body: flappingSettings });
return res.ok({ body: rewriteBodyRes(flappingSettings) });
})
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ beforeEach(() => {
rulesSettingsClient = rulesSettingsClientMock.create();
});

const mockFlappingSettings = {
enabled: true,
lookBackWindow: 10,
statusChangeThreshold: 10,
createdBy: 'test name',
updatedBy: 'test name',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
};

describe('updateFlappingSettingsRoute', () => {
test('updates flapping settings', async () => {
const licenseState = licenseStateMock.create();
Expand All @@ -40,20 +50,13 @@ describe('updateFlappingSettingsRoute', () => {
}
`);

(rulesSettingsClient.flapping().get as jest.Mock).mockResolvedValue({
enabled: true,
lookBackWindow: 10,
statusChangeThreshold: 10,
createdBy: 'test name',
updatedBy: 'test name',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
});
(rulesSettingsClient.flapping().get as jest.Mock).mockResolvedValue(mockFlappingSettings);
(rulesSettingsClient.flapping().update as jest.Mock).mockResolvedValue(mockFlappingSettings);

const updateResult = {
enabled: false,
lookBackWindow: 6,
statusChangeThreshold: 5,
look_back_window: 6,
status_change_threshold: 5,
};

const [context, req, res] = mockHandlerArguments(
Expand All @@ -77,6 +80,16 @@ describe('updateFlappingSettingsRoute', () => {
},
]
`);
expect(res.ok).toHaveBeenCalled();
expect(res.ok).toHaveBeenCalledWith({
body: expect.objectContaining({
enabled: true,
look_back_window: 10,
status_change_threshold: 10,
created_by: 'test name',
updated_by: 'test name',
created_at: expect.any(String),
updated_at: expect.any(String),
}),
});
});
});
46 changes: 40 additions & 6 deletions x-pack/plugins/alerting/server/routes/update_flapping_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,46 @@
import { IRouter } from '@kbn/core/server';
import { schema } from '@kbn/config-schema';
import { ILicenseState } from '../lib';
import { verifyAccessAndContext } from './lib';
import { verifyAccessAndContext, RewriteResponseCase, RewriteRequestCase } from './lib';
import { AlertingRequestHandlerContext, INTERNAL_BASE_ALERTING_API_PATH } from '../types';
import { API_PRIVILEGES } from '../../common';
import {
API_PRIVILEGES,
RulesSettingsFlapping,
RulesSettingsFlappingProperties,
} from '../../common';

const bodySchema = schema.object({
enabled: schema.boolean(),
lookBackWindow: schema.number(),
statusChangeThreshold: schema.number(),
look_back_window: schema.number(),
status_change_threshold: schema.number(),
});

const rewriteQueryReq: RewriteRequestCase<RulesSettingsFlappingProperties> = ({
look_back_window: lookBackWindow,
status_change_threshold: statusChangeThreshold,
...rest
}) => ({
...rest,
lookBackWindow,
statusChangeThreshold,
});

const rewriteBodyRes: RewriteResponseCase<RulesSettingsFlapping> = ({
lookBackWindow,
statusChangeThreshold,
createdBy,
updatedBy,
createdAt,
updatedAt,
...rest
}) => ({
...rest,
look_back_window: lookBackWindow,
status_change_threshold: statusChangeThreshold,
created_by: createdBy,
updated_by: updatedBy,
created_at: createdAt,
updated_at: updatedAt,
});

export const updateFlappingSettingsRoute = (
Expand All @@ -36,10 +68,12 @@ export const updateFlappingSettingsRoute = (
verifyAccessAndContext(licenseState, async function (context, req, res) {
const rulesSettingsClient = (await context.alerting).getRulesSettingsClient();

const updatedFlappingSettings = await rulesSettingsClient.flapping().update(req.body);
const updatedFlappingSettings = await rulesSettingsClient
.flapping()
.update(rewriteQueryReq(req.body));

return res.ok({
body: updatedFlappingSettings,
body: updatedFlappingSettings && rewriteBodyRes(updatedFlappingSettings),
});
})
)
Expand Down
60 changes: 60 additions & 0 deletions x-pack/plugins/apm/common/rules/default_action_message.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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 { i18n } from '@kbn/i18n';

export const errorCountMessage = i18n.translate(
'xpack.apm.alertTypes.errorCount.defaultActionMessage',
{
defaultMessage: `\\{\\{alertName\\}\\} alert is firing because of the following conditions:
- Service name: \\{\\{context.serviceName\\}\\}
- Environment: \\{\\{context.environment\\}\\}
- Threshold: \\{\\{context.threshold\\}\\}
- Triggered value: \\{\\{context.triggerValue\\}\\} errors over the last \\{\\{context.interval\\}\\}`,
}
);

export const transactionDurationMessage = i18n.translate(
'xpack.apm.alertTypes.transactionDuration.defaultActionMessage',
{
defaultMessage: `\\{\\{alertName\\}\\} alert is firing because of the following conditions:
- Service name: \\{\\{context.serviceName\\}\\}
- Type: \\{\\{context.transactionType\\}\\}
- Environment: \\{\\{context.environment\\}\\}
- Latency threshold: \\{\\{context.threshold\\}\\}ms
- Latency observed: \\{\\{context.triggerValue\\}\\} over the last \\{\\{context.interval\\}\\}`,
}
);

export const transactionErrorRateMessage = i18n.translate(
'xpack.apm.alertTypes.transactionErrorRate.defaultActionMessage',
{
defaultMessage: `\\{\\{alertName\\}\\} alert is firing because of the following conditions:
- Service name: \\{\\{context.serviceName\\}\\}
- Type: \\{\\{context.transactionType\\}\\}
- Environment: \\{\\{context.environment\\}\\}
- Threshold: \\{\\{context.threshold\\}\\}%
- Triggered value: \\{\\{context.triggerValue\\}\\}% of errors over the last \\{\\{context.interval\\}\\}`,
}
);

export const anomalyMessage = i18n.translate(
'xpack.apm.alertTypes.transactionDurationAnomaly.defaultActionMessage',
{
defaultMessage: `\\{\\{alertName\\}\\} alert is firing because of the following conditions:
- Service name: \\{\\{context.serviceName\\}\\}
- Type: \\{\\{context.transactionType\\}\\}
- Environment: \\{\\{context.environment\\}\\}
- Severity threshold: \\{\\{context.threshold\\}\\}
- Severity value: \\{\\{context.triggerValue\\}\\}
`,
}
);
Loading

0 comments on commit a13a495

Please sign in to comment.