server

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChaosAPI added in v0.2.0

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

ChaosAPI exposes HTTP control endpoints for the NetworkProxy attached to this node, plus cluster-wide orchestration endpoints that fan out to peers.

Per-node endpoints manipulate only the local proxy (affect this node's outbound traffic). Cluster endpoints let the UI issue a single request that installs matching rules on every node — essential for symmetric partitions and preset scenarios.

func NewChaosAPI added in v0.2.0

func NewChaosAPI(nodeID string, proxy *transport.NetworkProxy, httpPeers map[string]string) *ChaosAPI

func (*ChaosAPI) RegisterRoutes added in v0.2.0

func (c *ChaosAPI) RegisterRoutes(mux *http.ServeMux)

type Command

type Command struct {
	Op    string `json:"op"` // "put" or "delete"
	Key   string `json:"key"`
	Value string `json:"value,omitempty"` // only set for "put"
}

type ConfigAPI added in v0.2.0

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

func NewConfigAPI added in v0.2.0

func NewConfigAPI(nodeID string, node *raft.RaftNode, httpPeers map[string]string) *ConfigAPI

func (*ConfigAPI) RegisterRoutes added in v0.2.0

func (c *ConfigAPI) RegisterRoutes(mux *http.ServeMux)

type KVStore

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

KVStore is the state machine: map[string]string driven by the Raft commit log. Only applyLoop() writes to data; HTTP handlers read from it.

func NewKVStore

func NewKVStore(node *raft.RaftNode, httpPeers map[string]string, m *Metrics) *KVStore

func (*KVStore) HandleCluster added in v0.2.0

func (kv *KVStore) HandleCluster(w http.ResponseWriter, r *http.Request)

Handles: GET /api/cluster — aggregated snapshot across all peers.

func (*KVStore) HandleDelete

func (kv *KVStore) HandleDelete(w http.ResponseWriter, r *http.Request)

Handles: DELETE /keys/{key}

func (*KVStore) HandleEvents added in v0.2.0

func (kv *KVStore) HandleEvents(w http.ResponseWriter, r *http.Request)

Handles: GET /api/events — Server-Sent Events. Emits a "status" frame every 500ms and diff events (leader_change, term_change, node_down, node_up) whenever the snapshot changes.

func (*KVStore) HandleGet

func (kv *KVStore) HandleGet(w http.ResponseWriter, r *http.Request)

Handles: GET /keys/{key}

func (*KVStore) HandlePut

func (kv *KVStore) HandlePut(w http.ResponseWriter, r *http.Request)

Handles: PUT /keys/{key} body: {"value":"..."}

func (*KVStore) HandleStatus

func (kv *KVStore) HandleStatus(w http.ResponseWriter, r *http.Request)

Handles: GET /status — returns node's Raft state as JSON.

func (*KVStore) RegisterRoutes

func (kv *KVStore) RegisterRoutes(mux *http.ServeMux)

RegisterRoutes wires all KVStore handlers into an HTTP mux.

func (*KVStore) Start

func (kv *KVStore) Start()

Start launches the background goroutine that applies committed entries to the map.

func (*KVStore) Stop

func (kv *KVStore) Stop()

Stop signals the apply loop to exit.

type LogAPI added in v0.2.0

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

LogAPI exposes the Raft log for visualization in the dashboard. Each node serves its own log; the cluster endpoint fans out to every peer.

func NewLogAPI added in v0.2.0

func NewLogAPI(node *raft.RaftNode, httpPeers map[string]string) *LogAPI

func (*LogAPI) RegisterRoutes added in v0.2.0

func (l *LogAPI) RegisterRoutes(mux *http.ServeMux)

type Metrics

type Metrics struct {
	CurrentTerm    prometheus.Gauge
	State          prometheus.Gauge
	CommittedIndex prometheus.Gauge
	AppliedIndex   prometheus.Gauge

	LogEntriesTotal prometheus.Counter
	ElectionsTotal  prometheus.Counter
	LeaderChanges   prometheus.Counter

	ReplicationLag   *prometheus.HistogramVec
	WALFsyncDuration prometheus.Histogram
}

This holds all Prometheus instruments for the Raftly node. All prometheus types are safe for concurrent use.

func NewMetrics

func NewMetrics() *Metrics

func (*Metrics) Update

func (m *Metrics) Update(status raft.NodeStatus, prevLeader string)

Refreshes all gauges from the current node status. We call this on a regular interval (every second) from a background goroutine. prevLeader is the leaderID from the previous call - used to detect transitions.

type Server

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

Server owns and manages the lifecycle of every Raftly subsystem.

func New

func New(cfg *ServerConfig) (*Server, error)

Creates a server but doesn't start anything

func (*Server) Start

func (s *Server) Start() error

Begins all subsystems

func (*Server) Stop

func (s *Server) Stop(ctx context.Context)

Gracefully shuts everything down.

type ServerConfig

type ServerConfig struct {
	Raft      *raft.Config
	GRPCAddr  string            // this node's gRPC listen address (Raft peer communication)
	HttpAddr  string            // this node's HTTP listen address (client API + /metrics)
	HTTPPeers map[string]string // nodeID → HTTP address for ALL nodes (including self, for redirects)
}

Holds everything to start a Raftly server node

Jump to

Keyboard shortcuts

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