Ejemplo n.º 1
0
 def __init__(self, spec):
     super(Operation, self).__init__()
     self.spec = spec
     self.func, self.user_defined_funcs = self.generate_func(self.spec.serialized_fn)
     if self.spec.serialized_fn.metric_enabled:
         self.base_metric_group = GenericMetricGroup(None, None)
     else:
         self.base_metric_group = None
Ejemplo n.º 2
0
    def __init__(self, name, spec, counter_factory, sampler, consumers):
        super(StatelessFunctionOperation, self).__init__(name, spec, counter_factory, sampler)
        self.consumer = consumers['output'][0]
        self._value_coder_impl = self.consumer.windowed_coder.wrapped_value_coder.get_impl()

        self.func, self.user_defined_funcs = self.generate_func(self.spec.serialized_fn)
        self._metric_enabled = self.spec.serialized_fn.metric_enabled
        self.base_metric_group = None
        if self._metric_enabled:
            self.base_metric_group = GenericMetricGroup(None, None)
        self.open_func()
Ejemplo n.º 3
0
    def __init__(self, name, spec, counter_factory, sampler, consumers):
        super(StatelessFunctionOperation,
              self).__init__(name, spec, counter_factory, sampler)
        self.consumer = consumers['output'][0]
        self._value_coder_impl = self.consumer.windowed_coder.wrapped_value_coder.get_impl(
        )

        self.variable_dict = {}
        self.user_defined_funcs = []
        self.func = self.generate_func(self.spec.serialized_fn)
        base_metric_group = GenericMetricGroup(None, None)
        for user_defined_func in self.user_defined_funcs:
            user_defined_func.open(FunctionContext(base_metric_group))
Ejemplo n.º 4
0
 def __init__(self, spec):
     self.spec = spec
     if self.spec.serialized_fn.metric_enabled:
         self.base_metric_group = GenericMetricGroup(None, None)
     else:
         self.base_metric_group = None
Ejemplo n.º 5
0
 def __init__(self, serialized_fn):
     if serialized_fn.metric_enabled:
         self.base_metric_group = GenericMetricGroup(None, None)
     else:
         self.base_metric_group = None
     self.func, self.user_defined_funcs = self.generate_func(serialized_fn)
Ejemplo n.º 6
0
class MetricTests(unittest.TestCase):

    base_metric_group = GenericMetricGroup(None, None)

    @staticmethod
    def print_metric_group_path(mg: MetricGroup) -> str:
        if mg._parent is None:
            return 'root'
        else:
            return MetricTests.print_metric_group_path(mg._parent) + '.' + mg._name

    def test_add_group(self):
        new_group = MetricTests.base_metric_group.add_group('my_group')
        self.assertEqual(MetricTests.print_metric_group_path(new_group), 'root.my_group')

    def test_add_group_with_variable(self):
        new_group = MetricTests.base_metric_group.add_group('key', 'value')
        self.assertEqual(MetricTests.print_metric_group_path(new_group), 'root.key.value')

    def test_metric_not_enabled(self):
        fc = FunctionContext(None)
        with self.assertRaises(RuntimeError):
            fc.get_metric_group()

    def test_get_metric_name(self):
        new_group = MetricTests.base_metric_group.add_group('my_group')
        self.assertEqual(
            '["my_group", "MetricGroupType.generic"]',
            new_group._get_namespace())
        self.assertEqual(
            '["my_group", "MetricGroupType.generic", "60"]',
            new_group._get_namespace('60'))

    def test_metrics(self):
        sampler = statesampler.StateSampler('', counters.CounterFactory())
        statesampler.set_current_tracker(sampler)
        state1 = sampler.scoped_state(
            'mystep', 'myState', metrics_container=MetricsContainer('mystep'))

        try:
            sampler.start()
            with state1:
                counter = MetricTests.base_metric_group.counter("my_counter")
                meter = MetricTests.base_metric_group.meter("my_meter")
                distribution = MetricTests.base_metric_group.distribution("my_distribution")
                container = MetricsEnvironment.current_container()

                self.assertEqual(0, counter.get_count())
                self.assertEqual(0, meter.get_count())
                self.assertEqual(
                    DistributionData(
                        0, 0, 0, 0), container.get_distribution(
                        MetricName(
                            '[]', 'my_distribution')).get_cumulative())
                counter.inc(-2)
                meter.mark_event(3)
                distribution.update(10)
                distribution.update(2)
                self.assertEqual(-2, counter.get_count())
                self.assertEqual(3, meter.get_count())
                self.assertEqual(
                    DistributionData(
                        12, 2, 2, 10), container.get_distribution(
                        MetricName(
                            '[]', 'my_distribution')).get_cumulative())
        finally:
            sampler.stop()
Ejemplo n.º 7
0
 def __init__(self, serialized_fn, operator_state_backend=None):
     if serialized_fn.metric_enabled:
         self.base_metric_group = GenericMetricGroup(None, None)
     else:
         self.base_metric_group = None
     self.operator_state_backend = operator_state_backend