Skip to content

Commit

Permalink
Merge branch 'master' into fix-data-grid-time-column
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Oct 28, 2021
2 parents c13bbd7 + d596388 commit fb3fc29
Show file tree
Hide file tree
Showing 53 changed files with 1,453 additions and 964 deletions.
2 changes: 0 additions & 2 deletions .buildkite/pipelines/performance/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ steps:
agents:
queue: ci-group-6
depends_on: build
concurrency: 50
concurrency_group: 'performance-test-group'

- wait: ~
continue_on_failure: true
Expand Down
2 changes: 2 additions & 0 deletions .buildkite/scripts/steps/functional/performance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ cat << EOF | buildkite-agent pipeline upload
steps:
- command: .buildkite/scripts/steps/functional/performance_sub.sh
parallelism: "$ITERATION_COUNT"
concurrency: 20
concurrency_group: 'performance-test-group'
EOF


Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@
"cypress": "^8.5.0",
"cypress-axe": "^0.13.0",
"cypress-cucumber-preprocessor": "^2.5.2",
"cypress-file-upload": "^5.0.8",
"cypress-multi-reporters": "^1.5.0",
"cypress-pipe": "^2.0.0",
"cypress-real-events": "^1.5.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ function RevealImageComponent({
return imgStyles;
}

const additionaAlignerStyles: AlignerStyles = {};
const additionalAlignerStyles: AlignerStyles = {};

if (isValidUrl(emptyImage ?? '')) {
// only use empty image if one is provided
additionaAlignerStyles.backgroundImage = `url(${emptyImage})`;
additionalAlignerStyles.backgroundImage = `url(${emptyImage})`;
}

let additionalImgStyles: ImageStyles = {};
Expand All @@ -136,10 +136,10 @@ function RevealImageComponent({
return (
<div
className="revealImageAligner"
css={css({
css={{
...revealImageAlignerStyle,
...additionaAlignerStyles,
})}
...additionalAlignerStyles,
}}
>
<img
ref={imgRef}
Expand Down
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 { preprocessLegacyFields } from './get_apm_package_policy_definition';

const apmServerSchema = {
'apm-server.host': '0.0.0.0:8200',
'apm-server.secret_token': 'asdfkjhasdf',
'apm-server.read_timeout': 3600,
'apm-server.rum.event_rate.limit': 100,
'apm-server.rum.event_rate.lru_size': 100,
'apm-server.rum.allow_service_names': 'opbeans-test',
'logging.level': 'error',
'queue.mem.events': 2000,
'queue.mem.flush.timeout': '1s',
'setup.template.settings.index.number_of_jshards': 1,
};

describe('get_apm_package_policy_definition', () => {
describe('preprocessLegacyFields', () => {
it('should replace legacy fields with supported fields', () => {
const result = preprocessLegacyFields({ apmServerSchema });
expect(result).toMatchInlineSnapshot(`
Object {
"apm-server.auth.anonymous.allow_service": "opbeans-test",
"apm-server.auth.anonymous.rate_limit.event_limit": 100,
"apm-server.auth.anonymous.rate_limit.ip_limit": 100,
"apm-server.auth.secret_token": "asdfkjhasdf",
"apm-server.host": "0.0.0.0:8200",
"apm-server.read_timeout": 3600,
"logging.level": "error",
"queue.mem.events": 2000,
"queue.mem.flush.timeout": "1s",
"setup.template.settings.index.number_of_jshards": 1,
}
`);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function getApmPackagePolicyDefinition(
};
}

function preprocessLegacyFields({
export function preprocessLegacyFields({
apmServerSchema,
}: {
apmServerSchema: Record<string, any>;
Expand All @@ -64,6 +64,10 @@ function preprocessLegacyFields({
key: 'apm-server.auth.anonymous.allow_service',
legacyKey: 'apm-server.rum.allow_service_names',
},
{
key: 'apm-server.auth.secret_token',
legacyKey: 'apm-server.secret_token',
},
].forEach(({ key, legacyKey }) => {
if (!copyOfApmServerSchema[key]) {
copyOfApmServerSchema[key] = copyOfApmServerSchema[legacyKey];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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 { SavedObjectsClientContract } from 'kibana/server';
import { getUnsupportedApmServerSchema } from './get_unsupported_apm_server_schema';

const apmServerSchema = {
'apm-server.host': '0.0.0.0:8200',
'apm-server.secret_token': 'asdfkjhasdf',
'apm-server.read_timeout': 3600,
'apm-server.rum.event_rate.limit': 100,
'apm-server.rum.event_rate.lru_size': 100,
'apm-server.rum.allow_service_names': 'opbeans-test',
'logging.level': 'error',
'queue.mem.events': 2000,
'queue.mem.flush.timeout': '1s',
'setup.template.settings.index.number_of_jshards': 1,
};

const mockSavaedObectsClient = {
get: () => ({
attributes: { schemaJson: JSON.stringify(apmServerSchema) },
}),
} as unknown as SavedObjectsClientContract;

describe('get_unsupported_apm_server_schema', () => {
describe('getUnsupportedApmServerSchema', () => {
it('should return key-value pairs of unsupported configs', async () => {
const result = await getUnsupportedApmServerSchema({
savedObjectsClient: mockSavaedObectsClient,
});
expect(result).toMatchInlineSnapshot(`
Array [
Object {
"key": "logging.level",
"value": "error",
},
Object {
"key": "queue.mem.events",
"value": 2000,
},
Object {
"key": "queue.mem.flush.timeout",
"value": "1s",
},
Object {
"key": "setup.template.settings.index.number_of_jshards",
"value": 1,
},
]
`);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import {
APM_SERVER_SCHEMA_SAVED_OBJECT_TYPE,
APM_SERVER_SCHEMA_SAVED_OBJECT_ID,
} from '../../../common/apm_saved_object_constants';
import { apmConfigMapping } from './get_apm_package_policy_definition';
import {
apmConfigMapping,
preprocessLegacyFields,
} from './get_apm_package_policy_definition';

export async function getUnsupportedApmServerSchema({
savedObjectsClient,
Expand All @@ -24,7 +27,10 @@ export async function getUnsupportedApmServerSchema({
const apmServerSchema: Record<string, any> = JSON.parse(
(attributes as { schemaJson: string }).schemaJson
);
return Object.entries(apmServerSchema)
const preprocessedApmServerSchema = preprocessLegacyFields({
apmServerSchema,
});
return Object.entries(preprocessedApmServerSchema)
.filter(([name]) => !(name in apmConfigMapping))
.map(([key, value]) => ({ key, value }));
}
80 changes: 65 additions & 15 deletions x-pack/plugins/fleet/server/services/preconfiguration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { elasticsearchServiceMock, savedObjectsClientMock } from 'src/core/serve

import { SavedObjectsErrorHelpers } from '../../../../../src/core/server';

import type { PreconfiguredAgentPolicy, PreconfiguredOutput } from '../../common/types';
import type {
InstallResult,
PreconfiguredAgentPolicy,
PreconfiguredOutput,
} from '../../common/types';
import type { AgentPolicy, NewPackagePolicy, Output } from '../types';

import { AGENT_POLICY_SAVED_OBJECT_TYPE } from '../constants';
Expand All @@ -30,6 +34,7 @@ jest.mock('./output');
const mockedOutputService = outputService as jest.Mocked<typeof outputService>;

const mockInstalledPackages = new Map();
const mockInstallPackageErrors = new Map<string, string>();
const mockConfiguredPolicies = new Map();

const mockDefaultOutput: Output = {
Expand Down Expand Up @@ -99,8 +104,22 @@ function getPutPreconfiguredPackagesMock() {
}

jest.mock('./epm/packages/install', () => ({
installPackage({ pkgkey, force }: { pkgkey: string; force?: boolean }) {
async installPackage({
pkgkey,
force,
}: {
pkgkey: string;
force?: boolean;
}): Promise<InstallResult> {
const [pkgName, pkgVersion] = pkgkey.split('-');
const installError = mockInstallPackageErrors.get(pkgName);
if (installError) {
return {
error: new Error(installError),
installType: 'install',
};
}

const installedPackage = mockInstalledPackages.get(pkgName);
if (installedPackage) {
if (installedPackage.version === pkgVersion) return installedPackage;
Expand All @@ -109,7 +128,10 @@ jest.mock('./epm/packages/install', () => ({
const packageInstallation = { name: pkgName, version: pkgVersion, title: pkgName };
mockInstalledPackages.set(pkgName, packageInstallation);

return packageInstallation;
return {
status: 'installed',
installType: 'install',
};
},
ensurePackagesCompletedInstall() {
return [];
Expand All @@ -133,6 +155,8 @@ jest.mock('./epm/packages/get', () => ({
},
}));

jest.mock('./epm/kibana/index_pattern/install');

jest.mock('./package_policy', () => ({
...jest.requireActual('./package_policy'),
packagePolicyService: {
Expand Down Expand Up @@ -177,6 +201,7 @@ const spyAgentPolicyServicBumpAllAgentPoliciesForOutput = jest.spyOn(
describe('policy preconfiguration', () => {
beforeEach(() => {
mockInstalledPackages.clear();
mockInstallPackageErrors.clear();
mockConfiguredPolicies.clear();
spyAgentPolicyServiceUpdate.mockClear();
spyAgentPolicyServicBumpAllAgentPoliciesForOutput.mockClear();
Expand Down Expand Up @@ -266,7 +291,7 @@ describe('policy preconfiguration', () => {
);
});

it('should not create a policy if we are not able to add packages ', async () => {
it('should not create a policy and throw an error if install fails for required package', async () => {
const soClient = getPutPreconfiguredPackagesMock();
const esClient = elasticsearchServiceMock.createClusterClient().asInternalUser;
const policies: PreconfiguredAgentPolicy[] = [
Expand All @@ -282,23 +307,48 @@ describe('policy preconfiguration', () => {
],
},
];
mockInstallPackageErrors.set('test_package', 'REGISTRY ERROR');

let error;
try {
await ensurePreconfiguredPackagesAndPolicies(
await expect(
ensurePreconfiguredPackagesAndPolicies(
soClient,
esClient,
policies,
[{ name: 'CANNOT_MATCH', version: 'x.y.z' }],
[{ name: 'test_package', version: '3.0.0' }],
mockDefaultOutput
);
} catch (err) {
error = err;
}
)
).rejects.toThrow(
'[Test policy] could not be added. [test_package] could not be installed due to error: [Error: REGISTRY ERROR]'
);
});

expect(error).toBeDefined();
expect(error.message).toEqual(
'Test policy could not be added. test_package is not installed, add test_package to `xpack.fleet.packages` or remove it from Test package.'
it('should not create a policy and throw an error if package is not installed for an unknown reason', async () => {
const soClient = getPutPreconfiguredPackagesMock();
const esClient = elasticsearchServiceMock.createClusterClient().asInternalUser;
const policies: PreconfiguredAgentPolicy[] = [
{
name: 'Test policy',
namespace: 'default',
id: 'test-id',
package_policies: [
{
package: { name: 'test_package' },
name: 'Test package',
},
],
},
];

await expect(
ensurePreconfiguredPackagesAndPolicies(
soClient,
esClient,
policies,
[{ name: 'CANNOT_MATCH', version: 'x.y.z' }],
mockDefaultOutput
)
).rejects.toThrow(
'[Test policy] could not be added. [test_package] is not installed, add [test_package] to [xpack.fleet.packages] or remove it from [Test package].'
);
});
it('should not attempt to recreate or modify an agent policy if its ID is unchanged', async () => {
Expand Down
Loading

0 comments on commit fb3fc29

Please sign in to comment.