Skip to content

Commit

Permalink
Merge branch '8.0' into backport/8.0/pr-119494
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine committed Dec 8, 2021
2 parents 37f8df4 + 15e4eb0 commit da27720
Show file tree
Hide file tree
Showing 37 changed files with 8,481 additions and 169 deletions.
2 changes: 2 additions & 0 deletions docs/settings/fleet-settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Optional properties are:
`data_output_id`:: ID of the output to send data (Need to be identical to `monitoring_output_id`)
`monitoring_output_id`:: ID of the output to send monitoring data. (Need to be identical to `data_output_id`)
`package_policies`:: List of integration policies to add to this policy.
`id`::: Unique ID of the integration policy. The ID may be a number or string.
`name`::: (required) Name of the integration policy.
`package`::: (required) Integration that this policy configures
`name`:::: Name of the integration associated with this policy.
Expand Down Expand Up @@ -128,6 +129,7 @@ xpack.fleet.agentPolicies:
- package:
name: system
name: System Integration
id: preconfigured-system
inputs:
- type: system/metrics
enabled: true
Expand Down
56 changes: 56 additions & 0 deletions x-pack/plugins/alerting/server/saved_objects/migrations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2055,6 +2055,62 @@ describe('successful migrations', () => {
undefined
);
});

describe('Metrics Inventory Threshold rule', () => {
test('Migrates incorrect action group spelling', () => {
const migration800 = getMigrations(encryptedSavedObjectsSetup, isPreconfigured)['8.0.0'];

const actions = [
{
group: 'metrics.invenotry_threshold.fired',
params: {
level: 'info',
message:
'""{{alertName}} - {{context.group}} is in a state of {{context.alertState}} Reason: {{context.reason}}""',
},
actionRef: 'action_0',
actionTypeId: '.server-log',
},
];

const alert = getMockData({ alertTypeId: 'metrics.alert.inventory.threshold', actions });

expect(migration800(alert, migrationContext)).toMatchObject({
...alert,
attributes: {
...alert.attributes,
actions: [{ ...actions[0], group: 'metrics.inventory_threshold.fired' }],
},
});
});

test('Works with the correct action group spelling', () => {
const migration800 = getMigrations(encryptedSavedObjectsSetup, isPreconfigured)['8.0.0'];

const actions = [
{
group: 'metrics.inventory_threshold.fired',
params: {
level: 'info',
message:
'""{{alertName}} - {{context.group}} is in a state of {{context.alertState}} Reason: {{context.reason}}""',
},
actionRef: 'action_0',
actionTypeId: '.server-log',
},
];

const alert = getMockData({ alertTypeId: 'metrics.alert.inventory.threshold', actions });

expect(migration800(alert, migrationContext)).toMatchObject({
...alert,
attributes: {
...alert.attributes,
actions: [{ ...actions[0], group: 'metrics.inventory_threshold.fired' }],
},
});
});
});
});
});

Expand Down
42 changes: 41 additions & 1 deletion x-pack/plugins/alerting/server/saved_objects/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ export function getMigrations(
const migrationRules800 = createEsoMigration(
encryptedSavedObjects,
(doc: SavedObjectUnsanitizedDoc<RawAlert>): doc is SavedObjectUnsanitizedDoc<RawAlert> => true,
pipeMigrations(addThreatIndicatorPathToThreatMatchRules, addRACRuleTypes)
pipeMigrations(
addThreatIndicatorPathToThreatMatchRules,
addRACRuleTypes,
fixInventoryThresholdGroupId
)
);

return {
Expand Down Expand Up @@ -751,6 +755,42 @@ function removePreconfiguredConnectorsFromReferences(
return doc;
}

// This fixes an issue whereby metrics.alert.inventory.threshold rules had the
// group for actions incorrectly spelt as metrics.invenotry_threshold.fired vs metrics.inventory_threshold.fired
function fixInventoryThresholdGroupId(
doc: SavedObjectUnsanitizedDoc<RawAlert>
): SavedObjectUnsanitizedDoc<RawAlert> {
if (doc.attributes.alertTypeId === 'metrics.alert.inventory.threshold') {
const {
attributes: { actions },
} = doc;

const updatedActions = actions
? actions.map((action) => {
// Wrong spelling
if (action.group === 'metrics.invenotry_threshold.fired') {
return {
...action,
group: 'metrics.inventory_threshold.fired',
};
} else {
return action;
}
})
: [];

return {
...doc,
attributes: {
...doc.attributes,
actions: updatedActions,
},
};
} else {
return doc;
}
}

function getCorrespondingAction(
actions: SavedObjectAttribute,
connectorRef: string
Expand Down
6 changes: 6 additions & 0 deletions x-pack/plugins/fleet/common/constants/preconfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ type PreconfiguredAgentPolicyWithDefaultInputs = Omit<
package_policies: Array<Omit<PreconfiguredAgentPolicy['package_policies'][0], 'inputs'>>;
};

export const DEFAULT_SYSTEM_PACKAGE_POLICY_ID = 'default-system-policy';

export const DEFAULT_AGENT_POLICY: PreconfiguredAgentPolicyWithDefaultInputs = {
name: 'Default policy',
namespace: 'default',
description: 'Default agent policy created by Kibana',
package_policies: [
{
id: DEFAULT_SYSTEM_PACKAGE_POLICY_ID,
name: `${FLEET_SYSTEM_PACKAGE}-1`,
package: {
name: FLEET_SYSTEM_PACKAGE,
Expand All @@ -47,12 +50,15 @@ export const DEFAULT_AGENT_POLICY: PreconfiguredAgentPolicyWithDefaultInputs = {
monitoring_enabled: monitoringTypes,
};

export const DEFAULT_FLEET_SERVER_POLICY_ID = 'default-fleet-server-policy';

export const DEFAULT_FLEET_SERVER_AGENT_POLICY: PreconfiguredAgentPolicyWithDefaultInputs = {
name: 'Default Fleet Server policy',
namespace: 'default',
description: 'Default Fleet Server agent policy created by Kibana',
package_policies: [
{
id: DEFAULT_FLEET_SERVER_POLICY_ID,
name: `${FLEET_SERVER_PACKAGE}-1`,
package: {
name: FLEET_SERVER_PACKAGE,
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/common/types/models/package_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export interface PackagePolicyInput extends Omit<NewPackagePolicyInput, 'streams
}

export interface NewPackagePolicy {
id?: string | number;
name: string;
description?: string;
namespace: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface PreconfiguredAgentPolicy extends Omit<NewAgentPolicy, 'namespac
namespace?: string;
package_policies: Array<
Partial<Omit<NewPackagePolicy, 'inputs' | 'package'>> & {
id?: string | number;
name: string;
package: Partial<PackagePolicyPackage> & { name: string };
inputs?: InputsOverride[];
Expand Down
13 changes: 13 additions & 0 deletions x-pack/plugins/fleet/server/services/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { uniq, omit } from 'lodash';
import uuid from 'uuid/v4';
import uuidv5 from 'uuid/v5';
import type {
ElasticsearchClient,
SavedObjectsClientContract,
Expand Down Expand Up @@ -57,8 +58,12 @@ import { agentPolicyUpdateEventHandler } from './agent_policy_update';
import { normalizeKuery, escapeSearchQueryPhrase } from './saved_object';
import { appContextService } from './app_context';
import { getFullAgentPolicy } from './agent_policies';

const SAVED_OBJECT_TYPE = AGENT_POLICY_SAVED_OBJECT_TYPE;

// UUID v5 values require a namespace
const UUID_V5_NAMESPACE = 'dde7c2de-1370-4c19-9975-b473d0e03508';

class AgentPolicyService {
private triggerAgentPolicyUpdatedEvent = async (
soClient: SavedObjectsClientContract,
Expand Down Expand Up @@ -780,6 +785,7 @@ export async function addPackageToAgentPolicy(
agentPolicy: AgentPolicy,
defaultOutput: Output,
packagePolicyName?: string,
packagePolicyId?: string | number,
packagePolicyDescription?: string,
transformPackagePolicy?: (p: NewPackagePolicy) => NewPackagePolicy,
bumpAgentPolicyRevison = false
Expand All @@ -803,7 +809,14 @@ export async function addPackageToAgentPolicy(
? transformPackagePolicy(basePackagePolicy)
: basePackagePolicy;

// If an ID is provided via preconfiguration, use that value. Otherwise fall back to
// a UUID v5 value seeded from the agent policy's ID and the provided package policy name.
const id = packagePolicyId
? String(packagePolicyId)
: uuidv5(`${agentPolicy.id}-${packagePolicyName}`, UUID_V5_NAMESPACE);

await packagePolicyService.create(soClient, esClient, newPackagePolicy, {
id,
bumpRevision: bumpAgentPolicyRevison,
skipEnsureInstalled: true,
skipUniqueNameVerification: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ describe('policy preconfiguration', () => {
id: 'test-id',
package_policies: [
{
id: 'test-package',
package: { name: 'test_package' },
name: 'Test package',
},
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/fleet/server/services/preconfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ async function addPreconfiguredPolicyPackages(
agentPolicy: AgentPolicy,
installedPackagePolicies: Array<
Partial<Omit<NewPackagePolicy, 'inputs'>> & {
id?: string | number;
name: string;
installedPackage: Installation;
inputs?: InputsOverride[];
Expand All @@ -413,7 +414,7 @@ async function addPreconfiguredPolicyPackages(
bumpAgentPolicyRevison = false
) {
// Add packages synchronously to avoid overwriting
for (const { installedPackage, name, description, inputs } of installedPackagePolicies) {
for (const { installedPackage, id, name, description, inputs } of installedPackagePolicies) {
const packageInfo = await getPackageInfo({
savedObjectsClient: soClient,
pkgName: installedPackage.name,
Expand All @@ -427,6 +428,7 @@ async function addPreconfiguredPolicyPackages(
agentPolicy,
defaultOutput,
name,
id,
description,
(policy) => preconfigurePackageInputs(policy, packageInfo, inputs),
bumpAgentPolicyRevison
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export const PreconfiguredAgentPoliciesSchema = schema.arrayOf(
monitoring_output_id: schema.maybe(schema.string()),
package_policies: schema.arrayOf(
schema.object({
id: schema.maybe(schema.oneOf([schema.string(), schema.number()])),
name: schema.string(),
package: schema.object({
name: schema.string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface ExploratoryEmbeddableProps {
showCalculationMethod?: boolean;
axisTitlesVisibility?: XYState['axisTitlesVisibilitySettings'];
legendIsVisible?: boolean;
dataTypesIndexPatterns?: Record<AppDataType, string>;
dataTypesIndexPatterns?: Partial<Record<AppDataType, string>>;
reportConfigMap?: ReportConfigMap;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ const buildOrCondition = (values: string[]) => {
}
return `(${values.join(' or ')})`;
};

function addSlashes(str: string) {
return (str + '').replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');
}

export const urlFiltersToKueryString = (urlFilters: UrlFilter[]): string => {
let kueryString = '';
urlFilters.forEach(({ field, values, notValues, wildcards, notWildcards }) => {
const valuesT = values?.map((val) => `"${val}"`);
const notValuesT = notValues?.map((val) => `"${val}"`);
const valuesT = values?.map((val) => `"${addSlashes(val)}"`);
const notValuesT = notValues?.map((val) => `"${addSlashes(val)}"`);
const wildcardsT = wildcards?.map((val) => `*${val}*`);
const notWildcardsT = notWildcards?.map((val) => `*${val}*`);

Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/uptime/common/runtime_types/ping/synthetics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ export const JourneyStepType = t.intersection([
text: t.string,
}),
step: t.type({
status: t.string,
index: t.number,
name: t.string,
duration: t.type({
us: t.number,
}),
}),
isFullScreenshot: t.boolean,
isScreenshotRef: t.boolean,
Expand Down
Binary file not shown.
Loading

0 comments on commit da27720

Please sign in to comment.