Avoid overwriting runner cached values on job API calls

What does this MR do and why?

Describe in detail what your merge request does and why.

This MR fixes the bug reported in #389230 (closed) where the Redis cache key for Ci::Runner was getting overwritten with a new one containing only the ip_address. This manifested itself in the UI by showing an old version value (which is what is stored in the database) anytime that a job is running. This is because the GitLab Runner only sends the ip_address information in job update REST requests, compared to the more complete information that it sends when it is regularly polling for jobs.

We solve the problem by merging the values in the Redis cache key, instead of replacing them.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

Follow steps to reproduce laid out in the issue. With this branch, the version should no longer revert when a job is running.

NOTE: To work with different Runner versions, you could either:

  1. Change the VERSION file and compile the runner locally with make runner-bin-host, or

  2. Update the ci_runners.version column for the runner you're testing. For example, assuming you're working with runner with ID 1007:

    \c gitlabhq_development_ci
    
    UPDATE
      ci_runners
    SET version = '15.7.3~beta.150.gc46e07f5'
    WHERE id = 1007
  3. You could work with the Docker images:

    # Register runner
    docker run --rm -it -v $HOME/.gitlab-runner:/etc/gitlab-runner --add-host="gdk.test:$(ifconfig | grep inet | awk '$1=="inet" {print $2}' | tail -n1)" gitlab/gitlab-runner:v15.7.2 \
          register -config /etc/gitlab-runner/config.gdk.toml \
                   --non-interactive --url "http://gdk.test:3000" --description "Test instance runner" \
                   --registration-token="$INSTANCE_RUNNER_REGISTRATION_TOKEN" --executor shell
    
    # Run it
    docker run --rm -it -v $HOME/.gitlab-runner:/etc/gitlab-runner --add-host="gdk.test:$(ifconfig | grep inet | awk '$1=="inet" {print $2}' | tail -n1)" gitlab/gitlab-runner:v15.7.2 \
          run -config /etc/gitlab-runner/config.gdk.toml

    The docker command pulls in runner v15.7.2, makes the gdk.test DNS record point to the host machine's IP address (so that it can talk to the GDK), and points the configuration to $HOME/.gitlab-runner/config.gdk.toml (it's OK if you don't have that file).

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Pedro Pombeiro

Merge request reports

Loading