Skip to content

Commit

Permalink
[Ingest Manager] Better default value for fleet long polling timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed Sep 1, 2020
1 parent 9a27beb commit 33e7f7d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions x-pack/plugins/ingest_manager/common/constants/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const AGENT_TYPE_PERMANENT = 'PERMANENT';
export const AGENT_TYPE_EPHEMERAL = 'EPHEMERAL';
export const AGENT_TYPE_TEMPORARY = 'TEMPORARY';

export const AGENT_POLLING_REQUEST_TIMEOUT_MS = 300000; // 5 minutes
export const AGENT_POLLING_THRESHOLD_MS = 30000;
export const AGENT_POLLING_INTERVAL = 1000;
export const AGENT_UPDATE_LAST_CHECKIN_INTERVAL_MS = 30000;
Expand Down
6 changes: 5 additions & 1 deletion x-pack/plugins/ingest_manager/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { IngestManagerPlugin } from './plugin';
import {
AGENT_POLICY_ROLLOUT_RATE_LIMIT_INTERVAL_MS,
AGENT_POLICY_ROLLOUT_RATE_LIMIT_REQUEST_PER_INTERVAL,
AGENT_POLLING_REQUEST_TIMEOUT_MS,
} from '../common';
export { AgentService, ESIndexPatternService, getRegistryUrl } from './services';
export {
Expand All @@ -29,7 +30,10 @@ export const config = {
fleet: schema.object({
enabled: schema.boolean({ defaultValue: true }),
tlsCheckDisabled: schema.boolean({ defaultValue: false }),
pollingRequestTimeout: schema.number({ defaultValue: 60000 }),
pollingRequestTimeout: schema.number({
defaultValue: AGENT_POLLING_REQUEST_TIMEOUT_MS,
min: 5000,
}),
maxConcurrentConnections: schema.number({ defaultValue: 0 }),
kibana: schema.object({
host: schema.maybe(schema.string()),
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/ingest_manager/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export class IngestManagerPlugin
// we currently only use this global interceptor if fleet is enabled
// since it would run this func on *every* req (other plugins, CSS, etc)
registerLimitedConcurrencyRoutes(core, config);
registerAgentRoutes(router);
registerAgentRoutes(router, config);
registerEnrollmentApiKeyRoutes(router);
registerInstallScriptRoutes({
router,
Expand Down
15 changes: 13 additions & 2 deletions x-pack/plugins/ingest_manager/server/routes/agent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ import * as AgentService from '../../services/agents';
import { postNewAgentActionHandlerBuilder } from './actions_handlers';
import { appContextService } from '../../services';
import { postAgentsUnenrollHandler } from './unenroll_handler';
import { IngestManagerConfigType } from '../..';

export const registerRoutes = (router: IRouter) => {
export const registerRoutes = (router: IRouter, config: IngestManagerConfigType) => {
// Get one
router.get(
{
Expand Down Expand Up @@ -80,12 +81,22 @@ export const registerRoutes = (router: IRouter) => {
getAgentsHandler
);

const pollingRequestTimeout = config.fleet.pollingRequestTimeout;
// Agent checkin
router.post(
{
path: AGENT_API_ROUTES.CHECKIN_PATTERN,
validate: PostAgentCheckinRequestSchema,
options: { tags: [] },
options: {
tags: [],
...(pollingRequestTimeout
? {
timeout: {
idleSocket: pollingRequestTimeout,
},
}
: {}),
},
},
postAgentCheckinHandler
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ export function agentCheckinStateNewActionsFactory() {
}

const stream$ = agentPolicy$.pipe(
timeout(appContextService.getConfig()?.fleet.pollingRequestTimeout || 0),
timeout(
// Set a timeout 3s before the real timeout to have a chance to respond an empty response before socket timeout
Math.max((appContextService.getConfig()?.fleet.pollingRequestTimeout ?? 0) - 3000, 3000)
),
filter((agentPolicy) => shouldCreateAgentPolicyAction(agent, agentPolicy)),
rateLimiter(),
mergeMap((agentPolicy) => createAgentActionFromAgentPolicy(soClient, agent, agentPolicy)),
Expand Down

0 comments on commit 33e7f7d

Please sign in to comment.