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

Print cloudfunctions.net URL instead of run.app URL for 2nd Gen function #7887

Merged
merged 3 commits into from
Nov 20, 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
5 changes: 3 additions & 2 deletions src/deploy/functions/backend.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,16 @@ describe("Backend", () => {
maxInstanceRequestConcurrency: 80,
},
};
const RUN_URI = "https://id-nonce-region-project.run.app";
const GCF_URL = "https://region-project.cloudfunctions.net/id";
const HAVE_CLOUD_FUNCTION_V2: gcfV2.OutputCloudFunction = {
...CLOUD_FUNCTION_V2,
serviceConfig: {
service: "service",
uri: RUN_URI,
uri: GCF_URL,
availableCpu: "1",
maxInstanceRequestConcurrency: 80,
},
url: GCF_URL,
state: "ACTIVE",
updateTime: new Date(),
};
Expand Down
2 changes: 1 addition & 1 deletion src/deploy/functions/release/fabricator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
try {
await fn();
this.logOpSuccess(op, endpoint);
} catch (err: any) {

Check warning on line 126 in src/deploy/functions/release/fabricator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
result.error = err as Error;
}
result.durationMs = timer.stop();
Expand Down Expand Up @@ -223,7 +223,7 @@
}

async createV1Function(endpoint: backend.Endpoint, scraper: SourceTokenScraper): Promise<void> {
const sourceUrl = this.sources[endpoint.codebase!]?.sourceUrl;

Check warning on line 226 in src/deploy/functions/release/fabricator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Forbidden non-null assertion
if (!sourceUrl) {
logger.debug("Precondition failed. Cannot create a GCF function without sourceUrl");
throw new Error("Precondition failed");
Expand All @@ -242,7 +242,7 @@
const op: { name: string } = await gcf.createFunction(apiFunction);
return poller.pollOperation<gcf.CloudFunction>({
...gcfV1PollerOptions,
pollerName: `create-${endpoint.codebase}-${endpoint.region}-${endpoint.id}`,

Check warning on line 245 in src/deploy/functions/release/fabricator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Invalid type "string | undefined" of template literal expression
operationResourceName: op.name,
onPoll: scraper.poller,
});
Expand Down Expand Up @@ -279,7 +279,7 @@
}
} else if (
backend.isBlockingTriggered(endpoint) &&
AUTH_BLOCKING_EVENTS.includes(endpoint.blockingTrigger.eventType as any)

Check warning on line 282 in src/deploy/functions/release/fabricator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe argument of type `any` assigned to a parameter of type `"providers/cloud.auth/eventTypes/user.beforeCreate" | "providers/cloud.auth/eventTypes/user.beforeSignIn" | "providers/cloud.auth/eventTypes/user.beforeSendEmail" | "providers/cloud.auth/eventTypes/user.beforeSendSms"`

Check warning on line 282 in src/deploy/functions/release/fabricator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
) {
// Auth Blocking functions should always be public
await this.executor
Expand All @@ -291,7 +291,7 @@
}

async createV2Function(endpoint: backend.Endpoint, scraper: SourceTokenScraper): Promise<void> {
const storageSource = this.sources[endpoint.codebase!]?.storage;

Check warning on line 294 in src/deploy/functions/release/fabricator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Forbidden non-null assertion
if (!storageSource) {
logger.debug("Precondition failed. Cannot create a GCFv2 function without storage");
throw new Error("Precondition failed");
Expand All @@ -307,15 +307,15 @@
.run(async () => {
try {
await pubsub.createTopic({ name: topic });
} catch (err: any) {

Check warning on line 310 in src/deploy/functions/release/fabricator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
// Pub/Sub uses HTTP 409 (CONFLICT) with a status message of
// ALREADY_EXISTS if the topic already exists.
if (err.status === 409) {

Check warning on line 313 in src/deploy/functions/release/fabricator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .status on an `any` value
return;
}
throw new FirebaseError("Unexpected error creating Pub/Sub topic", {
original: err as Error,
status: err.status,

Check warning on line 318 in src/deploy/functions/release/fabricator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value

Check warning on line 318 in src/deploy/functions/release/fabricator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .status on an `any` value
});
}
})
Expand Down Expand Up @@ -394,7 +394,7 @@
});
}

endpoint.uri = resultFunction.serviceConfig?.uri;
endpoint.uri = resultFunction.url;
const serviceName = resultFunction.serviceConfig?.service;
endpoint.runServiceId = utils.last(serviceName?.split("/"));
if (!serviceName) {
Expand Down
25 changes: 14 additions & 11 deletions src/gcp/cloudfunctionsv2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ describe("cloudfunctionsv2", () => {
};

const RUN_URI = "https://id-nonce-region-project.run.app";
const GCF_URL = "https://region-project.cloudfunctions.net/id";
const HAVE_CLOUD_FUNCTION_V2: cloudfunctionsv2.OutputCloudFunction = {
...CLOUD_FUNCTION_V2,
serviceConfig: {
service: "service",
uri: RUN_URI,
},
url: GCF_URL,
state: "ACTIVE",
updateTime: new Date(),
};
Expand Down Expand Up @@ -408,7 +410,7 @@ describe("cloudfunctionsv2", () => {
...ENDPOINT,
httpsTrigger: {},
platform: "gcfv2",
uri: RUN_URI,
uri: GCF_URL,
});
});

Expand All @@ -425,7 +427,7 @@ describe("cloudfunctionsv2", () => {
...ENDPOINT,
httpsTrigger: {},
platform: "gcfv2",
uri: RUN_URI,
uri: GCF_URL,
runServiceId: "service-id",
});
});
Expand All @@ -434,7 +436,7 @@ describe("cloudfunctionsv2", () => {
let want: backend.Endpoint = {
...ENDPOINT,
platform: "gcfv2",
uri: RUN_URI,
uri: GCF_URL,
eventTrigger: {
eventType: events.v2.PUBSUB_PUBLISH_EVENT,
eventFilters: { topic: "projects/p/topics/t" },
Expand Down Expand Up @@ -561,7 +563,7 @@ describe("cloudfunctionsv2", () => {
const want: backend.Endpoint = {
...ENDPOINT,
platform: "gcfv2",
uri: RUN_URI,
uri: GCF_URL,
eventTrigger: {
eventType: "com.custom.event",
eventFilters: { customattr: "customvalue" },
Expand Down Expand Up @@ -596,7 +598,7 @@ describe("cloudfunctionsv2", () => {
...ENDPOINT,
taskQueueTrigger: {},
platform: "gcfv2",
uri: RUN_URI,
uri: GCF_URL,
labels: { "deployment-taskqueue": "true" },
});
});
Expand All @@ -613,7 +615,7 @@ describe("cloudfunctionsv2", () => {
eventType: events.v1.BEFORE_CREATE_EVENT,
},
platform: "gcfv2",
uri: RUN_URI,
uri: GCF_URL,
labels: { "deployment-blocking": "before-create" },
});
});
Expand All @@ -630,7 +632,7 @@ describe("cloudfunctionsv2", () => {
eventType: events.v1.BEFORE_SIGN_IN_EVENT,
},
platform: "gcfv2",
uri: RUN_URI,
uri: GCF_URL,
labels: { "deployment-blocking": "before-sign-in" },
});
});
Expand Down Expand Up @@ -668,7 +670,7 @@ describe("cloudfunctionsv2", () => {
...ENDPOINT,
platform: "gcfv2",
httpsTrigger: {},
uri: RUN_URI,
uri: GCF_URL,
...extraFields,
serviceAccount: "[email protected]",
vpc,
Expand Down Expand Up @@ -703,7 +705,7 @@ describe("cloudfunctionsv2", () => {
).to.deep.equal({
...ENDPOINT,
platform: "gcfv2",
uri: RUN_URI,
uri: GCF_URL,
httpsTrigger: {},
...extraFields,
});
Expand All @@ -721,7 +723,7 @@ describe("cloudfunctionsv2", () => {
).to.deep.equal({
...ENDPOINT,
platform: "gcfv2",
uri: RUN_URI,
uri: GCF_URL,
httpsTrigger: {},
labels: {
...ENDPOINT.labels,
Expand All @@ -744,7 +746,7 @@ describe("cloudfunctionsv2", () => {
).to.deep.equal({
...ENDPOINT,
platform: "gcfv2",
uri: RUN_URI,
uri: GCF_URL,
httpsTrigger: {},
labels: {
...ENDPOINT.labels,
Expand All @@ -761,6 +763,7 @@ describe("cloudfunctionsv2", () => {
...ENDPOINT,
platform: "gcfv2",
httpsTrigger: {},
uri: GCF_URL,
};
delete expectedEndpoint.runServiceId;
expect(
Expand Down
2 changes: 2 additions & 0 deletions src/gcp/cloudfunctionsv2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export type OutputCloudFunction = CloudFunctionBase & {
state: FunctionState;
updateTime: Date;
serviceConfig?: RequireKeys<ServiceConfig, "service" | "uri">;
url: string;
};

export type InputCloudFunction = CloudFunctionBase & {
Expand Down Expand Up @@ -781,6 +782,7 @@ export function endpointFromFunction(gcfFunction: OutputCloudFunction): backend.
endpoint.runServiceId = utils.last(serviceName.split("/"));
}
}
proto.renameIfPresent(endpoint, gcfFunction, "uri", "url");
endpoint.codebase = gcfFunction.labels?.[CODEBASE_LABEL] || projectConfig.DEFAULT_CODEBASE;
if (gcfFunction.labels?.[HASH_LABEL]) {
endpoint.hash = gcfFunction.labels[HASH_LABEL];
Expand Down
Loading