Dataflow 工作圖表

Dataflow 監控介面會提供每個工作的圖示,也就是「工作圖」。工作圖也會提供工作摘要、工作記錄,以及管道中每個步驟的相關資訊。

如要查看工作的作業圖,請執行下列步驟:

  1. 在 Google Cloud 控制台中,前往「Dataflow」>「Jobs」(工作) 頁面。

    前往「Jobs」(工作) 頁面

  2. 選取職務。

  3. 按一下「Job graph」(工作圖表) 分頁標籤。

管道的作業圖會以方塊表示管道中的各項轉換,每個方塊都包含轉換名稱和工作狀態資訊,而工作狀態有以下幾種:

  • 「Running」(執行中):這個步驟正在執行。
  • 「Queued」(已排入佇列):FlexRS 工作中的步驟已排入佇列
  • Succeeded (成功):這個步驟已順利完成
  • Stopped (已停止):工作已停止,因此這個步驟已停止
  • Unknown (不明):這個步驟無法回報狀態
  • 「Failed」(失敗):這個步驟無法完成

根據預設,作業圖表頁面會顯示「圖表檢視」。如要以表格形式查看工作圖表,請在「工作步驟檢視畫面」中選取「表格檢視畫面」。表格檢視畫面會以不同格式顯示相同資訊。表格檢視在下列情況中很有幫助:

  • 您的工作有許多階段,因此工作圖難以瀏覽。
  • 您想依特定屬性排序工作步驟。舉例來說,您可以依實際執行時間排序表格,找出速度緩慢的步驟。

基本工作圖表

管道程式碼:

Java

  // Read the lines of the input text.
  p.apply("ReadLines", TextIO.read().from(options.getInputFile()))
     // Count the words.
     .apply(new CountWords())
     // Write the formatted word counts to output.
     .apply("WriteCounts", TextIO.write().to(options.getOutput()));

Python

(
    pipeline
    # Read the lines of the input text.
    | 'ReadLines' >> beam.io.ReadFromText(args.input_file)
    # Count the words.
    | CountWords()
    # Write the formatted word counts to output.
    | 'WriteCounts' >> beam.io.WriteToText(args.output_path))

Go

  // Create the pipeline.
  p := beam.NewPipeline()
    s := p.Root()
  // Read the lines of the input text.
  lines := textio.Read(s, *input)
  // Count the words.
  counted := beam.ParDo(s, CountWords, lines)
  // Write the formatted word counts to output.
  textio.Write(s, *output, formatted)
工作圖表:

Dataflow 監控介面中顯示的 WordCount 管道執行圖。

圖 1:WordCount 管道的管道程式碼,與產生的執行圖並列顯示在 Dataflow 監控介面中。

複合式轉換

複合轉換是指包含多個巢狀子轉換的轉換。在工作圖中,複合式轉換可展開。如要展開轉換並查看子轉換,請按一下箭頭。

管道程式碼:

Java

  // The CountWords Composite Transform
  // inside the WordCount pipeline.

  public static class CountWords
    extends PTransform<PCollection<String>, PCollection<String>> {

    @Override
    public PCollection<String> apply(PCollection<String> lines) {

      // Convert lines of text into individual words.
      PCollection<String> words = lines.apply(
        ParDo.of(new ExtractWordsFn()));

      // Count the number of times each word occurs.
      PCollection<KV<String, Long>> wordCounts =
        words.apply(Count.<String>perElement());

      return wordCounts;
    }
  }

Python

# The CountWords Composite Transform inside the WordCount pipeline.
@beam.ptransform_fn
def CountWords(pcoll):
  return (
      pcoll
      # Convert lines of text into individual words.
      | 'ExtractWords' >> beam.ParDo(ExtractWordsFn())
      # Count the number of times each word occurs.
      | beam.combiners.Count.PerElement()
      # Format each word and count into a printable string.
      | 'FormatCounts' >> beam.ParDo(FormatCountsFn()))

Go

  // The CountWords Composite Transform inside the WordCount pipeline.
  func CountWords(s beam.Scope, lines beam.PCollection) beam.PCollection {
    s = s.Scope("CountWords")

    // Convert lines of text into individual words.
    col := beam.ParDo(s, &extractFn{SmallWordLength: *smallWordLength}, lines)

    // Count the number of times each word occurs.
    return stats.Count(s, col)
  }
工作圖表:

WordCount 管道的作業圖,管道的 CountWords 轉換已展開,顯示其中的子轉換。

圖 2:CountWords 轉換子步驟的管道程式碼。顯示整個管道的已展開工作圖。

在管道程式碼中,您可能會使用下列程式碼叫用複合轉換:

result = transform.apply(input);

以這種方式叫用的複合轉換會省略預期的巢狀結構,因此可能會在 Dataflow 監控介面中顯示為展開狀態。在執行管道時,您的管道也可能會產生有關穩定專屬名稱的警告或錯誤。

如要避免這些問題,請使用建議的格式叫用轉換作業:

result = input.apply(transform);

轉換名稱

Dataflow 可透過幾種不同方式取得監控工作圖中顯示的轉換名稱。轉換名稱會顯示在公開位置,包括 Dataflow 監控介面、記錄檔和偵錯工具。請勿使用包含個人識別資訊的轉換名稱,例如使用者名稱或機構名稱。

Java

  • Dataflow 可使用您套用轉換時指派的名稱。您提供給 apply 方法的第一個引數是轉換名稱。
  • Dataflow 可推論轉換的名稱,即根據類別名稱 (如果您建構了自訂轉換) 或 DoFn 函式物件名稱 (如果您使用 ParDo 等核心轉換) 來推論轉換的名稱。

Python

  • Dataflow 可使用您套用轉換時指派的名稱。您可指定轉換的 label 引數,藉此設定轉換名稱。
  • Dataflow 可推論轉換的名稱,即根據類別名稱 (如果您建構了自訂轉換) 或 DoFn 函式物件名稱 (如果您使用 ParDo 等核心轉換) 來推論轉換的名稱。

Go

  • Dataflow 可使用您套用轉換時指派的名稱。您可指定 Scope,藉此設定轉換名稱。
  • Dataflow 可推論轉換的名稱,即根據結構體名稱 (如果您使用結構性 DoFn) 或函式名稱 (如果您使用函式 DoFn) 來推論轉換的名稱。

查看步驟資訊

按一下工作圖中的步驟時,「步驟資訊」面板會顯示該步驟的詳細資訊。詳情請參閱工作步驟資訊