Exemplo n.º 1
0
 def test_error_resilience(self, mocked_logger):
     backend = ElasticsearchBackend(hosts=['non-existant-domain'])
     # ensure index and mapping setup failures are caught and logged
     self.assertEqual(2, len(mocked_logger.error.call_args_list))
     # ensure write failure is caught and logged
     backend.write(name='test_error_resilience')
     mocked_logger.warning.assert_called_once()
Exemplo n.º 2
0
    def configure_appmetrics(self, app):
        if not app.config.get('FEATURE_FLAG_ENABLE_APPMETRICS'):
            return

        if app.config['APPMETRICS_THREADED_BACKEND']:
            backend = ThreadedBackend(
                ElasticsearchBackend,
                backend_kwargs=dict(
                    hosts=app.config['APPMETRICS_ELASTICSEARCH_HOSTS'],
                    index=app.config['APPMETRICS_ELASTICSEARCH_INDEX']),
                lazy_init=True,
            )
        else:
            backend = ElasticsearchBackend(
                hosts=app.config['APPMETRICS_ELASTICSEARCH_HOSTS'],
                index=app.config['APPMETRICS_ELASTICSEARCH_INDEX'],
            )
        origin = 'inspire_next'

        hooks = [
            inspire_service_orcid_hooks.status_code_hook,
            inspire_service_orcid_hooks.orcid_error_code_hook,
            inspire_service_orcid_hooks.orcid_service_exception_hook,
            # Add other hooks here:
            exception_hook,
        ]
        time_execution.settings.configure(
            backends=[backend],
            hooks=hooks,
            origin=origin
        )
Exemplo n.º 3
0
def configure_metrics():
    # Check feature flag
    #if not settings.METRICS_ENABLED:
    #    return

    if False:
        elasticsearch = ElasticsearchBackend('localhost', index='metrics')
        settings.configure(backends=[elasticsearch])

    if True:
        metrics_backends = []
        async_es_metrics = ThreadedBackend(
            ElasticsearchBackend,
            backend_kwargs={
                'host': 'localhost',
                'port': '9200',
                #'url_prefix': settings.ELASTICSEARCH_PREFIX,
                #'use_ssl': settings.ELASTICSEARCH_SSL,
                #'verify_certs': settings.ELASTICSEARCH_VERIFY_CERTS,
                #'index': settings.ELASTICSEARCH_INDEX,
                #'http_auth': settings.ELASTICSEARCH_AUTH,
            },
        )
        metrics_backends.append(async_es_metrics)
        settings.configure(backends=metrics_backends,
                           hooks=[
                               status_code_hook,
                           ],
                           origin='inspire_next')
Exemplo n.º 4
0
    def configure_appmetrics(self, app):
        if not app.config.get("FEATURE_FLAG_ENABLE_APPMETRICS"):
            return

        if app.config["APPMETRICS_THREADED_BACKEND"]:
            backend = ThreadedBackend(
                ElasticsearchBackend,
                backend_kwargs=dict(
                    hosts=app.config["APPMETRICS_ELASTICSEARCH_HOSTS"],
                    index=app.config["APPMETRICS_ELASTICSEARCH_INDEX"],
                ),
            )
        else:
            backend = ElasticsearchBackend(
                hosts=app.config["APPMETRICS_ELASTICSEARCH_HOSTS"],
                index=app.config["APPMETRICS_ELASTICSEARCH_INDEX"],
            )
        origin = "inspirehep"
        hooks = [
            inspire_service_orcid_hooks.status_code_hook,
            inspire_service_orcid_hooks.orcid_error_code_hook,
            inspire_service_orcid_hooks.orcid_service_exception_hook,
        ]
        time_execution.settings.configure(
            backends=[backend], hooks=hooks, origin=origin
        )
Exemplo n.º 5
0
    def setUp(self):
        super(BaseTestTimeExecutionElasticSearch, self).setUp()

        self.backend = ElasticsearchBackend(ELASTICSEARCH_HOST,
                                            index="unittest")
        settings.configure(backends=[self.backend])
        self._clear()
Exemplo n.º 6
0
    def setUp(self):
        super(TestTimeExecution, self).setUp()

        self.backend = ElasticsearchBackend(
            'elasticsearch',
            index='unittest',
        )
        settings.configure(backends=[self.backend])
        self._clear()
Exemplo n.º 7
0
    def test_pipeline_present(self, mocked_index):
        backend = ElasticsearchBackend(ELASTICSEARCH_HOST,
                                       index="pipelinetest",
                                       pipeline="custom-pipeline")

        with settings(backends=[backend]):
            go()
            assert "pipeline" in mocked_index.call_args.kwargs
            assert mocked_index.call_args.kwargs[
                "pipeline"] == "custom-pipeline"

        ElasticTestMixin._clear(backend)
def configure(env):
    APPMETRICS_ELASTICSEARCH_KWARGS = dict(
        port=443,
        http_auth=(os.environ['APPMETRICS_ELASTICSEARCH_USERNAME'],
                   os.environ['APPMETRICS_ELASTICSEARCH_PASSWORD']),
        use_ssl=True,
        verify_certs=False,
    )
    APPMETRICS_ELASTICSEARCH_HOSTS = [
        dict(host='inspire-{}-logs-client1.cern.ch'.format(env),
             **APPMETRICS_ELASTICSEARCH_KWARGS),
        dict(host='inspire-{}-logs-client2.cern.ch'.format(env),
             **APPMETRICS_ELASTICSEARCH_KWARGS),
    ]
    INDEX_NAME = 'inspiremonitoring-{}'.format(env)
    backend = ElasticsearchBackend(hosts=APPMETRICS_ELASTICSEARCH_HOSTS,
                                   index=INDEX_NAME)
    time_execution.settings.configure(
        backends=[backend],
        # hooks=(status_code_hook,),
        origin='inspire_next')
Exemplo n.º 9
0
 def test_do_not_create_index(self, setup_index, setup_mapping):
     ElasticsearchBackend(ELASTICSEARCH_HOST,
                          index="unittest",
                          create_index=False)
     setup_index.assert_not_called()
     setup_mapping.assert_not_called()