Skip to content

WIP: implement initial set of MCP enhancements #10635

Closed
ayj wants to merge 16 commits intoistio:release-1.1from
ayj:release-1.1-mcpv2-rebased
Closed

WIP: implement initial set of MCP enhancements #10635
ayj wants to merge 16 commits intoistio:release-1.1from
ayj:release-1.1-mcpv2-rebased

Conversation

@ayj
Copy link
Copy Markdown
Contributor

@ayj ayj commented Dec 22, 2018

This introduces the initial set of MCP enhancements as described by the MCP enhancements design proposal. The existing client/server implementation is retained, though several internal interfaces have been refactored so both implementations can coexist during migration.

@ayj ayj requested a review from ozevren December 22, 2018 01:57
@istio-testing istio-testing added the do-not-merge/work-in-progress Block merging of a PR because it isn't ready yet. label Dec 22, 2018
@istio-testing
Copy link
Copy Markdown
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: ayj
To fully approve this pull request, please assign additional approvers.
We suggest the following additional approver: rshriram

If they are not already assigned, you can assign the PR to them by writing /assign @rshriram in a comment when ready.

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ayj
Copy link
Copy Markdown
Contributor Author

ayj commented Dec 22, 2018

cc @Nino-K @jeffmendoza @ozevren

This PR includes istio/api#741 and #10628. The relevant commit to this PR is ae865f3

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.

nackLimitFreq is unused (from deadcode)

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.

recvError is unused (from deadcode)

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.

connections is unused (from structcheck)

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.

typeURL is unused (from structcheck)

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.

connections is unused (from structcheck)

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.

error var updateError should have name of the form errFoo (from golint)

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.

type name will be used as source.SourceStream by other packages, and that stutters; consider calling this Stream (from golint)

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.

error var sendError should have name of the form errFoo (from golint)

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.

File is not goimports-ed (from goimports)

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.

makeWatchResponse - typeURL always receives test.FakeType0TypeURL ("type.googleapis.com/istio.io.galley.pkg.mcp.server.FakeType0") (from unparam)

@ayj ayj force-pushed the release-1.1-mcpv2-rebased branch from ae865f3 to 6e619bf Compare December 22, 2018 02:03
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.

errRecv is unused (from varcheck)

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.

connections is unused (from structcheck)

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.

File is not goimports-ed (from goimports)

@ayj ayj requested a review from geeknoid January 3, 2019 23:07
Copy link
Copy Markdown
Contributor

@geeknoid geeknoid left a comment

Choose a reason for hiding this comment

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

I'm surprised to see these abstractions with mutual exclusion logic. Are these really going to be used by multiple concurrent callers? When?

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.

Does this object init need to happen under lock or could it be moved out? Putting it under lock ensures that all the RecentRequestInfo instance are inserted in time order, but is that needed? At least, the call to proto.Clone could be done outside the lock.

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.

Good catch. I moved it outside the lock. We can optimize this further and remove the proto clone if we treat the request proto as immutable. One less memory allocation in the client/sink path.

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.

Is this really what you want here? I think this will end up allocating an ever-increasing array under the covers.

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.

This was copy/pasted from the original MCP journal code. I think the same concern was raised during the review of that code, but @ozevren said the golang runtime would reclaim the memory. In any case, I rewrote to use a fixed slice without additional memory allocations.

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.

failus -> failures
logs as a -> logged in a

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 think it's bad form to have an otherwise reentrant library pull in state from the ambient environment. I would prefer if these values came in as arguments when initializing this package, and let the wrapping command read the environment and supply the values.

That is, environment variables should handled like command-line arguments and read by the top-level command code.

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.

Fair enough. I've moved the envvar handling out of the common mcp packages and into the galley/configmap loading code. I've also added Option structs to the source/sink packages where callers can optionally set these sorts of overrides in addition to the other required parameters.

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.

If ServerSink a thread-safe abstraction? I wasn't expecting it to be...

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.

It's minimally thread-safe. The majority of state is per-connection/stream. The extra atomic check here prevents the case of multiple sources connecting, which isn't supported (yet). Eventually, Galley may status from multiple Pilot instances, in which case a single sink server may have multiple source connections.

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.

Stream is for sending...

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.

When is a sink used in a multithread environment?

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.

The lock here protects the per-type resource version state. This state is used in the request path for fast-resume on re-connection. The caller can invoke ResetResourceVersions() to reset this version information and force a full state delivery. This function is invoked outside of the normal request path and must therefore protect access to the state with a lock.

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.

Given this is a utility package that several components will use, it'd worth stating the multithreading expectations/support explicitly in 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.

h can be Watcher (from interfacer)

@istio-testing istio-testing added the needs-rebase Indicates a PR needs to be rebased before being merged label Jan 9, 2019
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.

struct field tag json:- not compatible with reflect.StructTag.Get: bad syntax for struct tag value (from govet)

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.

struct field tag json:- not compatible with reflect.StructTag.Get: bad syntax for struct tag value (from govet)

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.

ineffectual assignment to byNamespace (from ineffassign)

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.

fakeResource2 is unused (from varcheck)

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.

fakeResource1 is unused (from varcheck)

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.

fakeResource0 is unused (from varcheck)

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.

mustMarshalAny is unused (from deadcode)

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.

addedTracking is unused (from deadcode)

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.

obj is unused (from structcheck)

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.

updated is unused (from structcheck)

Copy link
Copy Markdown
Member

@Nino-K Nino-K Jan 10, 2019

Choose a reason for hiding this comment

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

@ayj Should I go ahead and close this #10446 since it's covered here?

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.

I think so. This PR still has some TODO's around optimizing ServiceEntry updates and invoking ConfigUpdate() directly that we'll still need to address in a follow-up PR

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.

is this still needed?

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.

It would be nice to call this New so the caller can do sink.New as oppose to sink.NewSink, but very minor.

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.

retryDelay?

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.

Just curious why is this needed? if no update received for a resource within a time frame it is destined to be removed.

@ayj ayj force-pushed the release-1.1-mcpv2-rebased branch from 048179d to 19063a5 Compare January 10, 2019 23:50
@istio-testing istio-testing removed the needs-rebase Indicates a PR needs to be rebased before being merged label Jan 10, 2019
@ayj ayj force-pushed the release-1.1-mcpv2-rebased branch from 19063a5 to 81497ac Compare January 10, 2019 23:52
@ayj ayj force-pushed the release-1.1-mcpv2-rebased branch from 81497ac to c43172b Compare January 11, 2019 00:00
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.

ineffectual assignment to err (from ineffassign)

@ayj ayj force-pushed the release-1.1-mcpv2-rebased branch from 4b99dbb to b54ae47 Compare January 11, 2019 18:12
@istio-testing istio-testing added the needs-rebase Indicates a PR needs to be rebased before being merged label Jan 11, 2019
@istio-testing istio-testing removed the needs-rebase Indicates a PR needs to be rebased before being merged label Jan 12, 2019
@ayj ayj force-pushed the release-1.1-mcpv2-rebased branch from 3933efa to c40901c Compare January 12, 2019 00:51
// We can do this, because there is no error that can be raised from now on.
b.state.items[kind] = newTypeState
for key, val := range added {
collection, found := b.state.items[key.Kind]
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.

ineffectual assignment to collection (from ineffassign)

@istio-testing
Copy link
Copy Markdown
Collaborator

istio-testing commented Jan 15, 2019

@ayj: The following tests failed, say /retest to rerun them all:

Test name Commit Details Rerun command
prow/istio-integ-local-tests.sh d8aac25 link /test istio-integ-local-tests
prow/istio-integ-k8s-tests.sh d8aac25 link /test istio-integ-k8s-tests
Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@istio-testing
Copy link
Copy Markdown
Collaborator

@ayj: PR needs rebase.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@istio-testing istio-testing added the needs-rebase Indicates a PR needs to be rebased before being merged label Jan 15, 2019
func (b *SchemaBuilder) Register(typeURL string) Info {
if _, found := b.schema.byURL[typeURL]; found {
panic(fmt.Sprintf("schema.Register: Proto type is registered multiple times: %q", typeURL))
func (b *SchemaBuilder) Register(rawCollection, typeURL string) Info {
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 thought we replace typeURL with collection, why do we keep them both?

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.

A collection has a corresponding schema (e.g. typeURL) defined by the proto. This mapping is defined in galley/tools/gen-meta/metadata.yaml and is registered at runtime here. The typeURL is used elsewhere to allocate new protobuf instances of the correct type.

@ayj ayj closed this Jan 26, 2019
@ayj ayj deleted the release-1.1-mcpv2-rebased branch January 26, 2019 01:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/work-in-progress Block merging of a PR because it isn't ready yet. needs-rebase Indicates a PR needs to be rebased before being merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants