Skip to content

Commit

Permalink
Merge branch 'main' into fix-connector-deprecation-for-preconfigured
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Apr 25, 2022
2 parents d28b901 + 780333b commit 8428a89
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 76 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@
"@dnd-kit/core": "^3.1.1",
"@dnd-kit/sortable": "^4.0.0",
"@dnd-kit/utilities": "^2.0.0",
"@elastic/apm-rum": "^5.10.2",
"@elastic/apm-rum-react": "^1.3.4",
"@elastic/apm-rum": "^5.11.0",
"@elastic/apm-rum-react": "^1.4.0",
"@elastic/apm-synthtrace": "link:bazel-bin/packages/elastic-apm-synthtrace",
"@elastic/charts": "46.0.1",
"@elastic/datemath": "5.0.3",
Expand Down
4 changes: 3 additions & 1 deletion test/functional/apps/dashboard/dashboard_unsaved_listing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
});

it('can discard unsaved changes using the discard link', async () => {
await PageObjects.dashboard.clickUnsavedChangesDiscard(dashboardTitle);
await PageObjects.dashboard.clickUnsavedChangesDiscard(
`discard-unsaved-${dashboardTitle.split(' ').join('-')}`
);
await PageObjects.dashboard.expectUnsavedChangesDoesNotExist(dashboardTitle);
await PageObjects.dashboard.loadSavedDashboard(dashboardTitle);
await PageObjects.dashboard.switchToEditMode();
Expand Down
69 changes: 34 additions & 35 deletions test/functional/apps/visualize/_tsvb_time_series.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
const browser = getService('browser');
const kibanaServer = getService('kibanaServer');

// Failing: See https://github.com/elastic/kibana/issues/129785
describe.skip('visual builder', function describeIndexTests() {
describe('visual builder', function describeIndexTests() {
before(async () => {
await security.testUser.setRoles([
'kibana_admin',
Expand Down Expand Up @@ -172,62 +171,62 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
});

describe('Clicking on the chart', () => {
it(`should create a filter`, async () => {
await visualBuilder.setMetricsGroupByTerms('machine.os.raw', {
include: 'win 7',
exclude: 'ios',
});
await visualBuilder.clickSeriesOption();
const act = async (visName: string, clickCoordinates: { x: number; y: number }) => {
await testSubjects.click('visualizeSaveButton');

await timeToVisualize.saveFromModal('My TSVB viz 1', {
await timeToVisualize.saveFromModal(visName, {
addToDashboard: 'new',
saveToLibrary: false,
});

await dashboard.waitForRenderComplete();
const el = await elasticChart.getCanvas();

await retry.try(async () => {
// click on specific coordinates
await browser
.getActions()
.move({ x: 105, y: 115, origin: el._webElement })
.click()
.perform();
await common.sleep(2000);
await testSubjects.click('applyFiltersPopoverButton');
await testSubjects.missingOrFail('applyFiltersPopoverButton');
const el = await elasticChart.getCanvas();

await el.clickMouseButton({
xOffset: clickCoordinates.x,
yOffset: clickCoordinates.y,
});
await common.sleep(1000);
await testSubjects.existOrFail('applyFiltersPopoverButton');
});

await testSubjects.click('applyFiltersPopoverButton');
};

const cleanup = async () => {
const discardDashboardPromptButton = 'discardDashboardPromptButton';
await common.navigateToApp('dashboard');
if (await testSubjects.exists(discardDashboardPromptButton)) {
await dashboard.clickUnsavedChangesDiscard(discardDashboardPromptButton, true);
}
};

afterEach(async () => {
await cleanup();
});

it(`should create a filter`, async () => {
await visualBuilder.setMetricsGroupByTerms('machine.os.raw', {
include: 'win 7',
exclude: 'ios',
});
await act('viz_1', { x: 105, y: 115 });
const hasMachineRawFilter = await filterBar.hasFilter('machine.os.raw', 'win 7');
expect(hasMachineRawFilter).to.be(true);
});

it('should create a filter for series with multiple split by terms fields one of which has formatting', async () => {
const expectedFilterPills = ['0, win xp, logstash-2015.09.20'];
const expectedFilterPills = ['0, win 7'];
await visualBuilder.setMetricsGroupByTerms('bytes');
await visualBuilder.setAnotherGroupByTermsField('machine.os.raw');
await visualBuilder.setAnotherGroupByTermsField('_index');

await visualBuilder.clickSeriesOption();
await visualBuilder.setChartType('Bar');
await visualBuilder.setStackedType('Stacked');
await visualBuilder.clickPanelOptions('timeSeries');
await visualBuilder.setIntervalValue('1w');

const el = await elasticChart.getCanvas();
await el.scrollIntoViewIfNecessary();
await browser
.getActions()
.move({ x: 100, y: 65, origin: el._webElement })
.click()
.perform();

await retry.try(async () => {
await testSubjects.click('applyFiltersPopoverButton');
await testSubjects.missingOrFail('applyFiltersPopoverButton');
});
await act('vis_2', { x: -100, y: 10 });

const filterPills = await filterBar.getFiltersLabel();
expect(filterPills).to.eql(expectedFilterPills);
Expand Down
8 changes: 4 additions & 4 deletions test/functional/page_objects/dashboard_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ export class DashboardPageObject extends FtrService {
await this.testSubjects.click(`edit-unsaved-${title.split(' ').join('-')}`);
}

public async clickUnsavedChangesDiscard(title: string, confirmDiscard = true) {
this.log.debug(`Click Unsaved Changes Discard for `, title);
await this.testSubjects.existOrFail(`discard-unsaved-${title.split(' ').join('-')}`);
await this.testSubjects.click(`discard-unsaved-${title.split(' ').join('-')}`);
public async clickUnsavedChangesDiscard(testSubject: string, confirmDiscard = true) {
this.log.debug(`Click Unsaved Changes Discard for `, testSubject);
await this.testSubjects.existOrFail(testSubject);
await this.testSubjects.click(testSubject);
if (confirmDiscard) {
await this.common.clickConfirmOnModal();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const onPackagePolicyDeleteCallback = async (
const { saved_objects: cspRules }: SavedObjectsFindResponse<CspRuleSchema> =
await soClient.find({
type: cspRuleAssetSavedObjectType,
filter: `csp_rule.attributes.package_policy_id: ${deletedPackagePolicy.id} AND csp_rule.attributes.policy_id: ${deletedPackagePolicy.policy_id}`,
filter: `${cspRuleAssetSavedObjectType}.attributes.package_policy_id: ${deletedPackagePolicy.id} AND ${cspRuleAssetSavedObjectType}.attributes.policy_id: ${deletedPackagePolicy.policy_id}`,
});
await Promise.all(
cspRules.map((rule) => soClient.delete(cspRuleAssetSavedObjectType, rule.id))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ describe('Update rules configuration API', () => {
});

it('validate getCspRules input parameters', async () => {
const packagePolicy = createPackagePolicyMock();
mockSoClient = savedObjectsClientMock.create();
mockSoClient.find.mockResolvedValueOnce({} as SavedObjectsFindResponse);
await getCspRules(mockSoClient);
await getCspRules(mockSoClient, packagePolicy);
expect(mockSoClient.find).toBeCalledTimes(1);
expect(mockSoClient.find).toHaveBeenCalledWith(
expect.objectContaining({ type: cspRuleAssetSavedObjectType })
Expand All @@ -127,23 +128,21 @@ describe('Update rules configuration API', () => {
saved_objects: [
{
type: 'csp_rule',
id: '1.1.1',
attributes: { enabled: true },
rego_rule_id: '1.1.1',
attributes: { enabled: true, rego_rule_id: 'cis_1_1_1' },
},
{
type: 'csp_rule',
id: '1.1.2',
attributes: { enabled: false },
attributes: { enabled: false, rego_rule_id: 'cis_1_1_2' },
},
{
type: 'csp_rule',
id: '1.1.3',
attributes: { enabled: true },
attributes: { enabled: true, rego_rule_id: 'cis_1_1_3' },
},
],
} as SavedObjectsFindResponse<CspRuleSchema>;
} as unknown as SavedObjectsFindResponse<CspRuleSchema>;
const cspConfig = await createRulesConfig(cspRules);
expect(cspConfig).toMatchObject({ activated_rules: { cis_k8s: ['1.1.1', '1.1.3'] } });
expect(cspConfig).toMatchObject({ activated_rules: { cis_k8s: ['cis_1_1_1', 'cis_1_1_3'] } });
});

it('create empty csp rules config when all rules are disabled', async () => {
Expand All @@ -154,16 +153,19 @@ describe('Update rules configuration API', () => {
saved_objects: [
{
type: 'csp_rule',
id: '1.1.1',
attributes: { enabled: false },
rego_rule_id: '1.1.1',
attributes: { enabled: false, rego_rule_id: 'cis_1_1_1' },
},
{
type: 'csp_rule',
attributes: { enabled: false, rego_rule_id: 'cis_1_1_2' },
},
{
type: 'csp_rule',
id: '1.1.2',
attributes: { enabled: false },
attributes: { enabled: false, rego_rule_id: 'cis_1_1_3' },
},
],
} as SavedObjectsFindResponse<CspRuleSchema>;
} as unknown as SavedObjectsFindResponse<CspRuleSchema>;
const cspConfig = await createRulesConfig(cspRules);
expect(cspConfig).toMatchObject({ activated_rules: { cis_k8s: [] } });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ export const getPackagePolicy = async (
return packagePolicies![0];
};

export const getCspRules = async (soClient: SavedObjectsClientContract) => {
export const getCspRules = async (
soClient: SavedObjectsClientContract,
packagePolicy: PackagePolicy
) => {
const cspRules = await soClient.find<CspRuleSchema>({
type: cspRuleAssetSavedObjectType,
search: '',
filter: `${cspRuleAssetSavedObjectType}.attributes.package_policy_id: ${packagePolicy.id} AND ${cspRuleAssetSavedObjectType}.attributes.policy_id: ${packagePolicy.policy_id}`,
searchFields: ['name'],
// TODO: research how to get all rules
perPage: 10000,
Expand All @@ -59,10 +62,9 @@ export const createRulesConfig = (
cspRules: SavedObjectsFindResponse<CspRuleSchema>
): CspRulesConfigSchema => {
const activatedRules = cspRules.saved_objects.filter((cspRule) => cspRule.attributes.enabled);

const config = {
activated_rules: {
cis_k8s: activatedRules.map((activatedRule) => activatedRule.id),
cis_k8s: activatedRules.map((activatedRule) => activatedRule.attributes.rego_rule_id),
},
};
return config;
Expand Down Expand Up @@ -126,7 +128,7 @@ export const defineUpdateRulesConfigRoute = (router: CspRouter, cspContext: CspA
packagePolicyId
);

const cspRules = await getCspRules(soClient);
const cspRules = await getCspRules(soClient, packagePolicy);
const rulesConfig = createRulesConfig(cspRules);
const dataYaml = convertRulesConfigToYaml(rulesConfig);

Expand Down
28 changes: 14 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1415,29 +1415,29 @@
dependencies:
tslib "^2.0.0"

"@elastic/apm-rum-core@^5.14.1":
version "5.14.1"
resolved "https://registry.yarnpkg.com/@elastic/apm-rum-core/-/apm-rum-core-5.14.1.tgz#8f65060967c8d68498f2c520e4169ec07eb3b5bb"
integrity sha512-RFgTpXUIEIoy44TPnEN7cVcf2YIBOwaNdALrYVc4lOTMH3u0v4gaS0n9/Aee5nTGqWBLKWXXvMk/dAkjQW6qEg==
"@elastic/apm-rum-core@^5.15.0":
version "5.15.0"
resolved "https://registry.yarnpkg.com/@elastic/apm-rum-core/-/apm-rum-core-5.15.0.tgz#f1067078080be1b7167c72ae6d155b0ed5cdf6c6"
integrity sha512-T5/1hZPskmU6N3Xo2CRNi5tX2ht8R5nLmh5t0I1v8RxkwbQms47AR1f0ZVvXN7W2FCDPadyQXC3f9do3k5A6OA==
dependencies:
error-stack-parser "^1.3.5"
opentracing "^0.14.3"
promise-polyfill "^8.1.3"

"@elastic/apm-rum-react@^1.3.4":
version "1.3.4"
resolved "https://registry.yarnpkg.com/@elastic/apm-rum-react/-/apm-rum-react-1.3.4.tgz#f60f1ba55696f4e04eba64edb323e43ef9d67acb"
integrity sha512-HPKU/tnTbiSQr6HYxHB9rP4TKBHZ9HKhBPzmCvZj8PNH5tkMFR4nj0PLN9eYL59A7omAmtH2Sg95T47OIG9ZtQ==
"@elastic/apm-rum-react@^1.4.0":
version "1.4.0"
resolved "https://registry.yarnpkg.com/@elastic/apm-rum-react/-/apm-rum-react-1.4.0.tgz#f36453e54d2ebdedb0d6d0c4f6cc76e16304b118"
integrity sha512-YIBuEJN6fkiB1M/o84PF4lQheAjrd3PQCm6t8pP4dKuWN1cWZnSsojnuGacx2bJn1kWWZxVDQ7wTjPJutkIy2A==
dependencies:
"@elastic/apm-rum" "^5.10.2"
"@elastic/apm-rum" "^5.11.0"
hoist-non-react-statics "^3.3.0"

"@elastic/apm-rum@^5.10.2":
version "5.10.2"
resolved "https://registry.yarnpkg.com/@elastic/apm-rum/-/apm-rum-5.10.2.tgz#06d3e9f08adc19e1227073dda7e5c4ab34be48c7"
integrity sha512-NrBQcgautAGwJOrJ20WUUXV1Ynux4dEEU/fgeqfdG7G3JGqMbuIlF8s/nqLgQ9oXz72Z5MirOf68P7m5Zh/5HA==
"@elastic/apm-rum@^5.11.0":
version "5.11.0"
resolved "https://registry.yarnpkg.com/@elastic/apm-rum/-/apm-rum-5.11.0.tgz#97dbc426d0ec27b46e78a649f73d9e4a198ae258"
integrity sha512-+98NLG4NDa7o1DCtkhXeGmKW5riDPHSpgy2UxzLK4j02ZPBOccOUjIw5F8yZAUsrPUpQmk39x13IJl0mFyzjyA==
dependencies:
"@elastic/apm-rum-core" "^5.14.1"
"@elastic/apm-rum-core" "^5.15.0"

"@elastic/apm-synthtrace@link:bazel-bin/packages/elastic-apm-synthtrace":
version "0.0.0"
Expand Down

0 comments on commit 8428a89

Please sign in to comment.