Auto status change to "Under Review"
Show More
@@ -1,63 +1,63 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright 2010 - 2017 RhodeCode GmbH and the AppEnlight project authors |
|
4 | 4 | # |
|
5 | 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
|
6 | 6 | # you may not use this file except in compliance with the License. |
|
7 | 7 | # You may obtain a copy of the License at |
|
8 | 8 | # |
|
9 | 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
|
10 | 10 | # |
|
11 | 11 | # Unless required by applicable law or agreed to in writing, software |
|
12 | 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
|
13 | 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 | 14 | # See the License for the specific language governing permissions and |
|
15 | 15 | # limitations under the License. |
|
16 | 16 | |
|
17 | 17 | from appenlight.models import Datastores |
|
18 | 18 | from appenlight.models.services.base import BaseService |
|
19 | 19 | from appenlight.lib.enums import ReportType |
|
20 | 20 | from appenlight.lib.utils import es_index_name_limiter |
|
21 | 21 | |
|
22 | 22 | |
|
23 | 23 | class ReportStatService(BaseService): |
|
24 | 24 | @classmethod |
|
25 | 25 | def count_by_type(cls, report_type, resource_id, since_when): |
|
26 | 26 | report_type = ReportType.key_from_value(report_type) |
|
27 | 27 | |
|
28 | 28 | index_names = es_index_name_limiter(start_date=since_when, ixtypes=["reports"]) |
|
29 | 29 | |
|
30 | 30 | es_query = { |
|
31 | 31 | "aggs": { |
|
32 | 32 | "reports": { |
|
33 | 33 | "aggs": { |
|
34 | "sub_agg": {"value_count": {"field": "tags.group_id.values"}} | |
|
34 | "sub_agg": {"value_count": {"field": "tags.group_id.values.keyword"}} | |
|
35 | 35 | }, |
|
36 | 36 | "filter": { |
|
37 | 37 | "bool": { |
|
38 | 38 | "filter": [ |
|
39 | 39 | {"terms": {"resource_id": [resource_id]}}, |
|
40 | 40 | {"exists": {"field": "tags.group_id.values"}}, |
|
41 | 41 | ] |
|
42 | 42 | } |
|
43 | 43 | }, |
|
44 | 44 | } |
|
45 | 45 | }, |
|
46 | 46 | "query": { |
|
47 | 47 | "bool": { |
|
48 | 48 | "filter": [ |
|
49 | 49 | {"terms": {"resource_id": [resource_id]}}, |
|
50 | 50 | {"terms": {"tags.type.values": [report_type]}}, |
|
51 | 51 | {"range": {"timestamp": {"gte": since_when}}}, |
|
52 | 52 | ] |
|
53 | 53 | } |
|
54 | 54 | }, |
|
55 | 55 | } |
|
56 | 56 | |
|
57 | 57 | if index_names: |
|
58 | 58 | result = Datastores.es.search( |
|
59 | 59 | body=es_query, index=index_names, doc_type="log", size=0 |
|
60 | 60 | ) |
|
61 | 61 | return result["aggregations"]["reports"]["sub_agg"]["value"] |
|
62 | 62 | else: |
|
63 | 63 | return 0 |
General Comments 4
Auto status change to "Under Review"
You need to be logged in to leave comments.
Login now