-
Notifications
You must be signed in to change notification settings - Fork 130
Add ConfigV2 Validator #2672
Add ConfigV2 Validator #2672
Conversation
Codecov Report
@@ Coverage Diff @@
## gapic_config_v2 #2672 +/- ##
=====================================================
- Coverage 86.77% 86.76% -0.01%
- Complexity 5584 5588 +4
=====================================================
Files 466 467 +1
Lines 22193 22222 +29
Branches 2428 2430 +2
=====================================================
+ Hits 19257 19281 +24
- Misses 2078 2081 +3
- Partials 858 860 +2
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## gapic_config_v2 #2672 +/- ##
=====================================================
- Coverage 86.76% 86.76% -0.01%
- Complexity 5584 5589 +5
=====================================================
Files 466 467 +1
Lines 22185 22204 +19
Branches 2428 2430 +2
=====================================================
+ Hits 19249 19265 +16
- Misses 2078 2080 +2
- Partials 858 859 +1
Continue to review full report at Codecov.
|
PTAL |
import com.google.protobuf.util.JsonFormat.TypeRegistry; | ||
import javax.annotation.Nonnull; | ||
|
||
public class ConfigNextVersionValidator { |
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.
This name is a bit odd. What about just ConfigVersionValidator?
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.
sure
|
||
try { | ||
// Serializing utils for Config V2. | ||
TypeRegistry typeRegistryV2 = |
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.
Is it necessary to use a TypeRegistry and json formatting functions? Can we not just use toByteArray, parseFrom(byte[]), and check for unknown fields?
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.
If we use the toByteArray and parseFrom functions, those will still preserve the unknown fields. The thing with the unknown fields is that they can exist at every single level of the protobuf object tree, and I don't feel like writing a tree search function to parse through every child message type and looking for unknown types (i've already been burned trying to implement a BFS haha)
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.
What about using a DiscardUnknownFieldsParser? I don't know, but my intuition is that there is an almost-one-liner that does this, something like:
configBytes = config.toByteArray();
configV2Bytes = DiscardUnknownFieldsParser.wrap(ConfigV2.parser())
.parseFrom(configBytes)
.toByteArray();
// compare byte arrays ...
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.
But - maybe I'm just wrong? Like, does the above fail because of unknown fields other than v1/v2 differences?
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.
oh i didn't see that! i heard that Go had the same thing, but i didn't look hard enough for a java version
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.
much shorter now :) i must have been looking at stackoverflow posts that are outdated now for help on this
* Throw {@link IllegalStateException} iff the given input contains fields unknown to the {@link | ||
* com.google.api.codegen.v2.ConfigProto} schema. | ||
*/ | ||
public void checkIsNextVersionConfig(@Nonnull com.google.api.codegen.ConfigProto configV1Proto) |
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.
What about something like validateV2Config
? I don't think it is desirable to make the function name version-agnostic (unless the implementation is also version-agnostic)
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.
ok!
|
renamed things |
PTAL |
} | ||
|
||
try { | ||
|
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.
Nit: remove extra line
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.
done
if (!Arrays.equals(configV2.toByteArray(), configV1Proto.toByteArray())) { | ||
throw new IllegalStateException( | ||
String.format( | ||
"Unknown fields in to ConfigProto v2 in configProto: %s", |
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.
s/in to ConfigProto/to ConfigProto/
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.
done
* Add Gapic config v2 (#2665) * Whittling down config_v2 (#2666) * Add ConfigV2 Validator (#2672) * AutoValue LongRunningConfig; always use gapic config's polling settings (#2698) * ResourceNameOneofConfig fixes (#2704) * Start parsing GAPIC config v2 (#2703) * Bring back timeout millis in GAPIC config v2 (#2708) * Resource names across different protofiles (#2711) * Fix missing default retries (#2718) * Bug fixes for gapic config v2 parsing (#2717)
* Add Gapic config v2 (googleapis#2665) * Whittling down config_v2 (googleapis#2666) * Add ConfigV2 Validator (googleapis#2672) * AutoValue LongRunningConfig; always use gapic config's polling settings (googleapis#2698) * ResourceNameOneofConfig fixes (googleapis#2704) * Start parsing GAPIC config v2 (googleapis#2703) * Bring back timeout millis in GAPIC config v2 (googleapis#2708) * Resource names across different protofiles (googleapis#2711) * Fix missing default retries (googleapis#2718) * Bug fixes for gapic config v2 parsing (googleapis#2717)
Add util to validate a ConfigProto object as valid under the V2 schema.
This util is currently not used, but it is planned to be used very soon.