Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions images/proton-bridge/exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"os"
"path/filepath"
"strings"
"sync/atomic"
"time"

"github.com/prometheus/client_golang/prometheus"
Expand All @@ -35,6 +36,10 @@ import (

const serverTokenMetadataKey = "server-token"

// internetEventSeen flips true once bridge emits its first InternetStatusEvent,
// after which the event stream (not the account-state seed) drives the gauge.
var internetEventSeen atomic.Bool

type serverConfig struct {
Port int `json:"port"`
Cert string `json:"cert"`
Expand Down Expand Up @@ -145,12 +150,14 @@ func poll(ctx context.Context, client pb.BridgeClient) error {

users := resp.GetUsers()
accountsTotal.Set(float64(len(users)))
anyConnected := false
for _, u := range users {
name := u.GetUsername()
state := u.GetState()
connected := 0.0
if state == pb.UserState_CONNECTED {
connected = 1
anyConnected = true
}
accountConnected.WithLabelValues(name).Set(connected)
for _, s := range []pb.UserState{pb.UserState_SIGNED_OUT, pb.UserState_LOCKED, pb.UserState_CONNECTED} {
Expand All @@ -164,6 +171,18 @@ func poll(ctx context.Context, client pb.BridgeClient) error {
accountTotalBytes.WithLabelValues(name).Set(float64(u.GetTotalBytes()))
}

// Bridge only emits InternetStatusEvent on change, so until the first such
// event arrives we seed internet_connected from account state (a connected
// account implies working connectivity). Once a real event is seen, the
// event stream stays authoritative and we stop seeding.
if !internetEventSeen.Load() {
v := 0.0
if anyConnected {
v = 1
}
internetConnected.Set(v)
}

if v, err := client.Version(ctx, &emptypb.Empty{}); err == nil {
info.Reset()
info.WithLabelValues(v.GetValue()).Set(1)
Expand Down Expand Up @@ -191,6 +210,7 @@ func streamEvents(ctx context.Context, client pb.BridgeClient) error {
v = 1
}
internetConnected.Set(v)
internetEventSeen.Store(true)
}
}
if ue := ev.GetUser(); ue != nil {
Expand Down
Loading