-
Notifications
You must be signed in to change notification settings - Fork 14
Protobuf system test for schema tracking #4044
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
Merged
+17,018
−8
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
4cb00a6
WIP add protobuf endpoints to java weblog
vandonr 6c91df3
add test
vandonr 4255dac
add csharp endpoint
vandonr f77093d
little updates to the proto used
vandonr 365487c
write assertions for the test
vandonr ca1edb6
add missing feature flag
vandonr 687f582
add comments and extra ignored message
vandonr 9298138
Merge branch 'main' into vandonr/proto
vandonr e9ac785
linting fix
vandonr 3c36f55
add feature
vandonr b6ef972
improve doc
vandonr 9fc44a2
lint fix
vandonr 859f497
remove trailing whitespace on generated file
vandonr 3853ef8
get rid of script file
vandonr b4199e2
restrict weblog variants + little fix
vandonr deff5bd
add annotations on versions supported
vandonr 71c5291
Merge remote-tracking branch 'origin/main' into vandonr/proto
vandonr 42cb443
s/bug/missing_feature
vandonr 0a5fe32
Merge branch 'main' into vandonr/proto
vandonr 03ba6da
Merge remote-tracking branch 'origin/main' into vandonr/proto
vandonr 93edb03
add doc on new endpoints
vandonr 6dbe531
move version requirement for tracers in the manifests
vandonr 4713eb3
move unimplemented tracers to manifests
vandonr fa77e98
Merge branch 'main' into vandonr/proto
vandonr 9f92328
Merge branch 'main' into vandonr/proto
vandonr 297f878
fix manifests
vandonr 7326b46
Merge branch 'main' into vandonr/proto
vandonr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import json | ||
|
|
||
| from utils import weblog, interfaces, features | ||
|
|
||
|
|
||
| # this test relies on the proto file at utils/build/docker/common/message.proto | ||
| @features.datastreams_monitoring_protobuf_schema_tracking | ||
| class Test_Protobuf: | ||
| def setup_protobuf(self): | ||
| self.serialization_response = weblog.get("/protobuf/serialize") | ||
| self.deserialization_response = weblog.get(f"/protobuf/deserialize?msg={self.serialization_response.text}") | ||
|
|
||
| def test_protobuf(self): | ||
| assert self.serialization_response.status_code == 200, self.serialization_response.text | ||
| assert self.deserialization_response.status_code == 200, self.deserialization_response.text | ||
|
|
||
| def validator(trace: list): | ||
| if len(trace) == 1: | ||
| span = trace[0] | ||
| else: | ||
| # find root span | ||
| span = next(s for s in trace if s["parent_id"] == 0) | ||
| # then find child-most span | ||
| while True: | ||
| child = next((s for s in trace if s["parent_id"] == span["span_id"]), None) | ||
| if child: | ||
| span = child | ||
| else: | ||
| break | ||
|
|
||
| meta = span.get("meta", {}) | ||
| assert "schema.id" in meta | ||
| assert "schema.type" in meta | ||
| assert "schema.definition" in meta | ||
| assert "schema.name" in meta | ||
| assert "schema.operation" in meta | ||
|
|
||
| assert meta["schema.id"] == "14603317962659197404", "hash should be the same across tracers" | ||
| assert meta["schema.type"] == "protobuf" | ||
| json.loads(meta["schema.definition"]) # will throw if malformed | ||
| assert "x-protobuf-number" in meta["schema.definition"] # rough check that we register the protobuf numbers | ||
| assert meta["schema.name"] == "proto_message.AddressBook" | ||
|
|
||
| return True | ||
|
|
||
| interfaces.library.validate_traces(request=self.serialization_response, validator=validator) | ||
| interfaces.library.validate_traces(request=self.deserialization_response, validator=validator) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| // to regenerate the source files when modifying this, run: | ||
| // protoc --csharp_out=../dotnet/weblog/Models/ --java_out=../java/spring-boot/src/main/java/com/datadoghq/system_tests/springboot/ message.proto | ||
|
|
||
| // used in tests/test_protobuf.py | ||
|
|
||
| syntax = "proto3"; | ||
| package proto_message; | ||
|
|
||
| message AddressBook { | ||
| map<int32, Person> people = 1; // checks that the types generated by the usage of a map are correctly handled | ||
| PhoneNumber central = 2; // here to check that we don't re-extract the PhoneNumber message when we encounter it again | ||
|
|
||
| // now just put every type to be exhaustive | ||
| // to help debugging a bit, the number given is the enum value of the type + 10 | ||
| double my_double = 11; | ||
| float my_float = 12; | ||
| int64 my_int64 = 13; | ||
| uint64 my_uint64 = 14; | ||
| int32 my_int32 = 15; | ||
| fixed64 my_fixed64 = 16; | ||
| fixed32 my_fixed32 = 17; | ||
| bool my_bool = 18; | ||
| string my_string = 19; | ||
| bytes my_bytes = 22; | ||
| uint32 my_uint32 = 23; | ||
| sfixed32 my_sfixed32 = 25; | ||
| sfixed64 my_sfixed64 = 26; | ||
| sint32 my_sint32 = 27; | ||
| sint64 my_sint64 = 28; | ||
|
|
||
| // here to test that we stop extracting after a certain depth | ||
| Deep d = 40; | ||
| } | ||
|
|
||
| message PhoneNumber { | ||
| string number = 1; | ||
| PhoneType type = 2; // check that enum are handled properly | ||
| } | ||
|
|
||
| enum PhoneType { | ||
| UNSPECIFIED = 0; | ||
| MOBILE = 1; | ||
| HOME = 2; | ||
| WORK = 3; | ||
| } | ||
|
|
||
| message Person { | ||
| string name = 1; | ||
| repeated PhoneNumber phones = 4; // check repeated fields | ||
| uint64 created = 5; | ||
| double last_updated = 6; | ||
|
|
||
| // this one is very artificial, but it's here to check that we stop at the same depth for all tracers | ||
| RecursiveField recurse = 7; | ||
|
|
||
| message RecursiveField { | ||
| sint32 value = 1; | ||
| RecursiveField deeper = 2; | ||
| } | ||
| } | ||
|
|
||
| message Deep { | ||
| A x = 1; | ||
|
|
||
| message A{ | ||
| B x = 1; | ||
| } | ||
|
|
||
| message B{ | ||
| C x = 1; | ||
| } | ||
|
|
||
| message C{ | ||
| D x = 1; | ||
| } | ||
|
|
||
| message D{ | ||
| E x = 1; | ||
| } | ||
|
|
||
| message E{ | ||
| F x = 1; | ||
| } | ||
|
|
||
| message F{ | ||
| G x = 1; | ||
| } | ||
|
|
||
| message G{ | ||
| H x = 1; | ||
| } | ||
|
|
||
| message H{ | ||
| I x = 1; // extraction should stop here (max depth = 10) | ||
| } | ||
|
|
||
| message I{ | ||
| J x = 1; | ||
| } | ||
|
|
||
| message J{ | ||
| int32 x = 1; | ||
| } | ||
| } | ||
|
|
||
| // just here to check that messages that are just floating around in the same file do not get extracted | ||
| message Ignored { | ||
| int32 x = 1; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
utils/build/docker/dotnet/weblog/Endpoints/ProtobufEndpoint.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| using System; | ||
| using System.IO; | ||
| using Google.Protobuf; | ||
| using Microsoft.AspNetCore.Builder; | ||
| using Microsoft.AspNetCore.Http; | ||
| using ProtoMessage; | ||
|
|
||
| namespace weblog; | ||
|
|
||
| public class ProtobufEndpoint : ISystemTestEndpoint | ||
| { | ||
| public void Register(Microsoft.AspNetCore.Routing.IEndpointRouteBuilder routeBuilder) | ||
| { | ||
| routeBuilder.MapGet("/protobuf/serialize", async context => | ||
| { | ||
| // the content of the message does not really matter since it's the schema that is observed. | ||
| var msg = new AddressBook { Central = new PhoneNumber { Number = "0123", Type = PhoneType.Work } }; | ||
| using (MemoryStream stream = new MemoryStream()) | ||
| { | ||
| msg.WriteTo(stream); | ||
| var b64Proto = Convert.ToBase64String(stream.ToArray()); | ||
| await context.Response.WriteAsync(b64Proto); | ||
| } | ||
| }); | ||
|
|
||
| routeBuilder.MapGet("/protobuf/deserialize", async context => | ||
| { | ||
| var b64Msg = context.Request.Query["msg"]; | ||
| var msg = Convert.FromBase64String(b64Msg); | ||
| new AddressBook().MergeFrom(msg); | ||
| await context.Response.WriteAsync("ok"); | ||
| }); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.