<commit_before>import time
from yandextank.core import AbstractPlugin
import logging
from random import randint
import threading as th
import sys

from contextlib import contextmanager

import requests
import imp

logger = logging.getLogger(__name__)

requests_logger = logging.getLogger('requests')
requests_logger.setLevel(logging.WARNING)

requests.packages.urllib3.disable_warnings()


class AbstractGun(AbstractPlugin):
    def __init__(self, core):
        super(AbstractGun, self).__init__(core)
        self.results = None

    @contextmanager
    def measure(self, marker):
        start_time = time.time()
        data_item = {
            "send_ts": start_time,
            "tag": marker,
            "interval_real": None,
            "connect_time": 0,
            "send_time": 0,
            "latency": 0,
            "receive_time": 0,
            "interval_event": 0,
            "size_out": 0,
            "size_in": 0,
            "net_code": 0,
            "proto_code": 200,
        }
        try:
            yield data_item
        except Exception:
            if data_item["proto_code"] == 200:
                data_item["proto_code"] = 500
            if data_item["net_code"] == 0:
                data_item["net_code"] == 1
        finally:
            if data_item.get("interval_real") is None:
                data_item["interval_real"] = int(
                    (time.time() - start_time) * 1e6)

            self.results.put(data_item, timeout=1)


class LogGun(AbstractGun):
    SECTION = 'log_gun'

    def __init__(self, core):
        super(LogGun, self).__init__(core)
        param = self.get_option("param", '15')
        logger.info('Initialized log gun for BFG with param = %s' % param)

    def shoot(self, missile, marker):
        logger.info("Missile: %s\n%s", marker, missile)
        rt = randint(2, 30000) * 1000
        with self.measure(marker) as di:
            di["interval_real"] = rt


class SqlGun(AbstractGun):
    SECTION = 'sql_gun'

    def __init__(self, core):<commit_msg>log measuring errors<commit_after>import time
from yandextank.core import AbstractPlugin
import logging
from random import randint
import threading as th
import sys

from contextlib import contextmanager

import requests
import imp

logger = logging.getLogger(__name__)

requests_logger = logging.getLogger('requests')
requests_logger.setLevel(logging.WARNING)

requests.packages.urllib3.disable_warnings()


class AbstractGun(AbstractPlugin):
    def __init__(self, core):
        super(AbstractGun, self).__init__(core)
        self.results = None

    @contextmanager
    def measure(self, marker):
        start_time = time.time()
        data_item = {
            "send_ts": start_time,
            "tag": marker,
            "interval_real": None,
            "connect_time": 0,
            "send_time": 0,
            "latency": 0,
            "receive_time": 0,
            "interval_event": 0,
            "size_out": 0,
            "size_in": 0,
            "net_code": 0,
            "proto_code": 200,
        }
        try:
            yield data_item
        except Exception as e:
            logger.warning("%s failed while measuring with %s", marker, e)
            if data_item["proto_code"] == 200:
                data_item["proto_code"] = 500
            if data_item["net_code"] == 0:
                data_item["net_code"] == 1
        finally:
            if data_item.get("interval_real") is None:
                data_item["interval_real"] = int((time.time() - start_time) *
                                                 1e6)

            self.results.put(data_item, timeout=1)


class LogGun(AbstractGun):
    SECTION = 'log_gun'

    def __init__(self, core):
        super(LogGun, self).__init__(core)
        param = self.get_option("param", '15')
        logger.info('Initialized log gun for BFG with param = %s' % param)

    def shoot(self, missile, marker):
        logger.info("Missile: %s\n%s", marker, missile)
        rt = randint(2, 30000) * 1000
        with self.measure(marker) as di:
            di["interval_real"] = rt


class SqlGun(AbstractGun):
    SECTION = 'sql_gun'

    def __init__(self, core):
{'fraction_non_alphanumeric': 0.10972985895290462, 'fraction_numerical': 0.01673440114750179, 'mean_word_length': 2.174506828528073, 'pattern_counts': {'":': 24, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2244954', 'n_tokens_mistral': 1314, 'n_tokens_neox': 1214, 'n_words': 300}