Skip to content

Commit

Permalink
[8.x] [SecuritySolution] Entity store status page - Add health status…
Browse files Browse the repository at this point in the history
… to transform (#202523) (#204692)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[SecuritySolution] Entity store status page - Add health status to
transform (#202523)](#202523)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Pablo
Machado","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-18T08:24:04Z","message":"[SecuritySolution]
Entity store status page - Add health status to transform
(#202523)\n\n## Summary\n\nAdd the actual transform status to the Entity
Store status page.\nBefore, it just showed green whenever the transform
was installed.\n\n### How to test it?\n* Install the Engine \n* Break
the transform by updating it on the stack management page\n* The status
change should be reflected in the engine status page\n\n\n![Screenshot
2024-12-16 at 11
05\n30](https://github.com/user-attachments/assets/a288a037-e1ea-4747-a2bb-266300dad946)","sha":"1550c90d3769ff27b0613b8004b9193a888c8236","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:
SecuritySolution","Theme: entity_analytics","Feature:Entity
Analytics","Team:Entity
Analytics","backport:version","v8.18.0"],"title":"[SecuritySolution]
Entity store status page - Add health status to
transform","number":202523,"url":"https://github.com/elastic/kibana/pull/202523","mergeCommit":{"message":"[SecuritySolution]
Entity store status page - Add health status to transform
(#202523)\n\n## Summary\n\nAdd the actual transform status to the Entity
Store status page.\nBefore, it just showed green whenever the transform
was installed.\n\n### How to test it?\n* Install the Engine \n* Break
the transform by updating it on the stack management page\n* The status
change should be reflected in the engine status page\n\n\n![Screenshot
2024-12-16 at 11
05\n30](https://github.com/user-attachments/assets/a288a037-e1ea-4747-a2bb-266300dad946)","sha":"1550c90d3769ff27b0613b8004b9193a888c8236"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/202523","number":202523,"mergeCommit":{"message":"[SecuritySolution]
Entity store status page - Add health status to transform
(#202523)\n\n## Summary\n\nAdd the actual transform status to the Entity
Store status page.\nBefore, it just showed green whenever the transform
was installed.\n\n### How to test it?\n* Install the Engine \n* Break
the transform by updating it on the stack management page\n* The status
change should be reflected in the engine status page\n\n\n![Screenshot
2024-12-16 at 11
05\n30](https://github.com/user-attachments/assets/a288a037-e1ea-4747-a2bb-266300dad946)","sha":"1550c90d3769ff27b0613b8004b9193a888c8236"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Pablo Machado <[email protected]>
  • Loading branch information
kibanamachine and machadoum authored Dec 18, 2024
1 parent 36264ae commit 2735f3c
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ import type { DataViewsService } from '@kbn/data-views-plugin/common';
import type { AppClient } from '../../..';
import type { EntityStoreConfig } from './types';
import { mockGlobalState } from '../../../../public/common/mock';
import type { EntityDefinition } from '@kbn/entities-schema';
import { getUnitedEntityDefinition } from './united_entity_definitions';

const unitedDefinition = getUnitedEntityDefinition({
entityType: 'host',
namespace: 'test',
fieldHistoryLength: 10,
indexPatterns: [],
syncDelay: '1m',
frequency: '1m',
});
const definition: EntityDefinition = unitedDefinition.entityManagerDefinition;

describe('EntityStoreDataClient', () => {
const mockSavedObjectClient = savedObjectsClientMock.create();
Expand Down Expand Up @@ -182,4 +194,137 @@ describe('EntityStoreDataClient', () => {
expect(response.records[0]).toEqual(fakeEntityRecord);
});
});

describe('getComponentFromEntityDefinition', () => {
it('returns installed false if no definition is provided', () => {
const result = dataClient.getComponentFromEntityDefinition('security_host_test', undefined);
expect(result).toEqual([
{
id: 'security_host_test',
installed: false,
resource: 'entity_definition',
},
]);
});

it('returns correct components for EntityDefinitionWithState', () => {
const definitionWithState = {
...definition,
state: {
installed: true,
running: true,
components: {
transforms: [
{
id: 'transforms_id',
installed: true,
running: true,
},
],
ingestPipelines: [
{
id: 'pipeline-1',
installed: true,
},
],
indexTemplates: [
{
id: 'indexTemplates_id',
installed: true,
},
],
},
},
};

const result = dataClient.getComponentFromEntityDefinition(
'security_host_test',
definitionWithState
);
expect(result).toEqual([
{
id: 'security_host_test',
installed: true,
resource: 'entity_definition',
},
{
id: 'security_host_test',
resource: 'transform',
installed: true,
health: 'unknown',
errors: undefined,
},
{
resource: 'ingest_pipeline',
id: 'pipeline-1',
installed: true,
},
{
id: 'security_host_test',
installed: true,
resource: 'index_template',
},
]);
});

it('returns empty array for EntityDefinition without state', () => {
const result = dataClient.getComponentFromEntityDefinition('security_host_test', definition);
expect(result).toEqual([]);
});

it('handles transform health issues correctly', () => {
const definitionWithState = {
...definition,
state: {
installed: true,
components: {
transforms: [
{
installed: true,
stats: {
health: {
status: 'yellow',
issues: [
{
type: 'issue-type',
issue: 'issue-message',
details: 'issue-details',
count: 1,
},
],
},
},
},
],
ingestPipelines: [],
indexTemplates: [],
},
},
};

const result = dataClient.getComponentFromEntityDefinition(
'security_host_test',
definitionWithState
);
expect(result).toEqual([
{
id: 'security_host_test',
installed: true,
resource: 'entity_definition',
},
{
id: 'security_host_test',
resource: 'transform',
installed: true,
health: 'yellow',
errors: [
{
title: 'issue-message',
message: 'issue-details',
},
],
},
]);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {
AnalyticsServiceSetup,
} from '@kbn/core/server';
import { EntityClient } from '@kbn/entityManager-plugin/server/lib/entity_client';
import type { SortOrder } from '@elastic/elasticsearch/lib/api/types';
import type { HealthStatus, SortOrder } from '@elastic/elasticsearch/lib/api/types';
import type { TaskManagerStartContract } from '@kbn/task-manager-plugin/server';
import type { DataViewsService } from '@kbn/data-views-plugin/common';
import { isEqual } from 'lodash/fp';
Expand Down Expand Up @@ -464,7 +464,7 @@ export class EntityStoreDataClient {

public getComponentFromEntityDefinition(
id: string,
definition: EntityDefinitionWithState | EntityDefinition
definition: EntityDefinitionWithState | EntityDefinition | undefined
): EngineComponentStatus[] {
if (!definition) {
return [
Expand All @@ -477,16 +477,22 @@ export class EntityStoreDataClient {
}

if ('state' in definition) {
const transformHealthToComponentHealth = (
health: HealthStatus | undefined
): EngineComponentStatus['health'] =>
health ? (health.toLowerCase() as Lowercase<HealthStatus>) : 'unknown';

return [
{
id: definition.id,
installed: definition.state.installed,
resource: EngineComponentResourceEnum.entity_definition,
},
...definition.state.components.transforms.map(({ installed, running, stats }) => ({
...definition.state.components.transforms.map(({ installed, stats }) => ({
id,
resource: EngineComponentResourceEnum.transform,
installed,
health: transformHealthToComponentHealth(stats?.health?.status),
errors: (stats?.health as TransformHealth)?.issues?.map(({ issue, details }) => ({
title: issue,
message: details,
Expand Down

0 comments on commit 2735f3c

Please sign in to comment.