Skip to content
Draft
Show file tree
Hide file tree
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
28 changes: 28 additions & 0 deletions cmd/unbounded-net-node/status_proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,34 @@ func statusUnixNano(t time.Time) int64 {
return t.UnixNano()
}

func nodeSummaryToProto(summary *NodeStatusOverview) *statusproto.NodeStatusOverview {
if summary == nil {
return nil
}

result := &statusproto.NodeStatusOverview{
TimestampUnixNs: statusUnixNano(summary.Timestamp),
NodeInfo: nodeInfoToProto(&summary.NodeInfo),
HealthCheck: healthCheckStatusToProto(summary.HealthCheck),
NodeErrors: nodeErrorsToProto(summary.NodeErrors),
FetchError: summary.FetchError,
StatusSource: summary.StatusSource,
NodePodInfo: nodePodInfoToProto(summary.NodePodInfo),
PeerCount: int32(summary.PeerCount),
HealthyPeers: int32(summary.HealthyPeers),
RouteCount: int32(summary.RouteCount),
RouteMismatch: summary.RouteMismatch,
RouteMismatchCount: int32(summary.RouteMismatchCount),
UnhealthyPeerLinks: int32(summary.UnhealthyPeerLinks),
UsesIpip: summary.UsesIPIP,
}
if summary.LastPushTime != nil {
result.LastPushTimeUnixNs = statusUnixNano(*summary.LastPushTime)
}

return result
}

// nodeStatusToProto converts a Go NodeStatusResponse to the protobuf NodeStatusFull message.
func nodeStatusToProto(status *NodeStatusResponse) *statusproto.NodeStatusFull {
if status == nil {
Expand Down
45 changes: 45 additions & 0 deletions cmd/unbounded-net-node/status_publishing_bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main
import (
"compress/gzip"
"context"
"encoding/json"
"io"
"net/http"
"net/http/httptest"
Expand All @@ -17,6 +18,7 @@ import (
"github.com/coder/websocket"
"google.golang.org/protobuf/proto"

configpkg "github.com/Azure/unbounded/internal/net/config"
statusproto "github.com/Azure/unbounded/internal/net/status/proto"
)

Expand Down Expand Up @@ -302,6 +304,7 @@ func TestStatusPublishersHonorDisabledTogglesAndJoin(t *testing.T) {

cfg := &config{
NodeName: "node-a",
StatusDetailMode: configpkg.DefaultStatusDetailMode,
StatusPushEnabled: false,
StatusPushURL: server.URL,
StatusPushInterval: time.Millisecond,
Expand All @@ -311,8 +314,50 @@ func TestStatusPublishersHonorDisabledTogglesAndJoin(t *testing.T) {
}

health := blockedBootstrapHealthState()
status := summaryRouteFixture()

var bpfCollections atomic.Int32

status.bpfCollector = func() []BpfEntry {
bpfCollections.Add(1)

return []BpfEntry{{}}
}
health.setStatusServer(status)
startStatusPublishers(context.Background(), cfg, health)

local := httptest.NewServer(newHealthMux(health))
defer local.Close()

for _, path := range []string{"/status/summary", "/status/json"} {
request, err := http.NewRequestWithContext(t.Context(), http.MethodGet, local.URL+path, nil)
if err != nil {
t.Fatal(err)
}

response, err := local.Client().Do(request)
if err != nil {
t.Fatal(err)
}

var snapshot NodeStatusResponse

err = json.NewDecoder(response.Body).Decode(&snapshot)
_ = response.Body.Close()

if err != nil || response.StatusCode != http.StatusOK || snapshot.NodeInfo.Name != "local" {
t.Fatalf("disabled publishers prevented local diagnostics: code=%d err=%v", response.StatusCode, err)
}

if path == "/status/summary" {
if len(snapshot.BpfEntries) != 0 || bpfCollections.Load() != 0 {
t.Fatal("local summary collected BPF details")
}
} else if len(snapshot.BpfEntries) != 1 || bpfCollections.Load() != 1 {
t.Fatal("explicit HTTP pull did not collect full details")
}
}

done := make(chan struct{})

go func() {
Expand Down
Loading