Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADDED] Support for multi-endpoint services #1180

Merged
merged 6 commits into from
Jan 12, 2023
Merged

Conversation

piotrpio
Copy link
Collaborator

@piotrpio piotrpio commented Jan 4, 2023

No description provided.

RootSubject: "area",
Endpoints: map[string]micro.Endpoint{
"Rectangle": {
Subject: "rec",
Copy link
Contributor

@ripienaar ripienaar Jan 4, 2023

Choose a reason for hiding this comment

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

Whats the benefit of having this be configurable rather than RootSubject.EndpointName? We should specify valid end point names matching kv bucket rules so they are always safe to use by concatenation.

We could make this a optional but I think it would need to have significant benefit in being setable (and can always later be added, but not removed)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm all for it, using endpoint name as subject may be a better option, especially since calling the field Subject here is a bit misleading (it's not the actual subject, just the part after root).

One thing I'm not sure about is validating the endpoints the same way as kv bucket names. From what I remember, bucket names cannot contain subject delimiters, whereas for endpoints I would imagine users wanting to have logical hierarchy, similarly to REST urls, e.g. foo.users.create and foo.users.delete, where foo is the root subject`.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah good question. My first instinct is to say it doesn’t matter since the endpoint names will often map to like functions in clients so c.Add(1, 2) and languages just don’t do dots and things in function names

so that forced things to be flat on the endpoint name and the subject is a hidden detail.

If people want to do like a mux of their own then that’s a single endpoint service (what we have now) and that would be the only case I think we want to support like wildcard subjects.

Copy link
Contributor

Choose a reason for hiding this comment

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

@aricart curious about your thoughts here

Copy link
Member

@Jarema Jarema Jan 5, 2023

Choose a reason for hiding this comment

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

I think that endpoint subject == endpoint name.
The Endpoint subject should be ... a valid subject, so we don't care if users wants to have endpoints with . or not.
As we enocurage users to put some queryable tokens in subjects, removing that possibility from services does not seem right.

We might in future consider different approach to build service subjects hierarchy though...

HTTP framerowsk often allow grouping:

r := http.Router()
v1 := r.Group("/v1")
products := v1.Group("products")
products.Endpoint("add", handler)

Which is useful for structuring and adding group specific logic/middleware etc.

We could easily achive that with NATS subject tokens.

Copy link
Member

Choose a reason for hiding this comment

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

@aricart curious about your thoughts here

I think that if we take the api that @Jarema is pointing above, the need for the root subject etc goes away - the group becomes a root subject for that set of endpoints. In otherwords, I think both should be supported - easy should be trivial, and grouped should be easy.

micro/service.go Outdated
Schema Schema `json:"schema"`

// Endpoints is a collenction of service endpoints.
// Map key serves as endpoint name.
Copy link
Contributor

Choose a reason for hiding this comment

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

should document what are valid endpoint names and enforce

@@ -66,11 +66,11 @@ func TestServiceBasics(t *testing.T) {
Name: "CoolAddService",
Version: "0.1.0",
Description: "Add things together",
Endpoint: micro.Endpoint{
Schema: micro.Schema{Request: "", Response: ""},
Copy link
Member

Choose a reason for hiding this comment

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

just realized - shouldn't we have schema per endpoint?

Copy link
Member

Choose a reason for hiding this comment

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

@Jarema I discussed this with Roland, and the schema would be in a single option. If the schema maps the endpoint name to the operations...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@aricart agreed, one thing I am wondering about is whether in that case we should have the schema as:

	Schema struct {
		Request  string `json:"request"`
		Response string `json:"response"`
	}

with separation of Request and Response.

Instead, we can have a single schema string with each endpoint containing 2 entries - one for request and one for response (similarly to how it's done in openAPI).

Copy link
Member

Choose a reason for hiding this comment

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

@Jarema @ripienaar had a discussion with @piotrpio and I believe we need to take a stance now on how this is presented for multiple endpoints. @piotrpio is making the ADR changes based on what we discussed

Copy link
Member

@aricart aricart left a comment

Choose a reason for hiding this comment

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

LGTM save for a little nit

micro/service.go Show resolved Hide resolved
@piotrpio piotrpio merged commit 44509e6 into main Jan 12, 2023
@piotrpio piotrpio deleted the services-multi-endpoint branch January 12, 2023 09:01
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.

None yet

4 participants