Skip to content

listwatch: do not duplicate resource versions - #3340

Merged
brancz merged 2 commits into
prometheus-operator:release-0.40from
lilic:fix-multi-ns-watch
Jul 20, 2020
Merged

brancz merged 2 commits into
prometheus-operator:release-0.40from
lilic:fix-multi-ns-watch

Conversation

@lilic

@lilic lilic commented Jul 17, 2020

Copy link
Copy Markdown
Contributor

This fixes a known bug #3218 as well as an unknown until the 0.39 release where List and Watch were producing a large amount of errors most likely due to a combination of bumping client-go, using multi namespace watcher and removing the CRD management done by operator. This left the option of the multi list watcher to create a wrong set of resourceVersions because of duplicates, most likely due to large amount of resources filling the cache at startup. As all of these things combined is very rare, even hard to reproduce, which is why this was most likely not experienced by a lot of users, hence lack of bug reports.

Note: I really want to move away from using a custom multi namespace watcher very soon so did not spend too much time on refactor. #3339

This was tested on both vanilla k8s 1.18.3 and more complex setup of OpenShift monitoring where we make heavy use of this feature.

cc @coreos/team-monitoring

Thanks @mfojtik for the initial fix.

Fixes #3218

@paulfantom paulfantom 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

@lilic
lilic changed the base branch from master to release-0.40 July 17, 2020 07:37
@lilic
lilic force-pushed the fix-multi-ns-watch branch from 2ca9f6d to 34ef014 Compare July 17, 2020 07:38
@lilic
lilic force-pushed the fix-multi-ns-watch branch from 34ef014 to 85c6afd Compare July 17, 2020 07:40
@simonpasquier

Copy link
Copy Markdown
Contributor

lgtm

Comment thread pkg/listwatch/listwatch.go Outdated
if len(rvs) != len(mlw) {
return nil, fmt.Errorf("expected resource version to have %d parts to match the number of ListerWatchers", len(mlw))
if len(rvs) != 1 {
return nil, fmt.Errorf("expected resource version to have 1 parts to match the number of ListerWatchers, got %d", len(rvs))

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 don't understand the logic here. The reason we combine multiple resource versions with a slash is to later be able to distribute the resources to multiple watchers. Yet here we are enforcing that there should only be one version. So why not simply not join versions in the first place rather than fail if we did join then?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes you are right but the new exception is that we always must have a single resource version (I realize this makes use of implemention details of resourceVersion right now, but until refactoring its reliable enough judging by our tests and manual testing) there is certainly room for refactoring but we would end up refactoring or removing the entire thing, the aim is to do the minimal to fix the bug yet not modify as this is aimed at 0.40 release. See #3218 for background of this specific one.

Comment thread pkg/listwatch/listwatch.go Outdated
for _, lw := range lws {
o := options.DeepCopy()
o.ResourceVersion = resourceVersions[i]
o.ResourceVersion = resourceVersions[0]

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.

This will produce odd results if more than one listerwatcher is given since they'll now be watching from the wrong version. Why not enforce that lws has length == 1? Or that it is a single instance vs a slice?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Or that it is a single instance vs a slice?

Yes exactly we could simply not pass in a slice and instead a single instance and refactor the entire function, but as mentioned in the description I did not want to focus too much on refactoring the entire thing as this fixes a bug in 0.40 version, but in master as per the linked issue we want to move away from custom multi listwatcher as we had a few bugs with it and it has known issues as we know now as from the research Paul did #3218. Hope that clarifies it? :)

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'm perfectly happy with a short term fix, just the string slice should be a single string, and we have a single call site, so it's a 3 line change from this one :)

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.

Agreed, as mentioned, let's make this a single string vs a slice to avoid confusion and unexpected results/usages

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure will make the change, but FYI it's not a 3 line change from this one ;)

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.

My apologies, if it does turn out to be way to complicated I'm happy with not doing it, just wanted us to try.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No worries, just need to adjust all the unit tests and retest on vanilla k8s and OpenShift clusters and CI so might take a day or two longer depending on CI. :) WIP until then.

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.

just chiming in that my fear is that without this last change we are leaving the library in a particularly weird place where it doesn't attempt to do the things it is supposedly designed for (even if the original impl has bugs). I am worried that this will be confusing and could lead to future issues or misunderstandings

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.

understandable, I'm not too worried since this is just on the release branch, and not into master, but leaving it up to Lili to judge the trade-offs, I'm happy with going either way

@brancz brancz left a comment

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.

lgtm once we change the resourceVersion to a single string

Comment thread pkg/listwatch/listwatch.go Outdated
for _, lw := range lws {
o := options.DeepCopy()
o.ResourceVersion = resourceVersions[i]
o.ResourceVersion = resourceVersions[0]

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'm perfectly happy with a short term fix, just the string slice should be a single string, and we have a single call site, so it's a 3 line change from this one :)

@lilic lilic changed the title listwatch: do not duplicate resource versions WIP: listwatch: do not duplicate resource versions Jul 17, 2020
@lilic
lilic force-pushed the fix-multi-ns-watch branch 3 times, most recently from 7a69396 to a07e6c5 Compare July 20, 2020 09:16
@lilic
lilic force-pushed the fix-multi-ns-watch branch from a07e6c5 to 47dd8c7 Compare July 20, 2020 09:17
@lilic

lilic commented Jul 20, 2020

Copy link
Copy Markdown
Contributor Author

We have one failure:

alertmanager_test.go:287: failed to wait for initialized alertmanager cluster: the server is currently unable to handle the request (get pods alertmanager-test-1): failed to get correct amount of peers, expected 3, got 1, addresses [{01EDNS7FGW81R8TNVCDWT0MPRF 172.17.0.5:9094}]

But I have checked and seems like we have had this failure or similar before a few times. Will restart the build.

@lilic lilic changed the title WIP: listwatch: do not duplicate resource versions listwatch: do not duplicate resource versions Jul 20, 2020
@lilic

lilic commented Jul 20, 2020

Copy link
Copy Markdown
Contributor Author

@brancz @squat PTAL I have addressed the comment, tested it on vanilla k8s and openshift and it works correctly.

@brancz
brancz merged commit 0dca0f2 into prometheus-operator:release-0.40 Jul 20, 2020
@lilic
lilic deleted the fix-multi-ns-watch branch July 20, 2020 11:57
@s-urbaniak

s-urbaniak commented Aug 7, 2020 •

Copy link
Copy Markdown
Contributor

I believe the code here introduces cascading failures again. The way I read the code here is that we might join resource versions in List [1] but we will always err out in Watch whenever that join happened just right before a previous List.

[1]

l.ListMeta.ResourceVersion = strings.Join(resourceVersions.List(), "/")

[2]

if len(rvs) > 1 {
return nil, fmt.Errorf("expected resource version to have 1 part, got %d", len(rvs))
}

@s-urbaniak

Copy link
Copy Markdown
Contributor

Also, I am trying to understand the reasoning for the fix. Do we assume here, that we will always get only one resource version from all underlying watchers the rationale being that API server always returns the latest resource version independent of the namespace being watched?

s-urbaniak added a commit to s-urbaniak/prometheus-operator that referenced this pull request Aug 7, 2020
prometheus-operator#3340
added a workaround to err out if multiple resource versions are reported from api server.

However the preceeding List function allows multiple resource versions to slip through.
This causes potential cascading failures.
s-urbaniak added a commit to s-urbaniak/prometheus-operator that referenced this pull request Aug 10, 2020
prometheus-operator#3340
added a workaround to err out if multiple resource versions are reported from api server.

However the preceeding List function allows multiple resource versions to slip through.
This causes potential cascading failures.
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.

Errors in log when watching multiple namespaces

7 participants