Skip to content

Commit

Permalink
Feat[1332] : Skip startup message (#1342)
Browse files Browse the repository at this point in the history
* add new switch

* redo unit teset

* bypass monika starting message

* remove test.only

* disable startup notifications
  • Loading branch information
sapiderman authored Jan 24, 2025
1 parent fb5b4f5 commit 544fa06
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 7 deletions.
8 changes: 8 additions & 0 deletions docs/src/pages/guides/cli-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,14 @@ By default Monika will follow redirects 21 times. You can set the value of `--fo
monika --follow-redirects 0 # disable following redirects
```

## SKIP

For applications where a startup message or startup notification is not desired, you can skip monika startup message using `--skip-start-message`.

```bash
monika --skip-start-message
```

## STUN

By default monika will continuously check the [STUN](https://en.wikipedia.org/wiki/STUN) server every 20 second intervals. Continuously STUN checking ensures that connectivity to the outside world is guaranteed. When STUN checking fails, Monika assumes the network is down and probing will be paused.
Expand Down
15 changes: 11 additions & 4 deletions src/commands/monika.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ export default class Monika extends Command {
}

await initLoaders(flags, this.config)
await logRunningInfo({ isSymonMode, isVerbose: flags.verbose })
if (flags['skip-start-message'] === false) {
await logRunningInfo({ isSymonMode, isVerbose: flags.verbose })
}

if (isSymonMode) {
symonClient = new SymonClient(flags)
Expand All @@ -170,6 +172,7 @@ export default class Monika extends Command {
// save some data into files for later
savePidFile(flags.config, config)
deprecationHandler(config)

logStartupMessage({
config,
flags,
Expand All @@ -189,9 +192,13 @@ export default class Monika extends Command {
break
}

sendMonikaStartMessage(notifications).catch((error) =>
log.error(error.message)
)
if (flags['skip-start-message'] === false) {
// if skipping, skip also startup notification
sendMonikaStartMessage(notifications).catch((error) =>
log.error(error.message)
)
}

// schedule status update notification
scheduleSummaryNotification({ config, flags })

Expand Down
37 changes: 37 additions & 0 deletions src/components/logger/startup-message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,4 +521,41 @@ describe('Startup message', () => {
expect(logMessage).include('config file')
})
})

describe('Skip startup test', () => {
it('should show startup message', () => {
// act
logStartupMessage({
config: defaultConfig,
flags: sanitizeFlags({
config: ['./test/testConfigs/simple-1p-1n.yaml'],
symonKey: '',
symonUrl: '',
verbose: false,
}),
isFirstRun: false,
})

// assert
expect(logMessage).include('Using config file:')
})

it('should not startup message', () => {
// act
logStartupMessage({
config: defaultConfig,
flags: sanitizeFlags({
'skip-start-message': true,
config: ['./test/testConfigs/simple-1p-1n.yaml'],
symonKey: '',
symonUrl: '',
verbose: false,
}),
isFirstRun: false,
})

// assert
expect(logMessage).not.include('Using config file:')
})
})
})
17 changes: 16 additions & 1 deletion src/components/logger/startup-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ type LogStartupMessage = {
config: ValidatedConfig
flags: Pick<
MonikaFlags,
'config' | 'symonKey' | 'symonUrl' | 'verbose' | 'native-fetch'
| 'config'
| 'symonKey'
| 'symonUrl'
| 'verbose'
| 'native-fetch'
| 'skip-start-message'
>
isFirstRun: boolean
}
Expand All @@ -49,6 +54,11 @@ export function logStartupMessage({
flags,
isFirstRun,
}: LogStartupMessage): void {
if (flags['skip-start-message'] === true) {
// if skipping, wont have any message
return
}

if (isSymonModeFrom(flags)) {
log.info('Running in Symon mode')
return
Expand Down Expand Up @@ -82,6 +92,11 @@ function generateStartupMessage({

let startupMessage = ''

if (flags['skip-start-message'] === true) {
// if skipping, wont have any message
return ''
}

// warn if config is empty
if (!hasNotification) {
startupMessage += generateEmptyNotificationMessage()
Expand Down
8 changes: 6 additions & 2 deletions src/flag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export type MonikaFlags = {
retryInitialDelayMs: number
retryMaxDelayMs: number
sitemap?: string
'skip-start-message'?: boolean
'status-notification'?: string
stun: number
summary: boolean
Expand Down Expand Up @@ -98,8 +99,8 @@ export const monikaFlagsDefaultValue: MonikaFlags = {
repeat: 0,
retryInitialDelayMs: 2000,
retryMaxDelayMs: 30_000,
// default is 20s interval lookup
stun: 20,
'skip-start-message': false,
stun: 20, // default is 20s interval lookup
summary: false,
'symon-api-version': SYMON_API_VERSION.v1,
symonGetProbesIntervalMs: 60_000,
Expand Down Expand Up @@ -244,6 +245,9 @@ export const flags = {
description: 'Run Monika using a Sitemap xml file.',
exclusive: ['har', 'insomnia', 'postman', 'text'],
}),
'skip-start-message': Flags.boolean({
description: 'Skip Monika startup message',
}),
'status-notification': Flags.string({
description: 'Cron syntax for status notification schedule',
}),
Expand Down

0 comments on commit 544fa06

Please sign in to comment.