예제 #1
0
 def end(self) -> vpb.ExecuteScriptResponse:
     """ Sends an end stream message. """
     return vpb.ExecuteScriptResponse(
         status=_ok(),
         data=vpb.QueryData(batch=self.row_batch(
             [[]] * len(self.relation.columns), eos=True, eow=True)),
     )
예제 #2
0
파일: api_test.py 프로젝트: pranay01/pixie
    def test_send_error_id_table_prop(self) -> None:
        # Sending an error over the stream should cause the table sub to exit.

        # Connect to a single fake cluster.
        # Connect to a single fake cluster.
        conn = self.px_client.connect_to_cluster(
            self.px_client.list_healthy_clusters()[0])

        http_table1 = self.http_table_factory.create_table(
            test_utils.table_id1)
        self.fake_vizier_service.add_fake_data(
            conn.cluster_id,
            [
                # Initialize the table on the stream and send over a rowbatch.
                http_table1.metadata_response(),
                http_table1.row_batch_response([["foo"], [200]]),
                # Send over an error on the stream after we've started sending data.
                # this should happen if something breaks on the Pixie side.
                # Note: the table does not send an end message over the stream.
                vpb.ExecuteScriptResponse(status=test_utils.invalid_argument(
                    message="server error"))
            ])

        # Create the script_executor object.
        script_executor = conn.prepare_script(pxl_script)
        # Add callback for http table.
        script_executor.add_callback("http", lambda _: None)

        with self.assertRaisesRegex(ValueError, "server error"):
            script_executor.run()
예제 #3
0
파일: api_test.py 프로젝트: pranay01/pixie
    def test_run_script_with_invalid_arg_error(self) -> None:

        # Connect to a single fake cluster.
        conn = self.px_client.connect_to_cluster(
            self.px_client.list_healthy_clusters()[0])

        # Send over an error in the Status field. This is the exact error you would
        # get if you sent over an empty pxl function in the ExecuteScriptRequest.
        self.fake_vizier_service.add_fake_data(conn.cluster_id, [
            vpb.ExecuteScriptResponse(status=test_utils.invalid_argument(
                message="Script should not be empty."))
        ])

        # Prepare the script_executor and run synchronously.
        script_executor = conn.prepare_script("")
        # Although we add a callback, we don't want this to throw an error.
        # Instead the error should be returned by the run function.
        script_executor.add_callback("http_table", lambda row: print(row))
        with self.assertRaisesRegex(ValueError, "Script should not be empty."):
            script_executor.run()
예제 #4
0
파일: api_test.py 프로젝트: pranay01/pixie
    def test_run_script_with_line_col_error(self) -> None:

        # Connect to a single fake cluster.
        conn = self.px_client.connect_to_cluster(
            self.px_client.list_healthy_clusters()[0])

        # Send over an error a line, column error. These kinds of errors come
        # from the compiler pointing to a specific failure in the pxl script_executor.
        self.fake_vizier_service.add_fake_data(conn.cluster_id, [
            vpb.ExecuteScriptResponse(status=test_utils.line_col_error(
                1, 2, message="name 'aa' is not defined"))
        ])

        # Prepare the script_executor and run synchronously.
        script_executor = conn.prepare_script("aa")
        # Although we add a callback, we don't want this to throw an error.
        # Instead the error should be returned by the run function.
        script_executor.add_callback("http_table", lambda row: print(row))
        with self.assertRaisesRegex(pxapi.PxLError,
                                    "PxL, line 1.*name 'aa' is not defined"):
            script_executor.run()
예제 #5
0
 def row_batch_response(self,
                        cols: List[List[Any]]) -> vpb.ExecuteScriptResponse:
     # Error out if the rowbatch does not have the right number of columns.
     return vpb.ExecuteScriptResponse(
         status=_ok(), data=vpb.QueryData(batch=self.row_batch(cols)))
예제 #6
0
 def metadata_response(self) -> vpb.ExecuteScriptResponse:
     return vpb.ExecuteScriptResponse(status=_ok(),
                                      meta_data=self._metadata())