From 479438b6d0000648ab89948fed88e38bf1c5e030 Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Mon, 5 Oct 2020 13:10:17 -0400 Subject: [PATCH] [Ingest Manager] Fix agent tests and short polling timeout (#79442) --- .../ingest_manager/server/routes/agent/index.ts | 10 ++++++++-- .../services/agents/checkin/state_new_actions.ts | 6 ++++++ .../apis/fleet/agents/complete_flow.ts | 3 +-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/ingest_manager/server/routes/agent/index.ts b/x-pack/plugins/ingest_manager/server/routes/agent/index.ts index 73ed276ba02e74..87b9fd590364e4 100644 --- a/x-pack/plugins/ingest_manager/server/routes/agent/index.ts +++ b/x-pack/plugins/ingest_manager/server/routes/agent/index.ts @@ -11,7 +11,12 @@ import { IRouter, RouteValidationResultFactory } from 'src/core/server'; import Ajv from 'ajv'; -import { PLUGIN_ID, AGENT_API_ROUTES, LIMITED_CONCURRENCY_ROUTE_TAG } from '../../constants'; +import { + PLUGIN_ID, + AGENT_API_ROUTES, + LIMITED_CONCURRENCY_ROUTE_TAG, + AGENT_POLLING_REQUEST_TIMEOUT_MARGIN_MS, +} from '../../constants'; import { GetAgentsRequestSchema, GetOneAgentRequestSchema, @@ -123,7 +128,8 @@ export const registerRoutes = (router: IRouter, config: IngestManagerConfigType) }, options: { tags: [], - ...(pollingRequestTimeout + // If the timeout is too short, do not set socket idle timeout and rely on Kibana global socket timeout + ...(pollingRequestTimeout && pollingRequestTimeout > AGENT_POLLING_REQUEST_TIMEOUT_MARGIN_MS ? { timeout: { idleSocket: pollingRequestTimeout, diff --git a/x-pack/plugins/ingest_manager/server/services/agents/checkin/state_new_actions.ts b/x-pack/plugins/ingest_manager/server/services/agents/checkin/state_new_actions.ts index 8ae151577fefa2..2481655ccdc6f5 100644 --- a/x-pack/plugins/ingest_manager/server/services/agents/checkin/state_new_actions.ts +++ b/x-pack/plugins/ingest_manager/server/services/agents/checkin/state_new_actions.ts @@ -167,6 +167,12 @@ export async function createAgentActionFromPolicyAction( function getPollingTimeoutMs() { const pollingTimeoutMs = appContextService.getConfig()?.fleet.pollingRequestTimeout ?? 0; + + // If polling timeout is too short do not use margin + if (pollingTimeoutMs <= AGENT_POLLING_REQUEST_TIMEOUT_MARGIN_MS) { + return pollingTimeoutMs; + } + // Set a timeout 20s before the real timeout to have a chance to respond an empty response before socket timeout return Math.max( pollingTimeoutMs - AGENT_POLLING_REQUEST_TIMEOUT_MARGIN_MS, diff --git a/x-pack/test/ingest_manager_api_integration/apis/fleet/agents/complete_flow.ts b/x-pack/test/ingest_manager_api_integration/apis/fleet/agents/complete_flow.ts index d925d77b5b93fd..a59b3ff0890f77 100644 --- a/x-pack/test/ingest_manager_api_integration/apis/fleet/agents/complete_flow.ts +++ b/x-pack/test/ingest_manager_api_integration/apis/fleet/agents/complete_flow.ts @@ -19,8 +19,7 @@ export default function (providerContext: FtrProviderContext) { const supertestWithoutAuth = getSupertestWithoutAuth(providerContext); const esClient = getService('es'); - // Failing: See https://github.com/elastic/kibana/issues/75241 - describe.skip('fleet_agent_flow', () => { + describe('fleet_agent_flow', () => { skipIfNoDockerRegistry(providerContext); before(async () => { await esArchiver.load('empty_kibana');