mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-18 20:51:45 +00:00
monitor/polling: reduce Cloud Run polling interval.
Cloud Run's routes never change at runtime. Don't poll it for route changes very often. Signed-off-by: Denton Gentry <dgentry@tailscale.com>
This commit is contained in:
parent
224e60cef2
commit
3089081349
@ -7,7 +7,9 @@
|
|||||||
package monitor
|
package monitor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -42,6 +44,20 @@ func (pm *pollingMon) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (pm *pollingMon) isCloudRun() bool {
|
||||||
|
// https: //cloud.google.com/run/docs/reference/container-contract#env-vars
|
||||||
|
if os.Getenv("K_REVISION") == "" || os.Getenv("K_CONFIGURATION") == "" ||
|
||||||
|
os.Getenv("K_SERVICE") == "" || os.Getenv("PORT") == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
vers, err := os.ReadFile("/proc/version")
|
||||||
|
if err != nil {
|
||||||
|
pm.logf("Failed to read /proc/version: %v", err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return string(bytes.TrimSpace(vers)) == "Linux version 4.4.0 #1 SMP Sun Jan 10 15:06:54 PST 2016"
|
||||||
|
}
|
||||||
|
|
||||||
func (pm *pollingMon) Receive() (message, error) {
|
func (pm *pollingMon) Receive() (message, error) {
|
||||||
d := 10 * time.Second
|
d := 10 * time.Second
|
||||||
if runtime.GOOS == "android" {
|
if runtime.GOOS == "android" {
|
||||||
@ -50,8 +66,12 @@ func (pm *pollingMon) Receive() (message, error) {
|
|||||||
// https://github.com/tailscale/tailscale/issues/1427
|
// https://github.com/tailscale/tailscale/issues/1427
|
||||||
d = 10 * time.Minute
|
d = 10 * time.Minute
|
||||||
}
|
}
|
||||||
// TODO: detect if we're running in Cloud Run, and reduce frequency of
|
if pm.isCloudRun() {
|
||||||
// polling as its routes never change.
|
// Cloud Run routes never change at runtime. the containers are killed within
|
||||||
|
// 15 minutes by default, set the interval long enough to be effectively infinite.
|
||||||
|
pm.logf("monitor polling: Cloud Run detected, reduce polling interval to 24h")
|
||||||
|
d = 24 * time.Hour
|
||||||
|
}
|
||||||
ticker := time.NewTicker(d)
|
ticker := time.NewTicker(d)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
base := pm.m.InterfaceState()
|
base := pm.m.InterfaceState()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user