Skip to content
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

fix(proto): update gRPC requests to use the correct request parameters #581

Merged
merged 7 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"test:load": "jest --runInBand --detectOpenHandles",
"test:load:http": "TEST_SECRET_1=secret_val_1 TEST_SECRET_2=secret_val_2 dapr run --app-id test-suite --app-protocol http --app-port 50001 --dapr-http-port 50000 --components-path ./test/components -- npm run test:load 'test/load'",
"test:e2e": "jest --runInBand --detectOpenHandles",
"test:e2e:all": "npm run test:e2e:http; npm run test:e2e:grpc; npm run test:e2e:common; npm run test:e2e:workflow",
"test:e2e:all": "npm run test:e2e:http && npm run test:e2e:grpc && npm run test:e2e:common && npm run test:e2e:workflow",
"test:e2e:grpc": "npm run test:e2e:grpc:client && npm run test:e2e:grpc:server && npm run test:e2e:grpc:clientWithApiToken",
"test:e2e:grpc:client": "npm run prebuild && TEST_SECRET_1=secret_val_1 TEST_SECRET_2=secret_val_2 dapr run --app-id test-suite --app-protocol grpc --app-port 50001 --dapr-grpc-port 50000 --components-path ./test/components -- jest --runInBand --detectOpenHandles --testMatch [ '**/test/e2e/grpc/*client.test.ts' ]",
"test:e2e:grpc:clientWithApiToken": "npm run prebuild && TEST_SECRET_1=secret_val_1 TEST_SECRET_2=secret_val_2 DAPR_API_TOKEN=test dapr run --app-id test-suite --app-protocol grpc --app-port 50001 --dapr-grpc-port 50000 --components-path ./test/components -- jest --runInBand --detectOpenHandles --testMatch [ '**/test/e2e/grpc/clientWithApiToken.test.ts' ]",
Expand Down
4 changes: 2 additions & 2 deletions src/actors/client/ActorClient/ActorClientGRPC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { Empty } from "google-protobuf/google/protobuf/empty_pb";
import { Any } from "google-protobuf/google/protobuf/any_pb";
import {
ExecuteActorStateTransactionRequest,
GetActorStateRequest,
GetActorStateResponse,
GetMetadataRequest,
GetMetadataResponse,
InvokeActorRequest,
InvokeActorResponse,
Expand Down Expand Up @@ -279,7 +279,7 @@ export default class ActorClientGRPC implements IClientActor {
const client = await this.client.getClient();

return new Promise((resolve, reject) => {
client.getMetadata(new Empty(), (err, res: GetMetadataResponse) => {
client.getMetadata(new GetMetadataRequest(), (err, res: GetMetadataResponse) => {
if (err) {
return reject(err);
}
Expand Down
5 changes: 2 additions & 3 deletions src/implementation/Client/GRPCClient/health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ limitations under the License.

import GRPCClient from "./GRPCClient";
import IClientHealth from "../../../interfaces/Client/IClientHealth";
import { GetMetadataResponse } from "../../../proto/dapr/proto/runtime/v1/dapr_pb";
import { Empty } from "google-protobuf/google/protobuf/empty_pb";
import { GetMetadataRequest, GetMetadataResponse } from "../../../proto/dapr/proto/runtime/v1/dapr_pb";

// https://docs.dapr.io/reference/api/health_api/
export default class GRPCClientHealth implements IClientHealth {
Expand All @@ -30,7 +29,7 @@ export default class GRPCClientHealth implements IClientHealth {

return new Promise((resolve, _reject) => {
try {
client.getMetadata(new Empty(), (err, _res: GetMetadataResponse) => {
client.getMetadata(new GetMetadataRequest(), (err, _res: GetMetadataResponse) => {
if (err) {
return resolve(false);
}
Expand Down
8 changes: 6 additions & 2 deletions src/implementation/Client/GRPCClient/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ limitations under the License.
*/

import GRPCClient from "./GRPCClient";
import { GetMetadataResponse, SetMetadataRequest } from "../../../proto/dapr/proto/runtime/v1/dapr_pb";
import {
GetMetadataRequest,
GetMetadataResponse,
SetMetadataRequest,
} from "../../../proto/dapr/proto/runtime/v1/dapr_pb";
import { Empty } from "google-protobuf/google/protobuf/empty_pb";
import IClientMetadata from "../../../interfaces/Client/IClientMetadata";
import { GetMetadataResponse as GetMetadataResponseResult } from "../../../types/metadata/GetMetadataResponse";
Expand All @@ -30,7 +34,7 @@ export default class GRPCClientMetadata implements IClientMetadata {
const client = await this.client.getClient();

return new Promise((resolve, reject) => {
client.getMetadata(new Empty(), (err, res: GetMetadataResponse) => {
client.getMetadata(new GetMetadataRequest(), (err, res: GetMetadataResponse) => {
if (err) {
return reject(err);
}
Expand Down
6 changes: 3 additions & 3 deletions src/implementation/Client/GRPCClient/sidecar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ limitations under the License.

import GRPCClient from "./GRPCClient";
import IClientSidecar from "../../../interfaces/Client/IClientSidecar";
import { GetMetadataResponse } from "../../../proto/dapr/proto/runtime/v1/dapr_pb";
import { GetMetadataRequest, GetMetadataResponse, ShutdownRequest } from "../../../proto/dapr/proto/runtime/v1/dapr_pb";
import { Empty } from "google-protobuf/google/protobuf/empty_pb";

// https://docs.dapr.io/reference/api/secrets_api/
Expand All @@ -28,7 +28,7 @@ export default class GRPCClientSidecar implements IClientSidecar {
const client = await this.client.getClient();

return new Promise((resolve, reject) => {
client.shutdown(new Empty(), (err, _res: Empty) => {
client.shutdown(new ShutdownRequest(), (err, _res: Empty) => {
if (err) {
return reject(err);
}
Expand All @@ -43,7 +43,7 @@ export default class GRPCClientSidecar implements IClientSidecar {

return new Promise((resolve, _reject) => {
try {
callClient.getMetadata(new Empty(), (err, _res: GetMetadataResponse) => {
callClient.getMetadata(new GetMetadataRequest(), (err, _res: GetMetadataResponse) => {
if (err) {
return resolve(false);
}
Expand Down
20 changes: 10 additions & 10 deletions test/e2e/grpc/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import { CommunicationProtocolEnum, DaprClient, LogLevel } from "../../../src";
import { SubscribeConfigurationResponse } from "../../../src/types/configuration/SubscribeConfigurationResponse";
import * as DockerUtils from "../../utils/DockerUtil";
import { DaprClient as DaprClientGrpc } from "../../../src/proto/dapr/proto/runtime/v1/dapr_grpc_pb";
import { Empty } from "google-protobuf/google/protobuf/empty_pb";
import { NextCall } from "@grpc/grpc-js/build/src/client-interceptors";
import { GetMetadataRequest } from "../../../src/proto/dapr/proto/runtime/v1/dapr_pb";

const daprHost = "localhost";
const daprPort = "50000"; // Dapr Sidecar Port of this Example Server
Expand Down Expand Up @@ -76,7 +76,7 @@ describe("grpc/client", () => {
interceptors: [mockInterceptor],
});

await new Promise((resolve) => clientProxy.getMetadata(new Empty(), resolve));
await new Promise((resolve) => clientProxy.getMetadata(new GetMetadataRequest(), resolve));

expect(mockInterceptor.mock.calls.length).toBe(1);
expect(mockMetadataRes.get("dapr-app-id")[0]).toBe("test-suite");
Expand Down Expand Up @@ -104,7 +104,7 @@ describe("grpc/client", () => {
interceptors: [mockInterceptor],
});

await new Promise((resolve) => clientProxy.getMetadata(new Empty(), resolve));
await new Promise((resolve) => clientProxy.getMetadata(new GetMetadataRequest(), resolve));

expect(mockInterceptor.mock.calls.length).toBe(1);
expect(mockMetadataRes.get("dapr-app-id")[0]).toBe(process.env.APP_ID);
Expand Down Expand Up @@ -362,13 +362,13 @@ describe("grpc/client", () => {
expect(config.items["myconfigkey3"].value == "key3_initialvalue");
});

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

expect(conf.items["myconfigkey1"].metadata).toHaveProperty("hello");
});
// todo: enable this once we have a component to test this with.
// Redis does not support metadata, PG and Azure App Config do.
// it("should be able to get the configuration items with metadata", async () => {
// const conf = await client.configuration.get("config-redis", ["myconfigkey1"], {
// hello: "world",
// });
// });

it("should be able to subscribe to configuration item changes on all keys", async () => {
const m = jest.fn(async (_res: SubscribeConfigurationResponse) => {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/grpc/clientWithApiToken.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ limitations under the License.
import * as grpc from "@grpc/grpc-js";
import { CommunicationProtocolEnum, DaprClient, LogLevel } from "../../../src";
import { DaprClient as DaprClientGrpc } from "../../../src/proto/dapr/proto/runtime/v1/dapr_grpc_pb";
import { Empty } from "google-protobuf/google/protobuf/empty_pb";
import { NextCall } from "@grpc/grpc-js/build/src/client-interceptors";
import { GetMetadataRequest } from "../../../src/proto/dapr/proto/runtime/v1/dapr_pb";

const daprHost = "localhost";
const daprPort = "50000"; // Dapr Sidecar Port of this Example Server
Expand Down Expand Up @@ -50,7 +50,7 @@ describe("grpc/client with api token", () => {
interceptors: [mockInterceptor],
});

await new Promise((resolve) => clientProxy.getMetadata(new Empty(), resolve));
await new Promise((resolve) => clientProxy.getMetadata(new GetMetadataRequest(), resolve));
expect(mockMetadataRes.get("dapr-api-token")[0]).toBe("test");
});
});
Loading