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 retry for event triggered functions #6391

Merged
merged 4 commits into from
Sep 26, 2023
Merged
Changes from 1 commit
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
Next Next commit
linking up retry to the api call
colerogers committed Sep 22, 2023
commit 122f87d0c60f5ec4fee391c893d4e67490cafd86
18 changes: 14 additions & 4 deletions src/gcp/cloudfunctionsv2.ts
Original file line number Diff line number Diff line change
@@ -36,6 +36,12 @@ export type FunctionState = "ACTIVE" | "FAILED" | "DEPLOYING" | "DELETING" | "UN
// Values allowed for the operator field in EventFilter
export type EventFilterOperator = "match-path-pattern";

// Values allowed for the event trigger retry policy in case of a function's execution failure.
export type RetryPolicy =
| "RETRY_POLICY_UNSPECIFIED"
| "RETRY_POLICY_DO_NOT_RETRY"
| "RETRY_POLICY_RETRY";

/** Settings for building a container out of the customer source. */
export interface BuildConfig {
runtime: runtimes.Runtime;
@@ -139,6 +145,8 @@ export interface EventTrigger {
// to the defualt compute service account.
serviceAccountEmail?: string;

retryPolicy?: RetryPolicy;

// The name of the channel associated with the trigger in
// `projects/{project}/locations/{location}/channels/{channel}` format.
channel?: string;
@@ -528,6 +536,7 @@ export function functionFromEndpoint(endpoint: backend.Endpoint): InputCloudFunc
if (backend.isEventTriggered(endpoint)) {
gcfFunction.eventTrigger = {
eventType: endpoint.eventTrigger.eventType,
retryPolicy: "RETRY_POLICY_UNSPECIFIED",
};
if (gcfFunction.eventTrigger.eventType === PUBSUB_PUBLISH_EVENT) {
if (!endpoint.eventTrigger.eventFilters?.topic) {
@@ -565,9 +574,10 @@ export function functionFromEndpoint(endpoint: backend.Endpoint): InputCloudFunc
);
proto.copyIfPresent(gcfFunction.eventTrigger, endpoint.eventTrigger, "channel");

if (endpoint.eventTrigger.retry) {
logger.warn("Cannot set a retry policy on Cloud Function", endpoint.id);
}
endpoint.eventTrigger.retry
? (gcfFunction.eventTrigger.retryPolicy = "RETRY_POLICY_RETRY")
: (gcfFunction.eventTrigger!.retryPolicy = "RETRY_POLICY_DO_NOT_RETRY");

// By default, Functions Framework in GCFv2 opts to downcast incoming cloudevent messages to legacy formats.
// Since Firebase Functions SDK expects messages in cloudevent format, we set FUNCTION_SIGNATURE_TYPE to tell
// Functions Framework to disable downcast before passing the cloudevent message to function handler.
@@ -651,7 +661,7 @@ export function endpointFromFunction(gcfFunction: OutputCloudFunction): backend.
trigger = {
eventTrigger: {
eventType: gcfFunction.eventTrigger.eventType,
retry: false,
retry: gcfFunction.eventTrigger.retryPolicy === "RETRY_POLICY_RETRY" ? true : false,
},
};
if (Object.keys(eventFilters).length) {
5 changes: 4 additions & 1 deletion src/test/gcp/cloudfunctionsv2.spec.ts
Original file line number Diff line number Diff line change
@@ -108,7 +108,7 @@ describe("cloudfunctionsv2", () => {
resource: "projects/p/regions/r/instances/i",
serviceName: "compute.googleapis.com",
},
retry: false,
retry: true,
channel: "projects/myproject/locations/us-wildwest11/channels/mychannel",
},
};
@@ -126,6 +126,7 @@ describe("cloudfunctionsv2", () => {
value: "compute.googleapis.com",
},
],
retryPolicy: "RETRY_POLICY_RETRY",
channel: "projects/myproject/locations/us-wildwest11/channels/mychannel",
},
serviceConfig: {
@@ -165,6 +166,7 @@ describe("cloudfunctionsv2", () => {
operator: "match-path-pattern",
},
],
retryPolicy: "RETRY_POLICY_DO_NOT_RETRY",
},
serviceConfig: {
...CLOUD_FUNCTION_V2.serviceConfig,
@@ -302,6 +304,7 @@ describe("cloudfunctionsv2", () => {
value: "pubsub.googleapis.com",
},
],
retryPolicy: "RETRY_POLICY_DO_NOT_RETRY",
},
serviceConfig: {
...CLOUD_FUNCTION_V2.serviceConfig,