Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
50d63b6
Fixed alerting_api_integration/security_and_spaces tests failing if a…
YulNaumenko Aug 17, 2020
4b694d1
-
YulNaumenko Aug 17, 2020
ff138da
Fixed get port from range for Slack and webhook simulators, removed s…
YulNaumenko Aug 19, 2020
869d8fa
Added check for listening proxy server
YulNaumenko Aug 19, 2020
63871c6
changed logger to debug removed not useful error
YulNaumenko Aug 19, 2020
6a30d5c
Merge remote-tracking branch 'upstream/master' into actions-proxy-fix…
YulNaumenko Aug 19, 2020
076b8e8
-
YulNaumenko Aug 20, 2020
045097f
changed proxy to dynamic target in a single place
YulNaumenko Aug 21, 2020
0c35062
test retry
YulNaumenko Aug 21, 2020
145b4d7
-
YulNaumenko Aug 21, 2020
3658bdf
Merge remote-tracking branch upstream/master into actions-proxy-fix-l…
YulNaumenko Aug 21, 2020
c74bf3e
-
YulNaumenko Aug 21, 2020
f8560c4
-
YulNaumenko Aug 22, 2020
bad2d49
-
YulNaumenko Aug 23, 2020
3626191
test with no cleanup
YulNaumenko Aug 24, 2020
1d26ae7
-
YulNaumenko Aug 24, 2020
bfdb97a
Merge remote-tracking branch 'upstream/master' into actions-proxy-fix…
YulNaumenko Aug 24, 2020
7aef590
-
YulNaumenko Aug 24, 2020
0e713b3
-
YulNaumenko Aug 24, 2020
5712d78
-
YulNaumenko Aug 24, 2020
afd4809
Added environment variable ALERTING_PROXY_PORT
YulNaumenko Aug 24, 2020
e30ef3e
fixed type checks
YulNaumenko Aug 24, 2020
d1e4077
Merge remote-tracking branch 'upstream/master' into actions-proxy-fix…
YulNaumenko Aug 24, 2020
9e4e5d7
fixed clean up proxy server port
YulNaumenko Aug 24, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions vars/kibanaPipeline.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def withFunctionalTestEnv(List additionalEnvs = [], Closure closure) {
def esPort = "61${parallelId}2"
def esTransportPort = "61${parallelId}3"
def ingestManagementPackageRegistryPort = "61${parallelId}4"
def alertingProxyPort = "61${parallelId}5"

withEnv([
"CI_GROUP=${parallelId}",
Expand All @@ -98,6 +99,7 @@ def withFunctionalTestEnv(List additionalEnvs = [], Closure closure) {
"TEST_ES_TRANSPORT_PORT=${esTransportPort}",
"KBN_NP_PLUGINS_BUILT=true",
"INGEST_MANAGEMENT_PACKAGE_REGISTRY_PORT=${ingestManagementPackageRegistryPort}",
"ALERTING_PROXY_PORT=${alertingProxyPort}"
] + additionalEnvs) {
closure()
}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@
"font-awesome": "4.7.0",
"formsy-react": "^1.1.5",
"fp-ts": "^2.3.1",
"get-port": "^4.2.0",
"get-port": "^5.0.0",
"getos": "^3.1.0",
"git-url-parse": "11.1.2",
"github-markdown-css": "^2.10.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ export const createExternalService = (

const createIncident = async ({ incident }: ExternalServiceParams) => {
try {
logger.warn(`incident error : ${JSON.stringify(proxySettings)}`);
logger.warn(`incident error : ${url}`);
const res = await request({
axios: axiosInstance,
url: `${incidentUrl}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ describe('execute()', () => {
rejectUnauthorizedCertificates: false,
},
});
expect(mockedLogger.info).toHaveBeenCalledWith(
expect(mockedLogger.debug).toHaveBeenCalledWith(
'IncomingWebhook was called with proxyUrl https://someproxyhost'
);
});
Expand Down
4 changes: 1 addition & 3 deletions x-pack/plugins/actions/server/builtin_action_types/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async function slackExecutor(
let proxyAgent: HttpsProxyAgent | HttpProxyAgent | undefined;
if (execOptions.proxySettings) {
proxyAgent = getProxyAgent(execOptions.proxySettings, logger);
logger.info(`IncomingWebhook was called with proxyUrl ${execOptions.proxySettings.proxyUrl}`);
logger.debug(`IncomingWebhook was called with proxyUrl ${execOptions.proxySettings.proxyUrl}`);
}

try {
Expand All @@ -130,8 +130,6 @@ async function slackExecutor(
});
result = await webhook.send(message);
} catch (err) {
logger.error(`error on ${actionId} slack event: ${err.message}`);

if (err.original == null || err.original.response == null) {
return serviceErrorResult(actionId, err.message);
}
Expand Down
8 changes: 6 additions & 2 deletions x-pack/test/alerting_api_integration/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ export function createTestConfig(name: string, options: CreateTestConfigOptions)
fs.statSync(path.resolve(__dirname, 'fixtures', 'plugins', file)).isDirectory()
);

const proxyPort =
process.env.ALERTING_PROXY_PORT ?? (await getPort({ port: getPort.makeRange(6200, 6300) }));
const actionsProxyUrl = options.enableActionsProxy
? [`--xpack.actions.proxyUrl=http://localhost:${await getPort()}`]
? [
`--xpack.actions.proxyUrl=http://localhost:${proxyPort}`,
'--xpack.actions.rejectUnauthorizedCertificates=false',
]
: [];

return {
Expand Down Expand Up @@ -92,7 +97,6 @@ export function createTestConfig(name: string, options: CreateTestConfigOptions)
'--xpack.encryptedSavedObjects.encryptionKey="wuGNaIhoMpk5sO4UBxgr3NyW1sFcLgIf"',
`--xpack.actions.enabledActionTypes=${JSON.stringify(enabledActionTypes)}`,
...actionsProxyUrl,
'--xpack.actions.rejectUnauthorizedCertificates=false',

'--xpack.eventLog.logEntries=true',
`--xpack.actions.preconfigured=${JSON.stringify({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ export async function initPlugin() {
response.statusCode = 400;
response.end('unknown request to slack simulator');
});
} else {
response.writeHead(400, { 'Content-Type': 'text/plain' });
response.end('Not supported http method to request slack simulator');
}
});
}
41 changes: 28 additions & 13 deletions x-pack/test/alerting_api_integration/common/lib/get_proxy_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,42 @@
* you may not use this file except in compliance with the Elastic License.
*/

import http from 'http';
import httpProxy from 'http-proxy';
import { ToolingLog } from '@kbn/dev-utils';

export const getHttpProxyServer = (
targetUrl: string,
onProxyResHandler: (proxyRes?: unknown, req?: unknown, res?: unknown) => void
): httpProxy => {
const proxyServer = httpProxy.createProxyServer({
target: targetUrl,
secure: false,
selfHandleResponse: false,
});
proxyServer.on('proxyRes', (proxyRes: unknown, req: unknown, res: unknown) => {
onProxyResHandler(proxyRes, req, res);
export const getHttpProxyServer = async (
defaultKibanaTargetUrl: string,
kbnTestServerConfig: any,
log: ToolingLog
): Promise<http.Server> => {
const proxy = httpProxy.createProxyServer({ secure: false, selfHandleResponse: false });

const proxyPort = getProxyPort(kbnTestServerConfig);
const proxyServer = http.createServer((req: http.IncomingMessage, res: http.ServerResponse) => {
const targetUrl = new URL(req.url ?? defaultKibanaTargetUrl);

if (targetUrl.hostname !== 'some.non.existent.com') {
proxy.web(req, res, {
target: `${targetUrl.protocol}//${targetUrl.hostname}:${targetUrl.port}`,
});
} else {
res.writeHead(500, { 'Content-Type': 'text/plain' });
res.write('error on call some.non.existent.com');
res.end();
}
});

proxyServer.listen(proxyPort);

return proxyServer;
};

export const getProxyUrl = (kbnTestServerConfig: any) => {
export const getProxyPort = (kbnTestServerConfig: any): number => {
const proxyUrl = kbnTestServerConfig
.find((val: string) => val.startsWith('--xpack.actions.proxyUrl='))
.replace('--xpack.actions.proxyUrl=', '');

return new URL(proxyUrl);
const urlObject = new URL(proxyUrl);
return Number(urlObject.port);
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import expect from '@kbn/expect';

import { getHttpProxyServer, getProxyUrl } from '../../../../common/lib/get_proxy_server';
import { FtrProviderContext } from '../../../../common/ftr_provider_context';

import {
Expand Down Expand Up @@ -36,7 +35,6 @@ const mapping = [
export default function jiraTest({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const kibanaServer = getService('kibanaServer');
const config = getService('config');

const mockJira = {
config: {
Expand Down Expand Up @@ -75,20 +73,12 @@ export default function jiraTest({ getService }: FtrProviderContext) {
};

let jiraSimulatorURL: string = '<could not determine kibana url>';
let proxyServer: any;
let proxyHaveBeenCalled = false;

// FLAKY: https://github.com/elastic/kibana/issues/75722
describe.skip('Jira', () => {
describe('Jira', () => {
before(() => {
jiraSimulatorURL = kibanaServer.resolveUrl(
getExternalServiceSimulatorPath(ExternalServiceSimulator.JIRA)
);
proxyServer = getHttpProxyServer(kibanaServer.resolveUrl('/'), () => {
proxyHaveBeenCalled = true;
});
const proxyUrl = getProxyUrl(config.get('kbnTestServer.serverArgs'));
proxyServer.listen(Number(proxyUrl.port));
});

describe('Jira - Action Creation', () => {
Expand Down Expand Up @@ -539,8 +529,6 @@ export default function jiraTest({ getService }: FtrProviderContext) {
})
.expect(200);

expect(proxyHaveBeenCalled).to.equal(true);

expect(body).to.eql({
status: 'ok',
actionId: simulatedActionId,
Expand All @@ -554,9 +542,5 @@ export default function jiraTest({ getService }: FtrProviderContext) {
});
});
});

after(() => {
proxyServer.close();
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import expect from '@kbn/expect';

import { getHttpProxyServer, getProxyUrl } from '../../../../common/lib/get_proxy_server';
import { FtrProviderContext } from '../../../../common/ftr_provider_context';

import {
Expand All @@ -18,26 +17,16 @@ import {
export default function pagerdutyTest({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const kibanaServer = getService('kibanaServer');
const config = getService('config');

// FLAKY: https://github.com/elastic/kibana/issues/75386
describe.skip('pagerduty action', () => {
describe('pagerduty action', () => {
let simulatedActionId = '';
let pagerdutySimulatorURL: string = '<could not determine kibana url>';
let proxyServer: any;
let proxyHaveBeenCalled = false;

// need to wait for kibanaServer to settle ...
before(() => {
pagerdutySimulatorURL = kibanaServer.resolveUrl(
getExternalServiceSimulatorPath(ExternalServiceSimulator.PAGERDUTY)
);

proxyServer = getHttpProxyServer(kibanaServer.resolveUrl('/'), () => {
proxyHaveBeenCalled = true;
});
const proxyUrl = getProxyUrl(config.get('kbnTestServer.serverArgs'));
proxyServer.listen(Number(proxyUrl.port));
});

it('should return successfully when passed valid create parameters', async () => {
Expand Down Expand Up @@ -155,7 +144,6 @@ export default function pagerdutyTest({ getService }: FtrProviderContext) {
},
})
.expect(200);
expect(proxyHaveBeenCalled).to.equal(true);

expect(result).to.eql({
status: 'ok',
Expand Down Expand Up @@ -215,9 +203,5 @@ export default function pagerdutyTest({ getService }: FtrProviderContext) {
expect(result.message).to.match(/error posting pagerduty event: http status 502/);
expect(result.retry).to.equal(true);
});

after(() => {
proxyServer.close();
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import expect from '@kbn/expect';

import { getHttpProxyServer, getProxyUrl } from '../../../../common/lib/get_proxy_server';
import { FtrProviderContext } from '../../../../common/ftr_provider_context';

import {
Expand Down Expand Up @@ -36,7 +35,6 @@ const mapping = [
export default function resilientTest({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const kibanaServer = getService('kibanaServer');
const config = getService('config');

const mockResilient = {
config: {
Expand Down Expand Up @@ -75,19 +73,12 @@ export default function resilientTest({ getService }: FtrProviderContext) {
};

let resilientSimulatorURL: string = '<could not determine kibana url>';
let proxyServer: any;
let proxyHaveBeenCalled = false;

describe('IBM Resilient', () => {
before(() => {
resilientSimulatorURL = kibanaServer.resolveUrl(
getExternalServiceSimulatorPath(ExternalServiceSimulator.RESILIENT)
);
proxyServer = getHttpProxyServer(kibanaServer.resolveUrl('/'), () => {
proxyHaveBeenCalled = true;
});
const proxyUrl = getProxyUrl(config.get('kbnTestServer.serverArgs'));
proxyServer.listen(Number(proxyUrl.port));
});

describe('IBM Resilient - Action Creation', () => {
Expand Down Expand Up @@ -538,8 +529,6 @@ export default function resilientTest({ getService }: FtrProviderContext) {
})
.expect(200);

expect(proxyHaveBeenCalled).to.equal(true);

expect(body).to.eql({
status: 'ok',
actionId: simulatedActionId,
Expand All @@ -553,9 +542,5 @@ export default function resilientTest({ getService }: FtrProviderContext) {
});
});
});

after(() => {
proxyServer.close();
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import expect from '@kbn/expect';

import { getHttpProxyServer, getProxyUrl } from '../../../../common/lib/get_proxy_server';
import { FtrProviderContext } from '../../../../common/ftr_provider_context';

import {
Expand Down Expand Up @@ -36,7 +35,6 @@ const mapping = [
export default function servicenowTest({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const kibanaServer = getService('kibanaServer');
const config = getService('config');

const mockServiceNow = {
config: {
Expand Down Expand Up @@ -74,21 +72,12 @@ export default function servicenowTest({ getService }: FtrProviderContext) {
};

let servicenowSimulatorURL: string = '<could not determine kibana url>';
let proxyServer: any;
let proxyHaveBeenCalled = false;

// FLAKY: https://github.com/elastic/kibana/issues/75522
describe.skip('ServiceNow', () => {
describe('ServiceNow', () => {
before(() => {
servicenowSimulatorURL = kibanaServer.resolveUrl(
getExternalServiceSimulatorPath(ExternalServiceSimulator.SERVICENOW)
);

proxyServer = getHttpProxyServer(kibanaServer.resolveUrl('/'), () => {
proxyHaveBeenCalled = true;
});
const proxyUrl = getProxyUrl(config.get('kbnTestServer.serverArgs'));
proxyServer.listen(Number(proxyUrl.port));
});

describe('ServiceNow - Action Creation', () => {
Expand Down Expand Up @@ -459,7 +448,6 @@ export default function servicenowTest({ getService }: FtrProviderContext) {
},
})
.expect(200);
expect(proxyHaveBeenCalled).to.equal(true);

expect(result).to.eql({
status: 'ok',
Expand All @@ -474,9 +462,5 @@ export default function servicenowTest({ getService }: FtrProviderContext) {
});
});
});

after(() => {
proxyServer.close();
});
});
}
Loading