예제 #1
0
    def wrapper(*args, **kwargs):
        runing_state = RunningState()
        result = function(*args, **kwargs)

        commit_time = float(runing_state.timestamp)
        time_spent = time.time() - commit_time

        name = f'{function.__module__}.{function.__qualname__}'
        reconcile_time.labels(
            name=name,
            integration=runing_state.integration).observe(amount=time_spent)

        return result
예제 #2
0
        def wrapper(*args, **kwargs):
            result = function(*args, **kwargs)
            msg = result[:-1] if isinstance(result, (list, tuple)) else result

            if not isinstance(msg, OCProcessReconcileTimeDecoratorMsg):
                return result

            running_state = RunningState()
            commit_time = float(running_state.timestamp)
            time_spent = time.time() - commit_time

            try:
                resource_kind = msg.resource['kind']
                resource_name = msg.resource['metadata']['name']
                annotations = \
                    msg.resource['metadata'].get('annotations', {})
            except KeyError as e:
                logging.warning(f'Error processing metric: {e}')
                return result

            function_name = f'{function.__module__}.{function.__qualname__}'
            ignore_reconcile_time = \
                annotations.get('qontract.ignore_reconcile_time') == 'true'
            if not ignore_reconcile_time:
                reconcile_time.labels(
                    name=function_name,
                    integration=running_state.integration).observe(
                        amount=time_spent)

            if not msg.is_log_slow_oc_reconcile:
                return result

            if time_spent > msg.slow_oc_reconcile_threshold:
                log_msg = f'Action {function_name} for {resource_kind} ' \
                          f'{resource_name} in namespace ' \
                          f'{msg.namespace} from ' \
                          f'{msg.server} took {time_spent} to ' \
                          f'reconcile. Commit sha {running_state.commit} ' \
                          f'and commit ts {running_state.timestamp}.'

                if ignore_reconcile_time:
                    log_msg += ' Ignored in the metric published.'

                logging.info(log_msg)

            return result