Uploaded image for project: 'Beam'
  1. Beam
  2. BEAM-14202

SpannerConfig does not respect SPANNER_EMULATOR_HOST

Details

    • Bug
    • Status: Open
    • P2
    • Resolution: Unresolved
    • 2.37.0
    • Not applicable
    • io-java-gcp
    • None

    Description

      com.google.cloud.spanner.SpannerOptions has to determine if the configuration should use the emulator or not. Essentially it will look for SPANNER_EMULATOR_HOST in the environment and if a spanner host is not explicitly set it will set the host as the emulator, [see here|https://github.com/googleapis/java-spanner/blob/main/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java#L1143-L1153

      By Contrast in Beam, SpannerConfig by default has a host set ([see here|https://github.com/apache/beam/blob/master/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/SpannerConfig.java#L83). When Beam goes to convert SpannerConfig to SpannerOptions in SpannerAccessor it will always call setHost on SpannerOptions which will set the emulatorHost to null, see here.

      The consequence of this is the SpannerAccessor will always ignore the SPANNER_EMULATOR_HOST environment variable unless withEmulatorHost is called explicitly on SpannerConfig. Ultimately this pushes the responsibility onto the user to manually check for the environment variable and conditionally set it rather than relying on the functionality that already exists in the underlying SpannerOptions provided by the spanner sdk.

      I think the solution would be for Beam to also check to see if SPANNER_EMULATOR_HOST is set and then fall back to the provided host or the DEFAULT_HOST in the event that we are not connecting to the emulator.

      Attachments

        Activity

          People

            Unassigned Unassigned
            ajorgensen Andrew Jorgensen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: