Skip to content

Commit

Permalink
[SecuritySolution] Fix data view not found when rendering with adHocD…
Browse files Browse the repository at this point in the history
…ataView (#149513)

## Summary

Please Enable feature flags. Please add this to kibana.dev.yml
xpack.securitySolution.enableExperimental: ['chartEmbeddablesEnabled']

<img width="1513" alt="Screenshot 2023-01-25 at 12 54 54"
src="https://user-images.githubusercontent.com/6295984/214573163-1e606e07-c7c6-4980-99c5-0ce4347fb6c0.png">

AdHocDataview requires a static reference to point internal reference Id
to the given data view.
The reference of data view will be lost If we re-generate internal
reference Id every time the function is called.
To fix this, I assigned the id out side of the function so it wouldn't
change when the function is called.

Expected: Risk score over time should be rendered properly:

<img width="1501" alt="Screenshot 2023-01-25 at 13 42 56"
src="https://user-images.githubusercontent.com/6295984/214578964-06dc8d11-cf65-4ede-a2ba-a42a1268d6e5.png">

<img width="1513" alt="Screenshot 2023-01-25 at 13 43 57"
src="https://user-images.githubusercontent.com/6295984/214579194-d64ef60f-28fe-407e-8d71-abb56ef845e4.png">


### Checklist

Delete any items that are not applicable to this PR.


- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
  • Loading branch information
angorayc authored Jan 25, 2023
1 parent d74e215 commit a3ba276
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 42 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ jest.mock('uuid', () => ({
v4: jest
.fn()
.mockReturnValueOnce('d594baeb-5eca-480c-8885-ba79eaf41372')
.mockReturnValue('1dd5663b-f062-43f8-8688-fc8166c2ca8e'),
.mockReturnValueOnce('1dd5663b-f062-43f8-8688-fc8166c2ca8e')
.mockReturnValue('2cc5663b-f062-43f8-8688-fc8166c2ca8e'),
}));

describe('getRiskScoreDonutAttributes', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
import { v4 as uuidv4 } from 'uuid';
import type { GetLensAttributes } from '../../../types';

const internalReferenceIdMapping: Record<string, string> = { host: uuidv4(), user: uuidv4() };

export const getRiskScoreDonutAttributes: GetLensAttributes = (
stackByField,
stackByField = 'host',
extraOptions = { spaceId: 'default' }
) => {
const layerId = uuidv4();
const internalReferenceId = uuidv4();
const internalReferenceId = internalReferenceIdMapping[stackByField];
return {
title: `${stackByField} risk donut`,
description: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jest.mock('uuid', () => ({
.mockReturnValueOnce('d594baeb-5eca-480c-8885-ba79eaf41372')
.mockReturnValueOnce('c604baeb-5eca-480c-8885-ba79eaf41372')
.mockReturnValueOnce('e614baeb-5eca-480c-8885-ba79eaf41372')
.mockReturnValueOnce('f614baeb-5eca-480c-8885-ba79eaf52483')
.mockReturnValue('1dd5663b-f062-43f8-8688-fc8166c2ca8e'),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@

import { v4 as uuidv4 } from 'uuid';
import type { GetLensAttributes } from '../../../types';

const internalReferenceIdMapping: Record<string, string> = { host: uuidv4(), user: uuidv4() };

export const getRiskScoreOverTimeAreaAttributes: GetLensAttributes = (
stackByField = 'host',
extraOptions = { spaceId: 'default' }
) => {
const layerIds = [uuidv4(), uuidv4()];
const internalReferenceId = uuidv4();
const layer2ColumnId = uuidv4();
const internalReferenceId = internalReferenceIdMapping[stackByField];
return {
title: `${stackByField} risk score over time`,
description: '',
Expand Down

0 comments on commit a3ba276

Please sign in to comment.