Skip to content

Commit

Permalink
[Ingest Manager] Fix agent config out of date display (#71103)
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet authored Jul 8, 2020
1 parent 90fb7a6 commit 595e9c2
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 48 deletions.
3 changes: 0 additions & 3 deletions x-pack/plugins/ingest_manager/common/openapi/spec_oas3.json
Original file line number Diff line number Diff line change
Expand Up @@ -4146,9 +4146,6 @@
"config_revision": {
"type": ["number", "null"]
},
"config_newest_revision": {
"type": "number"
},
"last_checkin": {
"type": "string"
},
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/ingest_manager/common/types/models/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ interface AgentBase {
default_api_key_id?: string;
config_id?: string;
config_revision?: number | null;
config_newest_revision?: number;
last_checkin?: string;
user_provided_metadata: AgentMetadata;
local_metadata: AgentMetadata;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import React, { useState } from 'react';
import React, { useState, useMemo } from 'react';
import {
EuiBasicTable,
EuiButton,
Expand All @@ -25,7 +25,7 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage, FormattedRelative } from '@kbn/i18n/react';
import { CSSProperties } from 'styled-components';
import { AgentEnrollmentFlyout } from '../components';
import { Agent } from '../../../types';
import { Agent, AgentConfig } from '../../../types';
import {
usePagination,
useCapabilities,
Expand Down Expand Up @@ -220,6 +220,13 @@ export const AgentListPage: React.FunctionComponent<{}> = () => {
});

const agentConfigs = agentConfigsRequest.data ? agentConfigsRequest.data.items : [];
const agentConfigsIndexedById = useMemo(() => {
return agentConfigs.reduce((acc, config) => {
acc[config.id] = config;

return acc;
}, {} as { [k: string]: AgentConfig });
}, [agentConfigs]);
const { isLoading: isAgentConfigsLoading } = agentConfigsRequest;

const columns = [
Expand Down Expand Up @@ -271,9 +278,10 @@ export const AgentListPage: React.FunctionComponent<{}> = () => {
</EuiText>
</EuiFlexItem>
)}
{agent.config_revision &&
agent.config_newest_revision &&
agent.config_newest_revision > agent.config_revision && (
{agent.config_id &&
agent.config_revision &&
agentConfigsIndexedById[agent.config_id] &&
agentConfigsIndexedById[agent.config_id].revision > agent.config_revision && (
<EuiFlexItem grow={false}>
<EuiText color="subdued" size="xs" className="eui-textNoWrap">
<EuiIcon size="m" type="alert" color="warning" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ const savedObjectTypes: { [key: string]: SavedObjectsType } = {
last_updated: { type: 'date' },
last_checkin: { type: 'date' },
config_revision: { type: 'integer' },
config_newest_revision: { type: 'integer' },
default_api_key_id: { type: 'keyword' },
default_api_key: { type: 'binary', index: false },
updated_at: { type: 'date' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { SavedObjectsClientContract } from 'src/core/server';
import { generateEnrollmentAPIKey, deleteEnrollmentApiKeyForConfigId } from './api_keys';
import { updateAgentsForConfigId, unenrollForConfigId } from './agents';
import { unenrollForConfigId } from './agents';
import { outputService } from './output';

export async function agentConfigUpdateEventHandler(
Expand All @@ -26,10 +26,6 @@ export async function agentConfigUpdateEventHandler(
});
}

if (action === 'updated') {
await updateAgentsForConfigId(soClient, configId);
}

if (action === 'deleted') {
await unenrollForConfigId(soClient, configId);
await deleteEnrollmentApiKeyForConfigId(soClient, configId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@ export async function reassignAgent(
await soClient.update<AgentSOAttributes>(AGENT_SAVED_OBJECT_TYPE, agentId, {
config_id: newConfigId,
config_revision: null,
config_newest_revision: config.revision,
});
}
32 changes: 0 additions & 32 deletions x-pack/plugins/ingest_manager/server/services/agents/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,6 @@ import { SavedObjectsClientContract } from 'src/core/server';
import { listAgents } from './crud';
import { AGENT_SAVED_OBJECT_TYPE } from '../../constants';
import { unenrollAgent } from './unenroll';
import { agentConfigService } from '../agent_config';

export async function updateAgentsForConfigId(
soClient: SavedObjectsClientContract,
configId: string
) {
const config = await agentConfigService.get(soClient, configId);
if (!config) {
throw new Error('Config not found');
}
let hasMore = true;
let page = 1;
while (hasMore) {
const { agents } = await listAgents(soClient, {
kuery: `${AGENT_SAVED_OBJECT_TYPE}.config_id:"${configId}"`,
page: page++,
perPage: 1000,
showInactive: true,
});
if (agents.length === 0) {
hasMore = false;
break;
}
const agentUpdate = agents.map((agent) => ({
id: agent.id,
type: AGENT_SAVED_OBJECT_TYPE,
attributes: { config_newest_revision: config.revision },
}));

await soClient.bulkUpdate(agentUpdate);
}
}

export async function unenrollForConfigId(soClient: SavedObjectsClientContract, configId: string) {
let hasMore = true;
Expand Down

0 comments on commit 595e9c2

Please sign in to comment.