topology

package
v0.0.0-...-5b49586 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package topology manages the network topology visualization and state.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager handles topology state tracking.

Summary: Represents a Manager.

func NewManager

NewManager creates a new Topology Manager.

Summary: Creates a new Topology Manager instance.

Parameters:

  • registry (serviceregistry.ServiceRegistryInterface): The service registry interface.
  • tm (tool.ManagerInterface): The tool manager interface.

Returns:

  • *Manager: A new instance of the Topology Manager.

Side Effects:

  • Starts the background process loop.

func (*Manager) Close

func (m *Manager) Close()

Close stops the background worker.

Summary: gracefully shuts down the Topology Manager.

Parameters:

  • None.

Side Effects:

  • Closes the shutdown channel, stopping the background loop.

func (*Manager) GetGraph

func (m *Manager) GetGraph(_ context.Context) *topologyv1.Graph

GetGraph generates the current topology graph.

Summary: Constructs the network topology graph.

Parameters:

  • _ (context.Context): Unused context parameter.

Returns:

  • *topologyv1.Graph: The constructed topology graph.

Side Effects:

  • Fetches all services and tools (may involve I/O).

func (*Manager) GetRecentServiceStats

func (m *Manager) GetRecentServiceStats(serviceID string, window time.Duration) (avgLatency time.Duration, errorRate float64)

GetRecentServiceStats returns the aggregated statistics for a service over a given time window. It uses trafficHistory which stores minute-level stats.

Summary: Calculates recent statistics for a service within a time window.

Parameters:

  • serviceID (string): The service ID to calculate stats for.
  • window (time.Duration): The time window to look back.

Returns:

  • avgLatency (time.Duration): The average latency over the window.
  • errorRate (float64): The error rate over the window.

Side Effects:

  • None.

func (*Manager) GetStats

func (m *Manager) GetStats(serviceID string) Stats

GetStats returns the aggregated stats.

Summary: Retrieves aggregated statistics, optionally filtered by service ID.

Parameters:

  • serviceID (string): The service ID to filter by (optional).

Returns:

  • Stats: The aggregated statistics.

Side Effects:

  • None.

func (*Manager) GetTrafficHistory

func (m *Manager) GetTrafficHistory(serviceID string) []TrafficPoint

GetTrafficHistory returns the traffic history for the last 24 hours.

Summary: Retrieves traffic history points for the last hour (minute granularity).

Parameters:

  • serviceID (string): The service ID to filter by (optional).

Returns:

  • []TrafficPoint: A slice of traffic data points.

Side Effects:

  • None.

func (*Manager) Middleware

func (m *Manager) Middleware(next mcp.MethodHandler) mcp.MethodHandler

Middleware returns a middleware function to track session activity.

Summary: Creates an MCP middleware for tracking and recording session activity metrics.

Parameters:

  • next: mcp.MethodHandler. The next handler in the chain.

Returns:

  • mcp.MethodHandler: The wrapped handler.

Side Effects:

  • Extracts session ID from context or request.
  • Records duration, success/error status, and response size.
  • Calls m.RecordActivity to persist metrics.

func (*Manager) RecordActivity

func (m *Manager) RecordActivity(sessionID string, meta map[string]interface{}, latency time.Duration, isError bool, serviceID string, responseLen int64)

RecordActivity updates the session activity. ⚡ BOLT: Offloaded to asynchronous channel to prevent blocking the request path. Randomized Selection from Top 5 High-Impact Targets

Summary: Records a new activity event for a session.

Parameters:

  • sessionID (string): The unique identifier of the session.
  • meta (map[string]interface{}): Metadata associated with the activity.
  • latency (time.Duration): The duration of the operation.
  • isError (bool): Whether the operation resulted in an error.
  • serviceID (string): The identifier of the service involved (optional).
  • responseLen (int64): The length of the response in bytes.

Side Effects:

  • Sends an activity event to the processing channel (non-blocking).

func (*Manager) SeedTrafficHistory

func (m *Manager) SeedTrafficHistory(points []TrafficPoint)

SeedTrafficHistory allows seeding the traffic history with external data. This is primarily for testing and debugging purposes.

Summary: Seeds the traffic history with provided data points.

Parameters:

  • points ([]TrafficPoint): The traffic data points to seed.

Side Effects:

  • Modifies the internal traffic history state.
  • Updates the "seed-data" session stats.

type MinuteStats

type MinuteStats struct {
	Requests     int64
	Errors       int64
	Latency      int64 // Total latency in ms
	Bytes        int64 // Total response bytes
	ServiceStats map[string]*ServiceTrafficStats
}

MinuteStats tracks stats for a single minute.

Summary: Represents a MinuteStats.

type ServiceTrafficStats

type ServiceTrafficStats struct {
	Requests int64
	Errors   int64
	Latency  int64
	Bytes    int64
}

ServiceTrafficStats tracks stats for a single service in a minute.

Summary: Represents a ServiceTrafficStats.

type SessionStats

type SessionStats struct {
	ID             string
	Metadata       map[string]string
	LastActive     time.Time
	RequestCount   int64
	TotalLatency   time.Duration
	ErrorCount     int64
	TotalBytes     int64
	ServiceCounts  map[string]int64         // Per service request count
	ServiceErrors  map[string]int64         // Per service error count
	ServiceLatency map[string]time.Duration // Per service latency
}

SessionStats contains statistics about a topology session.

Summary: Represents a SessionStats.

type Stats

type Stats struct {
	TotalRequests int64
	AvgLatency    time.Duration
	ErrorRate     float64
}

Stats aggregated metrics.

Summary: Represents a Stats.

type TrafficPoint

type TrafficPoint struct {
	Time    string `json:"time"`
	Total   int64  `json:"requests"` // mapped to "requests" for UI
	Errors  int64  `json:"errors"`
	Latency int64  `json:"latency"`
	Bytes   int64  `json:"bytes"`
}

TrafficPoint represents a data point for the traffic chart.

Summary: Represents a TrafficPoint.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL