Skip to content

Beam dynamic pipeline options raise TypeError instead of a config error #7182

Open

Description

@Anuj-72

Beam dynamic pipeline options fail with TypeError: exceptions must derive from BaseException whenever the value they are meant to look up is missing, which hides the real error and makes the failure look like a PKB bug rather than a missing IP address.

Where it happens: perfkitbenchmarker/beam_pipeline_options.py, in RetrieveNodePortIp() and RetrieveLoadBalancerIp(). Both call kubernetes_commands.GetWithWaitForContents(), which returns an empty string after its retries are exhausted, and then do:

if len(ip) == 0:
  raise 'Could not retrieve NodePort IP address'  # pyrefly: ignore[bad-raise]

Python 3 cannot raise a string, so the intended message is replaced by TypeError: exceptions must derive from BaseException. Both lines are suppressed with # pyrefly: ignore[bad-raise], which is why the defect never showed up in type checking.

How to reproduce, with no cluster and no cloud credentials:

import mock
from perfkitbenchmarker import beam_pipeline_options as b

with mock.patch.object(b.kubernetes_commands, 'GetWithWaitForContents', return_value=''):
  b.EvaluateDynamicPipelineOptions([
      {'name': 'node_port', 'type': 'NodePortIp', 'podLabel': 'app=test'}
  ])

Observed on master:

TypeError: exceptions must derive from BaseException

This is reachable in practice whenever a Beam benchmark on Kubernetes declares a NodePortIp or LoadBalancerIp dynamic option and the pod or service has not been assigned an IP yet, for example a pending LoadBalancer or a pod stuck in ContainerCreating. Instead of being told the IP could not be resolved, the user gets a bare TypeError with no mention of the option that failed.

Proposed fix: raise errors.Config.InvalidValue with the existing messages. That is already what the sibling validations in both functions do ('For NodePortIp arguments, you must provide a "selector"', 'For LoadBalancerIp arguments, you mustprovide a "serviceName"'), so this makes the failure path consistent with the input-validation path and lets it be caught like any other bad dynamic option.

Testing: two cases added to tests/linux_benchmarks/beam_integration_benchmark_test.py that mock the kubectl call to return an empty string and assert errors.Config.InvalidValue with the expected message. Both fail with TypeError against the current code and pass with the fix. The change also removes the two pyrefly: ignore[bad-raise] suppressions, since they are no longer needed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions