<commit_before>const assert = require('assert');
const axios = require('axios');

module.exports = (hydra, config) => {
    const trigger = (name, level, data) => hydra.emit('http-plugin-lb', {
        name,
        level,
        data
    });

    config.lb = Object.assign({
        strategy: {
            name: 'race',
            timeout: 3000,
            nodes: 3,
            healthPath: '_health'
        }
    }, config.lb || {});

    assert(config.lb.strategy.handler || handlers[config.lb.strategy.name],
        `The load balancer '${config.lb.strategy.name}' strategy handler is required!`);

    return {
        translate: async service => {
            try {
                let now = new Date().getTime();
                let presences = await hydra.getServicePresence(service);
                assert(presences.length > 0, '503:Service Unavailable!');

                let handler = config.lb.strategy.handler || handlers[config.lb.strategy.name];
                let url = await handler(config.lb.strategy, presences, hydra, service);

                trigger('translate', 'info', {
                    service,
                    translation: url,
                    strategy: config.lb.strategy.name,
                    responseTime: new Date().getTime() - now
                });<commit_msg>exposing the lb config on hydra.http.lb.config<commit_after>const assert = require('assert');
const axios = require('axios');

module.exports = (hydra, config) => {
    const trigger = (name, level, data) => hydra.emit('http-plugin-lb', {
        name,
        level,
        data
    });

    config.lb = Object.assign({
        strategy: {
            name: 'race',
            timeout: 3000,
            nodes: 3,
            healthPath: '_health'
        }
    }, config.lb || {});

    assert(config.lb.strategy.handler || handlers[config.lb.strategy.name],
        `The load balancer '${config.lb.strategy.name}' strategy handler is required!`);

    return {
        config: config.lb,
        translate: async service => {
            try {
                let now = new Date().getTime();
                let presences = await hydra.getServicePresence(service);
                assert(presences.length > 0, '503:Service Unavailable!');

                let handler = config.lb.strategy.handler || handlers[config.lb.strategy.name];
                let url = await handler(config.lb.strategy, presences, hydra, service);

                trigger('translate', 'info', {
                    service,
                    translation: url,
                    strategy: config.lb.strategy.name,
                    responseTime: new Date().getTime() - now
                });
{'fraction_non_alphanumeric': 0.129080118694362, 'fraction_numerical': 0.0066765578635014835, 'mean_word_length': 1.768993839835729, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '6216629', 'n_tokens_mistral': 758, 'n_tokens_neox': 700, 'n_words': 165}