Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Job launched with flex template fails with "Failed to read the result file"

Hi, I'm just getting up and running with DataFlow and have been hitting some hiccups along the way. I have a cloud function that is using the `dataflow_v1beta3.FlexTemplateServiceClient` in Python to launch a flex template. I have launched this template using my own credentials from the CLI with a successful run, however when my cloud function successfully launches the template, the job fails with this logged:

 

Failed to read the result file : gs://dataflow-staging-northamerica-northeast2-31664930760/staging/template_launches/2024-02-13_13_48_32-17616911554794094215/operation_result with error message: (a91b614d0c0827f5): Unable to open template file: gs://dataflow-staging-northamerica-northeast2-31664930760/staging/template_launches/2024-02-13_13_48_32-17616911554794094215/operation_result..

 

Indeed, there is no file at this path, but I'm not sure what the issue would be.

Some context on how things are set up:
python apache beam pipeline code:

 

def run():
    class MyPipelineOptions(PipelineOptions):
        @classmethod
        def _add_argparse_args(cls, parser):
            parser.add_argument(
                "--input-file",
                required=True,
                help="Input csv file to process.",
            )
            parser.add_argument(
                "--output-table",
                required=True,
                help="Output table to write results to.",
            )

    options = MyPipelineOptions()

    with beam.Pipeline(options=options) as p:

 

template manifest.json:

 

{
  "name": "Airbyte GCS Raw Dump to BigQuery Template",
  "description": "Takes raw data extracted to parquet format from Airbyte, transforms and loads it into BigQuery",
  "parameters": [
    {
      "name": "input-file",
      "label": "Input file",
      "helpText": "The path to the parquet file in GCS",
      "regexes": ["^gs:\\/\\/[^\\n\\r]+$"]
    },
    {
      "name": "output-table",
      "label": "Output table",
      "helpText": "The name of the table to create in BigQuery",
      "regexes": ["^[A-Za-z0-9_:.]+$"]
    }
  ]
}

 

cloud function call to trigger the job:

 

    client = dataflow_v1beta3.FlexTemplatesServiceClient()

    parameters = {
        "input-file": f"gs://{bucket_name}/{file_name}",
        "output-table": output_table,
    }

    launch_parameter = dataflow_v1beta3.LaunchFlexTemplateParameter(
        job_name=job_name,
        container_spec_gcs_path=container_spec_gcs_path, # where manifest.json is located in GCS
        parameters=parameters,
        environment={
            "service_account_email": dataflow_service_account, 
            "temp_location": temp_location,
        },
    )

    request = dataflow_v1beta3.LaunchFlexTemplateRequest(
        project_id=project_name,
        location=region,
        launch_parameter=launch_parameter,
    )
    response = client.launch_flex_template(request=request) # succeeds, but then the job fails

 

Solved Solved
0 5 6,399
1 ACCEPTED SOLUTION

This error signifies a problem encountered by Google Cloud Dataflow when attempting to generate or access a crucial result file within Google Cloud Storage (GCS). This file is essential for detailing the execution outcomes of a Dataflow Flex Template job. The error can stem from various issues, including but not limited to:

  • Incorrect GCS Permissions: The service account utilized by Dataflow worker nodes may not have the necessary permissions (e.g., "Storage Object Viewer" and "Storage Object Creator") for the GCS bucket in question.
  • Template File Issues: It's vital to ensure that the container_spec_gcs_path accurately points to the manifest.json file and that the template is correctly formatted and valid.
  • Network Restrictions: Firewalls or network configurations might prevent Dataflow workers from accessing GCS resources.
  • Internal Dataflow Error: On rarer occasions, the issue might originate from within the Dataflow service itself.
  • Temporary GCS Unavailability: The error could also be due to a temporary issue with GCS, affecting accessibility.
  • Worker Startup Issues: Problems during the initialization of Dataflow workers can impact the generation or access of the result file.
  • Parameter Matching Issues: Ensuring that the parameters (like input-file and output-table) match the expected data types and constraints defined in your Flex Template is crucial.

Troubleshooting Steps

  1. Verify GCS Permissions:

    • Check the IAM settings in the Google Cloud console to identify the service account used by Dataflow workers. Ensure it has the "Storage Object Viewer" and "Storage Object Creator" roles for the necessary GCS bucket.
  2. Check File Paths:

    • Confirm the accuracy of the GCS path mentioned in the error message. Implement logging within your cloud function to verify the container_spec_gcs_path at the start, ensuring correctness.
  3. Validate Template File:

    • Use a JSON validator to check the format of your manifest.json. Ensure that the parameters and their data types, along with any regex constraints, align with the data you're providing.
  4. Enable Robust Diagnostics:

    • Employ a comprehensive logging strategy within your cloud function. Utilize Cloud Logging for centralized error and job run information, ensuring detailed logging of paths, parameters, and errors.
  5. Check Job Resources:

    • Review the configuration for machine types and worker counts to ensure the job is provisioned with adequate resources, although this may not directly relate to the specific error.
  6. Retry with Monitoring:

    • Implement retries within your cloud function, particularly if temporary GCS unavailability is suspected. Close monitoring during retries can help capture more specific error messages.
  7. Contact Google Cloud Support:

    • If the issue persists despite these troubleshooting steps, reaching out to Google Cloud Support with your project ID, job ID, and detailed logs can facilitate further assistance.

View solution in original post

5 REPLIES 5