From f67e18b95f22a52d48342f4a06ab38c2da619ec7 Mon Sep 17 00:00:00 2001 From: Thomas Bouldin Date: Thu, 23 Jan 2025 08:26:48 -0800 Subject: [PATCH 1/3] Revert "Remove label annotations for genkit functions; they break" This reverts commit f6abd614b130878704d7158f8ea46b8960164df3. --- src/deploy/functions/backend.ts | 3 --- src/gcp/cloudfunctionsv2.spec.ts | 40 ++++++++++++++++++++++++++++++++ src/gcp/cloudfunctionsv2.ts | 6 +++++ 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/deploy/functions/backend.ts b/src/deploy/functions/backend.ts index fcea6d149a4..113d1ac09dd 100644 --- a/src/deploy/functions/backend.ts +++ b/src/deploy/functions/backend.ts @@ -42,9 +42,6 @@ export interface HttpsTriggered { /** API agnostic version of a Firebase callable function. */ export type CallableTrigger = { - // NOTE: This is currently unused because GCF 2nd gen labels do not support - // the characterset that may be in a genkit action name. - // This should be set as a Cloud Run attribute once we move to Cloud Run Functions. genkitAction?: string; }; diff --git a/src/gcp/cloudfunctionsv2.spec.ts b/src/gcp/cloudfunctionsv2.spec.ts index 4d3b89eab35..ef9486f9b9f 100644 --- a/src/gcp/cloudfunctionsv2.spec.ts +++ b/src/gcp/cloudfunctionsv2.spec.ts @@ -221,6 +221,23 @@ describe("cloudfunctionsv2", () => { [BLOCKING_LABEL]: "before-sign-in", }, }); + + expect( + cloudfunctionsv2.functionFromEndpoint({ + ...ENDPOINT, + platform: "gcfv2", + callableTrigger: { + genkitAction: "flows/flow", + }, + }), + ).to.deep.equal({ + ...CLOUD_FUNCTION_V2, + labels: { + ...CLOUD_FUNCTION_V2.labels, + "deployment-callable": "true", + "genkit-action": "flows/flow", + }, + }); }); it("should copy trival fields", () => { @@ -637,6 +654,29 @@ describe("cloudfunctionsv2", () => { }); }); + it("should translate genkit callables", () => { + expect( + cloudfunctionsv2.endpointFromFunction({ + ...HAVE_CLOUD_FUNCTION_V2, + labels: { + "deployment-callable": "true", + "genkit-action": "flows/flow", + }, + }), + ).to.deep.equal({ + ...ENDPOINT, + callableTrigger: { + genkitAction: "flows/flow", + }, + platform: "gcfv2", + uri: GCF_URL, + labels: { + "deployment-callable": "true", + "genkit-action": "flows/flow", + }, + }); + }); + it("should copy optional fields", () => { const extraFields: backend.ServiceConfiguration = { ingressSettings: "ALLOW_ALL", diff --git a/src/gcp/cloudfunctionsv2.ts b/src/gcp/cloudfunctionsv2.ts index af1cb92984a..6d17c607bbc 100644 --- a/src/gcp/cloudfunctionsv2.ts +++ b/src/gcp/cloudfunctionsv2.ts @@ -609,6 +609,9 @@ export function functionFromEndpoint(endpoint: backend.Endpoint): InputCloudFunc gcfFunction.labels = { ...gcfFunction.labels, "deployment-taskqueue": "true" }; } else if (backend.isCallableTriggered(endpoint)) { gcfFunction.labels = { ...gcfFunction.labels, "deployment-callable": "true" }; + if (endpoint.callableTrigger.genkitAction) { + gcfFunction.labels["genkit-action"] = endpoint.callableTrigger.genkitAction; + } } else if (backend.isBlockingTriggered(endpoint)) { gcfFunction.labels = { ...gcfFunction.labels, @@ -654,6 +657,9 @@ export function endpointFromFunction(gcfFunction: OutputCloudFunction): backend. trigger = { callableTrigger: {}, }; + if (gcfFunction.labels["genkit-action"]) { + trigger.callableTrigger.genkitAction = gcfFunction.labels["genkit-action"]; + } } else if (gcfFunction.labels?.[BLOCKING_LABEL]) { trigger = { blockingTrigger: { From 47776a45d3ba667cae30025e47553ce4a4ca82d4 Mon Sep 17 00:00:00 2001 From: Thomas Bouldin Date: Thu, 23 Jan 2025 08:29:58 -0800 Subject: [PATCH 2/3] Restore genkit-action label as a boolean --- src/gcp/cloudfunctionsv2.spec.ts | 25 +------------------------ src/gcp/cloudfunctionsv2.ts | 5 +---- 2 files changed, 2 insertions(+), 28 deletions(-) diff --git a/src/gcp/cloudfunctionsv2.spec.ts b/src/gcp/cloudfunctionsv2.spec.ts index ef9486f9b9f..2eb254cb233 100644 --- a/src/gcp/cloudfunctionsv2.spec.ts +++ b/src/gcp/cloudfunctionsv2.spec.ts @@ -235,7 +235,7 @@ describe("cloudfunctionsv2", () => { labels: { ...CLOUD_FUNCTION_V2.labels, "deployment-callable": "true", - "genkit-action": "flows/flow", + "genkit-action": "true", }, }); }); @@ -654,29 +654,6 @@ describe("cloudfunctionsv2", () => { }); }); - it("should translate genkit callables", () => { - expect( - cloudfunctionsv2.endpointFromFunction({ - ...HAVE_CLOUD_FUNCTION_V2, - labels: { - "deployment-callable": "true", - "genkit-action": "flows/flow", - }, - }), - ).to.deep.equal({ - ...ENDPOINT, - callableTrigger: { - genkitAction: "flows/flow", - }, - platform: "gcfv2", - uri: GCF_URL, - labels: { - "deployment-callable": "true", - "genkit-action": "flows/flow", - }, - }); - }); - it("should copy optional fields", () => { const extraFields: backend.ServiceConfiguration = { ingressSettings: "ALLOW_ALL", diff --git a/src/gcp/cloudfunctionsv2.ts b/src/gcp/cloudfunctionsv2.ts index 6d17c607bbc..56dd0a83694 100644 --- a/src/gcp/cloudfunctionsv2.ts +++ b/src/gcp/cloudfunctionsv2.ts @@ -610,7 +610,7 @@ export function functionFromEndpoint(endpoint: backend.Endpoint): InputCloudFunc } else if (backend.isCallableTriggered(endpoint)) { gcfFunction.labels = { ...gcfFunction.labels, "deployment-callable": "true" }; if (endpoint.callableTrigger.genkitAction) { - gcfFunction.labels["genkit-action"] = endpoint.callableTrigger.genkitAction; + gcfFunction.labels["genkit-action"] = "true"; } } else if (backend.isBlockingTriggered(endpoint)) { gcfFunction.labels = { @@ -657,9 +657,6 @@ export function endpointFromFunction(gcfFunction: OutputCloudFunction): backend. trigger = { callableTrigger: {}, }; - if (gcfFunction.labels["genkit-action"]) { - trigger.callableTrigger.genkitAction = gcfFunction.labels["genkit-action"]; - } } else if (gcfFunction.labels?.[BLOCKING_LABEL]) { trigger = { blockingTrigger: { From 1d44e96f690ba00db9f3288d3764325b0d6119ff Mon Sep 17 00:00:00 2001 From: Thomas Bouldin Date: Thu, 23 Jan 2025 08:33:30 -0800 Subject: [PATCH 3/3] Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e69de29bb2d..761519f0e65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -0,0 +1 @@ +Annotate onCallGenkit functions to allow for future Firebase Console annotations (#8135)