{"record":{"id":"abfa16b19a161fb1","repo":"apache/beam","slug":"failed-to-get-metrics","errorCode":null,"errorMessage":"failed to get metrics","messagePattern":"failed to get metrics","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/runners/dataflow/dataflowlib/execute.go","lineNumber":173,"sourceCode":"\n// PrintJob logs the Dataflow job.\nfunc PrintJob(ctx context.Context, job *df.Job) {\n\tstr, err := json.MarshalIndent(job, \"\", \"  \")\n\tif err != nil {\n\t\tlog.Infof(ctx, \"Failed to print job %v: %v\", job.Id, err)\n\t}\n\tlog.Info(ctx, string(str))\n}\n\ntype dataflowPipelineResult struct {\n\tjobID   string\n\tmetrics *metrics.Results\n}\n\nfunc newDataflowPipelineResult(ctx context.Context, client *df.Service, p *pipepb.Pipeline, project, region, jobID string) (*dataflowPipelineResult, error) {\n\tres, err := GetMetrics(ctx, client, project, region, jobID)\n\tif err != nil {\n\t\treturn &dataflowPipelineResult{jobID, nil}, errors.Wrap(err, \"failed to get metrics\")\n\t}\n\treturn &dataflowPipelineResult{jobID, FromMetricUpdates(res.Metrics, p)}, nil\n}\n\nfunc (pr dataflowPipelineResult) Metrics() metrics.Results {\n\treturn *pr.metrics\n}\n\nfunc (pr dataflowPipelineResult) JobID() string {\n\treturn pr.jobID\n}\n","sourceCodeStart":155,"sourceCodeEnd":185,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/runners/dataflow/dataflowlib/execute.go#L155-L185","documentation":"newDataflowPipelineResult fetches a Dataflow job's metric updates via GetMetrics to populate the pipeline result. If the GetMetrics API call fails, the error is wrapped with 'failed to get metrics' and a result with a nil metrics field is returned. This means the SDK could not read the job's final counters from the Dataflow API.","triggerScenarios":"Calling Execute (which calls newDataflowPipelineResult after job completion) when the Dataflow projects.locations.jobs.getMetrics request fails: network error, transient API 5xx, invalid job ID, or insufficient permissions.","commonSituations":"Transient Google API outages right at job completion, service accounts lacking monitoring/viewer or dataflow viewer roles, very fresh jobs whose metrics endpoint briefly 404s, or corporate proxies blocking googleapis.com.","solutions":["Retry — GetMetrics failures are often transient; the job may have completed fine","Verify the service account can read job metrics (roles/dataflow.viewer or equivalent)","Check project/region/jobID are correct in the metrics request","Inspect the wrapped error for the HTTP status and act on it (403 → permissions, 404 → wrong region/job, 5xx → retry)"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := run(); err != nil && strings.Contains(err.Error(), \"failed to get metrics\") {\n    // retry with backoff; job itself may have succeeded\n    time.Sleep(10 * time.Second)\n}","preventionTips":["Add exponential backoff around metric retrieval","Ensure service account has roles/dataflow.viewer","Verify region matches the job's region before querying metrics","Check GCP status page during incident windows"],"tags":["go","dataflow","metrics","api"],"backgroundTag":"api-request-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}