Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Refactor the way timeouts are enforced by the Functions Emulator (#5464)
- Fix bug where cloudevent emitted by various emulators didn't conform to spec (#5466)
8 changes: 8 additions & 0 deletions src/deploy/functions/runtimes/python/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ export class Delegate implements runtimes.RuntimeDelegate {
)} in ${this.sourceDir}`
);
const childProcess = runWithVirtualEnv(args, this.sourceDir, envWithAdminPort);
childProcess.stdout?.on("data", (chunk: Buffer) => {
const chunkString = chunk.toString();
logger.debug(`stdout: ${chunkString}`);
});
childProcess.stderr?.on("data", (chunk: Buffer) => {
const chunkString = chunk.toString();
logger.debug(`stderr: ${chunkString}`);
});
return Promise.resolve(async () => {
await fetch(`http://127.0.0.1:${port}/__/quitquitquit`);
const quitTimeout = setTimeout(() => {
Expand Down
17 changes: 13 additions & 4 deletions src/emulator/pubsubEmulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,20 +189,29 @@ export class PubsubEmulator implements EmulatorInstance {
topic: string,
message: Message
): CloudEvent<MessagePublishedData> {
// Pubsub events from Pubsub Emulator include a date with nanoseconds.
// Prod Pubsub doesn't publish timestamp at that level of precision. Timestamp with nanosecond precision also
// are difficult to parse in languages other than Node.js (e.g. python).
const truncatedPublishTime = new Date(message.publishTime.getMilliseconds()).toISOString();
const data: MessagePublishedData = {
message: {
messageId: message.id,
publishTime: message.publishTime,
publishTime: truncatedPublishTime,
attributes: message.attributes,
orderingKey: message.orderingKey,
data: message.data.toString("base64"),
},

// NOTE: We include camel_cased attributes since they also available and depended on by other runtimes
// like python.
message_id: message.id,
publish_time: truncatedPublishTime,
} as MessagePublishedData["message"],
subscription: this.subscriptionForTopic.get(topic)!.name,
};
return {
specversion: "1",
specversion: "1.0",
id: uuid.v4(),
time: message.publishTime.toISOString(),
time: truncatedPublishTime,
type: "google.cloud.pubsub.topic.v1.messagePublished",
source: `//pubsub.googleapis.com/projects/${this.args.projectId}/topics/${topic}`,
data,
Expand Down
6 changes: 3 additions & 3 deletions src/emulator/storage/cloudFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class StorageCloudFunctions {
time = typeof data.updated === "string" ? data.updated : data.updated.toISOString();
}
return {
specversion: "1",
specversion: "1.0",
id: uuid.v4(),
type: `google.cloud.storage.object.v1.${ceAction}`,
source: `//storage.googleapis.com/projects/_/buckets/${objectMetadataPayload.bucket}/objects/${objectMetadataPayload.name}`,
Expand Down Expand Up @@ -255,9 +255,9 @@ export interface ObjectMetadataPayload {
* Customer-supplied encryption key.
*
* This object contains the following properties:
* * `encryptionAlgorithm` (`string|undefined`): The encryption algorithm that
* `encryptionAlgorithm` (`string|undefined`): The encryption algorithm that
* was used. Always contains the value `AES256`.
* * `keySha256` (`string|undefined`): An RFC 4648 base64-encoded string of the
* `keySha256` (`string|undefined`): An RFC 4648 base64-encoded string of the
* SHA256 hash of your encryption key. You can use this SHA256 hash to
* uniquely identify the AES-256 encryption key required to decrypt the
* object, which you must store securely.
Expand Down