Skip to content

worker: add fallback to ATC streaming when P2P fails - #9390

Merged
taylorsilva merged 2 commits into
concourse:masterfrom
kurtmc:feature/p2p-fallback
Dec 15, 2025
Merged

taylorsilva merged 2 commits into
concourse:masterfrom
kurtmc:feature/p2p-fallback

Conversation

@kurtmc

@kurtmc kurtmc commented Dec 9, 2025

Copy link
Copy Markdown
Contributor

Changes proposed by this PR

Related to #7017

This PR implements an improvement for volume streaming by adding automatic fallback to ATC (web node) streaming when P2P streaming fails.

Key changes:

  • When P2P streaming fails (e.g., workers on different networks, connectivity issues), automatically fall back to streaming through the ATC web node
  • Added a log for when the fallback occurs
  • Add new metric volumes_streamed_via_fallback to track fallback usage for observability

Rationale:

I want to be able to run a small number of nodes in a different network and still have the majority of the nodes run in a seperate network and use p2p for peformance reasons.

Notes to reviewer

  • The fallback preserves the same error handling contract - if both P2P and ATC streaming fail, the error from ATC streaming is returned

Release Note

Volume streaming now automatically falls back to streaming through the web node when peer-to-peer streaming fails. This makes the enable-p2p-volume-streaming flag more resilient in environments where workers may be on different networks.

When P2P volume streaming fails (e.g., workers on different networks),
automatically fall back to streaming through the ATC web node. This
enables you to use the enable-p2p-volume-streaming event if nodes are
not on the same network.

Adds structured logging and a new metric volumes_streamed_via_fallback
for observability.

Related to concourse#7017

Signed-off-by: Kurt McAlpine <[email protected]>
@kurtmc
kurtmc requested a review from a team December 9, 2025 07:34
@linux-foundation-easycla

linux-foundation-easycla Bot commented Dec 9, 2025 •

Copy link
Copy Markdown

CLA Signed

The committers listed above are authorized under a signed CLA.

@kurtmc

kurtmc commented Dec 9, 2025

Copy link
Copy Markdown
Contributor Author

Here is what I did to test this feature.

docker-compose.yml with two workers on isolated networks:

services:
  # Key generation init container
  keys-init:
    image: concourse/concourse
    entrypoint:
      - /bin/sh
      - -c
      - |
        set -e
        mkdir -p /concourse-keys
        if [ ! -f /concourse-keys/tsa_host_key ]; then
          echo "Generating Concourse keys..."
          # TSA host key and worker key need to be SSH keys (they have .pub files)
          /usr/local/concourse/bin/concourse generate-key -t ssh -f /concourse-keys/tsa_host_key
          /usr/local/concourse/bin/concourse generate-key -t ssh -f /concourse-keys/worker_key
          # Session signing key is RSA (no .pub file)
          /usr/local/concourse/bin/concourse generate-key -t rsa -f /concourse-keys/session_signing_key
          cp /concourse-keys/worker_key.pub /concourse-keys/authorized_worker_keys
          echo "Keys generated successfully:"
          ls -la /concourse-keys/
        else
          echo "Keys already exist"
        fi
    volumes:
      - keys:/concourse-keys

  concourse-db:
    image: postgres:15
    environment:
      POSTGRES_DB: concourse
      POSTGRES_USER: concourse_user
      POSTGRES_PASSWORD: concourse_pass
      PGDATA: /database
    volumes:
      - data:/database
    networks:
      - web-network
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U concourse_user -d concourse"]
      interval: 3s
      timeout: 3s
      retries: 5

  concourse-web:
    image: concourse/concourse
    command: web
    privileged: true
    depends_on:
      keys-init:
        condition: service_completed_successfully
      concourse-db:
        condition: service_healthy
    ports:
      - "8080:8080"
    environment:
      CONCOURSE_POSTGRES_HOST: concourse-db
      CONCOURSE_POSTGRES_USER: concourse_user
      CONCOURSE_POSTGRES_PASSWORD: concourse_pass
      CONCOURSE_POSTGRES_DATABASE: concourse
      CONCOURSE_EXTERNAL_URL: http://localhost:8080
      CONCOURSE_ADD_LOCAL_USER: test:test
      CONCOURSE_MAIN_TEAM_LOCAL_USER: test
      CONCOURSE_TSA_HOST_KEY: /concourse-keys/tsa_host_key
      CONCOURSE_TSA_AUTHORIZED_KEYS: /concourse-keys/authorized_worker_keys
      CONCOURSE_SESSION_SIGNING_KEY: /concourse-keys/session_signing_key
      CONCOURSE_ENABLE_P2P_VOLUME_STREAMING: "true"
      CONCOURSE_CLUSTER_NAME: p2p-demo
      CONCOURSE_LOG_LEVEL: debug
    volumes:
      - keys:/concourse-keys:ro
    networks:
      - web-network
      - worker-network-a
      - worker-network-b

  # Worker A - on network A (isolated from Worker B)
  worker-a:
    image: concourse/concourse
    command: worker
    privileged: true
    cgroup: host
    dns:
      - 8.8.8.8
      - 1.1.1.1
    depends_on:
      keys-init:
        condition: service_completed_successfully
      concourse-web:
        condition: service_started
    environment:
      CONCOURSE_TSA_HOST: concourse-web:2222
      CONCOURSE_TSA_PUBLIC_KEY: /concourse-keys/tsa_host_key.pub
      CONCOURSE_TSA_WORKER_PRIVATE_KEY: /concourse-keys/worker_key
      CONCOURSE_WORK_DIR: /worker-state
      CONCOURSE_WORKER_BAGGAGECLAIM_DRIVER: overlay
      CONCOURSE_WORKER_RUNTIME: guardian
      CONCOURSE_GARDEN_DNS_PROXY_ENABLE: "true"
      CONCOURSE_NAME: worker-a
      CONCOURSE_TAG: network-a
      CONCOURSE_BAGGAGECLAIM_BIND_IP: 0.0.0.0
      CONCOURSE_BAGGAGECLAIM_BIND_PORT: 7788
      CONCOURSE_LOG_LEVEL: debug
    volumes:
      - keys:/concourse-keys:ro
    networks:
      - worker-network-a

  # Worker B - on network B (isolated from Worker A)
  worker-b:
    image: concourse/concourse
    command: worker
    privileged: true
    cgroup: host
    dns:
      - 8.8.8.8
      - 1.1.1.1
    depends_on:
      keys-init:
        condition: service_completed_successfully
      concourse-web:
        condition: service_started
    environment:
      CONCOURSE_TSA_HOST: concourse-web:2222
      CONCOURSE_TSA_PUBLIC_KEY: /concourse-keys/tsa_host_key.pub
      CONCOURSE_TSA_WORKER_PRIVATE_KEY: /concourse-keys/worker_key
      CONCOURSE_WORK_DIR: /worker-state
      CONCOURSE_WORKER_BAGGAGECLAIM_DRIVER: overlay
      CONCOURSE_WORKER_RUNTIME: guardian
      CONCOURSE_GARDEN_DNS_PROXY_ENABLE: "true"
      CONCOURSE_NAME: worker-b
      CONCOURSE_TAG: network-b
      CONCOURSE_BAGGAGECLAIM_BIND_IP: 0.0.0.0
      CONCOURSE_BAGGAGECLAIM_BIND_PORT: 7788
      CONCOURSE_LOG_LEVEL: debug
    volumes:
      - keys:/concourse-keys:ro
    networks:
      - worker-network-b

networks:
  web-network:
    driver: bridge
    ipam:
      config:
        - subnet: 172.28.0.0/24

  worker-network-a:
    driver: bridge
    ipam:
      config:
        - subnet: 172.29.0.0/24
    # No connection to worker-network-b

  worker-network-b:
    driver: bridge
    ipam:
      config:
        - subnet: 172.30.0.0/24
    # No connection to worker-network-a

volumes:
  data:
  keys:

start concourse:

docker-compose up -d

authenticate fly:

fly -t demo login -c http://localhost:8080 -u test -p test

create demo pipeline:

fly -t demo set-pipeline -p p2p-demo -c <(echo 'jobs:
  - name: test-p2p-streaming
    plan:
      # Step 1: Create data on worker-a
      - task: create-data-on-worker-a
        tags: [network-a]
        config:
          platform: linux
          image_resource:
            type: registry-image
            source:
              repository: alpine
          outputs:
            - name: data
          run:
            path: /bin/sh
            args:
              - -c
              - |
                echo "Running on worker-a (network-a)"
                echo "Creating test data..."
                # Create a file with some content
                dd if=/dev/urandom of=data/testfile.bin bs=1M count=10
                echo "Created 10MB test file"
                ls -la data/

      # Step 2: Read data on worker-b (THIS SHOULD FAIL with P2P enabled)
      # Worker-b cannot reach worker-a directly to stream the volume
      - task: read-data-on-worker-b
        tags: [network-b]
        config:
          platform: linux
          image_resource:
            type: registry-image
            source:
              repository: alpine
          inputs:
            - name: data
          run:
            path: /bin/sh
            args:
              - -c
              - |
                echo "Running on worker-b (network-b)"
                echo "Attempting to read data streamed from worker-a..."
                ls -la data/
                md5sum data/testfile.bin
                echo "SUCCESS: Data was streamed correctly"')
fly -t demo unpause-pipeline -p p2p-demo

trigger the job:

fly -t demo trigger-job -j p2p-demo/test-p2p-streaming -w

see it fail as expected.
2025-12-09_20-53

now, building this into a docker image and testing:

docker-compose down
echo 'FROM node:20 AS web-builder
WORKDIR /src
COPY package.json webpack.config.js ./

RUN npm install --legacy-peer-deps
COPY web ./web
COPY hack ./hack
RUN npm run build-less
RUN npm run build-elm
# Create stub bundle.js for legacy browser fallback (modern browsers use elm-setup.js module)
RUN echo '// Legacy browser fallback - use a modern browser for full support' > web/public/bundle.js

FROM golang:1.24 AS go-builder
ENV GOTOOLCHAIN=auto
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
COPY --from=web-builder /src/web/public ./web/public

RUN CGO_ENABLED=0 go build -o /concourse ./cmd/concourse

FROM concourse/concourse:latest
COPY --from=go-builder /concourse /usr/local/concourse/bin/concourse' > Dockerfile.p2p-fallback
docker build -t concourse:p2p-fallback -F Dockerfile.p2p-fallback .

update the image for concourse-web to concourse:p2p-fallback and then validate:

docker-compose up -d
fly -t demo trigger-job -j p2p-demo/test-p2p-streaming -w
2025-12-09_20-57

Comment thread atc/worker/streamer.go Outdated
err := s.p2pStream(ctx, p2pSrc, p2pDst)
if err != nil {
// P2P streaming failed - fallback to streaming through ATC (web node)
logger.Info("p2p-stream-failed-falling-back-to-atc", lager.Data{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

info level seems rather low, warn or error seem more appropriate IMO

@taylorsilva

taylorsilva commented Dec 9, 2025 •

Copy link
Copy Markdown
Member

This is super cool! Thanks for the PR, I'm excited to review it.

and THANK YOU for the very detailed steps to locally test and verify 👏 Saving me a bunch of time there!

@taylorsilva taylorsilva moved this from Todo to In Progress in Pull Requests Dec 11, 2025

@taylorsilva taylorsilva left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good! I would change the logger level from info to error. Otherwise this works wonderfully.

I tested using this pipeline and a similar docker-compose.yml as what you used:

pipeline.yml

resources:
  - name: mock
    type: mock
    tags: [network-a]

jobs:
  - name: job
    plan:
      - get: mock
        tags: [network-a]
      - put: mock
        no_get: true
        tags: [network-b]
        params:
          file: mock/version

Worked as expected:
image

I thought "maybe it would be nice to let the users know the initial P2P streaming failed", but realized we don't have a convenient way to communicate this back to the web node to log. Also thought that might be too noisy for users anyways. It does suck that volume streaming will appear to take longer than usual since we have to wait for the timeout to occur.

Comment thread atc/worker/streamer.go Resolved
@marcus-crane

marcus-crane commented Dec 15, 2025 •

Copy link
Copy Markdown
Contributor

@taylorsilva Hey Taylor, I'm one of Kurt's coworkers and just letting you know that he's on vacation for a week or two so don't be surprised if he doesn't reply for a little bit. He gave us a heads up about this PR before he left 😄

@taylorsilva taylorsilva left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - Thanks again for this PR!

@taylorsilva
taylorsilva merged commit a785c6e into concourse:master Dec 15, 2025
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Pull Requests Dec 15, 2025
@taylorsilva

Copy link
Copy Markdown
Member

@marcus-crane Thanks for letting me know. Thankfully he resolved the one thing that needed changing before he left :)

Enjoy your time off @kurtmc

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

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants