-
Notifications
You must be signed in to change notification settings - Fork 251
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
Add util methods to parse proto files with dependencies #3834
Conversation
Thank you for creating a pull request! Pinging @andreaTP to respond or triage. |
Caching of artifacts with no version (e.g. latest) did not work because reindex would use the new key that has the artifact version that was found in the lookup. This code changes the default behavior to index both the artifact with its version and the latest/null version. It also exposes a configuration property (`apicurio.registry.cache-latest`) where this behavior can be disabled for use cases where caching of latest is not desired. See Apicurio#3824 for details.
...-utilities/src/main/java/io/apicurio/registry/utils/protobuf/schema/FileDescriptorUtils.java
Outdated
Show resolved
Hide resolved
...-utilities/src/main/java/io/apicurio/registry/utils/protobuf/schema/FileDescriptorUtils.java
Show resolved
Hide resolved
6fd8906
to
61efb2a
Compare
@carlesarnal I've missed few tests (on purpose) because I need first to understand which parts to change/improve (and maybe deduplicate, cause i've introduced a couple of wrappers for concept that are maybe already defined elsewhere) Re the comment on the APi I would use in Hyperfoil at #3834 (comment), I've replaced it with something as simple as passing files, which is instead the parse method version used by Apicurio. |
61efb2a
to
c7c5fef
Compare
This PR doesn't just include the change to enable parsing protos + deps but it add a fix too to the ability to link protos which belong to different packages. |
b23b57e
to
50b7217
Compare
…a updates (#3839) * feat(schema-cache): ERCache.configureFaultTolerantRefresh #3807 (#3823) Adds the notion of a fault tolerance in refresh for production environments where it's better to use a stale cache value than die when a cache entry refresh fails. See issue #3807 for details. Co-authored-by: Devon Berry <devon.berry@riotgames.com> * fix(schema-resolver): caching of latest artifacts #3834 Caching of artifacts with no version (e.g. latest) did not work because reindex would use the new key that has the artifact version that was found in the lookup. This code changes the default behavior to index both the artifact with its version and the latest/null version. It also exposes a configuration property (`apicurio.registry.cache-latest`) where this behavior can be disabled for use cases where caching of latest is not desired. See #3824 for details. --------- Co-authored-by: Devon Berry <devon.berry@riotgames.com>
64203b7
to
10615e3
Compare
I've just noticed that loading the schema is keep on loading imports which are not used and it seems is due to private static FileSystem getFileSystem() throws IOException {
final FakeFileSystem inMemoryFileSystem = new FakeFileSystem();
inMemoryFileSystem.setWorkingDirectory(okio.Path.get("/"));
inMemoryFileSystem.setAllowSymlinks(true);
final ClassLoader classLoader = ProtobufSchemaLoader.class.getClassLoader();
createDirectory(GOOGLE_API_PATH.split("/"), inMemoryFileSystem);
loadProtoFiles(inMemoryFileSystem, classLoader, GOOGLE_API_PROTOS, GOOGLE_API_PATH);
createDirectory(GOOGLE_WELLKNOWN_PATH.split("/"), inMemoryFileSystem);
loadProtoFiles(inMemoryFileSystem, classLoader, GOOGLE_WELLKNOWN_PROTOS, GOOGLE_WELLKNOWN_PATH);
createDirectory(METADATA_PATH.split("/"), inMemoryFileSystem);
loadProtoFiles(inMemoryFileSystem, classLoader, Collections.singleton(METADATA_PROTO), METADATA_PATH);
createDirectory(DECIMAL_PATH.split("/"), inMemoryFileSystem);
loadProtoFiles(inMemoryFileSystem, classLoader, Collections.singleton(DECIMAL_PROTO), DECIMAL_PATH);
return inMemoryFileSystem;
} which is placing dependencies which maybe won't be required to resolve the specific proto file (nor its dependencies). This could be done in a follow-up PR but ideally we would like to re-use the transitive resolution of dependencies mechanism of this PR |
In addition I've checked how Before this PR:
With this PR:
And I've noticed that before this PR we always add ALL the base dependencies Fds, while this PR strip it out in order to use just the required one (which is a win). |
10615e3
to
cd32a4f
Compare
No need to split, it's fine as it is. |
@@ -93,6 +93,10 @@ private static void loadProtoFiles(FakeFileSystem inMemoryFileSystem, ClassLoade | |||
for (String proto : protos) { | |||
//Loads the proto file resource files. | |||
final InputStream inputStream = classLoader.getResourceAsStream(protoPath + proto); | |||
// TODO tmp fix to run tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just remember to remove this :)
Yes, this was done just to be sure we have all the well-known types available when resolving the main proto file in case any of them are being used. Obviously resolving the actually used ones and just adding them is way better than the current solution. |
Same as above, the old parser was just making anything "parsable" available. This is obviously a win (just as you said :)) |
Caching of artifacts with no version (e.g. latest) did not work because reindex would use the new key that has the artifact version that was found in the lookup. This code changes the default behavior to index both the artifact with its version and the latest/null version. It also exposes a configuration property (`apicurio.registry.cache-latest`) where this behavior can be disabled for use cases where caching of latest is not desired. See #3824 for details. Co-authored-by: Devon Berry <devon.berry@riotgames.com>
4f0b335
to
63545d8
Compare
397e727
to
d565880
Compare
This is to open a discussion about a new public API to parse a file and its dependencies.
In the current state I don't like (at all) the other public API I've exposed for #3819
ie