Ejemplo n.º 1
0
    def setup_influxdb(self, config):
        """Configure the InfluxDB module for measurement submission.

        :param dict config: The InfluxDB configuration stanza

        """
        base_tags = {
            'connection': self.connection_name,
            'version': self.consumer_version
        }
        measurement = self.config.get('influxdb_measurement',
                                      os.environ.get('SERVICE'))
        if measurement != self.consumer_name:
            base_tags['consumer'] = self.consumer_name
        for key in {'ENVIRONMENT', 'SERVICE'}:
            if key in os.environ:
                base_tags[key.lower()] = os.environ[key]
        influxdb.install(
            '{}://{}:{}/write'.format(
                config.get('scheme',
                           os.environ.get('INFLUXDB_SCHEME', 'http')),
                config.get('host',
                           os.environ.get('INFLUXDB_HOST', 'localhost')),
                config.get('port', os.environ.get('INFLUXDB_PORT', '8086'))
            ),
            config.get('user', os.environ.get('INFLUXDB_USER')),
            config.get('password', os.environ.get('INFLUXDB_PASSWORD')),
            base_tags=base_tags)
        return config.get('database', 'rejected'), measurement
Ejemplo n.º 2
0
 def test_set_auth_credentials(self):
     influxdb.install()
     username = str(uuid.uuid4())
     password = str(uuid.uuid4())
     influxdb.set_auth_credentials(username, password)
     expectation = username, password
     self.assertEqual(influxdb._credentials, expectation)
     self.assertTrue(influxdb._dirty)
Ejemplo n.º 3
0
    def test_password_envvar_is_masked(self):
        password = str(uuid.uuid4())
        os.environ['INFLUXDB_USER'] = str(uuid.uuid4())
        os.environ['INFLUXDB_PASSWORD'] = password
        influxdb.install()

        expectation = 'X' * len(password)
        self.assertEqual(os.environ['INFLUXDB_PASSWORD'], expectation)
Ejemplo n.º 4
0
    def test_credentials_from_environment_variables(self):
        password = str(uuid.uuid4())
        os.environ['INFLUXDB_USER'] = str(uuid.uuid4())
        os.environ['INFLUXDB_PASSWORD'] = password
        influxdb.install()

        expectation = (os.environ['INFLUXDB_USER'], password)
        self.assertEqual(influxdb._credentials, expectation)
Ejemplo n.º 5
0
    def test_set_io_loop(self):
        influxdb.install()
        previous = influxdb._io_loop
        io_loop = self.get_new_ioloop()

        influxdb.set_io_loop(io_loop)
        self.assertEqual(influxdb._io_loop, io_loop)
        self.assertNotEqual(io_loop, previous)
        self.assertTrue(influxdb._dirty)
Ejemplo n.º 6
0
 def test_http_client_defaults(self):
     password = str(uuid.uuid4())
     os.environ['INFLUXDB_USER'] = str(uuid.uuid4())
     os.environ['INFLUXDB_PASSWORD'] = password
     influxdb.install()
     influxdb._create_http_client()
     expectation = {
         'auth_username': os.environ['INFLUXDB_USER'],
         'auth_password': password,
         'user_agent': influxdb.USER_AGENT
     }
     for key in expectation:
         self.assertEqual(influxdb._http_client.defaults.get(key),
                          expectation[key])
Ejemplo n.º 7
0
    def setup_influxdb(self, config):
        """Configure the InfluxDB module for measurement submission.

        :param dict config: The InfluxDB configuration stanza

        """
        base_tags = {'version': self.consumer_version}
        measurement = self.config.get('influxdb_measurement',
                                      os.environ.get('SERVICE'))
        if measurement != self.consumer_name:
            base_tags['consumer'] = self.consumer_name
        for key in {'ENVIRONMENT', 'SERVICE'}:
            if key in os.environ:
                base_tags[key.lower()] = os.environ[key]
        influxdb.install('{}://{}:{}/write'.format(
            config.get('scheme', os.environ.get('INFLUXDB_SCHEME', 'http')),
            config.get('host', os.environ.get('INFLUXDB_HOST', 'localhost')),
            config.get('port', os.environ.get('INFLUXDB_PORT', '8086'))),
                         config.get('user', os.environ.get('INFLUXDB_USER')),
                         config.get('password',
                                    os.environ.get('INFLUXDB_PASSWORD')),
                         base_tags=base_tags)
        return config.get('database', 'rejected'), measurement
Ejemplo n.º 8
0
 def test_set_base_url(self):
     influxdb.install()
     expectation = 'https://influxdb.com:8086/write'
     influxdb.set_base_url(expectation)
     self.assertEqual(influxdb._base_url, expectation)
     self.assertTrue(influxdb._dirty)
Ejemplo n.º 9
0
 def test_calling_install_again_returns_false(self):
     self.assertFalse(influxdb.install())
Ejemplo n.º 10
0
 def test_set_invalid_sample_probability(self):
     influxdb.install()
     with self.assertRaises(ValueError):
         influxdb.set_sample_probability(2.0)
     with self.assertRaises(ValueError):
         influxdb.set_sample_probability(-1.0)
Ejemplo n.º 11
0
 def test_set_sample_probability(self):
     influxdb.install()
     expectation = random.random()
     influxdb.set_sample_probability(expectation)
     self.assertEqual(influxdb._sample_probability, expectation)
Ejemplo n.º 12
0
 def test_set_timeout(self):
     io_loop = self.get_new_ioloop()
     influxdb.install(io_loop=io_loop)
     expectation = random.randint(1000, 10000)
     influxdb.set_timeout(expectation)
     self.assertEqual(influxdb._timeout_interval, expectation)
Ejemplo n.º 13
0
 def setUp(self):
     super(InstallDefaultsTestCase, self).setUp()
     os.environ['ENVIRONMENT'] = str(uuid.uuid4())
     influxdb.install()
Ejemplo n.º 14
0
 def test_set_max_clients(self):
     influxdb.install()
     expectation = random.randint(1, 100)
     influxdb.set_max_clients(expectation)
     self.assertEqual(influxdb._max_clients, expectation)
     self.assertTrue(influxdb._dirty)
Ejemplo n.º 15
0
 def test_set_max_batch_size(self):
     influxdb.install()
     expectation = random.randint(1000, 100000)
     influxdb.set_max_batch_size(expectation)
     self.assertEqual(influxdb._max_batch_size, expectation)
Ejemplo n.º 16
0
 def test_set_io_loop_invalid_raises(self):
     influxdb.install()
     with self.assertRaises(ValueError):
         influxdb.set_io_loop('bad value')