Loading src/common/rpc_method_wrapper/Decorator.py +7 −2 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ import grpc, logging from enum import Enum from typing import Dict, List from prometheus_client import Counter, Histogram from prometheus_client.metrics import MetricWrapperBase from prometheus_client.metrics import MetricWrapperBase, INF from common.tools.grpc.Tools import grpc_message_to_json_string from .ServiceExceptions import ServiceException Loading @@ -34,7 +34,12 @@ def get_counter_requests(method_name : str, request_condition : RequestCondition def get_histogram_duration(method_name : str) -> Histogram: name = '{:s}_histogram_duration'.format(method_name.replace(':', '_')) description = '{:s} histogram of request duration'.format(method_name) return Histogram(name, description) return Histogram(name, description, buckets=( .005, .01, .02, .03, .04, .05, .06, .07, .08, .09, .1, .2, .3, .4, .5, .6, .7, .8, .9, 1, 2, 3, 4, 5, 6, 7, 8, 9, INF)) METRIC_TEMPLATES = { '{:s}_COUNTER_STARTED' : lambda method_name: get_counter_requests (method_name, RequestConditionEnum.STARTED), Loading src/common/tools/object_factory/PolicyRule.py +17 −11 Original line number Diff line number Diff line Loading @@ -15,20 +15,26 @@ import logging from typing import Dict, List, Optional from common.proto.policy_condition_pb2 import BooleanOperator from common.proto.policy_pb2 import PolicyRuleStateEnum LOGGER = logging.getLogger(__name__) def json_policy_rule_id(policy_rule_uuid : str) -> Dict: return {'uuid': {'uuid': policy_rule_uuid}} def json_policyrule_id(policyrule_uuid : str) -> Dict: return {'uuid': {'uuid': policyrule_uuid}} def json_policy_rule( policy_rule_uuid : str, policy_priority : int = 1, def json_policyrule( policyrule_uuid : str, policy_priority : int = 1, policy_state : PolicyRuleStateEnum = PolicyRuleStateEnum.POLICY_UNDEFINED, policy_state_message : str = '', boolean_operator : BooleanOperator = BooleanOperator.POLICYRULE_CONDITION_BOOLEAN_AND, condition_list : List[Dict] = [], action_list : List[Dict] = [], service_id : Optional[Dict] = None, device_id_list : List[Dict] = [] ) -> Dict: basic = { 'policyRuleId': json_policy_rule_id(policy_rule_uuid), 'policyRuleId': json_policyrule_id(policyrule_uuid), 'policyRuleState': { 'policyRuleState': policy_state, 'policyRuleStateMessage': policy_state_message, }, 'priority': policy_priority, 'conditionList': condition_list, 'booleanOperator': boolean_operator, Loading @@ -37,12 +43,12 @@ def json_policy_rule( result = {} if service_id is not None: policy_rule_type = 'service' result[policy_rule_type] = {'policyRuleBasic': basic} result[policy_rule_type]['serviceId'] = service_id policyrule_type = 'service' result[policyrule_type] = {'policyRuleBasic': basic} result[policyrule_type]['serviceId'] = service_id else: policy_rule_type = 'device' result[policy_rule_type] = {'policyRuleBasic': basic} policyrule_type = 'device' result[policyrule_type] = {'policyRuleBasic': basic} result[policy_rule_type]['deviceList'] = device_id_list result[policyrule_type]['deviceList'] = device_id_list return result Loading
src/common/rpc_method_wrapper/Decorator.py +7 −2 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ import grpc, logging from enum import Enum from typing import Dict, List from prometheus_client import Counter, Histogram from prometheus_client.metrics import MetricWrapperBase from prometheus_client.metrics import MetricWrapperBase, INF from common.tools.grpc.Tools import grpc_message_to_json_string from .ServiceExceptions import ServiceException Loading @@ -34,7 +34,12 @@ def get_counter_requests(method_name : str, request_condition : RequestCondition def get_histogram_duration(method_name : str) -> Histogram: name = '{:s}_histogram_duration'.format(method_name.replace(':', '_')) description = '{:s} histogram of request duration'.format(method_name) return Histogram(name, description) return Histogram(name, description, buckets=( .005, .01, .02, .03, .04, .05, .06, .07, .08, .09, .1, .2, .3, .4, .5, .6, .7, .8, .9, 1, 2, 3, 4, 5, 6, 7, 8, 9, INF)) METRIC_TEMPLATES = { '{:s}_COUNTER_STARTED' : lambda method_name: get_counter_requests (method_name, RequestConditionEnum.STARTED), Loading
src/common/tools/object_factory/PolicyRule.py +17 −11 Original line number Diff line number Diff line Loading @@ -15,20 +15,26 @@ import logging from typing import Dict, List, Optional from common.proto.policy_condition_pb2 import BooleanOperator from common.proto.policy_pb2 import PolicyRuleStateEnum LOGGER = logging.getLogger(__name__) def json_policy_rule_id(policy_rule_uuid : str) -> Dict: return {'uuid': {'uuid': policy_rule_uuid}} def json_policyrule_id(policyrule_uuid : str) -> Dict: return {'uuid': {'uuid': policyrule_uuid}} def json_policy_rule( policy_rule_uuid : str, policy_priority : int = 1, def json_policyrule( policyrule_uuid : str, policy_priority : int = 1, policy_state : PolicyRuleStateEnum = PolicyRuleStateEnum.POLICY_UNDEFINED, policy_state_message : str = '', boolean_operator : BooleanOperator = BooleanOperator.POLICYRULE_CONDITION_BOOLEAN_AND, condition_list : List[Dict] = [], action_list : List[Dict] = [], service_id : Optional[Dict] = None, device_id_list : List[Dict] = [] ) -> Dict: basic = { 'policyRuleId': json_policy_rule_id(policy_rule_uuid), 'policyRuleId': json_policyrule_id(policyrule_uuid), 'policyRuleState': { 'policyRuleState': policy_state, 'policyRuleStateMessage': policy_state_message, }, 'priority': policy_priority, 'conditionList': condition_list, 'booleanOperator': boolean_operator, Loading @@ -37,12 +43,12 @@ def json_policy_rule( result = {} if service_id is not None: policy_rule_type = 'service' result[policy_rule_type] = {'policyRuleBasic': basic} result[policy_rule_type]['serviceId'] = service_id policyrule_type = 'service' result[policyrule_type] = {'policyRuleBasic': basic} result[policyrule_type]['serviceId'] = service_id else: policy_rule_type = 'device' result[policy_rule_type] = {'policyRuleBasic': basic} policyrule_type = 'device' result[policyrule_type] = {'policyRuleBasic': basic} result[policy_rule_type]['deviceList'] = device_id_list result[policyrule_type]['deviceList'] = device_id_list return result