Skip to content

Commit

Permalink
[Fleet] Replace INTERNAL_POLICY_REASSIGN by POLICY_REASSIGN (#94116)
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet authored Mar 25, 2021
1 parent 80e53d5 commit 00c53c5
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 25 deletions.
3 changes: 1 addition & 2 deletions x-pack/plugins/fleet/common/types/models/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ export type AgentActionType =
| 'UNENROLL'
| 'UPGRADE'
| 'SETTINGS'
// INTERNAL* actions are mean to interupt long polling calls these actions will not be distributed to the agent
| 'INTERNAL_POLICY_REASSIGN';
| 'POLICY_REASSIGN';

export interface NewAgentAction {
type: AgentActionType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
getAgentPolicyActionByIds,
} from '../actions';
import { appContextService } from '../../app_context';
import { getAgentById, updateAgent } from '../crud';
import { updateAgent } from '../crud';

import { toPromiseAbortable, AbortError, createRateLimiter } from './rxjs_utils';

Expand Down Expand Up @@ -262,25 +262,6 @@ export function agentCheckinStateNewActionsFactory() {
return EMPTY;
}

const hasConfigReassign = newActions.some(
(action) => action.type === 'INTERNAL_POLICY_REASSIGN'
);
if (hasConfigReassign) {
return from(getAgentById(esClient, agent.id)).pipe(
concatMap((refreshedAgent) => {
if (!refreshedAgent.policy_id) {
throw new Error('Agent does not have a policy assigned');
}
const newAgentPolicy$ = getOrCreateAgentPolicyObservable(refreshedAgent.policy_id);
return newAgentPolicy$;
}),
rateLimiter(),
concatMap((policyAction) =>
createAgentActionFromPolicyAction(soClient, esClient, agent, policyAction)
)
);
}

return of(newActions);
}),
filter((data) => data !== undefined),
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/fleet/server/services/agents/reassign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function reassignAgent(
await createAgentAction(soClient, esClient, {
agent_id: agentId,
created_at: new Date().toISOString(),
type: 'INTERNAL_POLICY_REASSIGN',
type: 'POLICY_REASSIGN',
});
}

Expand Down Expand Up @@ -164,7 +164,7 @@ export async function reassignAgents(
agentsToUpdate.map((agent) => ({
agent_id: agent.id,
created_at: now,
type: 'INTERNAL_POLICY_REASSIGN',
type: 'POLICY_REASSIGN',
}))
);

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/server/types/models/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const NewAgentActionSchema = schema.oneOf([
schema.literal('POLICY_CHANGE'),
schema.literal('UNENROLL'),
schema.literal('UPGRADE'),
schema.literal('INTERNAL_POLICY_REASSIGN'),
schema.literal('POLICY_REASSIGN'),
]),
data: schema.maybe(schema.any()),
ack_data: schema.maybe(schema.any()),
Expand Down

0 comments on commit 00c53c5

Please sign in to comment.