当前位置: 首页>>代码示例>>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;未经允许,请勿转载。