server

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: MIT Imports: 37 Imported by: 9

README

Server module

This repository contains codebase to define FOXDEN/CHESS HTTP server functionality. It provides common router, server functions and middleware shared among all FOXDEN/CHESS services.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AvgGetRequestTime float64

AvgGetRequestTime represents average GET request time

View Source
var AvgPostRequestTime float64

AvgPostRequestTime represents average POST request time

View Source
var AvgPutRequestTime float64

AvgPutRequestTime represents average PUT request time

View Source
var LimiterMiddleware gin.HandlerFunc

LimiterMiddleware provides limiter middleware pointer

View Source
var MetricsLastUpdateTime time.Time

MetricsLastUpdateTime keeps track of last update time of the metrics

View Source
var NumLogicalCores int

NumLogicalCores represents number of cores in our node

View Source
var NumPhysicalCores int

NumPhysicalCores represents number of cores in our node

RPS represents requests per second for a given server

View Source
var RPSLogical float64

RPSLogical represents requests per second for a given server times number of logical CPU cores

View Source
var RPSPhysical float64

RPSPhysical represents requests per second for a given server times number of physical CPU cores

View Source
var StartTime time.Time

StartTime represents initial time when we started the server

View Source
var Time0 time.Time

Time0 represents initial time when we started the server

View Source
var TotalDeleteRequests uint64

TotalDeleteRequests counts total number of DELETE requests received by the server

View Source
var TotalGetRequests uint64

TotalGetRequests counts total number of GET requests received by the server

View Source
var TotalPostRequests uint64

TotalPostRequests counts total number of POST requests received by the server

View Source
var TotalPutRequests uint64

TotalPutRequests counts total number of PUT requests received by the server

Functions

func ApisHandler added in v0.0.1

func ApisHandler(c *gin.Context)

ApisHandler provides JSON output for server routes

func CaptchaHandler

func CaptchaHandler() gin.HandlerFunc

CaptchaHandler provides access to captcha server

func CounterMiddleware

func CounterMiddleware() gin.HandlerFunc

CounterMiddleware counts GET/POST/PUT/DELETE requests

func ErrorPage

func ErrorPage(fsys fs.FS, msg string, err error) string

ErrorPage returns error page

func ErrorTmpl

func ErrorTmpl(fsys fs.FS, msg string, err error) string

ErrorTmpl provides error template message

func Etag added in v0.0.5

func Etag(str string, weak bool) string

Generates an Etag for given string, provided by https://github.com/amalfra/etag

func FAQPage added in v0.0.1

func FAQPage(fsys fs.FS) string

FAQPage provides FAQ page

func FooterPage

func FooterPage(fsys fs.FS) string

FooterPage returns footer page

func GinHandlerFunc added in v0.0.3

func GinHandlerFunc(hdlr http.HandlerFunc) gin.HandlerFunc

GinHandlerFunc converts given http.Handler to gin.HandlerFunc

func HeaderMiddleware added in v0.0.5

func HeaderMiddleware(webServer srvConfig.WebServer) gin.HandlerFunc

HeaderMiddleware represents header middleware

func HeaderPage

func HeaderPage(fsys fs.FS) string

HeaderPage returns header page

func InitServer added in v0.0.2

func InitServer(webServer srvConfig.WebServer)

InitServer provides server initialization

func LoggerMiddleware added in v0.3.7

func LoggerMiddleware() gin.HandlerFunc

LoggerMiddleware is custom logger for gin server

func MDToHTML added in v0.1.0

func MDToHTML(fsys fs.FS, fname string) (string, error)

MDToHTML function to generate HTML from given markdown file

func MetricsHandler added in v0.0.8

func MetricsHandler(c *gin.Context)

MetricsHandler provides metrics JSON for monitoring purposes (Prometheus)

func ParseTmpl added in v0.0.1

func ParseTmpl(tdir, tmpl string, data interface{}) (string, error)

ParseTmpl parses template with given data

func QLKeysHandler added in v0.2.2

func QLKeysHandler(c *gin.Context)

QLKeysHandler provides list of keys used in QueryLanguage in given service

func Router added in v0.0.1

func Router(routes []Route, fsys fs.FS, static string, webServer srvConfig.WebServer) *gin.Engine

Router provids server router, it takes two maps: one for non-authorized routes and anotehr for authorized ones

func StartServer added in v0.0.7

func StartServer(r *gin.Engine, webServer srvConfig.WebServer)

StartServer starts HTTP(s) server

func SuccessTmpl

func SuccessTmpl(fsys fs.FS, msg string) string

SuccessTmpl provides success template message

func TmplPage added in v0.0.1

func TmplPage(fsys fs.FS, tmpl string, tmplData TmplRecord) string

TmplPage parses given template and return HTML page

Types

type CustomResponseWriter added in v0.3.8

type CustomResponseWriter struct {
	gin.ResponseWriter
	// contains filtered or unexported fields
}

CustomResponseWriter wraps gin.ResponseWriter to track response size.

func (*CustomResponseWriter) Write added in v0.3.8

func (w *CustomResponseWriter) Write(data []byte) (int, error)

Write tracks the number of bytes written in the response.

type GinRoute added in v0.0.1

type GinRoute struct {
	Method string `json:"method"`
	Path   string `json:"path"`
}

GinRoute represents git route info

type Mem

type Mem struct {
	Virtual Memory `json:"virtual"` // virtual memory metrics from gopsutils
	Swap    Memory `json:"swap"`    // swap memory metrics from gopsutils
}

Mem structure keeps track of virtual/swap memory of the server

type Memory

type Memory struct {
	Total       uint64  `json:"total"`
	Free        uint64  `json:"free"`
	Used        uint64  `json:"used"`
	UsedPercent float64 `json:"usedPercent"`
}

Memory structure keeps track of server memory

type Metrics added in v0.0.8

type Metrics struct {
	CPU                []float64               `json:"cpu"`                // cpu metrics from gopsutils
	CpuPercent         float64                 `json:"cpu_pct"`            // cpu percent
	Connections        []net.ConnectionStat    `json:"connections"`        // connections metrics from gopsutils
	Load               load.AvgStat            `json:"load"`               // load metrics from gopsutils
	Memory             Mem                     `json:"memory"`             // memory metrics from gopsutils
	OpenFiles          []process.OpenFilesStat `json:"openFiles"`          // open files metrics from gopsutils
	GoRoutines         uint64                  `json:"goroutines"`         // total number of go routines at run-time
	Uptime             float64                 `json:"uptime"`             // uptime of the server
	GetRequests        uint64                  `json:"getRequests"`        // total number of get requests across all services
	PostRequests       uint64                  `json:"postRequests"`       // total number of post requests across all services
	PutRequests        uint64                  `json:"putRequests"`        // total number of post requests across all services
	AvgGetTime         float64                 `json:"avgGetTime"`         // avg GET request time
	AvgPostTime        float64                 `json:"avgPostTime"`        // avg POST request time
	AvgPutTime         float64                 `json:"avgPutTime"`         // avg PUT request time
	RPS                float64                 `json:"rps"`                // throughput req/sec
	RPSPhysical        float64                 `json:"rpsPhysical"`        // throughput req/sec using physical cpu
	RPSLogical         float64                 `json:"rpsLogical"`         // throughput req/sec using logical cpu
	ProcFS             ProcFS                  `json:"procfs"`             // metrics from prometheus procfs
	MaxDBConnections   uint64                  `json:"maxDBConnections"`   // max number of DB connections
	MaxIdleConnections uint64                  `json:"maxIdleConnections"` // max number of idle DB connections

	// Migration server metrics
	MigrationRequests   uint64 `json:"migrationRequests"`   // total number of migration requests across all services
	MigrationPending    uint64 `json:"migrationPending"`    // total number of pending migration requests across all services
	MigrationInProgress uint64 `json:"migrationInProgress"` // total number of in progress migration requests across all services
	MigrationFailed     uint64 `json:"migrationFailed"`     // total number of failed migration requests across all services
	MigrationTermFailed uint64 `json:"migrationTermFailed"` // total number of term failed migration requests across all services
	MigrationCompleted  uint64 `json:"migrationCompleted"`  // total number of completed migration requests across all services
	MigrationQueued     uint64 `json:"migrationQueued"`     // total number of queued migration requests across all services
	MigrationExistInDB  uint64 `json:"migrationExistInDB"`  // total number of exist in db migration requests across all services
}

Metrics provide various metrics about our server

type ProcFS added in v0.0.8

type ProcFS struct {
	CpuTotal      float64
	Vsize         float64
	Rss           float64
	OpenFDs       float64
	MaxFDs        float64
	MaxVsize      float64
	UserCPUs      []float64
	SystemCPUs    []float64
	SumUserCPUs   float64
	SumSystemCPUs float64
}

ProcFS represents prometheus profcs metrics

func ProcFSMetrics added in v0.0.8

func ProcFSMetrics() ProcFS

ProcFSMetrics returns procfs (prometheus) metrics

type RequestStats added in v0.0.8

type RequestStats struct {
	TotalGetRequests  uint64
	TotalPostRequests uint64
	TotalPutRequests  uint64
	Time              time.Time
	NumPhysicalCores  int
	NumLogicalCores   int
}

RequestStats holds metrics related to number of requests on a server

func (*RequestStats) Update added in v0.0.8

func (r *RequestStats) Update()

Update RequestStatus metrics

type Route added in v0.0.1

type Route struct {
	Method     string
	Path       string
	Scope      string
	Authorized bool
	Handler    gin.HandlerFunc
}

Route represents routes structure

type Templates added in v0.0.1

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

Templates structure

func (Templates) TextTmpl added in v0.0.1

func (q Templates) TextTmpl(fsys fs.FS, tfile string, tmplData map[string]interface{}) string

Tmpl method for ServerTemplates structure

func (Templates) Tmpl added in v0.0.1

func (q Templates) Tmpl(fsys fs.FS, tfile string, tmplData map[string]interface{}) string

Tmpl method for ServerTemplates structure

type TmplRecord added in v0.0.1

type TmplRecord map[string]interface{}

TmplRecord represent template record

func MakeTmpl

func MakeTmpl(fsys fs.FS, title string) TmplRecord

helper function to make initial template struct

func MetricsPage

func MetricsPage(fsys fs.FS) TmplRecord

MetricsPage represents metrics page

func (TmplRecord) GetBytes added in v0.0.1

func (t TmplRecord) GetBytes(key string) []byte

GetBytes returns bytes object for given key

func (TmplRecord) GetElapsedTime added in v0.0.1

func (t TmplRecord) GetElapsedTime() string

GetElapsedTime returns elapsed time

func (TmplRecord) GetError added in v0.0.1

func (t TmplRecord) GetError() string

GetError returns error string

func (TmplRecord) GetInt added in v0.0.1

func (t TmplRecord) GetInt(key string) int

GetInt converts given value for provided key to int data-type

func (TmplRecord) GetString added in v0.0.1

func (t TmplRecord) GetString(key string) string

GetString converts given value for provided key to string data-type

Jump to

Keyboard shortcuts

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