Unverified Commit 21a7e7ba authored by Jeremy Morrell's avatar Jeremy Morrell Committed by GitHub

Add node 12 as a support / tested version for Node Metrics beta (#662)

parent a7994e4b
...@@ -8,7 +8,7 @@ TAG_NAME=${1:-} ...@@ -8,7 +8,7 @@ TAG_NAME=${1:-}
PLUGIN_DIR=$(dirname $0) PLUGIN_DIR=$(dirname $0)
handle_failure() { handle_failure() {
echo "Failure running script." echo "Failure running script on line $1."
echo "This may be rate-limiting from Github if you've run this script a few times. Here is the rate limit response:" echo "This may be rate-limiting from Github if you've run this script a few times. Here is the rate limit response:"
...@@ -34,6 +34,8 @@ download() { ...@@ -34,6 +34,8 @@ download() {
delete_old_plugin() { delete_old_plugin() {
local dir=${1} local dir=${1}
rm -f "$dir/heroku-nodejs-plugin-node-12.sha512"
rm -f "$dir/heroku-nodejs-plugin-node-12.tar.gz"
rm -f "$dir/heroku-nodejs-plugin-node-11.sha512" rm -f "$dir/heroku-nodejs-plugin-node-11.sha512"
rm -f "$dir/heroku-nodejs-plugin-node-11.tar.gz" rm -f "$dir/heroku-nodejs-plugin-node-11.tar.gz"
rm -f "$dir/heroku-nodejs-plugin-node-10.sha512" rm -f "$dir/heroku-nodejs-plugin-node-10.sha512"
...@@ -64,6 +66,10 @@ download_assets_for_release() { ...@@ -64,6 +66,10 @@ download_assets_for_release() {
# Node 11 # Node 11
download "https://github.com/heroku/heroku-nodejs-plugin/releases/download/$tag/heroku-nodejs-plugin-node-11-$tag.sha512" "$dir/heroku-nodejs-plugin-node-11.sha512" download "https://github.com/heroku/heroku-nodejs-plugin/releases/download/$tag/heroku-nodejs-plugin-node-11-$tag.sha512" "$dir/heroku-nodejs-plugin-node-11.sha512"
download "https://github.com/heroku/heroku-nodejs-plugin/releases/download/$tag/heroku-nodejs-plugin-node-11-$tag.tar.gz" "$dir/heroku-nodejs-plugin-node-11.tar.gz" download "https://github.com/heroku/heroku-nodejs-plugin/releases/download/$tag/heroku-nodejs-plugin-node-11-$tag.tar.gz" "$dir/heroku-nodejs-plugin-node-11.tar.gz"
# Node 12
download "https://github.com/heroku/heroku-nodejs-plugin/releases/download/$tag/heroku-nodejs-plugin-node-12-$tag.sha512" "$dir/heroku-nodejs-plugin-node-12.sha512"
download "https://github.com/heroku/heroku-nodejs-plugin/releases/download/$tag/heroku-nodejs-plugin-node-12-$tag.tar.gz" "$dir/heroku-nodejs-plugin-node-12.tar.gz"
} }
test_hash() { test_hash() {
...@@ -81,7 +87,7 @@ test_hash() { ...@@ -81,7 +87,7 @@ test_hash() {
fi fi
} }
trap 'handle_failure' ERR trap 'handle_failure ${LINENO}' ERR
if [[ -z $TAG_NAME ]]; then if [[ -z $TAG_NAME ]]; then
TAG_NAME=$(get_latest_release) TAG_NAME=$(get_latest_release)
...@@ -100,5 +106,6 @@ test_hash 8 $PLUGIN_DIR ...@@ -100,5 +106,6 @@ test_hash 8 $PLUGIN_DIR
test_hash 9 $PLUGIN_DIR test_hash 9 $PLUGIN_DIR
test_hash 10 $PLUGIN_DIR test_hash 10 $PLUGIN_DIR
test_hash 11 $PLUGIN_DIR test_hash 11 $PLUGIN_DIR
test_hash 12 $PLUGIN_DIR
echo "Done" echo "Done"
10e91fb8f741a42226fe91daf41a30032f6950f560622ce4523766d93dfd9d01dc88b3d5bfb26968d69d5f8fb6c61f0b35db310f61c366ae0c8d48c9181ee02c heroku-nodejs-plugin-node-10-v4.tar.gz d6ad0f45d5564f324147f590ce9ac39c5973a64dfb1905eb993dfcf3dce21b6934a7821ffbd853ff30e89952ba17e7667809152e187453d7c18579d945a5f8bd heroku-nodejs-plugin-node-10-v5.tar.gz
6d0732e32f6cb2a818c415c5fc454912113da273c3b158124c630db473aa0b157fc81c41dd90de887a804e3c2c2eae0b9897d0da329b7a6e52b9cf27db4e5d0a heroku-nodejs-plugin-node-11-v4.tar.gz 0afc36d4268b7ce3dd1c59813d7727a1bae715645bc0fb006ca992ccd028df692e31d2a4df697ab08d6b4baad03cd6ebef8525e481e0c5cf12e810c30e1da0cb heroku-nodejs-plugin-node-11-v5.tar.gz
0020b60fd3aebcc1fb13770e3445a93c0633579853ee0d31d3dc12d02e4a8a1d418a4d4add2145da46f9d2820f6ae1e412a0beb4eb3e46d7fc8326d2e2d8248d heroku-nodejs-plugin-node-12-v5.tar.gz
82a7f67bf61490d40aa69455a6a1fd7459f9fc219dfe9b0ac65cf7345e8a1c10070ce96ef42eecc5eb82fb5d7ea74b69e1a060c44f0a438eb02e81fd109c2ea4 heroku-nodejs-plugin-node-8-v4.tar.gz d96566824853bc7657fbf2f651067ed0b1747e4d6b4b9b443df6f2d490742b4e571dff5165e68c6d8af44501af0bdddd98e71eeb5fcc9816348453a1f8a314d9 heroku-nodejs-plugin-node-8-v5.tar.gz
d7bca7b45d0852e082103041b7a5d1331470074223314273275c4cd8d09ef6174c14b270ede7f501e6280e935814535783a8d4050d9e21a8918b1ab81f444870 heroku-nodejs-plugin-node-9-v4.tar.gz eefbf22a508e0fd4dea303a7d247a4c6ebb60803c5221e43dd6a9921332ad32791f6b4e95a3379c519290a6767a1dc797f3e68ed583427a53695f47c7b80ccdd heroku-nodejs-plugin-node-9-v5.tar.gz
require_relative '../spec_helper'
describe "Node Metrics for v12.x" do
context "test metrics for Node v12.x app" do
let(:app) {
Hatchet::Runner.new(
"spec/fixtures/repos/node-12-metrics",
config: {
"HEROKU_METRICS_URL" => "http://localhost:3000",
"METRICS_INTERVAL_OVERRIDE" => "10000"
}
)
}
it "should deploy" do
app.deploy do |app|
data = successful_json_body(app)
expect(data["gauges"]["node.eventloop.delay.ms.max"]).to be >= 2000
expect(data["counters"]["node.gc.collections"]).to be >= 0
expect(data["counters"]["node.gc.young.collections"]).to be >= 0
expect(data["counters"]["node.gc.old.collections"]).to be >= 0
end
end
end
end
require_relative '../spec_helper'
describe "Hello World for Node v12.x" do
context "a single-process Node v12.x app" do
let(:app) {
Hatchet::Runner.new("spec/fixtures/repos/node-12")
}
it "should deploy successfully" do
app.deploy do |app|
expect(successful_body(app).strip).to eq("Hello, world!")
end
end
end
end
{
"name": "node-metrics-test-app",
"version": "1.0.0",
"engines": {
"node": "12.x"
},
"main": "index.js",
"license": "MIT",
"devDependencies": {},
"dependencies": {}
}
#!/usr/bin/env node
const http = require('http');
const EventEmitter = require('events');
const PORT = process.env.PORT || 5000;
const Events = new EventEmitter();
// This will block the event loop for ~lengths of time
function blockCpuFor(ms) {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log(`blocking the event loop for ${ms}ms`);
let now = new Date().getTime();
let result = 0
while(true) {
result += Math.random() * Math.random();
if (new Date().getTime() > now + ms)
break;
}
resolve();
}, 100);
});
}
function getNextMetricsEvent() {
return new Promise((resolve, reject) => Events.once('metrics', resolve));
}
const server = http.createServer((req, res) => {
// wait for the next metrics event
getNextMetricsEvent()
.then(blockCpuFor(2000))
.then(blockCpuFor(100))
.then(blockCpuFor(100))
.then(blockCpuFor(100))
.then(blockCpuFor(100))
.then(blockCpuFor(100))
.then(blockCpuFor(100))
.then(blockCpuFor(100))
.then(blockCpuFor(100))
.then(blockCpuFor(100))
.then(blockCpuFor(100))
// gather the next metrics data which should include these pauses
.then(getNextMetricsEvent())
.then(data => {
res.setHeader('Content-Type', 'application/json');
res.end(data);
})
.catch(() => {
res.statusCode = 500;
res.end("Something went wrong");
});
});
server.listen(PORT, () => console.log(`Listening on ${PORT}`));
// Create a second server that intercepts the HTTP requests
// sent by the metrics plugin
const metricsListener = http.createServer((req, res) => {
if (req.method == 'POST') {
let body = '';
req.on('data', (data) => body += data);
req.on('end', () => Events.emit('metrics', body));
res.statusCode = 200;
res.end();
}
});
metricsListener.listen(3000, () => console.log('Listening for metrics on 3000'));
{
"name": "hello-world",
"version": "1.0.0",
"engines": {
"node": "12.x"
},
"scripts": {
"prettify": "prettier --single-quote --trailing-comma all --write 'bin/*' 'src/**/*.js'",
"test": "jest --silent",
"dev": "nodemon --watch . --watch src/* src/index.js",
"heroku-postbuild": "echo NODE_OPTIONS: $NODE_OPTIONS"
},
"main": "index.js",
"license": "MIT",
"devDependencies": {
"jest": "^19.0.2",
"nodemon": "^1.11.0",
"prettier": "^0.22.0"
},
"dependencies": {}
}
#!/usr/bin/env node
const http = require('http');
const crypto = require('crypto');
const PORT = process.env.PORT || 5000;
// This will block the event loop for ~lengths of time
function blockCpuFor(ms) {
var now = new Date().getTime();
var result = 0
while(true) {
result += Math.random() * Math.random();
if (new Date().getTime() > now +ms)
return;
}
}
// block the event loop for 100ms every second
setInterval(() => {
blockCpuFor(100);
}, 1000)
// block the event loop for 1sec every 30 seconds
setInterval(() => {
blockCpuFor(1000);
}, 30000)
// Allocate and erase memory on an interval
let store = [];
setInterval(() => {
store.push(crypto.randomBytes(1000000).toString('hex'));
}, 500);
setInterval(() => {
store = [];
}, 60000);
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end("Hello, world!");
})
server.listen(PORT, () => console.log(`Listening on ${PORT}`));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment