def test_client_building_from_env(self):
     with patch_environ({legion.config.MODEL_SERVER_URL[0]: 'test:10'}):
         client = legion.model.client.ModelClient(self.MODEL_ID)
         root_url = 'test:10/api/model/{}'.format(self.MODEL_ID)
         self.assertEqual(client.api_url, root_url)
         self.assertEqual(client.info_url, root_url + '/info')
         self.assertEqual(client.invoke_url, root_url + '/invoke')
Example #2
0
    def test_metrics_send(self):
        model_id = 'demo'
        build_number = 10
        metric = metrics.Metric.TEST_ACCURACY
        value = 30.0
        host, port, namespace = metrics.get_metric_endpoint()

        with patch_environ({env.BUILD_NUMBER[0]: build_number}):
            with patch('legion.metrics.send_tcp') as send_tcp_mock:
                timestamp = int(time.time())
                metrics.send_metric(model_id, metric, value)

                self.assertTrue(len(send_tcp_mock.call_args_list) == 2, '2 calls founded')
                for call in send_tcp_mock.call_args_list:
                    self.assertEqual(call[0][0], host)
                    self.assertEqual(call[0][1], port)

                delimiter = ' '

                call_with_metric = send_tcp_mock.call_args_list[0][0][2].strip().split(delimiter)
                call_with_build_number = send_tcp_mock.call_args_list[1][0][2].strip().split(delimiter)

                self.assertEqual(call_with_metric[0], '{}.{}.metrics.{}'.format(namespace, model_id, metric.value))
                self.assertEqual(float(call_with_metric[1]), value)
                self.assertEqual(call_with_metric[2], str(timestamp))

                self.assertEqual(call_with_build_number[0], '{}.{}.metrics.build'.format(namespace, model_id))
                self.assertEqual(int(float(call_with_build_number[1])), build_number)
                self.assertEqual(call_with_build_number[2], str(timestamp))
Example #3
0
    def test_custom_endpoint_detection(self):
        new_host = 'localhost'
        new_port = 1000
        new_namespace = 'tes'

        additional_environment = {
            legion.config.GRAPHITE_HOST[0]: new_host,
            legion.config.GRAPHITE_PORT[0]: str(new_port),
            legion.config.GRAPHITE_NAMESPACE[0]: new_namespace
        }
        with patch_environ(additional_environment):
            host, port, namespace = metrics.get_metric_endpoint()
            self.assertEqual(host, new_host)
            self.assertEqual(port, new_port)
            self.assertEqual(namespace, new_namespace)
Example #4
0
 def test_metrics_get_build_number(self):
     build_number = 10
     with patch_environ({env.BUILD_NUMBER[0]: build_number}):
         self.assertEqual(metrics.get_build_number(), build_number)