engine

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RateLimitRequests = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Name: "gopher_guard_requests_total",
			Help: "Total number of rate limit requests processed by Gopher-Guard",
		},
		[]string{"status"},
	)

	TotalGRPCRequest = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Name: "grpc_requests_total",
			Help: "Total no of grpc requests achieved",
		},
		[]string{"method"},
	)

	RaftCurrentTerm = promauto.NewGauge(
		prometheus.GaugeOpts{
			Name: "raft_current_term",
			Help: "The current raft term(increments on elections)",
		},
	)

	RaftIsLeader = promauto.NewGauge(
		prometheus.GaugeOpts{
			Name: "raft_is_leader",
			Help: "Returns 1 if the node is the leader otherwise 0",
		},
	)
)

Functions

This section is empty.

Types

type CommandType

type CommandType string
const (
	CommandAddTimestamp CommandType = "ADD_TIMESTAMP"
	CommandDeleteKey    CommandType = "DELETE_KEY"
)

type LimiterFSM

type LimiterFSM struct {
	Engine *SlidingWindow
}

func (*LimiterFSM) Apply

func (f *LimiterFSM) Apply(logEntry *raft.Log) interface{}

func (*LimiterFSM) Restore

func (f *LimiterFSM) Restore(rc io.ReadCloser) error

func (*LimiterFSM) Snapshot

func (f *LimiterFSM) Snapshot() (raft.FSMSnapshot, error)

type LogCommand

type LogCommand struct {
	Type      CommandType `json:"type"`
	Key       string      `json:"key"`
	Timestamp time.Time   `json:"timestamp"`
}

func DecodeCommand

func DecodeCommand(data []byte) (*LogCommand, error)

func (*LogCommand) Encode

func (lg *LogCommand) Encode() ([]byte, error)

type SlidingWindow

type SlidingWindow struct {
	RaftNode *raft.Raft
	// contains filtered or unexported fields
}

func NewSlidingWindow

func NewSlidingWindow() *SlidingWindow

func (*SlidingWindow) Allow

func (sw *SlidingWindow) Allow(key string, limit int32, windowMs time.Duration) (bool, int32, error)

func (*SlidingWindow) StartJanitor

func (sw *SlidingWindow) StartJanitor(interval time.Duration, maxWindow time.Duration)

type Snapshot

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

func (*Snapshot) Persist

func (s *Snapshot) Persist(sink raft.SnapshotSink) error

func (*Snapshot) Release

func (s *Snapshot) Release()

Jump to

Keyboard shortcuts

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