From f66d9faa17e06543a153f9050a4d6bc420ef1bd5 Mon Sep 17 00:00:00 2001 From: Pierre beucher Date: Tue, 7 Jan 2025 14:24:19 +0100 Subject: [PATCH 1/3] analytics: fix curl request in install script --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 58c5d205..bc56c4ee 100755 --- a/install.sh +++ b/install.sh @@ -24,7 +24,7 @@ send_analytics_event() { \"distinct_id\": \"$INSTALL_POSTHOG_DISTINCT_ID\", \"properties\": { \"\$process_person_profile\": false, - \"event_details\": $eventDetails, + \"event_details\": \"$eventDetails\", \"os_name\": \"$(uname -s)\", \"os_arch\": \"$(uname -m)\" } From c0b2bf00d4adf6ff451f416aaf6e235368ada23c Mon Sep 17 00:00:00 2001 From: Pierre beucher Date: Tue, 7 Jan 2025 14:51:37 +0100 Subject: [PATCH 2/3] analytics: properly shutdown analytics client on error --- src/index.ts | 6 ++++-- src/tools/analytics/client.ts | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 1f9788b5..2527a61a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,7 +24,6 @@ async function main(){ const program = buildProgram() await program.parseAsync(process.argv) - // Shutdown await AnalyticsManager.get().shutdown() } catch (e){ @@ -32,7 +31,10 @@ async function main(){ logger.error("If you think this is a bug, please file an issue with error logs: https://github.com/PierreBeucher/cloudypad/issues") const eventProps = e instanceof Error ? { errorMessage: e.message, stackTrace: e.stack } : { errorMessage: String(e), stackTrace: "unknown" } - AnalyticsManager.get().sendEvent("error", eventProps) + const analytics = AnalyticsManager.get() + analytics.sendEvent("error", eventProps) + await analytics.shutdown() + process.exit(1) } } diff --git a/src/tools/analytics/client.ts b/src/tools/analytics/client.ts index 75a5c072..bf6899b7 100644 --- a/src/tools/analytics/client.ts +++ b/src/tools/analytics/client.ts @@ -75,7 +75,7 @@ export class PostHogAnalyticsClient extends AbstractAnalyticsClient { protected async doShutdown() { this.logger.debug(`Shutting down PostHog analytics client...`) - await this.postHog.shutdown() // Wait at most 5s before final shutdown + await this.postHog.shutdown() this.logger.debug(`Shut down complete for PostHog analytics client`) } From abcf356325c3bda6406dcd7ff87fc2a20e9b973a Mon Sep 17 00:00:00 2001 From: Pierre beucher Date: Tue, 7 Jan 2025 15:02:03 +0100 Subject: [PATCH 3/3] feat: prettier Pulumi outputs with colors and without unnecessary newlines --- src/tools/pulumi/client.ts | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/tools/pulumi/client.ts b/src/tools/pulumi/client.ts index 11ece3e5..965139cd 100644 --- a/src/tools/pulumi/client.ts +++ b/src/tools/pulumi/client.ts @@ -9,6 +9,8 @@ export interface InstancePulumiClientArgs { stackName: string } +const LOG_ON_OUTPUT_COLOR = "always" + /** * An abstract Pulumi client for a Cloudy Pad instance */ @@ -97,7 +99,7 @@ export abstract class InstancePulumiClient { // Might become a flag later await stack.cancel() - const upRes = await stack.up({ onOutput: (msg) => { console.info(msg.trim()) }, color: "auto", refresh: true }) + const upRes = await stack.up({ onOutput: this.stackLogOnOutput, color: LOG_ON_OUTPUT_COLOR, refresh: true }) this.logger.trace(`Up result: ${JSON.stringify(upRes)}`) @@ -120,7 +122,7 @@ export abstract class InstancePulumiClient { // Might become a flag later await stack.cancel() - const prevRes = await stack.preview({ onOutput: (msg) => { console.info(msg.trim()) }, color: "auto", refresh: true }) + const prevRes = await stack.preview({ onOutput: this.stackLogOnOutput, color: LOG_ON_OUTPUT_COLOR, refresh: true }) this.logger.trace(`Preview result: ${JSON.stringify(prevRes)}`) @@ -139,10 +141,22 @@ export abstract class InstancePulumiClient { this.logger.debug(`Refreshing stack ${stack.name} before destroy result`) - const refreshRes = await stack.refresh({ onOutput: console.info, color: "auto" }) + const refreshRes = await stack.refresh({ onOutput: this.stackLogOnOutput, color: LOG_ON_OUTPUT_COLOR }) this.logger.trace(`Refresh result: ${JSON.stringify(refreshRes)}`) - const destroyRes = await stack.destroy({ onOutput: console.info, color: "auto", remove: true }) + const destroyRes = await stack.destroy({ onOutput: this.stackLogOnOutput, color: LOG_ON_OUTPUT_COLOR, remove: true }) this.logger.trace(`Destroy result: ${JSON.stringify(destroyRes)}`) } -} \ No newline at end of file + + /** + * Log Pulumi output to console using stdout directly and tweaking a bit the output for nicer display + * @param msg raw pulumi output on stack action + */ + private async stackLogOnOutput(_msg: string){ + + let msg = _msg + if(msg.trim() === ".") msg = "." // if msg is a dot with newlines or spaces, print it as a dot without newline + + process.stdout.write(msg) + } +}