Skip to content
Closed
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
11 changes: 6 additions & 5 deletions internal/net/status/overview.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ func OverviewFromStatus(full *v1alpha1.NodeStatusResponse, now time.Time) v1alph
if PeerHealthyForOverview(&full.Peers[i], now) {
overview.HealthyPeers++
}
}

for _, route := range full.RoutingTable.Routes {
if RouteMismatchForOverview(route) {
overview.RouteMismatch = true
break
if full.Peers[i].Tunnel.Protocol == "IPIP" {
overview.UsesIPIP = true
}
}

overview.UnhealthyPeerLinks = UnhealthyPeerLinkCount(full.Peers, now)
overview.RouteMismatchCount = RouteMismatchCount(full.RoutingTable.Routes)
overview.RouteMismatch = overview.RouteMismatchCount > 0

return overview
}

Expand Down
99 changes: 99 additions & 0 deletions internal/net/status/overview_diagnostics_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0

package status

import (
"encoding/json"
"reflect"
"testing"
"time"

"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"

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

func TestOverviewDiagnosticFactsPreserveLegacyRules(t *testing.T) {
now := time.Unix(1000, 0)
yes := true
full := &v1alpha1.NodeStatusResponse{
NodeInfo: v1alpha1.NodeInfo{Name: "node", ProviderID: "azure://vm"},
NodeErrors: []v1alpha1.NodeError{{Type: "cni", Message: "not ready"}},
Peers: []v1alpha1.PeerStatus{
{Name: "same", Tunnel: v1alpha1.PeerTunnelStatus{Protocol: "IPIP"}, HealthCheck: &v1alpha1.HealthCheckPeerStatus{Enabled: true, Status: " UP "}},
{Name: "same", HealthCheck: &v1alpha1.HealthCheckPeerStatus{Status: " up "}},
{Name: "same", Tunnel: v1alpha1.PeerTunnelStatus{LastHandshake: now}, HealthCheck: &v1alpha1.HealthCheckPeerStatus{Status: " down "}},
},
RoutingTable: v1alpha1.RoutingTableInfo{Routes: []v1alpha1.RouteEntry{
{NextHops: []v1alpha1.NextHop{{Expected: &yes}, {Present: &yes}}},
{NextHops: []v1alpha1.NextHop{{Expected: &yes}}},
}},
}

got := OverviewFromStatus(full, now)
if got.RouteMismatchCount != 3 || !got.RouteMismatch || got.UnhealthyPeerLinks != 1 || !got.UsesIPIP {
t.Fatalf("diagnostic facts changed: %+v", got)
}

if got.UnhealthyPeerLinks == got.PeerCount-got.HealthyPeers {
t.Fatal("fixture must distinguish diagnostic normalization from overview peer counts")
}

if !reflect.DeepEqual(got.NodeErrors, full.NodeErrors) {
t.Fatal("IPIP warning must not be injected into node errors or alter CNI status")
}

full.Peers = nil
full.RoutingTable.Routes = nil

got = OverviewFromStatus(full, now)
if got.RouteMismatchCount != 0 || got.RouteMismatch || got.UnhealthyPeerLinks != 0 || got.UsesIPIP {
t.Fatalf("removed diagnostics remained in projection: %+v", got)
}
}

func TestOverviewDiagnosticWireFields(t *testing.T) {
data, err := json.Marshal(v1alpha1.NodeStatusOverview{})
if err != nil {
t.Fatal(err)
}

var fields map[string]json.RawMessage
if err := json.Unmarshal(data, &fields); err != nil {
t.Fatal(err)
}

for _, field := range []string{"routeMismatchCount", "unhealthyPeerLinks", "usesIPIP"} {
if fields[field] == nil {
t.Errorf("zero-valued diagnostic fact %q was omitted", field)
}
}

want := &statusproto.NodeStatusOverview{RouteMismatchCount: 3, UnhealthyPeerLinks: 2, UsesIpip: true}

data, err = proto.Marshal(want)
if err != nil {
t.Fatal(err)
}

got := &statusproto.NodeStatusOverview{}
if err := proto.Unmarshal(data, got); err != nil {
t.Fatal(err)
}

if !proto.Equal(got, want) {
t.Fatalf("diagnostic facts lost on protobuf round trip: %v", got)
}

protoFields := got.ProtoReflect().Descriptor().Fields()
for name, number := range map[protoreflect.Name]protoreflect.FieldNumber{
"route_mismatch_count": 13, "unhealthy_peer_links": 14, "uses_ipip": 15,
} {
if field := protoFields.ByName(name); field == nil || field.Number() != number {
t.Errorf("field %s no longer has number %d", name, number)
}
}
}
31 changes: 29 additions & 2 deletions internal/net/status/proto/status.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions internal/net/status/proto/status.proto
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ message NodeStatusOverview {
int32 healthy_peers = 10;
int32 route_count = 11;
bool route_mismatch = 12;
int32 route_mismatch_count = 13;
int32 unhealthy_peer_links = 14; // normalized diagnostic rules, not peer_count - healthy_peers
bool uses_ipip = 15;
}

// DetailRequest uses the same deadline across all delivery attempts.
Expand Down
27 changes: 15 additions & 12 deletions internal/net/status/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@ import "time"
// NodeStatusOverview contains routine status without peer, route, or BPF details.
// Counts and mismatch state are observed facts, not inferred from missing details.
type NodeStatusOverview struct {
Timestamp time.Time `json:"timestamp"`
NodeInfo NodeInfo `json:"nodeInfo"`
HealthCheck *HealthCheckStatus `json:"healthCheck,omitempty"`
NodeErrors []NodeError `json:"nodeErrors,omitempty"`
FetchError string `json:"fetchError,omitempty"`
LastPushTime *time.Time `json:"lastPushTime,omitempty"`
StatusSource string `json:"statusSource,omitempty"`
NodePodInfo *NodePodInfo `json:"nodePodInfo,omitempty"`
PeerCount int `json:"peerCount"`
HealthyPeers int `json:"healthyPeers"`
RouteCount int `json:"routeCount"`
RouteMismatch bool `json:"routeMismatch"`
Timestamp time.Time `json:"timestamp"`
NodeInfo NodeInfo `json:"nodeInfo"`
HealthCheck *HealthCheckStatus `json:"healthCheck,omitempty"`
NodeErrors []NodeError `json:"nodeErrors,omitempty"`
FetchError string `json:"fetchError,omitempty"`
LastPushTime *time.Time `json:"lastPushTime,omitempty"`
StatusSource string `json:"statusSource,omitempty"`
NodePodInfo *NodePodInfo `json:"nodePodInfo,omitempty"`
PeerCount int `json:"peerCount"`
HealthyPeers int `json:"healthyPeers"`
RouteCount int `json:"routeCount"`
RouteMismatch bool `json:"routeMismatch"`
RouteMismatchCount int `json:"routeMismatchCount"`
UnhealthyPeerLinks int `json:"unhealthyPeerLinks"`
UsesIPIP bool `json:"usesIPIP"`
}

// NodeStatusResponse is the top-level status response for a node.
Expand Down