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 bug where 2nd Gen firestore functions were mistakenly parsed as pubsub function #6456

Merged
merged 3 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
Fix bug where 2nd Gen firestore functions were mistakenly parsed as p…
…ubsub function.

Firestore trigger also includes pubsubTopic since they use pubsub as transport. This triggered a bug where 2nd Gen Firestore bugs were being parsed as pubsub function which manifests in bugs like #6453.
  • Loading branch information
taeold committed Oct 19, 2023
commit ecd78051191bb2d3ed57c796252478a6299538a5
5 changes: 4 additions & 1 deletion src/gcp/cloudfunctionsv2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@
* @param type Type of deployment - create, update, or delete.
* @param err The error returned from the operation.
*/
function functionsOpLogReject(func: InputCloudFunction, type: string, err: any): void {

Check warning on line 251 in src/gcp/cloudfunctionsv2.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unexpected any. Specify a different type
if (err?.message?.includes("maxScale may not exceed")) {

Check warning on line 252 in src/gcp/cloudfunctionsv2.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe member access .message on an `any` value

Check warning on line 252 in src/gcp/cloudfunctionsv2.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe call of an `any` typed value
const maxInstances = func.serviceConfig.maxInstanceCount || DEFAULT_MAX_INSTANCE_COUNT;
utils.logLabeledWarning(
"functions",
Expand All @@ -265,14 +265,14 @@
`You can adjust the max instances value in your function's runtime options:\n\t${suggestedFix}`
);
} else {
utils.logLabeledWarning("functions", `${err?.message}`);

Check warning on line 268 in src/gcp/cloudfunctionsv2.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Invalid type "any" of template literal expression

Check warning on line 268 in src/gcp/cloudfunctionsv2.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe member access .message on an `any` value
if (err?.context?.response?.statusCode === 429) {

Check warning on line 269 in src/gcp/cloudfunctionsv2.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe member access .context on an `any` value
utils.logLabeledWarning(
"functions",
`Got "Quota Exceeded" error while trying to ${type} ${func.name}. Waiting to retry...`
);
} else if (
err?.message?.includes(

Check warning on line 275 in src/gcp/cloudfunctionsv2.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe member access .message on an `any` value

Check warning on line 275 in src/gcp/cloudfunctionsv2.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe call of an `any` typed value
"If you recently started to use Eventarc, it may take a few minutes before all necessary permissions are propagated to the Service Agent"
)
) {
Expand All @@ -288,8 +288,8 @@
);
}
throw new FirebaseError(`Failed to ${type} function ${func.name}`, {
original: err,

Check warning on line 291 in src/gcp/cloudfunctionsv2.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe assignment of an `any` value
status: err?.context?.response?.statusCode,

Check warning on line 292 in src/gcp/cloudfunctionsv2.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe assignment of an `any` value
context: { function: func.name },
});
}
Expand Down Expand Up @@ -661,7 +661,10 @@
} else if (gcfFunction.eventTrigger) {
const eventFilters: Record<string, string> = {};
const eventFilterPathPatterns: Record<string, string> = {};
if (gcfFunction.eventTrigger.pubsubTopic) {
if (
gcfFunction.eventTrigger.pubsubTopic &&
gcfFunction.eventTrigger.eventType === PUBSUB_PUBLISH_EVENT
) {
eventFilters.topic = gcfFunction.eventTrigger.pubsubTopic;
} else {
for (const eventFilter of gcfFunction.eventTrigger.eventFilters || []) {
Expand Down
40 changes: 40 additions & 0 deletions src/test/gcp/cloudfunctionsv2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,46 @@ describe("cloudfunctionsv2", () => {
},
})
).to.deep.equal(want);

// And again with a pattern match event trigger
want = {
...want,
eventTrigger: {
eventType: "google.cloud.firestore.document.v1.written",
eventFilters: {
database: "(default)",
namespace: "(default)",
},
eventFilterPathPatterns: {
document: "users/{userId}",
},
retry: false,
},
};
expect(
cloudfunctionsv2.endpointFromFunction({
...HAVE_CLOUD_FUNCTION_V2,
eventTrigger: {
eventType: "google.cloud.firestore.document.v1.written",
eventFilters: [
{
attribute: "database",
value: "(default)",
},
{
attribute: "namespace",
value: "(default)",
},
{
attribute: "document",
value: "users/{userId}",
operator: "match-path-pattern",
},
],
pubsubTopic: "eventarc-us-central1-abc", // firestore triggers use pubsub as transport
},
})
).to.deep.equal(want);
});

it("should translate custom event triggers", () => {
Expand Down
Loading