From 887ff13f33baacfa106bf8bdc6c1d8f6c3cc017c Mon Sep 17 00:00:00 2001 From: Jason Hall Date: Wed, 5 Nov 2025 11:27:47 -0500 Subject: [PATCH] try to fix Signed-off-by: Jason Hall --- README.md | 3 --- action.yml | 4 ---- dist/post/index.js | 28 +++++++++++----------------- lib/config.js | 6 ------ lib/exporter.js | 22 +++++++++++----------- 5 files changed, 22 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index ebfc01a..278ec05 100644 --- a/README.md +++ b/README.md @@ -170,9 +170,6 @@ steps: # Optional: Customize metric name prefix metric-prefix: 'ci.metrics' - - # Optional: Adjust export interval (milliseconds) - export-interval-millis: '1000' ``` ## Metrics Collected diff --git a/action.yml b/action.yml index ae27052..c1dc31f 100644 --- a/action.yml +++ b/action.yml @@ -27,10 +27,6 @@ inputs: description: 'Prefix for metric names' required: false default: 'github.actions' - export-interval-millis: - description: 'Export interval in milliseconds' - required: false - default: '1000' runs: using: 'node20' diff --git a/dist/post/index.js b/dist/post/index.js index b1c6491..5fab10d 100644 --- a/dist/post/index.js +++ b/dist/post/index.js @@ -138,7 +138,6 @@ function getConfig() { serviceName: core.getInput('service-name') || 'github-actions', serviceNamespace: core.getInput('service-namespace') || 'ci', metricPrefix: core.getInput('metric-prefix') || 'github.actions', - exportIntervalMillis: parseInt(core.getInput('export-interval-millis') || '1000', 10), }; // Validate configuration @@ -146,11 +145,6 @@ function getConfig() { throw new Error('gcp-project-id is required'); } - if (config.exportIntervalMillis < 1000) { - core.warning('export-interval-millis is too low, setting to 1000ms'); - config.exportIntervalMillis = 1000; - } - // Log config without sensitive data const safeConfig = { ...config, gcpServiceAccountKey: config.gcpServiceAccountKey ? '[REDACTED]' : null }; core.debug(`Configuration: ${JSON.stringify(safeConfig, null, 2)}`); @@ -207,9 +201,12 @@ function createMeterProvider(config) { const exporter = new MetricExporter(exporterOptions); + // Note: We use PeriodicExportingMetricReader not for periodic exports, + // but because it handles metric aggregation and collection. + // We trigger export manually via forceFlush() in the shutdown function. const metricReader = new PeriodicExportingMetricReader({ exporter, - exportIntervalMillis: config.exportIntervalMillis, + exportIntervalMillis: 60000, // Set high since we export manually via forceFlush() }); const meterProvider = new MeterProvider({ @@ -301,22 +298,19 @@ function recordMetrics(meter, metrics, metricPrefix) { * @returns {Promise} */ async function shutdown(meterProvider) { - core.info('Flushing and shutting down MeterProvider'); + core.info('Exporting metrics and shutting down MeterProvider'); try { - core.info('Calling forceFlush...'); + // forceFlush() triggers an immediate export and waits for completion + core.info('Triggering metric export...'); await meterProvider.forceFlush(); - core.info('forceFlush completed'); + core.info('Metrics exported successfully'); - // Add a delay to ensure metrics are fully exported - // This gives the exporter time to complete the async export - core.info('Waiting 3 seconds for metrics export to complete...'); - await new Promise(resolve => setTimeout(resolve, 3000)); - - core.info('Calling shutdown...'); + // Shutdown the provider + core.info('Shutting down MeterProvider...'); await meterProvider.shutdown(); core.info('MeterProvider shut down successfully'); } catch (error) { - core.error(`Error during shutdown: ${error.message}`); + core.error(`Error during export/shutdown: ${error.message}`); core.error(`Stack trace: ${error.stack}`); throw error; } diff --git a/lib/config.js b/lib/config.js index d9ce939..fecc64c 100644 --- a/lib/config.js +++ b/lib/config.js @@ -28,7 +28,6 @@ function getConfig() { serviceName: core.getInput('service-name') || 'github-actions', serviceNamespace: core.getInput('service-namespace') || 'ci', metricPrefix: core.getInput('metric-prefix') || 'github.actions', - exportIntervalMillis: parseInt(core.getInput('export-interval-millis') || '1000', 10), }; // Validate configuration @@ -36,11 +35,6 @@ function getConfig() { throw new Error('gcp-project-id is required'); } - if (config.exportIntervalMillis < 1000) { - core.warning('export-interval-millis is too low, setting to 1000ms'); - config.exportIntervalMillis = 1000; - } - // Log config without sensitive data const safeConfig = { ...config, gcpServiceAccountKey: config.gcpServiceAccountKey ? '[REDACTED]' : null }; core.debug(`Configuration: ${JSON.stringify(safeConfig, null, 2)}`); diff --git a/lib/exporter.js b/lib/exporter.js index 03d15f4..e30b075 100644 --- a/lib/exporter.js +++ b/lib/exporter.js @@ -39,9 +39,12 @@ function createMeterProvider(config) { const exporter = new MetricExporter(exporterOptions); + // Note: We use PeriodicExportingMetricReader not for periodic exports, + // but because it handles metric aggregation and collection. + // We trigger export manually via forceFlush() in the shutdown function. const metricReader = new PeriodicExportingMetricReader({ exporter, - exportIntervalMillis: config.exportIntervalMillis, + exportIntervalMillis: 60000, // Set high since we export manually via forceFlush() }); const meterProvider = new MeterProvider({ @@ -133,22 +136,19 @@ function recordMetrics(meter, metrics, metricPrefix) { * @returns {Promise} */ async function shutdown(meterProvider) { - core.info('Flushing and shutting down MeterProvider'); + core.info('Exporting metrics and shutting down MeterProvider'); try { - core.info('Calling forceFlush...'); + // forceFlush() triggers an immediate export and waits for completion + core.info('Triggering metric export...'); await meterProvider.forceFlush(); - core.info('forceFlush completed'); + core.info('Metrics exported successfully'); - // Add a delay to ensure metrics are fully exported - // This gives the exporter time to complete the async export - core.info('Waiting 3 seconds for metrics export to complete...'); - await new Promise(resolve => setTimeout(resolve, 3000)); - - core.info('Calling shutdown...'); + // Shutdown the provider + core.info('Shutting down MeterProvider...'); await meterProvider.shutdown(); core.info('MeterProvider shut down successfully'); } catch (error) { - core.error(`Error during shutdown: ${error.message}`); + core.error(`Error during export/shutdown: ${error.message}`); core.error(`Stack trace: ${error.stack}`); throw error; }