Skip to content

Commit

Permalink
add upgrade available button and update agent list endpoint to accept…
Browse files Browse the repository at this point in the history
… showUpgradeable
  • Loading branch information
neptunian committed Oct 1, 2020
1 parent e5e0cb5 commit 011a0bc
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface GetAgentsRequest {
perPage: number;
kuery?: string;
showInactive: boolean;
showUpgradeable?: boolean;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export const AgentListPage: React.FunctionComponent<{}> = () => {

// Agent data states
const [showInactive, setShowInactive] = useState<boolean>(false);

const [showUpgradeable, setShowUpgradeable] = useState<boolean>(false);
// Table and search states
const [search, setSearch] = useState<string>(defaultKuery);
const [selectionMode, setSelectionMode] = useState<SelectionMode>('manual');
Expand Down Expand Up @@ -254,6 +254,7 @@ export const AgentListPage: React.FunctionComponent<{}> = () => {
perPage: pagination.pageSize,
kuery: kuery && kuery !== '' ? kuery : undefined,
showInactive,
showUpgradeable,
},
{
pollIntervalMs: REFRESH_INTERVAL_MS,
Expand Down Expand Up @@ -577,6 +578,17 @@ export const AgentListPage: React.FunctionComponent<{}> = () => {
))}
</div>
</EuiPopover>
<EuiFilterButton
hasActiveFilters={showUpgradeable}
onClick={() => {
setShowUpgradeable(!showUpgradeable);
}}
>
<FormattedMessage
id="xpack.ingestManager.agentList.showUpgradeableFilterLabel"
defaultMessage="Upgrade available"
/>
</EuiFilterButton>
<EuiFilterButton
hasActiveFilters={showInactive}
onClick={() => setShowInactive(!showInactive)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ export const getAgentsHandler: RequestHandler<
page: request.query.page,
perPage: request.query.perPage,
showInactive: request.query.showInactive,
showUpgradeable: request.query.showUpgradeable,
kuery: request.query.kuery,
});
const totalInactive = request.query.showInactive
Expand Down
13 changes: 12 additions & 1 deletion x-pack/plugins/ingest_manager/server/services/agents/crud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
*/
import Boom from 'boom';
import { SavedObjectsClientContract } from 'src/core/server';
import { isAgentUpgradeable } from '../../../common';
import { AGENT_SAVED_OBJECT_TYPE, AGENT_EVENT_SAVED_OBJECT_TYPE } from '../../constants';
import { AgentSOAttributes, Agent, AgentEventSOAttributes, ListWithKuery } from '../../types';
import { escapeSearchQueryPhrase, normalizeKuery, findAllSOs } from '../saved_object';
import { savedObjectToAgent } from './saved_objects';
import { appContextService } from '../../services';

const ACTIVE_AGENT_CONDITION = `${AGENT_SAVED_OBJECT_TYPE}.attributes.active:true`;
const INACTIVE_AGENT_CONDITION = `NOT (${ACTIVE_AGENT_CONDITION})`;
Expand Down Expand Up @@ -41,6 +43,7 @@ export async function listAgents(
sortOrder = 'desc',
kuery,
showInactive = false,
showUpgradeable,
} = options;
const filters = [];

Expand All @@ -52,14 +55,22 @@ export async function listAgents(
filters.push(ACTIVE_AGENT_CONDITION);
}

const { saved_objects: agentSOs, total } = await soClient.find<AgentSOAttributes>({
let { saved_objects: agentSOs, total } = await soClient.find<AgentSOAttributes>({
type: AGENT_SAVED_OBJECT_TYPE,
filter: _joinFilters(filters),
sortField,
sortOrder,
page,
perPage,
});
// filtering for a range on the version string will not work,
// nor does filtering on a flattened field (local_metadata), so filter here
if (showUpgradeable) {
agentSOs = agentSOs.filter((agent) =>
isAgentUpgradeable(savedObjectToAgent(agent), appContextService.getKibanaVersion())
);
total = agentSOs.length;
}

return {
agents: agentSOs.map(savedObjectToAgent),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const GetAgentsRequestSchema = {
perPage: schema.number({ defaultValue: 20 }),
kuery: schema.maybe(schema.string()),
showInactive: schema.boolean({ defaultValue: false }),
showUpgradeable: schema.boolean({ defaultValue: false }),
}),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const ListWithKuerySchema = schema.object({
perPage: schema.maybe(schema.number({ defaultValue: 20 })),
sortField: schema.maybe(schema.string()),
sortOrder: schema.maybe(schema.oneOf([schema.literal('desc'), schema.literal('asc')])),
showUpgradeable: schema.maybe(schema.boolean()),
kuery: schema.maybe(schema.string()),
});

Expand Down

0 comments on commit 011a0bc

Please sign in to comment.