Skip to content

Commit

Permalink
feat(ping): #1260 deprecate ping request (#1288)
Browse files Browse the repository at this point in the history
* deprecate ping request

* clean up documentation tutorial

* fix wrong sample
  • Loading branch information
syamsudotdev authored May 13, 2024
1 parent b4c1256 commit c9fb205
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 24 deletions.
16 changes: 4 additions & 12 deletions docs/src/pages/tutorial/run-using-ping-method.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,15 @@ probes:
name: ping_test
description: requesting icmp ping
interval: 10
requests:
- url: https://google.com
ping: true
- method: GET
url: https://reqres.in/api/users
alerts:
- query: response.status != 200
message: Status code is not 200
- query: response.time > 2000
message: Request took more than 2 seconds
ping:
- uri: google.com
```

Let me explain this configuration a little bit:

- This configuration uses Desktop notifications
- This probe configuration will do two requests: **Hit google.com using PING**. After PING success, it will **hit** [**https://reqres.in/api/users**](https://reqres.in/api/users) **using the GET method**. If by chance the first request fails, it will not proceed to the next request.
- This probe configuration will alert you if the status code is not 200, or the request took longer than two seconds
- This probe configuration will **hit google.com using PING**
- This probe configuration will alert you if ping request is not successful (200), or the request took longer than two seconds

Save the configuration above as `monika.yaml` in your local machine and run `monika -c monika.yaml` command in your terminal inside the directory where you saved the configuration file.

Expand Down
8 changes: 2 additions & 6 deletions monika.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,8 @@ probes:
# name: ping_test
# description: requesting icmp ping
# interval: 10
# requests:
# - url: http://google.com
# ping: true
# alerts:
# - assertion: response.status == 500
# message: response status message
# ping:
# - uri: http://google.com

# Configuration example for sending Multiple requests
# Requests could be define in array to run for multiple requests
Expand Down
19 changes: 19 additions & 0 deletions src/components/logger/startup-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ function generateStartupMessage({
startupMessage += generateNotificationMessage(notifications)
}

if (probes.some((p) => p.requests?.some((r) => r.ping))) {
startupMessage += generateDeprecatedPingMessage()
}

return startupMessage
}

Expand All @@ -118,6 +122,21 @@ function generateEmptyNotificationMessage(): string {
})
}

function generateDeprecatedPingMessage(): string {
const message = `We are deprecating probe requests with flag "ping: true", please migrate to standalone probe https://monika.hyperjump.tech/guides/probes#ping-request`
return boxen(chalk.yellow(message), {
padding: 1,
margin: {
top: 2,
right: 1,
bottom: 2,
left: 1,
},
borderStyle: 'bold',
borderColor: 'yellow',
})
}

type GenerateConfigInfoMessageParams = {
isFirstRun: boolean
notificationTotal: number
Expand Down
3 changes: 3 additions & 0 deletions src/components/probe/prober/http/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ export async function httpRequest({
try {
// is this a request for ping?
if (newReq.ping === true) {
log.warn(
`PING ${renderedURL}: Requests with "ping: true" is deprecated, please migrate to standalone probe https://monika.hyperjump.tech/guides/probes#ping-request`
)
return icmpRequest({ host: renderedURL })
}

Expand Down
1 change: 0 additions & 1 deletion src/components/probe/prober/icmp/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ export async function icmpRequest(

return processICMPRequestResult(icmpResp)
} catch (error: unknown) {
console.error('icmp got error:', error)
baseResponse.data = ''
baseResponse.error = getErrorMessage(error)
}
Expand Down
8 changes: 3 additions & 5 deletions src/monika-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@
"type": "object",
"additionalProperties": false,
"required": ["url"],
"patternProperties": {
"ping": { "type": "boolean" }
},
"properties": {
"id": {
"title": "Id",
Expand Down Expand Up @@ -296,11 +299,6 @@
"alerts": {
"$ref": "#/definitions/alerts"
},
"ping": {
"title": "Ping",
"type": "boolean",
"description": "If defined and to true, the request is an ICMP ping"
},
"allowUnauthorized": {
"title": "AllowUnauthorized",
"type": "boolean",
Expand Down

0 comments on commit c9fb205

Please sign in to comment.