<commit_before>http = require('http');
httpProxy = require('http-proxy');
var express = require('express');
var sioc = require('socket.io-client');


var proxy = httpProxy.createProxyServer({});

var canary_fail = false;

var i = 0;


var socket = sioc('http://localhost:4006');

socket.on("heartbeat", function(client) 
{
	canary_fail = client.status;
	if((canary_fail == true) && (i == 0)){
		i++;
		console.log("Canary Server Failed.");
	}
});



var server = http.createServer(function(req, res) {

		var port = 3000;
		var percent = Math.floor((Math.random() * 10) + 1);
		console.log("Number: " + percent);
		if((percent > 7) && (!canary_fail)){
			port = 3001;
			console.log("Forwarding request to [CANARY - localhost:" + port+ "].");
		}
		else{
			port = 3000;
			console.log("Forwarding request to [STABLE - localhost:" + port+ "].");
		}
		proxy.web(req, res, { target: "http://localhost:" + port});
});
 
console.log("listening on port 5050")
server.listen(5050);

<commit_msg>update proxy code<commit_after>http = require('http');
httpProxy = require('http-proxy');
var express = require('express');
var sioc = require('socket.io-client');
var os = require('os');

var interfaces = os.networkInterfaces();

var proxy = httpProxy.createProxyServer({});

var canary_fail = false;

var i = 0;


var socket = sioc('http://' + interfaces.eth0[0].address + ':4006');

socket.on("heartbeat", function(client) 
{
	canary_fail = client.status;
	if((canary_fail == true) && (i == 0)){
		i++;
		console.log("Canary Server Failed.");
	}
});



var server = http.createServer(function(req, res) {

		var port = 3000;
		var percent = Math.floor((Math.random() * 10) + 1);
		console.log("Number: " + percent);
		if((percent > 7) && (!canary_fail)){
			port = 3001;
			console.log("Forwarding request to [CANARY - localhost:" + port+ "].");
		}
		else{
			port = 3000;
			console.log("Forwarding request to [STABLE - localhost:" + port+ "].");
		}
		proxy.web(req, res, { target: "http://localhost:" + port});
});
 
console.log("listening on port 5050")
server.listen(5050);


{'fraction_non_alphanumeric': 0.19623915139826423, 'fraction_numerical': 0.029893924783027964, 'mean_word_length': 4.1875, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5955211', 'n_tokens_mistral': 810, 'n_tokens_neox': 704, 'n_words': 166}