Skip to content

Commit

Permalink
[Security Solution] Fix rule monitoring dashboard (elastic#160316)
Browse files Browse the repository at this point in the history
**Epic:** elastic/security-team#6032
(internal)
**Related to:** elastic#159875

## Summary

In this PR we:

- add a text block to the dashboard itself with helpful info about it
- fix the 4 tables at the bottom of the dashboard
- add unit tests for the dashboard's source `.json` files

## Text block

<img width="1792" alt="Screenshot 2023-06-22 at 20 15 30"
src="https://github.com/elastic/kibana/assets/7359339/55d267b7-7c39-4cdf-a917-fd17e9231a59">

## Tables

There were two issues with the tables:

1. When having the same prebuilt rules installed in two or more Kibana
spaces, sorting in a table could break if the table rendered two
different rules with the same name. It has been fixed by making the rule
ID the first field in the table and making a few minor tweaks. Thanks to
@maximpn for noticing the bug.
2. Widths of the columns were off in some cases.

The fixed tables look like that:

<img width="1775" alt="Screenshot 2023-06-22 at 19 52 13"
src="https://github.com/elastic/kibana/assets/7359339/53475848-3238-4866-af70-080b8acd1f9e">

## Full comparison

| **BEFORE** | **AFTER** |
|:------------:|:-----------:|
| ![Dashboard
BEFORE](https://github.com/elastic/kibana/assets/7359339/755cc044-5613-4c78-b89f-2a9734ded76d)
| ![Dashboard
AFTER](https://github.com/elastic/kibana/assets/7359339/38ac67f7-b9f8-4ddf-833f-e8e98eb2bfb1)
|


### Checklist

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [x]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
    - elastic/security-docs#3478
  • Loading branch information
banderror authored Jun 27, 2023
1 parent d1e9c87 commit f622809
Show file tree
Hide file tree
Showing 2 changed files with 235 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
/*
* 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 sourceRuleMonitoringDashboard from './dashboard_rule_monitoring.json';
import sourceKibanaEventLogDataView from './data_view_kibana_event_log.json';
import sourceManagedTag from './tag_managed.json';
import sourceSecuritySolutionTag from './tag_security_solution.json';

describe('Assets for rule monitoring', () => {
describe('Dashboard: "[Elastic Security] Detection rule monitoring"', () => {
it('has correct type and id', () => {
expect(sourceRuleMonitoringDashboard).toEqual(
expect.objectContaining({
type: 'dashboard',
id: 'security-detection-rule-monitoring-<spaceId>',
})
);
});

it('is marked as managed', () => {
expect(sourceRuleMonitoringDashboard).toEqual(
expect.objectContaining({
managed: true,
})
);
});

it('has "coreMigrationVersion" and "typeMigrationVersion" fields', () => {
expect(sourceRuleMonitoringDashboard).toEqual(
expect.objectContaining({
coreMigrationVersion: expect.any(String),
typeMigrationVersion: expect.any(String),
})
);
});

it('has references to ".kibana-event-log-*" data view', () => {
expect(sourceRuleMonitoringDashboard).toEqual(
expect.objectContaining({
references: expect.any(Array),
})
);

const dataViewReferences = sourceRuleMonitoringDashboard.references.filter(
(r) => r.type === 'index-pattern' && r.id === 'kibana-event-log-data-view'
);

expect(dataViewReferences.length).toBeGreaterThan(1);
});

it('has references to the tags', () => {
expect(sourceRuleMonitoringDashboard).toEqual(
expect.objectContaining({
references: expect.any(Array),
})
);

const tagsReferences = sourceRuleMonitoringDashboard.references.filter(
(r) => r.type === 'tag'
);

expect(tagsReferences).toEqual([
{
id: 'fleet-managed-<spaceId>',
name: 'tag-ref-fleet-managed',
type: 'tag',
},
{
id: 'security-solution-<spaceId>',
name: 'tag-ref-security-solution',
type: 'tag',
},
]);
});
});

describe('Data view: ".kibana-event-log-*"', () => {
it('has correct type and id', () => {
expect(sourceKibanaEventLogDataView).toEqual(
expect.objectContaining({
type: 'index-pattern',
id: 'kibana-event-log-data-view',
})
);
});

it('is marked as managed', () => {
expect(sourceKibanaEventLogDataView).toEqual(
expect.objectContaining({
managed: true,
})
);
});

it('has "coreMigrationVersion" and "typeMigrationVersion" fields', () => {
expect(sourceKibanaEventLogDataView).toEqual(
expect.objectContaining({
coreMigrationVersion: expect.any(String),
typeMigrationVersion: expect.any(String),
})
);
});

it('has correct and minimal attributes', () => {
expect(sourceKibanaEventLogDataView).toEqual(
expect.objectContaining({
attributes: {
// We don't specify any concrete fields and their formatting for this data view
name: '.kibana-event-log-*',
title: '.kibana-event-log-*',
timeFieldName: '@timestamp',
allowNoIndex: true,
},
})
);
});

it('has no references', () => {
expect(sourceKibanaEventLogDataView).toEqual(
expect.objectContaining({
references: expect.any(Array),
})
);

expect(sourceKibanaEventLogDataView.references.length).toEqual(0);
});
});

describe('Tag: "Managed"', () => {
it('has correct type and id', () => {
expect(sourceManagedTag).toEqual(
expect.objectContaining({
type: 'tag',
id: 'fleet-managed-<spaceId>',
})
);
});

it('is marked as managed', () => {
expect(sourceManagedTag).toEqual(
expect.objectContaining({
managed: true,
})
);
});

it('has "coreMigrationVersion" and "typeMigrationVersion" fields', () => {
expect(sourceManagedTag).toEqual(
expect.objectContaining({
coreMigrationVersion: expect.any(String),
typeMigrationVersion: expect.any(String),
})
);
});

it('has correct attributes', () => {
expect(sourceManagedTag).toEqual(
expect.objectContaining({
attributes: expect.objectContaining({
name: 'Managed',
}),
})
);
});

it('has no references', () => {
expect(sourceManagedTag).toEqual(
expect.objectContaining({
references: expect.any(Array),
})
);

expect(sourceManagedTag.references.length).toEqual(0);
});
});

describe('Tag: "Security Solution"', () => {
it('has correct type and id', () => {
expect(sourceSecuritySolutionTag).toEqual(
expect.objectContaining({
type: 'tag',
id: 'security-solution-<spaceId>',
})
);
});

it('is marked as managed', () => {
expect(sourceSecuritySolutionTag).toEqual(
expect.objectContaining({
managed: true,
})
);
});

it('has "coreMigrationVersion" and "typeMigrationVersion" fields', () => {
expect(sourceSecuritySolutionTag).toEqual(
expect.objectContaining({
coreMigrationVersion: expect.any(String),
typeMigrationVersion: expect.any(String),
})
);
});

it('has correct attributes', () => {
expect(sourceSecuritySolutionTag).toEqual(
expect.objectContaining({
attributes: expect.objectContaining({
name: 'Security Solution',
}),
})
);
});

it('has no references', () => {
expect(sourceSecuritySolutionTag).toEqual(
expect.objectContaining({
references: expect.any(Array),
})
);

expect(sourceSecuritySolutionTag.references.length).toEqual(0);
});
});
});

Large diffs are not rendered by default.

0 comments on commit f622809

Please sign in to comment.