##// END OF EJS Templates
setup: change url to github
setup: change url to github

File last commit:

r168:b242e5b8
r196:472d1df0 master
Show More
report_stat.py
81 lines | 3.1 KiB | text/x-python | PythonLexer
project: initial commit
r0 # -*- coding: utf-8 -*-
license: change the license to Apache 2.0
r112 # Copyright 2010 - 2017 RhodeCode GmbH and the AppEnlight project authors
project: initial commit
r0 #
license: change the license to Apache 2.0
r112 # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
project: initial commit
r0 #
license: change the license to Apache 2.0
r112 # http://www.apache.org/licenses/LICENSE-2.0
project: initial commit
r0 #
license: change the license to Apache 2.0
r112 # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
project: initial commit
r0
import sqlalchemy as sa
from appenlight.lib.enums import ReportType
from appenlight.models import Base
from ziggurat_foundations.models.base import BaseModel
class ReportStat(Base, BaseModel):
black: reformat source
r153 __tablename__ = "reports_stats"
__table_args__ = {"implicit_returning": False}
project: initial commit
r0
black: reformat source
r153 group_id = sa.Column(
sa.BigInteger(), sa.ForeignKey("reports_groups.id"), nullable=False
)
resource_id = sa.Column(
sa.Integer(), sa.ForeignKey("applications.resource_id"), nullable=False
)
project: initial commit
r0 start_interval = sa.Column(sa.DateTime(), nullable=False)
occurences = sa.Column(sa.Integer, nullable=True, default=0)
black: reformat source
r153 owner_user_id = sa.Column(sa.Integer(), sa.ForeignKey("users.id"), nullable=True)
project: initial commit
r0 type = sa.Column(sa.Integer, nullable=True, default=0)
duration = sa.Column(sa.Float, nullable=True, default=0)
id = sa.Column(sa.BigInteger, nullable=False, primary_key=True)
black: reformat source
r153 server_name = sa.Column(sa.Unicode(128), nullable=False, default="")
view_name = sa.Column(sa.Unicode(128), nullable=False, default="")
project: initial commit
r0
@property
def partition_id(self):
black: reformat source
r153 return "rcae_r_%s" % self.start_interval.strftime("%Y_%m")
project: initial commit
r0
def es_doc(self):
return {
black: reformat source
r153 "resource_id": self.resource_id,
"timestamp": self.start_interval,
elasticsearch: move to single doctype indices
r168 "report_stat_id": str(self.id),
black: reformat source
r153 "permanent": True,
"request_id": None,
"log_level": "ERROR",
"message": None,
"namespace": "appenlight.error",
elasticsearch: move to single doctype indices
r168 "group_id": str(self.group_id),
black: reformat source
r153 "tags": {
"duration": {"values": self.duration, "numeric_values": self.duration},
"occurences": {
"values": self.occurences,
"numeric_values": self.occurences,
},
"group_id": {"values": self.group_id, "numeric_values": self.group_id},
"type": {
"values": ReportType.key_from_value(self.type),
"numeric_values": self.type,
},
"server_name": {"values": self.server_name, "numeric_values": None},
"view_name": {"values": self.view_name, "numeric_values": None},
project: initial commit
r0 },
black: reformat source
r153 "tag_list": [
"duration",
"occurences",
"group_id",
"type",
"server_name",
"view_name",
],
elasticsearch: move to single doctype indices
r168 "type": "report_stat",
project: initial commit
r0 }