Skip to content

Commit

Permalink
[6.x] Upgrade Hapi in legacy platform to v17 (#21707) (#24608)
Browse files Browse the repository at this point in the history
* Upgrade Hapi in legacy platform to v17 (#21707)

* Disable even-better monitoring

* Upgrade to Hapi v15

* Upgrade to Hapi v16

* Handle optional req params correctly

* Update http and kbnServer

* Get mocha tests passing

* Convert `reply` usages [wip]

* Fix Joi and Plugin incompatibilities

* Get server up and running

* Get basic logging working

* Fix optimizer

* Fix recent route handlers

* Various fixes

* Fix recent routes

* Upgrade wreck for async/await

* Fix mocha tests

* Fix joi issues

* Fix xpack jest tests

* Fix recent routes

* Fix tests

* Fix index setup

* Decouple monitoring stats collection from good plugin

* Update reload logging test to work

* Reimplement logging with updated good plugin

* Fix unit tests

* Fix getConnections back

* Make LegacyLoggingServer compatible with Hapi v17

* Update joi types

* Fix x-pack unit tests

* Remove stray debugger

* Remove hapi-compat

* Fix API integrations

* Upgrade boom

* Fix security plugin

* Misc fixes

* bump

* Fix licensePreRoutingFactory

* Fix failing integration tests

* Remove unnecessary test change

* Remove hapi-latest package

* fx

* Various cleanup

* Fix race condition in oppsy events

* Use elastic/good fork

* Fix boom.wrap and hapi-latest changes

* Simplify LegacyLoggingServer updates

* package.json cleanup + test fix

* yarn.lock cleanup

* Change good tag

* Fixes

* Change return err -> throw err in routes

* Fix await returns

* Fix new load_data test

* Make cookie security flags consistent

* tmp doc

* Fix types

* Fix tests

* Upgrade canvas plugin

* Move good package to published @elastic/good one

* Fix SO test

* Fix logging reloading

* Update APM apis

* Fix error logging

* Fix logging test

* Convert spaces plugin

* Add validation error shim

* Remove 7.0 release notes

* Await renderApp

* Fix ccr routes

* Prevent header popovers from scrolling with page content (#23850)

* Fix spaces test

* new yarn.lock-s

* Fix spaces tests

* Remove h2o2-latest

* Fix @types/hapi

* Upgrade InfraOps plugin

* Fix package.json

* Add back isSameSite: false

* Upgrade beats_management plugin

* Update snapshot

* Fix InfraOps

* Upgrade kql_telemetry

* Merge upstream/master

* Upgrade apm and ml

* Put snapshot test back

* Fx beats

* Upgrade rollups

* Update boom usages in new plugins

* Update url shortener

* Don't throw errors in optimizer (#24660)
  • Loading branch information
joshdover authored Oct 26, 2018
1 parent fe94151 commit 306d06c
Show file tree
Hide file tree
Showing 362 changed files with 3,033 additions and 3,496 deletions.
6 changes: 3 additions & 3 deletions docs/development/core/development-basepath.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ Append `request.getBasePath()` to any absolute URL path.
const basePath = server.config().get('server.basePath');
server.route({
path: '/redirect',
handler(request, reply) {
reply.redirect(`${request.getBasePath()}/otherLocation`);
handler(request, h) {
return h.redirect(`${request.getBasePath()}/otherLocation`);
}
});
-----------
Expand Down Expand Up @@ -84,4 +84,4 @@ or `yarn start`.
["source","shell"]
-----------
yarn start --no-base-path
-----------
-----------
25 changes: 13 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"dependencies": {
"@elastic/eui": "4.5.1",
"@elastic/filesaver": "1.1.2",
"@elastic/good": "8.1.1-kibana1",
"@elastic/numeral": "2.3.2",
"@elastic/ui-ace": "0.2.3",
"@kbn/babel-preset": "link:packages/kbn-babel-preset",
Expand All @@ -109,7 +110,7 @@
"babel-polyfill": "6.20.0",
"babel-register": "6.18.0",
"bluebird": "2.9.34",
"boom": "5.2.0",
"boom": "^7.2.0",
"brace": "0.11.1",
"cache-loader": "1.0.3",
"chalk": "^2.4.1",
Expand All @@ -125,7 +126,6 @@
"elasticsearch": "^15.1.1",
"elasticsearch-browser": "^15.1.1",
"encode-uri-query": "1.0.0",
"even-better": "7.0.2",
"execa": "^0.10.0",
"expiry-js": "0.1.7",
"extract-text-webpack-plugin": "3.0.1",
Expand All @@ -135,16 +135,15 @@
"glob": "^7.1.2",
"glob-all": "^3.1.0",
"good-squeeze": "2.1.0",
"h2o2": "5.1.1",
"h2o2-latest": "npm:h2o2@8.1.2",
"h2o2": "^8.1.2",
"handlebars": "4.0.5",
"hapi": "14.2.0",
"hapi-latest": "npm:hapi@17.5.0",
"hapi": "^17.5.3",
"hjson": "3.1.0",
"hoek": "^5.0.4",
"http-proxy-agent": "^2.1.0",
"https-proxy-agent": "^2.2.1",
"inert": "4.0.2",
"joi": "10.4.1",
"inert": "^5.1.0",
"joi": "^13.5.2",
"jquery": "^3.3.1",
"js-yaml": "3.4.1",
"json-stringify-pretty-compact": "1.0.4",
Expand All @@ -168,6 +167,7 @@
"ngreact": "0.5.1",
"no-ui-slider": "1.2.0",
"node-fetch": "1.3.2",
"oppsy": "^2.0.0",
"pegjs": "0.9.0",
"postcss-loader": "2.0.6",
"prop-types": "15.5.8",
Expand Down Expand Up @@ -221,11 +221,11 @@
"vega-lite": "^2.4.0",
"vega-schema-url-parser": "1.0.0",
"vega-tooltip": "^0.9.14",
"vision": "4.1.0",
"vision": "^5.3.3",
"webpack": "3.6.0",
"webpack-merge": "4.1.0",
"whatwg-fetch": "^2.0.3",
"wreck": "12.4.0",
"wreck": "^14.0.2",
"x-pack": "link:x-pack",
"yauzl": "2.7.0"
},
Expand Down Expand Up @@ -256,10 +256,11 @@
"@types/fetch-mock": "^5.12.2",
"@types/getopts": "^2.0.0",
"@types/glob": "^5.0.35",
"@types/hapi-latest": "npm:@types/hapi@17.0.12",
"@types/hapi": "^17.0.18",
"@types/has-ansi": "^3.0.0",
"@types/hoek": "^4.1.3",
"@types/jest": "^23.3.1",
"@types/joi": "^10.4.4",
"@types/joi": "^13.4.2",
"@types/jquery": "^3.3.6",
"@types/js-yaml": "^3.11.1",
"@types/listr": "^0.13.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-config-schema/src/internals/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import * as Joi from 'joi';
import Joi from 'joi';
import {
AnySchema,
JoiRoot,
Expand Down
7 changes: 1 addition & 6 deletions packages/kbn-config-schema/src/types/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,7 @@ export abstract class Type<V> {
return error;
}

const { context = {}, type, path: rawPath, message } = error;

// Before v11.0.0 Joi reported paths as `.`-delimited strings, but more
// recent version use arrays instead. Once we upgrade Joi, we should just
// remove this split logic and use `path` provided by Joi directly.
const path = rawPath ? rawPath.split('.') : [];
const { context = {}, type, path, message } = error;

const errorHandleResult = this.handleError(type, context, path);
if (errorHandleResult instanceof SchemaTypeError) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ export default function (server) {
server.route({
path: '/api/<%= name %>/example',
method: 'GET',
handler(req, reply) {
reply({ time: (new Date()).toISOString() });
handler() {
return { time: (new Date()).toISOString() };
}
});

Expand Down

This file was deleted.

39 changes: 12 additions & 27 deletions src/cli/serve/integration_tests/reload_logging_config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import { writeFileSync } from 'fs';
import { relative, resolve } from 'path';
import { safeDump } from 'js-yaml';
import es from 'event-stream';
import stripAnsi from 'strip-ansi';
import { getConfigFromFiles } from '../../../core/server/config';
import { getConfigFromFiles } from '../../../core/server/config/read_config';

const testConfigFile = follow('__fixtures__/reload_logging_config/kibana.test.yml');
const kibanaPath = follow('../../../../scripts/kibana.js');
Expand All @@ -42,19 +41,7 @@ function setLoggingJson(enabled) {
writeFileSync(testConfigFile, yaml);
}

const prepareJson = obj => ({
...obj,
pid: '## PID ##',
'@timestamp': '## @timestamp ##'
});

const prepareLogLine = str =>
stripAnsi(str.replace(
/\[\d{2}:\d{2}:\d{2}.\d{3}\]/,
'[## timestamp ##]'
));

describe.skip('Server logging configuration', function () {
describe('Server logging configuration', function () {
let child;
let isJson;

Expand All @@ -80,20 +67,23 @@ describe.skip('Server logging configuration', function () {
});
} else {
it('should be reloadable via SIGHUP process signaling', function (done) {
expect.assertions(1);
expect.assertions(3);

child = spawn('node', [kibanaPath, '--config', testConfigFile]);

child.on('error', err => {
done(new Error(`error in child process while attempting to reload config. ${err.stack || err.message || err}`));
});

const lines = [];
let sawJson = false;
let sawNonjson = false;

child.on('exit', _code => {
const code = _code === null ? 0 : _code;

expect({ code, lines }).toMatchSnapshot();
expect(code).toEqual(0);
expect(sawJson).toEqual(true);
expect(sawNonjson).toEqual(true);
done();
});

Expand All @@ -107,23 +97,18 @@ describe.skip('Server logging configuration', function () {

if (isJson) {
const data = JSON.parse(line);
lines.push(prepareJson(data));
sawJson = true;

if (data.tags.includes('listening')) {
switchToPlainTextLog();
}
} else if (line.startsWith('{')) {
// We have told Kibana to stop logging json, but it hasn't completed
// the switch yet, so we verify the messages that are logged while
// switching over.

const data = JSON.parse(line);
lines.push(prepareJson(data));
// the switch yet, so we ignore before switching over.
} else {
// Kibana has successfully stopped logging json, so we verify the
// log line and kill the server.
// Kibana has successfully stopped logging json, so kill the server.

lines.push(prepareLogLine(line));
sawNonjson = true;

child.kill();
child = undefined;
Expand Down
42 changes: 20 additions & 22 deletions src/cli_plugin/install/downloaders/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import Wreck from 'wreck';
import Progress from '../progress';
import { fromNode as fn } from 'bluebird';
import { createWriteStream } from 'fs';
import HttpProxyAgent from 'http-proxy-agent';
import HttpsProxyAgent from 'https-proxy-agent';
Expand All @@ -41,32 +40,31 @@ function getProxyAgent(sourceUrl, logger) {
}
}

function sendRequest({ sourceUrl, timeout }, logger) {
async function sendRequest({ sourceUrl, timeout }, logger) {
const maxRedirects = 11; //Because this one goes to 11.
return fn(cb => {
const reqOptions = { timeout, redirects: maxRedirects };
const proxyAgent = getProxyAgent(sourceUrl, logger);
const reqOptions = { timeout, redirects: maxRedirects };
const proxyAgent = getProxyAgent(sourceUrl, logger);

if (proxyAgent) {
reqOptions.agent = proxyAgent;
}

const req = Wreck.request('GET', sourceUrl, reqOptions, (err, resp) => {
if (err) {
if (err.code === 'ECONNREFUSED') {
err = new Error('ENOTFOUND');
}
if (proxyAgent) {
reqOptions.agent = proxyAgent;
}

return cb(err);
}
try {
const promise = Wreck.request('GET', sourceUrl, reqOptions);
const req = promise.req;
const resp = await promise;
if (resp.statusCode >= 400) {
throw new Error('ENOTFOUND');
}

if (resp.statusCode >= 400) {
return cb(new Error('ENOTFOUND'));
}
return { req, resp };
} catch (err) {
if (err.code === 'ECONNREFUSED') {
err = new Error('ENOTFOUND');
}

cb(null, { req, resp });
});
});
throw err;
}
}

function downloadResponse({ resp, targetPath, progress }) {
Expand Down
3 changes: 3 additions & 0 deletions src/core/server/http/__snapshots__/http_server.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ Object {
"maxBytes": 1024,
},
"validate": Object {
"failAction": [Function],
"options": Object {
"abortEarly": false,
},
},
},
"state": Object {
"isHttpOnly": true,
"isSameSite": false,
"strictHeader": false,
},
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/server/http/base_path_proxy_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { ByteSizeValue } from '@kbn/config-schema';
import { Server } from 'hapi-latest';
import { Server } from 'hapi';
import { Agent as HttpsAgent, ServerOptions as TlsOptions } from 'https';
import { sample } from 'lodash';
import { DevConfig } from '../dev';
Expand Down Expand Up @@ -66,7 +66,7 @@ export class BasePathProxyServer {

// Register hapi plugin that adds proxying functionality. It can be configured
// through the route configuration object (see { handler: { proxy: ... } }).
await this.server.register({ plugin: require('h2o2-latest') });
await this.server.register({ plugin: require('h2o2') });

if (this.httpConfig.ssl.enabled) {
const tlsOptions = serverOptions.tls as TlsOptions;
Expand Down
Loading

0 comments on commit 306d06c

Please sign in to comment.