Skip to content

Commit

Permalink
feat: add stream-id
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Dec 4, 2021
1 parent 1ff16db commit 8653dd1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ node_modules
.*
!.editorconfig
!.eslintignore
!.eslintrc
!.eslintrc.js
!.flowconfig
!.github
!.gitignore
!.husky
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ export ROARR_API_KEY=00000000-0000-0000-0000-000000000000

View logs by opening `https://roarr.io?room=[YOUR API KEY]`.

By default, every time you run `roarr` it will generate a new stream ID and it will appear as a new source in roarr.io. However, you can configure a stable stream ID, e.g.

```bash
export ROARR_STREAM_ID=00000000-0000-0000-0000-000000000000
```

#### Identifying Log Source

By default, all `@roarr/cli` agents are assigned a random name.
Expand Down
5 changes: 5 additions & 0 deletions src/bin/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"node/shebang": 0
}
}
26 changes: 20 additions & 6 deletions src/bin/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env node

/* eslint-disable node/shebang */

import {
Instance as Chalk,
} from 'chalk';
import split from 'split2';
import {
v4 as uuid,
} from 'uuid';
import yargs from 'yargs';
import {
createLogFilter,
Expand Down Expand Up @@ -65,6 +66,10 @@ const argv = yargs
],
default: 'pretty',
},
'stream-id': {
description: 'roarr.io stream ID.',
type: 'string',
},
tags: {
description: 'List of (comma separated) tags. Used by roarr.io to identify the source of logs.',
type: 'string',
Expand All @@ -79,16 +84,16 @@ const argv = yargs
.wrap(80)
.parseSync();

const UuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12}$/ui;

const roarrConfigurationPath = findNearestRoarrConfigurationPath();

let filterFunction: FilterFunction | null = null;

if (roarrConfigurationPath) {
/* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires */
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
const roarrConfiguration: RoarrConfigurationType = require(roarrConfigurationPath);

/* eslint-enable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires */

if (roarrConfiguration?.filterFunction) {
filterFunction = roarrConfiguration.filterFunction;
}
Expand All @@ -100,10 +105,19 @@ const chalk = new Chalk({

let remoteStream;

if (argv['stream-id'] && !UuidRegex.test(argv['stream-id'])) {
throw new Error('stream-id must be a valid UUID');
}

if (argv['api-key']) {
if (!UuidRegex.test(argv['api-key'])) {
throw new Error('api-key must be a valid UUID');
}

remoteStream = createRemoteStream(
argv['api-url'],
String(argv['api-key']),
argv['api-key'],
argv['stream-id'] ?? uuid(),
argv.name ?? '',
argv.tags ?? '',
);
Expand Down
6 changes: 2 additions & 4 deletions src/factories/createRemoteStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import {
import {
throttle,
} from 'throttle-debounce';
import {
v4 as uuid,
} from 'uuid';

type StreamConfiguration = {
enabled: boolean,
Expand All @@ -16,6 +13,7 @@ type StreamConfiguration = {
export const createRemoteStream = (
apiUrl: string,
apiKey: string,
streamId: string,
name: string,
tags: string,
) => {
Expand All @@ -26,7 +24,7 @@ export const createRemoteStream = (
query: {
hostname: os.hostname(),
name: name || '',
stream: uuid(),
stream: streamId,
tags: tags || '',
token: apiKey,
version: '1.0.0',
Expand Down

0 comments on commit 8653dd1

Please sign in to comment.