當前位置: 首頁>>代碼示例>>Python>>正文


Python elasticsearch.exceptions方法代碼示例

本文整理匯總了Python中elasticsearch.exceptions方法的典型用法代碼示例。如果您正苦於以下問題:Python elasticsearch.exceptions方法的具體用法?Python elasticsearch.exceptions怎麽用?Python elasticsearch.exceptions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在elasticsearch的用法示例。


在下文中一共展示了elasticsearch.exceptions方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_agg_no_writeback_connectivity

# 需要導入模塊: import elasticsearch [as 別名]
# 或者: from elasticsearch import exceptions [as 別名]
def test_agg_no_writeback_connectivity(ea):
    """ Tests that if writeback_es throws an exception, the matches will be added to 'agg_matches' and when
    run again, that they will be passed again to add_aggregated_alert """
    hit1, hit2, hit3 = '2014-09-26T12:34:45', '2014-09-26T12:40:45', '2014-09-26T12:47:45'
    hits = generate_hits([hit1, hit2, hit3])
    ea.thread_data.current_es.search.return_value = hits
    ea.rules[0]['aggregation'] = datetime.timedelta(minutes=10)
    ea.rules[0]['type'].matches = [{'@timestamp': hit1},
                                   {'@timestamp': hit2},
                                   {'@timestamp': hit3}]
    ea.writeback_es.index.side_effect = elasticsearch.exceptions.ElasticsearchException('Nope')
    with mock.patch('elastalert.elastalert.elasticsearch_client'):
        with mock.patch.object(ea, 'find_pending_aggregate_alert', return_value=None):
            ea.run_rule(ea.rules[0], END, START)

    assert ea.rules[0]['agg_matches'] == [{'@timestamp': hit1, 'num_hits': 0, 'num_matches': 3},
                                          {'@timestamp': hit2, 'num_hits': 0, 'num_matches': 3},
                                          {'@timestamp': hit3, 'num_hits': 0, 'num_matches': 3}]

    ea.thread_data.current_es.search.return_value = {'hits': {'total': 0, 'hits': []}}
    ea.add_aggregated_alert = mock.Mock()

    with mock.patch.object(ea, 'run_query'):
        ea.run_rule(ea.rules[0], END, START)

    ea.add_aggregated_alert.assert_any_call({'@timestamp': hit1, 'num_hits': 0, 'num_matches': 3}, ea.rules[0])
    ea.add_aggregated_alert.assert_any_call({'@timestamp': hit2, 'num_hits': 0, 'num_matches': 3}, ea.rules[0])
    ea.add_aggregated_alert.assert_any_call({'@timestamp': hit3, 'num_hits': 0, 'num_matches': 3}, ea.rules[0]) 
開發者ID:Yelp,項目名稱:elastalert,代碼行數:30,代碼來源:base_test.py

示例2: test_trace_error_not_found

# 需要導入模塊: import elasticsearch [as 別名]
# 或者: from elasticsearch import exceptions [as 別名]
def test_trace_error_not_found(self, request_mock):
        msg = "record not found"
        exc = elasticsearch.exceptions.NotFoundError(404, msg)
        request_mock.return_value = (1, {}, {})
        request_mock.side_effect = exc
        self._test_trace_error(StatusCanonicalCode.NOT_FOUND, exc) 
開發者ID:open-telemetry,項目名稱:opentelemetry-python,代碼行數:8,代碼來源:test_elasticsearch.py

示例3: test_search_arg_named_index

# 需要導入模塊: import elasticsearch [as 別名]
# 或者: from elasticsearch import exceptions [as 別名]
def test_search_arg_named_index(elasticsearch_client, tracked_request):
    with pytest.raises(elasticsearch.exceptions.NotFoundError):
        # body, index
        elasticsearch_client.search(None, "myindex")

    assert len(tracked_request.complete_spans) == 1
    span = tracked_request.complete_spans[0]
    assert span.operation == "Elasticsearch/Myindex/Search" 
開發者ID:scoutapp,項目名稱:scout_apm_python,代碼行數:10,代碼來源:test_elasticsearch.py

示例4: test_search_kwarg_named_index

# 需要導入模塊: import elasticsearch [as 別名]
# 或者: from elasticsearch import exceptions [as 別名]
def test_search_kwarg_named_index(elasticsearch_client, tracked_request):
    with pytest.raises(elasticsearch.exceptions.NotFoundError):
        elasticsearch_client.search(index="myindex")

    assert len(tracked_request.complete_spans) == 1
    span = tracked_request.complete_spans[0]
    assert span.operation == "Elasticsearch/Myindex/Search" 
開發者ID:scoutapp,項目名稱:scout_apm_python,代碼行數:9,代碼來源:test_elasticsearch.py

示例5: test_search_kwarg_index_list

# 需要導入模塊: import elasticsearch [as 別名]
# 或者: from elasticsearch import exceptions [as 別名]
def test_search_kwarg_index_list(elasticsearch_client, tracked_request):
    with pytest.raises(elasticsearch.exceptions.NotFoundError):
        elasticsearch_client.search(index=["myindex", "myindex2"])

    assert len(tracked_request.complete_spans) == 1
    span = tracked_request.complete_spans[0]
    assert span.operation == "Elasticsearch/Myindex,Myindex2/Search" 
開發者ID:scoutapp,項目名稱:scout_apm_python,代碼行數:9,代碼來源:test_elasticsearch.py

示例6: _wrap_perform_request

# 需要導入模塊: import elasticsearch [as 別名]
# 或者: from elasticsearch import exceptions [as 別名]
def _wrap_perform_request(tracer, span_name_prefix):
    def wrapper(wrapped, _, args, kwargs):
        method = url = None
        try:
            method, url, *_ = args
        except IndexError:
            logger.warning(
                "expected perform_request to receive two positional arguments. "
                "Got %d",
                len(args),
            )

        op_name = span_name_prefix + (url or method or _DEFALT_OP_NAME)
        params = kwargs.get("params", {})
        body = kwargs.get("body", None)

        attributes = {
            "component": "elasticsearch-py",
            "db.type": "elasticsearch",
        }

        if url:
            attributes["elasticsearch.url"] = url
        if method:
            attributes["elasticsearch.method"] = method
        if body:
            attributes["db.statement"] = str(body)
        if params:
            attributes["elasticsearch.params"] = str(params)

        with tracer.start_as_current_span(
            op_name, kind=SpanKind.CLIENT, attributes=attributes
        ) as span:
            try:
                rv = wrapped(*args, **kwargs)
                if isinstance(rv, dict):
                    for member in _ATTRIBUTES_FROM_RESULT:
                        if member in rv:
                            span.set_attribute(
                                "elasticsearch.{0}".format(member),
                                str(rv[member]),
                            )
                return rv
            except Exception as ex:  # pylint: disable=broad-except
                if isinstance(ex, elasticsearch.exceptions.NotFoundError):
                    status = StatusCanonicalCode.NOT_FOUND
                else:
                    status = StatusCanonicalCode.UNKNOWN
                span.set_status(Status(status, str(ex)))
                raise ex

    return wrapper 
開發者ID:open-telemetry,項目名稱:opentelemetry-python,代碼行數:54,代碼來源:__init__.py


注:本文中的elasticsearch.exceptions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。