<commit_before>import time
import json
import datetime

from twisted.internet import reactor, defer, task
from twisted.python import log

from duct.objects import Output
from duct.protocol.opentsdb import OpenTSDBClient

from duct.outputs import opentsdb
from duct.utils import HTTPRequest

class Bosun(opentsdb.OpenTSDB):
    """Bosun HTTP API output

    **Configuration arguments:**

    :param url: URL (default: http://localhost:4242)
    :type url: str
    :param maxsize: Maximum queue backlog size (default: 250000, 0 disables)
    :type maxsize: int
    :param maxrate: Maximum rate of documents added to index (default: 100)
    :type maxrate: int
    :param interval: Queue check interval in seconds (default: 1.0)
    :type interval: int
    :param user: Optional basic auth username
    :type user: str
    :param password: Optional basic auth password
    :type password: str
    :param debug: Log tracebacks from OpenTSDB
    :type debug: str
    """
    def __init__(self, *a):
        opentsdb.OpenTSDB.__init__(self, *a)

        self.url = self.url.rstrip('/')

        self.metacache = {}

    def createMetadata(self, metas):
        headers = {}
        path = '/api/metadata/put'
        if self.user:
            authorization = b64encode('%s:%s' % (self.user, self.password)).decode()
            headers['Authorization'] = ['Basic ' + authorization]

        return HTTPRequest().getBody(
            self.url + path, 'POST', headers=headers, data=json.dumps(metas).encode())

    @defer.inlineCallbacks
    def sendEvents(self, events):
        tsdbEvents = []
        metadataBatch = []
        for e in events:
            if not self.metacache.get(e.service):
                metadataBatch.append({
                    "Metric": e.service,
                    "Name": "rate",
                    "Value": "gauge"
                })
                self.metacache[e.service] = True

            tsdbEvents.append(self.transformEvent(e))

        if metadataBatch:
            meta = yield self.createMetadata(metadataBatch)

        #result = yield self.client.put(tsdbEvents)
        result = {}

        defer.returnValue(result)<commit_msg>No idea<commit_after>import time
import json
import datetime

from twisted.internet import reactor, defer, task
from twisted.python import log

from duct.objects import Output
from duct.protocol.opentsdb import OpenTSDBClient

from duct.outputs import opentsdb
from duct.utils import HTTPRequest

class Bosun(opentsdb.OpenTSDB):
    """Bosun HTTP API output

    **Configuration arguments:**

    :param url: URL (default: http://localhost:4242)
    :type url: str.
    :param maxsize: Maximum queue backlog size (default: 250000, 0 disables)
    :type maxsize: int.
    :param maxrate: Maximum rate of documents added to index (default: 100)
    :type maxrate: int.
    :param interval: Queue check interval in seconds (default: 1.0)
    :type interval: int.
    :param user: Optional basic auth username
    :type user: str.
    :param password: Optional basic auth password
    :type password: str.
    :param debug: Log tracebacks from OpenTSDB
    :type debug: bool.
    """
    def __init__(self, *a):
        opentsdb.OpenTSDB.__init__(self, *a)

        self.url = self.url.rstrip('/')

        self.metacache = {}

    def createMetadata(self, metas):
        headers = {}
        path = '/api/metadata/put'
        if self.user:
            authorization = b64encode('%s:%s' % (self.user, self.password)).decode()
            headers['Authorization'] = ['Basic ' + authorization]

        return HTTPRequest().getBody(
            self.url + path, 'POST', headers=headers, data=json.dumps(metas).encode())

    @defer.inlineCallbacks
    def sendEvents(self, events):
        tsdbEvents = []
        metadataBatch = []
        for e in events:
            if not self.metacache.get(e.service):
                metadataBatch.append({
                    "Metric": e.service,
                    "Name": "rate",
                    "Value": "gauge"
                })
                self.metacache[e.service] = True

            tsdbEvents.append(self.transformEvent(e))

        if metadataBatch:
            meta = yield self.createMetadata(metadataBatch)

        result = yield self.client.put(tsdbEvents)

        defer.returnValue(result)
{'fraction_non_alphanumeric': 0.10566473988439307, 'fraction_numerical': 0.008323699421965317, 'mean_word_length': 2.4224683544303796, 'pattern_counts': {'":': 6, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3703089', 'n_tokens_mistral': 1277, 'n_tokens_neox': 1203, 'n_words': 353}