Skip to content

Commit

Permalink
Adjust group by feature
Browse files Browse the repository at this point in the history
  • Loading branch information
crespocarlos committed Nov 4, 2024
1 parent b23fae2 commit 8ba7131
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ export class K8sEntity extends Serializable<EntityFields> {
super({
...fields,
'entity.type': entityTypeWithSchema,
'entity.definitionId': `builtin_${entityTypeWithSchema}`,
'entity.identityFields': identityFields,
'entity.displayName': getDisplayName({ identityFields, fields }),
'entity.definitionVersion': '1.0.0',
'entity.schemaVersion': '1.0',
'entity.definition_id': `builtin_${entityTypeWithSchema}`,
'entity.identity_fields': identityFields,
'entity.display_name': getDisplayName({ identityFields, fields }),
'entity.definition_version': '1.0.0',
'entity.schema_version': '1.0',
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const commonEntityFields: EnitityInstance = {
id: '1',
display_name: 'entity_name',
definition_id: 'entity_definition_id',
},
} as EnitityInstance['entity'],
};

describe('EntityClient', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import React, { useCallback, useState } from 'react';
import { i18n } from '@kbn/i18n';
import { css } from '@emotion/react';
import { EuiAccordion, EuiPanel, EuiSpacer, EuiTitle, useEuiTheme } from '@elastic/eui';
import { flattenObject } from '@kbn/observability-utils/object/flatten_object';
import { GroupedEntitiesGrid } from './grouped_entities_grid';
import type { EntityGroup } from '../../../common/entities';
import { InventoryPanelBadge } from './inventory_panel_badge';
Expand All @@ -29,7 +30,7 @@ export function InventoryGroupAccordion({
isLoading,
}: InventoryGroupAccordionProps) {
const { euiTheme } = useEuiTheme();
const field = group[groupBy];
const field = flattenObject(group)[groupBy];
const [open, setOpen] = useState(false);

const onToggle = useCallback(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import type { ObservabilityElasticsearchClient } from '@kbn/observability-utils/es/client/create_observability_es_client';
import { kqlQuery } from '@kbn/observability-utils/es/queries/kql_query';
import { esqlResultToPlainObjects } from '@kbn/observability-utils/es/utils/esql_result_to_plain_objects';
import { ENTITY_TYPE } from '@kbn/observability-shared-plugin/common';
import { ScalarValue } from '@elastic/elasticsearch/lib/api/types';
import {
Expand Down Expand Up @@ -44,7 +43,7 @@ export async function getEntityGroupsBy({
const limit = `LIMIT ${MAX_NUMBER_OF_ENTITIES}`;
const query = [from, ...where, group, sort, limit].join(' | ');

const groups = await inventoryEsClient.esql('get_entities_groups', {
return inventoryEsClient.esql<EntityGroup>('get_entities_groups', {
query,
filter: {
bool: {
Expand All @@ -53,6 +52,4 @@ export async function getEntityGroupsBy({
},
params,
});

return esqlResultToPlainObjects<EntityGroup>(groups);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function getEntityTypes({
}: {
inventoryEsClient: ObservabilityElasticsearchClient;
}) {
const entityTypesEsqlResponse = await inventoryEsClient.esql<{ [ENTITY_TYPE]: string }>(
const entityTypesEsqlResponse = await inventoryEsClient.esql<{ entity: { type: string } }>(
'get_entity_types',
{
query: `FROM ${ENTITIES_LATEST_ALIAS}
Expand All @@ -25,5 +25,5 @@ export async function getEntityTypes({
}
);

return entityTypesEsqlResponse.flatMap((types) => Object.values(types));
return entityTypesEsqlResponse.map((response) => response.entity.type);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,14 @@ export async function getHasData({
inventoryEsClient: ObservabilityElasticsearchClient;
logger: Logger;
}) {
try {
const esqlResults = await inventoryEsClient.esql<{ _count: number }>('get_has_data', {
query: `FROM ${ENTITIES_LATEST_ALIAS}
const esqlResults = await inventoryEsClient.esql<{ _count: number }>('get_has_data', {
query: `FROM ${ENTITIES_LATEST_ALIAS}
| ${getBuiltinEntityDefinitionIdESQLWhereClause()}
| STATS _count = COUNT(*)
| LIMIT 1`,
});
});

const totalCount = esqlResults[0]._count;
const totalCount = esqlResults[0]._count;

return { hasData: totalCount > 0 };
} catch (e) {
logger.error(e);
return { hasData: false };
}
return { hasData: totalCount > 0 };
}

0 comments on commit 8ba7131

Please sign in to comment.