lyc8503 / UptimeFlare

✔ Free and serverless uptime monitoring / status page on Cloudflare Workers, with Geo-specific checks
Apache License 2.0
1.67k stars 157 forks source link

Error: proxy request failed | Improve checkLocationWorkerRoute #55

Open EthraZa opened 2 months ago

EthraZa commented 2 months ago

Tonight I have experienced 2 consecutive hours of route downtime: Error: proxy request failed, cannot connect to the specified address

Today I have added another CF IP location to my worker route so it will random change between than and I will be able to see some uptime if other route downtime like this happens again.

But I guess a best option would be to make checkLocationWorkerRoute an array, so UptimeFlare could loop throught it and by doing this it will have the ability to skeep a defunct route and jump to the next working one in the same check round.

I imagine that when loop throught the routes we could have the option to stop in the first working one or go ahead and check all the options, and now graph could show the "avarage response time" or, if possible, even show the multiple routes as different lines for comparece.

What do you think?

ps. I guess it is being discussed in #48 but the chinese letters there intimidate me. :)

lyc8503 commented 2 months ago

I'm sorry for the trouble caused by Chinese, many users are Chinese and they may be more accustomed to communicating in Chinese, I will set up an English issue template afterwards.

My comment from #48:

Indeed, the current checkLocationWorkerRoute configuration is not very friendly, I may consider maintaining a CNAME list, users only need to fill in the desired region in the config file. It can greatly simplify the configuration process and keep IPs up-to-date.

But I've been busy lately, and I'm the only one maintaining it, so I may have to wait until I have time to update it with other features.

I envision the user being able to specify a region code such as US / UK instead of having to manually scan and specify an IP address.

If this is implemented, the user could also specify multiple regions at the same time, and Worker could show the average access latency and overall success rate for those multiple regions.

However this looks like more work and will take quite a bit of time to complete, and as I said in my reply above, I haven't been very available lately and won't necessarily be able to get it done right away. Maybe I should also refine the documentation for developers so that more interested open source developers can participate and contribute to the project.

EthraZa commented 2 months ago

I guess I don´t have the TS/Workers proficiency to implement your vision, but I tryed to implement the simple array solution to have a prefered route and the backup routes after it.

Obs: I have no idea on how to setup a Cloudflare ambient to test and debug, so I was limited to commit and see what happens.

Changed code so far in worker/src/index.ts (mainly lines 2 and 3 and the break after a good fetch):

    if (monitor.checkLocationWorkerRoute) {
        const workerRoutes = typeof(monitor.checkLocationWorkerRoute) === 'string' ? [monitor.checkLocationWorkerRoute] : monitor.checkLocationWorkerRoute;

        for (const route of workerRoutes) {
          // Initiate a check from a different location
          try {
            console.log('Calling worker: (' + workerRoutes.indexOf(route) + '/' + workerRoutes.length + ') ' + route)
            const resp = await (
              await fetch(route, {
                method: 'POST',
                body: JSON.stringify({
                  target: monitor.id,
                }),
              })
            ).json<{ location: string; status: { ping: number; up: boolean; err: string } }>()
            checkLocation = resp.location
            status = resp.status
            break
          } catch (err) {
            console.log('Error calling worker: ' + err)
            status = { ping: 0, up: false, err: 'Error initiating check from remote worker' }
          }
        };
      } else {
        // Initiate a check from the current location
        status = await getStatus(monitor)
      }

Also uptime.types.ts: checkLocationWorkerRoute?: string | string[]