Skip to content

Commit 319e2fb

Browse files
authored
Fix Configuration GRPC calls not sending metadata (#571)
* Fix Configuration GRPC calls not sending metadata Signed-off-by: Trevor Lund <[email protected]> * Address PR comment Signed-off-by: Trevor Lund <[email protected]> --------- Signed-off-by: Trevor Lund <[email protected]>
1 parent 5c2b40a commit 319e2fb

File tree

2 files changed

+7
-25
lines changed

2 files changed

+7
-25
lines changed

src/implementation/Client/GRPCClient/configuration.ts

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ limitations under the License.
1212
*/
1313

1414
import GRPCClient from "./GRPCClient";
15-
import * as grpc from "@grpc/grpc-js";
1615
import {
1716
GetConfigurationRequest,
1817
GetConfigurationResponse,
@@ -28,7 +27,7 @@ import { SubscribeConfigurationResponse as SubscribeConfigurationResponseResult
2827
import { SubscribeConfigurationCallback } from "../../../types/configuration/SubscribeConfigurationCallback";
2928
import { SubscribeConfigurationStream } from "../../../types/configuration/SubscribeConfigurationStream";
3029
import { ConfigurationItem } from "../../../types/configuration/ConfigurationItem";
31-
import { createConfigurationType } from "../../../utils/Client.util";
30+
import { addMetadataToMap, createConfigurationType } from "../../../utils/Client.util";
3231

3332
export default class GRPCClientConfiguration implements IClientConfiguration {
3433
client: GRPCClient;
@@ -38,25 +37,18 @@ export default class GRPCClientConfiguration implements IClientConfiguration {
3837
}
3938

4039
async get(storeName: string, keys: string[], metadataObj?: KeyValueType): Promise<GetConfigurationResponseResult> {
41-
const metadata = new grpc.Metadata();
42-
4340
const msg = new GetConfigurationRequest();
4441
msg.setStoreName(storeName);
4542

4643
if (keys && keys.length > 0) {
4744
msg.setKeysList(keys.filter((i) => i !== ""));
4845
}
49-
50-
if (metadataObj) {
51-
for (const [key, value] of Object.entries(metadataObj)) {
52-
metadata.add(key, value);
53-
}
54-
}
46+
addMetadataToMap(msg.getMetadataMap(), metadataObj);
5547

5648
const client = await this.client.getClient();
5749

5850
return new Promise((resolve, reject) => {
59-
client.getConfiguration(msg, metadata, (err, res: GetConfigurationResponse) => {
51+
client.getConfiguration(msg, (err, res: GetConfigurationResponse) => {
6052
if (err) {
6153
return reject(err);
6254
}
@@ -99,8 +91,6 @@ export default class GRPCClientConfiguration implements IClientConfiguration {
9991
keys?: string[],
10092
metadataObj?: KeyValueType,
10193
): Promise<SubscribeConfigurationStream> {
102-
const metadata = new grpc.Metadata();
103-
10494
const msg = new SubscribeConfigurationRequest();
10595
msg.setStoreName(storeName);
10696

@@ -109,20 +99,15 @@ export default class GRPCClientConfiguration implements IClientConfiguration {
10999
} else {
110100
msg.setKeysList([]);
111101
}
112-
113-
if (metadataObj) {
114-
for (const [key, value] of Object.entries(metadataObj)) {
115-
metadata.add(key, value);
116-
}
117-
}
102+
addMetadataToMap(msg.getMetadataMap(), metadataObj);
118103

119104
const client = await this.client.getClient();
120105

121106
// Open a stream. Note that this is a never-ending stream
122107
// and will stay open as long as the client is open
123108
// we will thus create a set with our listeners so we don't
124109
// break on multi listeners
125-
const stream = client.subscribeConfiguration(msg, metadata);
110+
const stream = client.subscribeConfiguration(msg);
126111
let streamId: string;
127112

128113
stream.on("data", async (data: SubscribeConfigurationResponse) => {

test/e2e/grpc/client.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,14 +363,11 @@ describe("grpc/client", () => {
363363
});
364364

365365
it("should be able to get the configuration items with metadata", async () => {
366-
await client.configuration.get("config-redis", ["myconfigkey1"], {
366+
const conf = await client.configuration.get("config-redis", ["myconfigkey1"], {
367367
hello: "world",
368368
});
369369

370-
// Disabled for now as I am unsure if Dapr returns the metadata items
371-
// Java SDK: https://github.com/dapr/java-sdk/blob/06d92dafca62a6b48e74ccf939feeac7189e360f/sdk/src/test/java/io/dapr/client/DaprPreviewClientGrpcTest.java#L119
372-
// ^ shows that it is not being tested, it tries but doesn't assert
373-
// expect(conf.items.filter(i => i.key == "myconfigkey1")[0].metadata).toHaveProperty("hello");
370+
expect(conf.items["myconfigkey1"].metadata).toHaveProperty("hello");
374371
});
375372

376373
it("should be able to subscribe to configuration item changes on all keys", async () => {

0 commit comments

Comments
 (0)