fns

package module
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2022 License: Apache-2.0 Imports: 35 Imported by: 8

README

fns

压力测试

K6 结果(50 VUS 30s)


          /\      |‾‾| /‾‾/   /‾‾/
     /\  /  \     |  |/  /   /  /
    /  \/    \    |     (   /   ‾‾\
   /          \   |  |\  \ |  (‾)  |
  / __________ \  |__| \__\ \_____/ .io

  execution: local
     script: ./test.js
     output: -

  scenarios: (100.00%) 1 scenario, 50 max VUs, 1m0s max duration (incl. graceful stop):
           * default: 50 looping VUs for 30s (gracefulStop: 30s)


running (0m30.0s), 00/50 VUs, 3565697 complete and 0 interrupted iterations
default ✓ [======================================] 50 VUs  30s

     ✓ status was 200

     checks.........................: 100.00% ✓ 3565697       ✗ 0
     data_received..................: 564 MB  19 MB/s
     data_sent......................: 521 MB  17 MB/s
     http_req_blocked...............: avg=1.58µs   min=0s med=0s   max=5.57ms   p(90)=0s      p(95)=0s
     http_req_connecting............: avg=24ns     min=0s med=0s   max=2.31ms   p(90)=0s      p(95)=0s
     http_req_duration..............: avg=261.31µs min=0s med=0s   max=12.92ms  p(90)=844.7µs p(95)=1ms
       { expected_response:true }...: avg=261.31µs min=0s med=0s   max=12.92ms  p(90)=844.7µs p(95)=1ms
     http_req_failed................: 0.00%   ✓ 0             ✗ 3565697
     http_req_receiving.............: avg=26.91µs  min=0s med=0s   max=8.65ms   p(90)=0s      p(95)=29.3µs
     http_req_sending...............: avg=10.53µs  min=0s med=0s   max=7.7ms    p(90)=0s      p(95)=0s
     http_req_tls_handshaking.......: avg=0s       min=0s med=0s   max=0s       p(90)=0s      p(95)=0s
     http_req_waiting...............: avg=223.86µs min=0s med=0s   max=12.43ms  p(90)=641.9µs p(95)=1ms
     http_reqs......................: 3565697 118850.991763/s
     iteration_duration.............: avg=412.23µs min=0s med=92µs max=118.81ms p(90)=1ms     p(95)=1ms
     iterations.....................: 3565697 118850.991763/s
     vus............................: 50      min=50          max=50
     vus_max........................: 50      min=50          max=50

Documentation

Index

Constants

View Source
const (
	B = 1 << (10 * iota)
	KB
	MB
	GB
	TB
	PB
	EB
)

Variables

This section is empty.

Functions

func ConfigActiveFromENV added in v0.1.1

func ConfigActiveFromENV(key string) (active string)

func RegisterAuthorizationsRetriever

func RegisterAuthorizationsRetriever(kind string, retriever AuthorizationsRetriever)

func RegisterPermissionsDefinitionsLoaderRetriever added in v0.1.1

func RegisterPermissionsDefinitionsLoaderRetriever(kind string, retriever PermissionsDefinitionsLoaderRetriever)

func RegisterServiceDiscoveryRetriever

func RegisterServiceDiscoveryRetriever(kind string, retriever ServiceDiscoveryRetriever)

func UID

func UID() (id string)

Types

type AbstractService added in v0.9.0

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

func NewAbstractService added in v0.9.0

func NewAbstractService() AbstractService

func NewAbstractServiceWithOption added in v0.9.0

func NewAbstractServiceWithOption(option ServiceOption) AbstractService

func (AbstractService) Build added in v0.9.0

func (s AbstractService) Build(config configuares.Config) (err error)

func (AbstractService) Meta added in v0.9.0

func (s AbstractService) Meta() (v ServiceMeta)

type AbstractServiceDiscovery added in v0.1.1

type AbstractServiceDiscovery struct {
	Local   ServiceDiscovery
	Clients *HttpClients
	Manager *RegistrationsManager
}

func NewAbstractServiceDiscovery added in v0.1.1

func NewAbstractServiceDiscovery(clients *HttpClients) AbstractServiceDiscovery

func (*AbstractServiceDiscovery) Close added in v0.1.1

func (discovery *AbstractServiceDiscovery) Close()

func (*AbstractServiceDiscovery) IsLocal added in v0.1.1

func (discovery *AbstractServiceDiscovery) IsLocal(namespace string) (ok bool)

func (*AbstractServiceDiscovery) Proxy added in v0.1.1

func (discovery *AbstractServiceDiscovery) Proxy(ctx Context, namespace string) (proxy ServiceProxy, err errors.CodeError)

type AppRuntime added in v0.1.1

type AppRuntime interface {
	ClusterMode() (ok bool)
	PublicAddress() (address string)
	Log() (log logs.Logger)
	Validate(v interface{}) (err errors.CodeError)
	ServiceProxy(ctx Context, namespace string) (proxy ServiceProxy, err error)
	ServiceMeta() (meta ServiceMeta)
	Authorizations() (authorizations Authorizations)
	Permissions() (permissions Permissions)
	HttpClient() (client HttpClient)
}

type Application

type Application interface {
	Log() (log logs.Logger)
	Deploy(service ...Service) (err error)
	Run(ctx sc.Context) (err error)
	Sync()
	SyncWithTimeout(timeout time.Duration)
}

func New

func New(options ...Option) (app Application, err error)

type ApplicationConfig

type ApplicationConfig struct {
	Name        string         `json:"name,omitempty"`
	Description string         `json:"description,omitempty"`
	Terms       string         `json:"terms,omitempty"`
	Contact     *appContact    `json:"contact,omitempty"`
	License     *appLicense    `json:"license,omitempty"`
	Concurrency int            `json:"concurrency,omitempty"`
	Http        HttpConfig     `json:"http,omitempty"`
	Log         LogConfig      `json:"log,omitempty"`
	Services    ServicesConfig `json:"services,omitempty"`
}

type Argument

type Argument interface {
	json.Marshaler
	json.Unmarshaler
	As(v interface{}) (err errors.CodeError)
}

func EmptyArgument added in v0.6.16

func EmptyArgument() (arg Argument)

func NewArgument

func NewArgument(v interface{}) (arg Argument, err errors.CodeError)

type Authorizations

type Authorizations interface {
	Encode(ctx Context) (token []byte, err errors.CodeError)
	Decode(ctx Context, token []byte) (err errors.CodeError)
}

type AuthorizationsConfig

type AuthorizationsConfig struct {
	Enable bool            `json:"enable,omitempty"`
	Kind   string          `json:"kind,omitempty"`
	Config configuares.Raw `json:"config,omitempty"`
}

type AuthorizationsRetriever

type AuthorizationsRetriever func(config configuares.Raw) (authorizations Authorizations, err error)

type Context

type Context interface {
	sc.Context
	InternalRequested() (ok bool)
	RequestId() (id string)
	User() (user User)
	Meta() (meta ContextMeta)
	Timeout() (has bool)
	App() (app AppRuntime)
}

func WithFn

func WithFn(ctx Context, fn string) Context

func WithNamespace

func WithNamespace(ctx Context, namespace string) Context

func WithServiceMeta added in v0.9.0

func WithServiceMeta(ctx Context, meta ServiceMeta) Context

type ContextMeta

type ContextMeta interface {
	Exists(key string) (has bool)
	Put(key string, value interface{})
	Get(key string, value interface{}) (err error)
	Remove(key string)
	GetString(key string) (value string, has bool)
	GetInt(key string) (value int, has bool)
	GetInt32(key string) (value int32, has bool)
	GetInt64(key string) (value int64, has bool)
	GetFloat32(key string) (value float32, has bool)
	GetFloat64(key string) (value float64, has bool)
	GetBool(key string) (value bool, has bool)
	GetTime(key string) (value time.Time, has bool)
	GetDuration(key string) (value time.Duration, has bool)
	SetExactProxyServiceAddress(namespace string, address string)
	GetExactProxyServiceAddress(namespace string) (address string, has bool)
	DelExactProxyServiceAddress(namespace string)
	Encode() (value []byte)
}

type CorsConfig

type CorsConfig struct {
	Enable           bool     `json:"enable,omitempty"`
	AllowedOrigins   []string `json:"allowedOrigins,omitempty"`
	AllowedMethods   []string `json:"allowedMethods,omitempty"`
	AllowedHeaders   []string `json:"allowedHeaders,omitempty"`
	ExposedHeaders   []string `json:"exposedHeaders,omitempty"`
	AllowCredentials bool     `json:"allowCredentials,omitempty"`
	MaxAge           int      `json:"maxAge,omitempty"`
}

type DiscoveryConfig

type DiscoveryConfig struct {
	Enable bool            `json:"enable,omitempty"`
	Kind   string          `json:"kind,omitempty"`
	Config configuares.Raw `json:"config,omitempty"`
}

type Empty

type Empty struct{}

Empty @description Empty

type FnDocument added in v0.8.4

type FnDocument struct {
	Name             string          `json:"name,omitempty"`
	Title            string          `json:"title,omitempty"`
	Description      string          `json:"description,omitempty"`
	HasAuthorization bool            `json:"hasAuthorization,omitempty"`
	Argument         *ObjectDocument `json:"argument,omitempty"`
	Result           *ObjectDocument `json:"result,omitempty"`
	Deprecated       bool            `json:"deprecated,omitempty"`
}

func NewFnDocument added in v0.8.4

func NewFnDocument(name string, title string, description string, hasAuthorization bool, deprecated bool) *FnDocument

func (*FnDocument) SetArgument added in v0.8.5

func (doc *FnDocument) SetArgument(v *ObjectDocument)

func (*FnDocument) SetResult added in v0.8.5

func (doc *FnDocument) SetResult(v *ObjectDocument)

type Hook

type Hook interface {
	Build(config configuares.Config) (err error)
	Handle(unit HookUnit)
	Close()
}

type HookUnit

type HookUnit struct {
	Namespace     string
	FnName        string
	RequestId     string
	Authorization []byte
	RequestSize   int64
	ResponseSize  int64
	Latency       time.Duration
	HandleError   errors.CodeError
}

type HttpClient added in v0.1.1

type HttpClient interface {
	Get(url string, head http.Header, timeout time.Duration) (response *HttpResponse, err error)
	Post(url string, head http.Header, body []byte, timeout time.Duration) (response *HttpResponse, err error)
	Put(url string, head http.Header, body []byte, timeout time.Duration) (response *HttpResponse, err error)
	Delete(url string, head http.Header, timeout time.Duration) (response *HttpResponse, err error)
}

type HttpClients added in v0.1.1

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

func NewHttpClients added in v0.1.1

func NewHttpClients(poolSize int) (hc *HttpClients)

func (*HttpClients) Close added in v0.1.1

func (hc *HttpClients) Close()

type HttpConfig

type HttpConfig struct {
	Host                     string        `json:"host,omitempty"`
	Port                     int           `json:"port,omitempty"`
	PublicHost               string        `json:"publicHost,omitempty"`
	PublicPort               int           `json:"publicPort,omitempty"`
	MaxConnectionsPerIP      int           `json:"maxConnectionsPerIp,omitempty"`
	MaxRequestsPerConnection int           `json:"maxRequestsPerConnection,omitempty"`
	KeepAlive                bool          `json:"keepAlive,omitempty"`
	KeepalivePeriodSecond    int           `json:"keepalivePeriodSecond,omitempty"`
	RequestTimeoutSeconds    int           `json:"requestTimeoutSeconds,omitempty"`
	ReadBufferSize           string        `json:"readBufferSize"`
	WriteBufferSize          string        `json:"writeBufferSize"`
	Cors                     CorsConfig    `json:"cors"`
	TLS                      HttpTlsConfig `json:"tls,omitempty"`
}

type HttpResponse added in v0.1.1

type HttpResponse struct {
	Status int
	Head   http.Header
	Body   []byte
}

type HttpTlsConfig added in v0.8.4

type HttpTlsConfig struct {
	Enable     bool   `json:"enable,omitempty"`
	PublicKey  string `json:"publicKey,omitempty"`
	PrivateKey string `json:"privateKey,omitempty"`
}

type LocaledServiceProxy added in v0.1.1

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

func NewLocaledServiceProxy added in v0.1.1

func NewLocaledServiceProxy(service Service) *LocaledServiceProxy

func (*LocaledServiceProxy) Request added in v0.1.1

func (proxy *LocaledServiceProxy) Request(ctx Context, fn string, argument Argument) (result Result)

type LogConfig

type LogConfig struct {
	Level     string `json:"level,omitempty"`
	Formatter string `json:"formatter,omitempty"`
	Color     bool   `json:"color,omitempty"`
}

type ObjectDocument added in v0.8.4

type ObjectDocument struct {
	Package     string                     `json:"package,omitempty"`
	Name        string                     `json:"name,omitempty"`
	Title       string                     `json:"title,omitempty"`
	Description string                     `json:"description,omitempty"`
	Type        string                     `json:"type,omitempty"`
	Format      string                     `json:"format,omitempty"`
	Enum        []interface{}              `json:"enum,omitempty"`
	Required    bool                       `json:"required,omitempty"`
	Validation  string                     `json:"validation,omitempty"`
	Properties  map[string]*ObjectDocument `json:"properties,omitempty"`
	Additional  bool                       `json:"additional,omitempty"`
	Deprecated  bool                       `json:"deprecated,omitempty"`
	Example     interface{}                `json:"example,omitempty"`
}

func ArrayObjectDocument added in v0.8.4

func ArrayObjectDocument(name string, title string, description string, item *ObjectDocument) *ObjectDocument

func BoolObjectDocument added in v0.8.4

func BoolObjectDocument() *ObjectDocument

func DateObjectDocument added in v0.8.4

func DateObjectDocument() *ObjectDocument

func DateTimeObjectDocument added in v0.8.4

func DateTimeObjectDocument() *ObjectDocument

func EmptyObjectDocument added in v0.8.4

func EmptyObjectDocument() *ObjectDocument

func Float32ObjectDocument added in v0.8.4

func Float32ObjectDocument() *ObjectDocument

func Float64ObjectDocument added in v0.8.4

func Float64ObjectDocument() *ObjectDocument

func Int32ObjectDocument added in v0.8.5

func Int32ObjectDocument() *ObjectDocument

func Int64ObjectDocument added in v0.8.4

func Int64ObjectDocument() *ObjectDocument

func IntObjectDocument added in v0.8.4

func IntObjectDocument() *ObjectDocument

func JsonRawObjectDocument added in v0.8.5

func JsonRawObjectDocument() *ObjectDocument

func MapObjectDocument added in v0.8.4

func MapObjectDocument(name string, title string, description string, item *ObjectDocument) *ObjectDocument

func NewObjectDocument added in v0.8.5

func NewObjectDocument(pkg string, name string, typ string, format string, title string, description string) *ObjectDocument

func StringObjectDocument added in v0.8.4

func StringObjectDocument() *ObjectDocument

func StructObjectDocument added in v0.8.6

func StructObjectDocument(pkg string, name string, title string, description string) *ObjectDocument

func (*ObjectDocument) AddEnum added in v0.8.5

func (obj *ObjectDocument) AddEnum(v ...interface{}) *ObjectDocument

func (*ObjectDocument) AddProperty added in v0.8.4

func (obj *ObjectDocument) AddProperty(name string, prop *ObjectDocument) *ObjectDocument

func (*ObjectDocument) AsDeprecated added in v0.8.5

func (obj *ObjectDocument) AsDeprecated() *ObjectDocument

func (*ObjectDocument) AsRequired added in v0.8.5

func (obj *ObjectDocument) AsRequired(validation string) *ObjectDocument

func (*ObjectDocument) SetDescription added in v0.8.6

func (obj *ObjectDocument) SetDescription(description string) *ObjectDocument

func (*ObjectDocument) SetExample added in v0.8.6

func (obj *ObjectDocument) SetExample(example interface{}) *ObjectDocument

func (*ObjectDocument) SetFormat added in v0.8.6

func (obj *ObjectDocument) SetFormat(format string) *ObjectDocument

func (*ObjectDocument) SetTitle added in v0.8.6

func (obj *ObjectDocument) SetTitle(title string) *ObjectDocument

func (*ObjectDocument) SetValidation added in v0.8.6

func (obj *ObjectDocument) SetValidation(validation string) *ObjectDocument

type Option

type Option func(*Options) error

func ConfigRetriever

func ConfigRetriever(path string, format string, active string, prefix string, splitter byte) Option

func CustomizeValidate

func CustomizeValidate(validate *validator.Validate) Option

func GOPROCS added in v0.3.0

func GOPROCS(min int, max int) Option

func Hooks

func Hooks(hooks ...Hook) Option

func SecretKeyFile

func SecretKeyFile(path string) Option

func Version

func Version(version string) Option

type Options

type Options struct {
	ConfigRetrieverOption configuares.RetrieverOption
	Validate              *validator.Validate
	Hooks                 []Hook
	Version               string
	SecretKey             []byte
	MinPROCS              int
	MaxPROCS              int
}

type Permissions

type Permissions interface {
	// Validate 验证当前 context 中 user 对 fn 的权限
	Validate(ctx Context, namespace string, fn string) (err errors.CodeError)
	// SaveUserRoles 将角色保存到 当前 context 的 user attributes 中
	SaveUserRoles(ctx Context, roles ...string) (err errors.CodeError)
}

Permissions 基于RBAC的权限控制器 角色:角色树,控制器不存储用户的角色。 资源:fn 控制:是否可以使用(不可以使用优先于可以使用)

type PermissionsConfig

type PermissionsConfig struct {
	Enable bool            `json:"enable,omitempty"`
	Loader string          `json:"loader,omitempty"`
	Config configuares.Raw `json:"config,omitempty"`
}

type PermissionsDefinitions added in v0.1.1

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

func (*PermissionsDefinitions) Accessible added in v0.1.1

func (d *PermissionsDefinitions) Accessible(namespace string, fn string, roles []string) (accessible bool)

func (*PermissionsDefinitions) Add added in v0.1.1

func (d *PermissionsDefinitions) Add(namespace string, fn string, role string, accessible bool)

type PermissionsDefinitionsLoader added in v0.1.1

type PermissionsDefinitionsLoader interface {
	Load() (definitions *PermissionsDefinitions, err errors.CodeError)
}

PermissionsDefinitionsLoader 存储权限设定的加载器

type PermissionsDefinitionsLoaderRetriever added in v0.1.1

type PermissionsDefinitionsLoaderRetriever func(config configuares.Raw) (loader PermissionsDefinitionsLoader, err error)

type Registration added in v0.1.1

type Registration struct {
	Id        string `json:"id"`
	Namespace string `json:"namespace,omitempty"`
	Address   string `json:"address"`
	Reversion int64  `json:"-"`
}

func (Registration) Key added in v0.1.1

func (r Registration) Key() (key string)

type Registrations added in v0.1.1

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

func NewRegistrations added in v0.1.1

func NewRegistrations() (registrations *Registrations)

func (*Registrations) Append added in v0.1.1

func (r *Registrations) Append(v Registration)

func (*Registrations) Next added in v0.1.1

func (r *Registrations) Next() (v *Registration, has bool)

func (*Registrations) Remove added in v0.1.1

func (r *Registrations) Remove(v Registration)

func (*Registrations) Size added in v0.1.1

func (r *Registrations) Size() (size int)

type RegistrationsManager added in v0.1.1

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

func (*RegistrationsManager) Append added in v0.1.1

func (manager *RegistrationsManager) Append(registration Registration)

func (*RegistrationsManager) CheckRegistration added in v0.1.1

func (manager *RegistrationsManager) CheckRegistration(registration Registration) (ok bool)

func (*RegistrationsManager) Close added in v0.1.1

func (manager *RegistrationsManager) Close()

func (*RegistrationsManager) Get added in v0.1.1

func (manager *RegistrationsManager) Get(namespace string) (registration *Registration, exists bool)

func (*RegistrationsManager) ListenProblemChan added in v0.1.1

func (manager *RegistrationsManager) ListenProblemChan()

func (*RegistrationsManager) ProblemChan added in v0.1.1

func (manager *RegistrationsManager) ProblemChan() (ch chan<- *Registration)

func (*RegistrationsManager) Registrations added in v0.1.1

func (manager *RegistrationsManager) Registrations() (v []Registration)

func (*RegistrationsManager) Remove added in v0.1.1

func (manager *RegistrationsManager) Remove(registration Registration)

type RemotedServiceProxy

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

func NewRemotedServiceProxy added in v0.1.1

func NewRemotedServiceProxy(clients *HttpClients, registration *Registration, problemCh chan<- *Registration) (proxy *RemotedServiceProxy)

func (*RemotedServiceProxy) Request

func (proxy *RemotedServiceProxy) Request(ctx Context, fn string, argument Argument) (result Result)

type Result

type Result interface {
	Succeed(v interface{})
	Failed(err errors.CodeError)
	Get(ctx sc.Context, v interface{}) (err errors.CodeError)
}

func AsyncResult

func AsyncResult() Result

func SyncResult

func SyncResult() Result

type Service

type Service interface {
	Namespace() (namespace string)
	Internal() (internal bool)
	Build(config configuares.Config) (err error)
	Document() (doc *ServiceDocument)
	Handle(context Context, fn string, argument Argument) (result interface{}, err errors.CodeError)
	Shutdown() (err error)
}

Service 管理 Fn 的服务

type ServiceDiscovery

type ServiceDiscovery interface {
	Publish(service Service) (err error)
	IsLocal(namespace string) (ok bool)
	Proxy(ctx Context, namespace string) (proxy ServiceProxy, err errors.CodeError)
	Registrations() (registrations map[string]*Registration)
	Close()
}

type ServiceDiscoveryOption

type ServiceDiscoveryOption struct {
	Address     string
	HttpClients *HttpClients
	Config      configuares.Raw
}

type ServiceDiscoveryRetriever

type ServiceDiscoveryRetriever func(option ServiceDiscoveryOption) (discovery ServiceDiscovery, err error)

type ServiceDocument added in v0.6.26

type ServiceDocument struct {
	// Namespace
	// as tag
	Namespace string `json:"namespace,omitempty"`
	// Description
	// as description of tag, support markdown
	Description string `json:"description,omitempty"`
	// Fns
	// key: fn
	Fns map[string]*FnDocument `json:"fns,omitempty"`
}

func NewServiceDocument added in v0.8.4

func NewServiceDocument(namespace string, description string) *ServiceDocument

func (*ServiceDocument) AddFn added in v0.8.4

func (doc *ServiceDocument) AddFn(fn *FnDocument)

type ServiceMeta added in v0.9.0

type ServiceMeta map[string]interface{}

func NewServiceMeta added in v0.9.0

func NewServiceMeta() ServiceMeta

func (ServiceMeta) Get added in v0.9.0

func (meta ServiceMeta) Get(key string) (v interface{}, has bool)

func (ServiceMeta) Set added in v0.9.0

func (meta ServiceMeta) Set(key string, value interface{})

type ServiceMetaBuilder added in v0.9.0

type ServiceMetaBuilder func(config configuares.Config) (meta ServiceMeta, err error)

type ServiceOption added in v0.9.0

type ServiceOption struct {
	MetaBuilder ServiceMetaBuilder
}

type ServiceProxy

type ServiceProxy interface {
	Request(ctx Context, fn string, argument Argument) (result Result)
}

type ServicesConfig

type ServicesConfig struct {
	HandleTimeoutSecond int                  `json:"handleTimeoutSecond,omitempty"`
	MaxIdleTimeSecond   int                  `json:"maxIdleTimeSecond,omitempty"`
	ReduceMemoryUsage   bool                 `json:"reduceMemoryUsage,omitempty"`
	Discovery           DiscoveryConfig      `json:"discovery,omitempty"`
	Authorization       AuthorizationsConfig `json:"authorization,omitempty"`
	Permission          PermissionsConfig    `json:"permission,omitempty"`
	HttpClientPoolSize  int                  `json:"httpClientPoolSize,omitempty"`
}

type User

type User interface {
	Exists() (ok bool)
	Id() (id string)
	Principals() (principal *json.Object)
	Attributes() (attributes *json.Object)
	Authorization() (authorization []byte, has bool)
	SetAuthorization(authorization []byte)
	String() (value string)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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