Skip to content

[WIP] Fix race that causes tests to fail with timeout - #11410

Closed
php-coder wants to merge 1 commit into
openshift:masterfrom
php-coder:fix_waiting_for_registry
Closed

php-coder wants to merge 1 commit into
openshift:masterfrom
php-coder:fix_waiting_for_registry

Conversation

@php-coder

Copy link
Copy Markdown

It was possible that between command where we're getting value of the metadata.generation field and the command where we're checking the current state, value has been changed.

Thanks to @legionus for the code and @Kargakis for confirming that this is a race.

PTAL @bparees
@miminar JFYI

Fixes #11406

Comment thread hack/util.sh Outdated
readonly -f install_registry

function wait_for_registry() {
function wait_generation() {

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.

wait_for_synced_registry is a more appropriate name since you don't wait only for generation

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Maybe I should rename it to is_registry_ready? Because this function doesn't wait but returns the status of deployment.

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.

sure, that's fine too

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done, thanks!

@php-coder
php-coder force-pushed the fix_waiting_for_registry branch from 515b22b to 23a014d Compare October 18, 2016 12:51
Comment thread hack/util.sh Outdated
local generation="$(oc get dc/docker-registry -o 'jsonpath={.metadata.generation}')"
local onereplicajs='{.status.observedGeneration},{.status.replicas},{.status.updatedReplicas},{.status.availableReplicas}'
wait_for_command "oc get dc/docker-registry -o 'jsonpath=${onereplicajs}' --config='${ADMIN_KUBECONFIG}' | grep '^${generation},1,1,1$'" "$((5*TIME_MIN))"
oc get dc/docker-registry -o "jsonpath=${onereplicajs}" --config="${ADMIN_KUBECONFIG}" | fgrep -x "${generation},1,1,1"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This function shouldn't probably return anything. Or make it return just the generation. Returning 2,1,1,1 as a value indicating success doesn't make any sense.

@php-coder php-coder Oct 18, 2016 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch! I added -q parameter to suppress grep's output.

Comment thread hack/util.sh
readonly -f install_registry

function wait_for_registry() {
function is_registry_ready() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This probably won't be used on its own apart from wait_for_registry function. Maybe we could make it "private" by adding _ or __ prefix.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

When I'm looking in this file I don't see any function that uses such naming convention.

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.

NACK to prefixing it with anything. The correct format in correct files (I'm working on it ...) is os::<whatever>::internal::<funcname>

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@stevekuznetsov Where is documentation for this? Why even this file doesn't respect this rules? I see that this file has 28 functions without namespace and only 10 that having it.

…ith timeout.

It was possible that between command where we're getting value of
the metadata.generation field and the command where we're checking the
current state, value has been changed.
@php-coder
php-coder force-pushed the fix_waiting_for_registry branch from 23a014d to 4c421a9 Compare October 18, 2016 13:07
Comment thread hack/util.sh
readonly -f install_registry

function wait_for_registry() {
function is_registry_ready() {

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.

NACK to prefixing it with anything. The correct format in correct files (I'm working on it ...) is os::<whatever>::internal::<funcname>

Comment thread hack/util.sh
local generation="$(oc get dc/docker-registry -o 'jsonpath={.metadata.generation}')"
local onereplicajs='{.status.observedGeneration},{.status.replicas},{.status.updatedReplicas},{.status.availableReplicas}'
wait_for_command "oc get dc/docker-registry -o 'jsonpath=${onereplicajs}' --config='${ADMIN_KUBECONFIG}' | grep '^${generation},1,1,1$'" "$((5*TIME_MIN))"
oc get dc/docker-registry -o "jsonpath=${onereplicajs}" --config="${ADMIN_KUBECONFIG}" | fgrep -qx "${generation},1,1,1"

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.

Why change the grep invocation?

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.

I also feel like there's no good reason to conflate these four tests with each other -- we want to test:

  • observedGeneration == dc.generation
  • replicas == 1
  • updatedReplicas == 1
  • availableReplicas == 1

We aren't hurting for API calls, right? I would pefer to have four tests instead of one that sticks commas in there. I won't block this PR on it, though.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Why change the grep invocation?

@stevekuznetsov I have an opposite question: why I shouldn't?

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.

I also feel like there's no good reason to conflate these four tests with each other

we want to make sure the object has a coherent view of all four of those things at a single point in time. four consecutive checks wouldn't do that.

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.

@stevekuznetsov I have an opposite question: why I shouldn't?

@php-coder

  • change for the sake of change is not a good argument
  • fgrep is not preferred to grep -F

Justify your change by what it adds?

@liggitt

liggitt commented Oct 18, 2016

Copy link
Copy Markdown
Contributor

We specifically locked the expected generation at the beginning of the function, because nothing should be modifying the registry dc spec asynchronously while we're waiting here. If that is happening, we need to find out what is doing that and fix it.

@stevekuznetsov

Copy link
Copy Markdown
Contributor

We specifically locked the expected generation at the beginning of the function

While we're at it let's leave a comment to explain this subtle but important point about this function ...

@php-coder

Copy link
Copy Markdown
Author

We specifically locked the expected generation at the beginning of the function, because nothing should be modifying the registry dc spec asynchronously while we're waiting here. If that is happening, we need to find out what is doing that and fix it.

@liggitt How to debug this and find out who is changing the registry dc?

@php-coder

Copy link
Copy Markdown
Author

@liggitt I suspect that it happens because POST /oapi/v1/namespaces/default/deploymentconfigs/docker-registry/instantiate failed with 500 at least once:

I1018 14:22:45.851264    9853 audit.go:97] AUDIT: id="df4cf7ca-f504-4d66-86da-86e3473aa681" ip="10.0.2.15" method="POST" user="system:openshift-master" as="<self>" asgroups="" namespace="default" uri="/oapi/v1/namespaces/default/deploymentconfigs/docker-registry/instantiate"
I1018 14:22:45.885696    9853 factory.go:152] Replication controller "docker-registry-1" added.
I1018 14:22:45.886651    9853 controller_utils.go:159] Controller default/docker-registry-1 either never recorded expectations, or the ttl expired.
I1018 14:22:45.886981    9853 replication_controller_utils.go:52] Updating replica count for rc: default/docker-registry-1, replicas 0->0 (need 0), fullyLabeledReplicas 0->0, readyReplicas 0->0, sequence No: 0->1
E1018 14:22:45.913633    9853 apiserver.go:516] apiserver was unable to write a JSON response: http: request method or response status code does not allow body
E1018 14:22:45.913647    9853 errors.go:63] apiserver received an error that is not an unversioned.Status: http: request method or response status code does not allow body
I1018 14:22:45.913667    9853 audit.go:25] AUDIT: id="df4cf7ca-f504-4d66-86da-86e3473aa681" response="500"
I1018 14:22:45.913680    9853 logs.go:41] http: multiple response.WriteHeader calls
I1018 14:22:45.913922    9853 controller.go:55] Error instantiating deployment config default/docker-registry: empty data

@liggitt

liggitt commented Oct 18, 2016

Copy link
Copy Markdown
Contributor

I1018 14:22:45.913922 9853 controller.go:55] Error instantiating deployment config default/docker-registry: empty data

that's concerning, and seems like a more fundamental issue we need to track down and fix

nothing should be bumping the generation of the docker-registry dc after we call this helper function

@0xmichalis

0xmichalis commented Oct 18, 2016 •

Copy link
Copy Markdown
Contributor

There are two places in the deployment api that bump generation: the normal update strategy and the strategy used by /instantiate. The normal create hook sets generation to 1 and the update hook will increment on a spec or latestVersion update.

It seems though that prior to /instantiate we would end up with a deployment config with latestVersion=1 and generation=1 though generation is supposed to be 2:
--> Deployment config is created: latestVersion=0, generation=1
--> Trigger controller bumps latestVersion to 1
--> API server never updates generation to 2

After we got instantiate, the time for incrementing a version has become higher because we delegate to the API server via instantiate:
--> Deployment config is created: latestVersion=0, generation=1
--> Trigger controller calls instantiate
--> API server bumps latesVersion to 1 and generation to 2

We have an extended test for generation here.

@php-coder

Copy link
Copy Markdown
Author

@liggitt As far I understand @Kargakis explanation, we always should wait for generation=2. In this case I don't see a reason for extracting metadata.generation field at all. I'm suggesting to do grep '2,1,1,1'. Will such changes be approved by you?

@php-coder php-coder changed the title Fix race that causes tests to fail with timeout [WIP] Fix race that causes tests to fail with timeout Oct 19, 2016
@liggitt

liggitt commented Oct 19, 2016

Copy link
Copy Markdown
Contributor

I don't see a reason for extracting metadata.generation field at all. I'm suggesting to do grep '2,1,1,1'. Will such changes be approved by you?

no, we use this function in other places to wait for the registry to deploy an updated version based on changes made to the deployment config.

@mmilata

mmilata commented Oct 20, 2016

Copy link
Copy Markdown
Contributor

Can we use oc rollout status for this?

@0xmichalis

Copy link
Copy Markdown
Contributor

@mmilata good idea, we should use oc rollout status instead of fighting with grep

@mmilata

mmilata commented Oct 21, 2016

Copy link
Copy Markdown
Contributor

Something like this might work:

wait_for_command "oc rollout status dc/docker-registry --request-timeout=1m"  "$((5*TIME_MIN))"

@mmilata

mmilata commented Oct 21, 2016 •

Copy link
Copy Markdown
Contributor

With Slava's permission I've opened PR for using oc rollout status: #11487.
Edit: nvm, this is actually not what we want to do.

@php-coder

Copy link
Copy Markdown
Author

Closing this in favor of #11487

@php-coder php-coder closed this Oct 24, 2016
@php-coder
php-coder deleted the fix_waiting_for_registry branch October 24, 2016 17:59
@0xmichalis

Copy link
Copy Markdown
Contributor

You don't need a wait with rollout status since it uses a watch and never
returns until the rollout completes (so it uses the deployment config
timeout by default)

On Fri, Oct 21, 2016 at 3:52 PM, Martin Milata [email protected]
wrote:

Something like this might work:

wait_for_command "oc rollout status dc/docker-registry --request-timeout=1m" "$((5*TIME_MIN))"

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#11410 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ADuFf4ZQ4lSJVVb7K9o35IQvWT5Ii3b-ks5q2MOngaJpZM4KZt6Z
.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants