-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(repeater): send runtime information upon repeater registration (#…
- Loading branch information
Showing
12 changed files
with
212 additions
and
5 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
import { Event } from '../../Bus'; | ||
|
||
interface RepeaterRuntime { | ||
readonly transport?: 'rabbitmq' | 'ws'; | ||
readonly arch?: string; | ||
readonly os?: string; | ||
readonly docker?: boolean; | ||
readonly distribution?: string; | ||
readonly nodeVersion?: string; | ||
} | ||
|
||
export class RepeaterRegistering implements Event { | ||
constructor( | ||
public readonly repeaterId: string, | ||
public readonly version: string, | ||
public readonly localScriptsUsed: boolean | ||
public readonly localScriptsUsed: boolean, | ||
public readonly runtime?: RepeaterRuntime | ||
) {} | ||
} |
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,110 @@ | ||
import packageInfo from '../../package.json'; | ||
import { RuntimeDetector } from './RuntimeDetector'; | ||
import arch from 'arch'; | ||
import { execSync } from 'child_process'; | ||
import os from 'os'; | ||
|
||
export class DefaultRuntimeDetector implements RuntimeDetector { | ||
public distribution(): string | undefined { | ||
return packageInfo.brightCli.distribution; | ||
} | ||
|
||
public isInsideDocker(): boolean { | ||
return !!process.env['BRIGHT_CLI_DOCKER']; | ||
} | ||
|
||
public nodeVersion(): string { | ||
return process.version; | ||
} | ||
|
||
public arch(): string { | ||
try { | ||
return arch(); | ||
} catch { | ||
// pass | ||
} | ||
|
||
// As a fallback use arch info for which the Node.js binary was compiled | ||
return os.arch(); | ||
} | ||
|
||
public os(): string { | ||
const platform = os.platform(); | ||
|
||
if (platform === 'darwin') { | ||
return this.detectMacosVersion(); | ||
} else if (platform === 'linux') { | ||
return this.detectLinuxVersion(); | ||
} else if (platform === 'win32') { | ||
return this.detectWindowsVersion(); | ||
} | ||
|
||
// As a fallback use OS info for which the Node.js binary was compiled | ||
return `${os.platform()} (${os.release()})`; | ||
} | ||
|
||
private detectMacosVersion() { | ||
try { | ||
const name = execSync('sw_vers -productName', { | ||
encoding: 'utf8' | ||
}).trim(); | ||
const version = execSync('sw_vers -productVersion', { | ||
encoding: 'utf8' | ||
}).trim(); | ||
const build = execSync('sw_vers -buildVersion', { | ||
encoding: 'utf8' | ||
}).trim(); | ||
|
||
if (name.length && version.length && build.length) { | ||
return `${name} ${version} (${build})`; | ||
} | ||
} catch { | ||
// pass | ||
} | ||
|
||
return `${os.platform()} (${os.release()})`; | ||
} | ||
|
||
private detectLinuxVersion() { | ||
try { | ||
const osRelease = execSync('cat /etc/os-release', { | ||
encoding: 'utf8' | ||
}).trim(); | ||
const extractValue = (key: string) => | ||
new RegExp( | ||
`(?:^|[\r\n]+)${key}(?:\\s*=\\s*?|:\\s+?)(\\s*'(?:\\\\'|[^'])*'|\\s*"(?:\\\\"|[^"])*"|\\s*\`(?:\\\\\`|[^\`])*\`|[^#\r\n]+)?`, | ||
'i' | ||
) | ||
.exec(osRelease)?.[1] | ||
.replace(/^(['"`])([\s\S]*)\1$/i, '$2'); | ||
|
||
const name = extractValue('NAME') || extractValue('ID'); | ||
const version = extractValue('VERSION') || extractValue('VERSION_ID'); | ||
const prettyName = extractValue('PRETTY_NAME'); | ||
|
||
if (name.length && version.length) { | ||
return `${name} ${version}`; | ||
} else if (prettyName.length) { | ||
return prettyName; | ||
} | ||
} catch { | ||
// pass | ||
} | ||
|
||
return `${os.platform()} (${os.release()})`; | ||
} | ||
|
||
private detectWindowsVersion() { | ||
try { | ||
const version = execSync('ver', { encoding: 'utf8' }).trim(); | ||
|
||
if (version.length) { | ||
return version; | ||
} | ||
} catch { | ||
// pass | ||
} | ||
|
||
return `${os.platform()} (${os.release()})`; | ||
} | ||
} |
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,13 @@ | ||
export interface RuntimeDetector { | ||
os(): string; | ||
|
||
arch(): string; | ||
|
||
isInsideDocker(): boolean; | ||
|
||
nodeVersion(): string; | ||
|
||
distribution(): string | undefined; | ||
} | ||
|
||
export const RuntimeDetector: unique symbol = Symbol('RuntimeDetector'); |
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