-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/yk/add-missing-licenses' into yk…
…/add-missing-licenses
- Loading branch information
Showing
21 changed files
with
1,113 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// (c) Copyright 2024, Microsoft and ClearlyDefined contributors. Licensed under the MIT license. | ||
// SPDX-License-Identifier: MIT | ||
|
||
// =================================================== | ||
// Log the heap statistics at regular intervals | ||
// =================================================== | ||
// NOTE: set 'LOG_NODE_HEAPSTATS' env var to 'true' to log heap stats | ||
// NOTE: set 'LOG_NODE_HEAPSTATS_INTERVAL_MS' env var to '<time_in_milliseconds>' for logging interval | ||
// NOTE: To better understand heap stats being logged, check: | ||
// - https://nodejs.org/docs/v22.12.0/api/v8.html#v8getheapspacestatistics | ||
// - https://nodejs.org/docs/v22.12.0/api/v8.html#v8getheapstatistics | ||
function trySetHeapLoggingAtInterval(config, logger) { | ||
logger.debug('heapLogger.js :: Entered "trySetHeapLoggingAtInterval"...') | ||
|
||
const shouldLogHeapstats = config.heapstats.logHeapstats | ||
? config.heapstats.logHeapstats.toLowerCase() === 'true' | ||
: false | ||
|
||
logger.debug(`heapLogger.js :: "shouldLogHeapstats" set to "${shouldLogHeapstats}"`) | ||
|
||
if (shouldLogHeapstats) { | ||
const v8 = require('v8') | ||
|
||
const addCommas = num => Number(num).toLocaleString() | ||
const isNumeric = num => !isNaN(Number(num)) | ||
|
||
// Set the heapstats logging interval | ||
const maybeInterval = config.heapstats.logInverval | ||
const heapStatsInverval = maybeInterval && isNumeric(maybeInterval) ? maybeInterval : 30000 | ||
|
||
logger.debug(`heapLogger.js :: heap stats logging interval will be "${heapStatsInverval}" ms`) | ||
|
||
// Function to log the heap space statistics | ||
const logHeapSpaceStats = () => { | ||
// Get the current timestamp | ||
const currentTimestamp = new Date().toISOString() | ||
|
||
// Get the heap space statistics | ||
const heapSpaceStats = v8.getHeapSpaceStatistics() | ||
|
||
heapSpaceStats.forEach(space => { | ||
const heapStatsMessage = | ||
`[${currentTimestamp}] Heap Space Statistics: ` + | ||
`Space Name: '${space.space_name}', ` + | ||
`Space Size: '${addCommas(space.space_size)}' bytes, ` + | ||
`Space Used Size: '${addCommas(space.space_used_size)}' bytes, ` + | ||
`Space Available Size: '${addCommas(space.space_available_size)}' bytes, ` + | ||
`Physical Space Size: '${addCommas(space.physical_space_size)}' bytes` + | ||
'\n--------------------------' | ||
|
||
logger.info(heapStatsMessage) | ||
}) | ||
|
||
// Get the heap statistics | ||
const heapStats = v8.getHeapStatistics() | ||
|
||
const heapStatsMessage = | ||
`[${currentTimestamp}] Heap Statistics: ` + | ||
`Total Heap Size: '${addCommas(heapStats.total_heap_size)}' bytes, ` + | ||
`Total Heap Size Executable: '${addCommas(heapStats.total_heap_size_executable)}' bytes, ` + | ||
`Total Physical Size: '${addCommas(heapStats.total_physical_size)}' bytes, ` + | ||
`Total Available Size: '${addCommas(heapStats.total_available_size)}' bytes, ` + | ||
`Used Heap Size: '${addCommas(heapStats.used_heap_size)}' bytes, ` + | ||
`Heap Size Limit: '${addCommas(heapStats.heap_size_limit)}' bytes` + | ||
'\n--------------------------' | ||
|
||
logger.info(heapStatsMessage) | ||
} | ||
|
||
// Only run if not in a test environment | ||
if (process.argv.every(arg => !arg.includes('mocha'))) { | ||
logger.debug(`heapLogger.js :: setting heap stats logging at "${heapStatsInverval}" ms interval...`) | ||
|
||
// Set the interval to log the heap space statistics | ||
setInterval(logHeapSpaceStats, heapStatsInverval) | ||
|
||
logger.debug(`heapLogger.js :: set heap stats logging at "${heapStatsInverval}" ms interval.`) | ||
} | ||
} else { | ||
logger.debug('heapLogger.js :: heap stats logging not enabled.') | ||
} | ||
|
||
logger.debug('heapLogger.js :: Exiting "trySetHeapLoggingAtInterval".') | ||
} | ||
|
||
module.exports = trySetHeapLoggingAtInterval |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// (c) Copyright 2024, SAP SE and ClearlyDefined contributors. Licensed under the MIT license. | ||
// SPDX-License-Identifier: MIT | ||
|
||
const config = require('painless-config') | ||
const AzureStorageQueue = require('../queueing/azureStorageQueue') | ||
|
||
const defaultOptions = { | ||
connectionString: | ||
config.get('DEFINITION_UPGRADE_QUEUE_CONNECTION_STRING') || config.get('HARVEST_AZBLOB_CONNECTION_STRING'), | ||
queueName: config.get('DEFINITION_UPGRADE_QUEUE_NAME') || 'definitions-upgrade', | ||
dequeueOptions: { | ||
numOfMessages: config.get('DEFINITION_UPGRADE_DEQUEUE_BATCH_SIZE') || 16, | ||
visibilityTimeout: 10 * 60 // 10 min. The default value is 30 seconds. | ||
} | ||
} | ||
|
||
function azure(options) { | ||
const realOptions = options || defaultOptions | ||
return new AzureStorageQueue(realOptions) | ||
} | ||
|
||
module.exports = azure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// (c) Copyright 2024, SAP SE and ClearlyDefined contributors. Licensed under the MIT license. | ||
// SPDX-License-Identifier: MIT | ||
|
||
const { DefinitionVersionChecker } = require('./defVersionCheck') | ||
const { setup } = require('./process') | ||
|
||
class DefinitionQueueUpgrader extends DefinitionVersionChecker { | ||
async validate(definition) { | ||
if (!definition) return | ||
const result = await super.validate(definition) | ||
if (result) return result | ||
|
||
await this._queueUpgrade(definition) | ||
return definition | ||
} | ||
|
||
async _queueUpgrade(definition) { | ||
if (!this._upgrade) throw new Error('Upgrade queue is not set') | ||
try { | ||
const message = this._constructMessage(definition) | ||
await this._upgrade.queue(message) | ||
this.logger.info('Queued for definition upgrade ', { | ||
coordinates: DefinitionVersionChecker.getCoordinates(definition) | ||
}) | ||
} catch (error) { | ||
//continue if queueing fails and requeue at the next request. | ||
this.logger.error(`Error queueing for definition upgrade ${error.message}`, { | ||
error, | ||
coordinates: DefinitionVersionChecker.getCoordinates(definition) | ||
}) | ||
} | ||
} | ||
|
||
_constructMessage(definition) { | ||
const { coordinates, _meta } = definition | ||
const content = { coordinates, _meta } | ||
return Buffer.from(JSON.stringify(content)).toString('base64') | ||
} | ||
|
||
async initialize() { | ||
this._upgrade = this.options.queue() | ||
return this._upgrade.initialize() | ||
} | ||
|
||
setupProcessing(definitionService, logger, once) { | ||
return setup(this._upgrade, definitionService, logger, once) | ||
} | ||
} | ||
|
||
module.exports = DefinitionQueueUpgrader |
Oops, something went wrong.