Skip to content

Commit

Permalink
[agent] enable basic metric collection and exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
Frostman committed Apr 23, 2024
1 parent 592ea31 commit 6b33ca4
Show file tree
Hide file tree
Showing 10 changed files with 1,669 additions and 4 deletions.
197 changes: 196 additions & 1 deletion api/agent/v1alpha2/agent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package v1alpha2
import (
"sort"

"github.com/pkg/errors"
"go.githedgehog.com/fabric/api/meta"
vpcapi "go.githedgehog.com/fabric/api/vpc/v1alpha2"
wiringapi "go.githedgehog.com/fabric/api/wiring/v1alpha2"
Expand Down Expand Up @@ -126,14 +127,208 @@ type AgentStatus struct {
LastAppliedTime metav1.Time `json:"lastAppliedTime,omitempty"`
// Generation of the last successful configuration application
LastAppliedGen int64 `json:"lastAppliedGen,omitempty"`
// Information about the switch and NOS
// Detailed switch state updated with each heartbeat
State SwitchState `json:"state,omitempty"`
// Information about the switch and NOS updated with each heartbeat
NOSInfo NOSInfo `json:"nosInfo,omitempty"`
// Status updates from the agent
StatusUpdates []ApplyStatusUpdate `json:"statusUpdates,omitempty"`
// Conditions of the agent, includes readiness marker for use with kubectl wait
Conditions []metav1.Condition `json:"conditions"`
}

type SwitchState struct {
// Switch interfaces state (incl. physical, management and port channels)
Interfaces map[string]SwitchStateInterface `json:"interfaces,omitempty"` // TODO add LLDP to interface?
// Switch transceivers state (port -> transceiver)
Transceivers map[string]SwitchStateTransceiver `json:"transceivers,omitempty"` // TODO move to interface?
// State of all BGP neighbors (VRF -> neighbor address -> state)
BGPNeighbors map[string]map[string]SwitchStateBGPNeighbor `json:"bgpNeighbors,omitempty"`

// TODO add FAN info, PSU info, Temperature info
}

type SwitchStateInterface struct {
Enabled bool `json:"enabled,omitempty"`
AdminStatus AdminStatus `json:"adminStatus,omitempty"`
OperStatus OperStatus `json:"operStatus,omitempty"`
MAC string `json:"mac,omitempty"`
LastChange metav1.Time `json:"lastChanged,omitempty"`
Counters SwitchStateInterfaceCounters `json:"counters,omitempty"`
}

type SwitchStateInterfaceCounters struct {
InBitsPerSecond float64 `json:"inBitsPerSecond,omitempty"`
InDiscards uint64 `json:"inDiscards,omitempty"`
InErrors uint64 `json:"inErrors,omitempty"`
InPktsPerSecond float64 `json:"inPktsPerSecond,omitempty"`
InUtilization uint8 `json:"inUtilization,omitempty"`
LastClear metav1.Time `json:"lastClear,omitempty"`
OutBitsPerSecond float64 `json:"outBitsPerSecond,omitempty"`
OutDiscards uint64 `json:"outDiscards,omitempty"`
OutErrors uint64 `json:"outErrors,omitempty"`
OutPktsPerSecond float64 `json:"outPktsPerSecond,omitempty"`
OutUtilization uint8 `json:"outUtilization,omitempty"`
}

type AdminStatus string

const (
AdminStatusUnset AdminStatus = ""
AdminStatusUp AdminStatus = "up"
AdminStatusDown AdminStatus = "down"
AdminStatusTesting AdminStatus = "testing"
)

func (a AdminStatus) ID() (uint8, error) {
switch a {
case AdminStatusUnset:
return 0, nil
case AdminStatusUp:
return 1, nil
case AdminStatusDown:
return 2, nil
case AdminStatusTesting:
return 3, nil
default:
return 0, errors.Errorf("unknown AdminStatus %s", a)
}
}

type OperStatus string

const (
OperStatusUnset OperStatus = ""
OperStatusUp OperStatus = "up"
OperStatusDown OperStatus = "down"
OperStatusTesting OperStatus = "testing"
OperStatusUnknown OperStatus = "unknown"
OperStatusDormant OperStatus = "dormant"
OperStatusNotPresent OperStatus = "notPresent"
OperStatusLowerLayerDown OperStatus = "lowerLayerDown"
)

func (o OperStatus) ID() (uint8, error) {
switch o {
case OperStatusUnset:
return 0, nil
case OperStatusUp:
return 1, nil
case OperStatusDown:
return 2, nil
case OperStatusTesting:
return 3, nil
case OperStatusUnknown:
return 4, nil
case OperStatusDormant:
return 5, nil
case OperStatusNotPresent:
return 6, nil
case OperStatusLowerLayerDown:
return 7, nil
default:
return 0, errors.Errorf("unknown OperStatus %s", o)
}
}

type SwitchStateTransceiver struct {
CableClass string `json:"cable-class,omitempty"`
Temperature float64 `json:"temperature,omitempty"`
Voltage float64 `json:"voltage,omitempty"`

// TODO add vendor, serial number, etc
// Vendor *string `json:"vendor,omitempty" module:"openconfig-platform-diagnostics"`
// VendorPart *string `json:"vendor-part,omitempty" module:"openconfig-platform-diagnostics"`
}

type SwitchStateBGPNeighbor struct {
ConnectionsDropped uint64 `json:"connectionsDropped,omitempty"`
Enabled bool `json:"enabled,omitempty"`
EstablishedTransitions uint64 `json:"establishedTransitions,omitempty"`
LastEstablished metav1.Time `json:"lastEstablished,omitempty"`
LastRead metav1.Time `json:"lastRead,omitempty"`
LastResetReason string `json:"lastResetReason,omitempty"`
LastResetTime metav1.Time `json:"lastResetTime,omitempty"`
LastWrite metav1.Time `json:"lastWrite,omitempty"`
LocalAS uint32 `json:"localAS,omitempty"`
Messages BGPMessages `json:"messages,omitempty"`
PeerAS uint32 `json:"peerAS,omitempty"`
PeerGroup string `json:"peerGroup,omitempty"`
PeerPort uint16 `json:"peerPort,omitempty"`
PeerType BGPPeerType `json:"peerType,omitempty"`
RemoteRouterID string `json:"remoteRouterID,omitempty"`
SessionState BGPNeighborSessionState `json:"sessionState,omitempty"`
ShutdownMessage string `json:"shutdownMessage,omitempty"`
}

type BGPNeighborSessionState string

const (
BGPNeighborSessionStateUnset BGPNeighborSessionState = ""
BGPNeighborSessionStateIdle BGPNeighborSessionState = "idle"
BGPNeighborSessionStateConnect BGPNeighborSessionState = "connect"
BGPNeighborSessionStateActive BGPNeighborSessionState = "active"
BGPNeighborSessionStateOpenSent BGPNeighborSessionState = "openSent"
BGPNeighborSessionStateOpenConfirm BGPNeighborSessionState = "openConfirm"
BGPNeighborSessionStateEstablished BGPNeighborSessionState = "established"
)

func (b BGPNeighborSessionState) ID() (uint8, error) {
switch b {
case BGPNeighborSessionStateUnset:
return 0, nil
case BGPNeighborSessionStateIdle:
return 1, nil
case BGPNeighborSessionStateConnect:
return 2, nil
case BGPNeighborSessionStateActive:
return 3, nil
case BGPNeighborSessionStateOpenSent:
return 4, nil
case BGPNeighborSessionStateOpenConfirm:
return 5, nil
case BGPNeighborSessionStateEstablished:
return 6, nil
default:
return 0, errors.Errorf("unknown BGPNeighborSessionState %s", b)
}
}

type BGPPeerType string

const (
BGPPeerTypeUnset BGPPeerType = ""
BGPPeerTypeInternal BGPPeerType = "internal"
BGPPeerTypeExternal BGPPeerType = "external"
)

func (b BGPPeerType) ID() (uint8, error) {
switch b {
case BGPPeerTypeUnset:
return 0, nil
case BGPPeerTypeInternal:
return 1, nil
case BGPPeerTypeExternal:
return 2, nil
default:
return 0, errors.Errorf("unknown BGPPeerType %s", b)
}
}

type BGPMessages struct {
Received BGPMessagesCounters `json:"received,omitempty"`
Sent BGPMessagesCounters `json:"sent,omitempty"`
}

type BGPMessagesCounters struct {
Capability uint64 `json:"capability,omitempty"`
Keepalive uint64 `json:"keepalive,omitempty"`
Notification uint64 `json:"notification,omitempty"`
Open uint64 `json:"open,omitempty"`
RouteRefresh uint64 `json:"routeRefresh,omitempty"`
Update uint64 `json:"update,omitempty"`
}

// NOSInfo contains information about the switch and NOS received from the switch itself by the agent
type NOSInfo struct {
// ASIC name, such as "broadcom" or "vs"
Expand Down
148 changes: 148 additions & 0 deletions api/agent/v1alpha2/zz_generated.deepcopy.go

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

Loading

0 comments on commit 6b33ca4

Please sign in to comment.