Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 64a257f

Browse files
[Feature] Improve GRPC JSON Handling (#1963)
1 parent 5d5296d commit 64a257f

File tree

8 files changed

+23
-12
lines changed

8 files changed

+23
-12
lines changed

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- (Bugfix) Fix AnyPB Parsing in Meta Service
1212
- (Feature) Add Arch Tolerations
1313
- (Bugfix) Enable Platform Operator on EE Chart
14+
- (Feature) Improve GRPC JSON Handling
1415

1516
## [1.3.0](https://github.com/arangodb/kube-arangodb/tree/1.3.0) (2025年08月01日)
1617
- (Feature) (Platform) Storage Debug

‎integrations/inventory/v1/definition/inventory.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (s *Inventory) JSON() ([]byte, error) {
3737
return []byte("{}"), nil
3838
}
3939

40-
return ugrpc.Marshal(s)
40+
return ugrpc.Marshal(s, ugrpc.WithUseProtoNames(true))
4141
}
4242

4343
func NewArangoDBConfiguration(spec api.DeploymentSpec, status api.DeploymentStatus) *ArangoDBConfiguration {

‎integrations/inventory/v1/definition/inventory_test.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func Test_State_Marshal(t *testing.T) {
4545

4646
data, err := ugrpc.Marshal(&s, func(in *protojson.MarshalOptions) {
4747
in.EmitDefaultValues = true
48+
in.UseProtoNames = false
4849
})
4950
require.NoError(t, err)
5051

‎pkg/deployment/resources/config_map_gateway.go‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,8 @@ func (r *Resources) ensureGatewayConfig(ctx context.Context, cachedStatus inspec
131131
},
132132
Marshaller: ugrpc.Marshal[*pbInventoryV1.Inventory],
133133
Options: []util.Mod[protojson.MarshalOptions]{
134-
func(in *protojson.MarshalOptions) {
135-
in.EmitDefaultValues = true
136-
},
134+
ugrpc.WithUseProtoNames(true),
135+
ugrpc.WithEmitDefaultValues(true),
137136
},
138137
},
139138
}

‎pkg/deployment/resources/gateway/dynamic.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func NodeDynamicConfig(cluster, id string, cds, lds *DynamicConfig) ([]byte, str
7878
b.DynamicResources.LdsConfig = v.AsConfigSource()
7979
}
8080

81-
data, err := ugrpc.MarshalYAML(&b)
81+
data, err := ugrpc.MarshalYAML(&b, ugrpc.WithUseProtoNames(true))
8282
if err != nil {
8383
return nil, "", nil, err
8484
}

‎pkg/deployment/resources/gateway/gateway_config.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (c Config) RenderYAML() ([]byte, string, *pbEnvoyBootstrapV3.Bootstrap, err
7777
return nil, "", nil, err
7878
}
7979

80-
data, err := ugrpc.MarshalYAML(cfg)
80+
data, err := ugrpc.MarshalYAML(cfg, ugrpc.WithUseProtoNames(true))
8181
if err != nil {
8282
return nil, "", nil, err
8383
}
@@ -90,7 +90,7 @@ func (c Config) RenderCDSYAML() ([]byte, string, *discoveryApi.DiscoveryResponse
9090
return nil, "", nil, err
9191
}
9292

93-
data, err := ugrpc.MarshalYAML(cfg)
93+
data, err := ugrpc.MarshalYAML(cfg, ugrpc.WithUseProtoNames(true))
9494
if err != nil {
9595
return nil, "", nil, err
9696
}
@@ -103,7 +103,7 @@ func (c Config) RenderLDSYAML() ([]byte, string, *discoveryApi.DiscoveryResponse
103103
return nil, "", nil, err
104104
}
105105

106-
data, err := ugrpc.MarshalYAML(cfg)
106+
data, err := ugrpc.MarshalYAML(cfg, ugrpc.WithUseProtoNames(true))
107107
if err != nil {
108108
return nil, "", nil, err
109109
}

‎pkg/util/grpc/http.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func Get[T proto.Message](ctx context.Context, client operatorHTTP.HTTPClient, u
105105
}
106106

107107
func Post[IN, T proto.Message](ctx context.Context, client operatorHTTP.HTTPClient, in IN, url string, mods ...util.Mod[goHttp.Request]) HTTPResponse[T] {
108-
data, err := Marshal(in)
108+
data, err := Marshal(in, WithUseProtoNames(true))
109109
if err != nil {
110110
return httpErrorResponse[T]{err: err}
111111
}

‎pkg/util/grpc/marshal.go‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,20 @@ import (
2828
"github.com/arangodb/kube-arangodb/pkg/util"
2929
)
3030

31-
func Marshal[T proto.Message](in T, opts ...util.Mod[protojson.MarshalOptions]) ([]byte, error) {
32-
options := protojson.MarshalOptions{
33-
UseProtoNames: true,
31+
func WithUseProtoNames(value bool) util.Mod[protojson.MarshalOptions] {
32+
return func(in *protojson.MarshalOptions) {
33+
in.UseProtoNames = value
34+
}
35+
}
36+
37+
func WithEmitDefaultValues(value bool) util.Mod[protojson.MarshalOptions] {
38+
return func(in *protojson.MarshalOptions) {
39+
in.EmitDefaultValues = value
3440
}
41+
}
42+
43+
func Marshal[T proto.Message](in T, opts ...util.Mod[protojson.MarshalOptions]) ([]byte, error) {
44+
options := protojson.MarshalOptions{}
3545

3646
util.ApplyMods(&options, opts...)
3747

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /