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

Latest Schema method does not return "Schema Id" #53

Closed
akshayzendesk opened this issue Jul 10, 2020 · 10 comments
Closed

Latest Schema method does not return "Schema Id" #53

akshayzendesk opened this issue Jul 10, 2020 · 10 comments
Labels
question Further information is requested

Comments

@akshayzendesk
Copy link

The AVRO client method GetLatestSchema only returns schema but not the schema_id associated with it. Also there's no other method in the library to retrieve it. https://github.com/hamba/avro/blob/master/registry/client.go#L183-L191

func (c *Client) GetLatestSchema(subject string) (avro.Schema, error) {
	var payload schemaPayload
	err := c.request(http.MethodGet, "/subjects/"+subject+"/versions/latest", nil, &payload)
	if err != nil {
		return nil, err
	}

	return avro.Parse(payload.Schema)
}
@nrwiersma nrwiersma added the enhancement New feature or request label Jul 10, 2020
@nrwiersma
Copy link
Member

The subject latest endpoint does not return the schema id, just the version and the schema as seen here:

https://docs.confluent.io/current/schema-registry/develop/api.html

{
  "name": "test",
  "version": 1,
  "schema": "{\"type\": \"string\"}"
}

@nrwiersma nrwiersma added question Further information is requested and removed enhancement New feature or request labels Jul 20, 2020
@mcgrawia
Copy link
Contributor

mcgrawia commented Jul 22, 2020

Hi @nrwiersma I was trying to figure this out as well. Looking at the doc you linked above, it looks like the GET /subjects/(string: subject)/versions/(versionId: version) endpoint does return the schema ID: https://docs.confluent.io/current/schema-registry/develop/api.html#get--subjects-(string-%20subject)-versions-(versionId-%20version)

It isn't in the example response but it is in the response description. I was also able to confirm running the registry locally with the confluentinc/cp-schema-registry:latest docker image.

Response JSON Object:
--
subject (string) – Name of the subject that this schema is registered under
id (int) – Globally unique identifier of the schema
version (int) – Version of the returned schema
schema (string) – The schema string

Sample response:

{
    "subject": "test",
    "version": 1,
    "id": 2,
    "schema": "..."
}

thanks!

@nrwiersma
Copy link
Member

No, there is a mismatch between the reported returns and the example. Interestingly I checked https://github.com/salsify/avro-schema-registry which I have for a long time used as my registry, and it does not return the id in this command. I assume it was added since the client was added.

I will gladly add an additional function to get it, to not break backward compatibility, but it should be noted for the kafka case, this should not be needed. We instead used fingerprint checking that is provided by https://github.com/salsify/avro-schema-registry which tells you if a schema is registered and what its id is. This allows the publication of multiple versions of the schema at the same time by multiple versions of your application.

@mcgrawia
Copy link
Contributor

That would be fantastic, thank you. Let me know if a PR would be helpful. I'm relatively new to go but happy to try my hand at one.

One of the reason my use cases needs this ability is because our producing application consumes unique messages from customers. The application looks up the latest schema for a customer by subject, then writes the data to kafka. I don't think we would be able to use the pattern you described because our application does not have the schema in the source code?

@nrwiersma
Copy link
Member

Fair enough.

If you would like to try your hand at it, that would be great, I am always glad to get PRs. We cannot add it to the current function at this time, as it would be backward breaking. I would suggest you add function GetLatestSchemaId with its own payload. You can follow the tests for GetLatestSchema as coveralls will not let it pass without them.

Have fun 😄

@mcgrawia
Copy link
Contributor

@nrwiersma sounds good. I have a PR ready but I'm getting a "access denied" error when trying to push my new branch to the repo. Could you give me write access or is there another way to create a PR?

Thanks

@nrwiersma
Copy link
Member

Hi. You need to make a fork of it and then make your branch. You can then create the PR against master on the main repo.

@mcgrawia
Copy link
Contributor

thanks that did the trick

@nrwiersma
Copy link
Member

Fixed by #56

@nrwiersma
Copy link
Member

The fix can be found in v1.2.0, with thanks to @mcgrawia for providing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Development

No branches or pull requests

3 participants