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

Trigger parser can create callable triggers #4310

Merged
merged 5 commits into from
Mar 16, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fixes bug where deploying callable functions failed (#4310).
15 changes: 10 additions & 5 deletions src/deploy/functions/runtimes/node/parseTriggers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,17 @@ export function addResourcesToBackend(
reason: "Needed for task queue functions.",
});
} else if (annotation.httpsTrigger) {
const trigger: backend.HttpsTrigger = {};
if (annotation.failurePolicy) {
logger.warn(`Ignoring retry policy for HTTPS function ${annotation.name}`);
if (annotation.labels?.["deployment-callable"]) {
delete annotation.labels["deployment-callable"];
triggered = { callableTrigger: {} };
} else {
const trigger: backend.HttpsTrigger = {};
if (annotation.failurePolicy) {
logger.warn(`Ignoring retry policy for HTTPS function ${annotation.name}`);
}
proto.copyIfPresent(trigger, annotation.httpsTrigger, "invoker");
triggered = { httpsTrigger: trigger };
}
proto.copyIfPresent(trigger, annotation.httpsTrigger, "invoker");
triggered = { httpsTrigger: trigger };
} else if (annotation.schedule) {
want.requiredAPIs.push({
api: "cloudscheduler.googleapis.com",
Expand Down
15 changes: 13 additions & 2 deletions src/gcp/cloudfunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,18 @@ export function endpointFromFunction(gcfFunction: CloudFunction): backend.Endpoi
trigger = {
taskQueueTrigger: {},
};
} else if (gcfFunction.labels?.["deployment-callable"]) {
} else if (
gcfFunction.labels?.["deployment-callable"] ||
// NOTE: "deployment-callabled" is a typo we introduced in https://github.com/firebase/firebase-tools/pull/4124.
// More than a month passed before we caught this typo, and we expect many callable functions in production
// to have this typo. It is convenient for users for us to treat the typo-ed label as a valid marker for callable
// function, so we do that here.
//
// The typo will be overwritten as callable functions are re-deployed. Eventually, there may be no callable
// functions with the typo-ed label, but we can't ever be sure. Sadly, we may have to carry this scar for a very long
// time.
gcfFunction.labels?.["deployment-callabled"]
) {
trigger = {
callableTrigger: {},
};
Expand Down Expand Up @@ -600,7 +611,7 @@ export function functionFromEndpoint(
} else {
gcfFunction.httpsTrigger = {};
if (backend.isCallableTriggered(endpoint)) {
gcfFunction.labels = { ...gcfFunction.labels, "deployment-callabled": "true" };
gcfFunction.labels = { ...gcfFunction.labels, "deployment-callable": "true" };
}
if (endpoint.securityLevel) {
gcfFunction.httpsTrigger.securityLevel = endpoint.securityLevel;
Expand Down
20 changes: 20 additions & 0 deletions src/test/deploy/functions/runtimes/node/parseTriggers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,26 @@ describe("addResourcesToBackend", () => {
expect(result).to.deep.equal(expected);
});

it("should handle a callable trigger", () => {
const trigger: parseTriggers.TriggerAnnotation = {
...BASIC_TRIGGER,
httpsTrigger: {},
labels: {
"deployment-callable": "true",
},
};

const result = backend.empty();
parseTriggers.addResourcesToBackend("project", "nodejs16", trigger, result);

const expected: backend.Backend = backend.of({
...BASIC_ENDPOINT,
callableTrigger: {},
labels: {},
});
expect(result).to.deep.equal(expected);
});

it("should handle a minimal task queue trigger", () => {
const trigger: parseTriggers.TriggerAnnotation = {
...BASIC_TRIGGER,
Expand Down