dionysus

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: MIT Imports: 9 Imported by: 0

README

dionysus

codecov GitHub issues license

概要

dionysus是一个集成实现了gin, ctl和grpc等服务等golang项目集。 基于cobra cmd实现,管理维护了gin, ctl和grpc等子cmd的生命周期。 并将默认加载log, config, trace和metrics等实现,方便服务管控。 并将提供orm, redis和grpool等一些工具包的封装方便使用。


dionysus执行流程说明

dionysuslife dionysus执行流程如上图所示,有颜色的是用户可定义的行为,相应的颜色是对于的定义阶段和执行阶段。空白颜色的是框架定义的行为,不可更改。
其中只有绿色的run是用户必须定义的,其它颜色的项目用户根据需求使用。
cmd的执行顺序为SysPreRun-->UserPreRun-->Run-->UserPostRun-->SysPostRun

1: dionysus初始化阶段

1.1: 首先创建相应的子cmd(gin,ctl和grpc), 定义子cmd的run执行逻辑和shutdown关闭逻辑

1.2: 创建dionysus框架,注册用户侧的PreRun(在cmd的run之前执行)和PostRun(在cmd的shutdown之后执行)
注册用户自定义的health Checkers。

1.3: 将子cmd注册进dionysus框架中,注册dionysus的PreRun和PostRun函数及注册相应类型的健康检查cmd

2: dionysus执行流程

2.1: 执行框架注册的PreRun函数

2.2: 执行用户注册的PreRunE函数,(比如连接数据库等服务依赖项的初始化内容)

2.3: 执行 Run , 协程执行Run函数并开始相应健康检查服务状态

2.4: 等待 Run 执行完成或系统停止的signal

3: dionysus停止流程

3.1: 停止流程有两种情况,一种是Run执行完毕exit了,还有一种是接收到了(SIGINT, SIGTERM, SIGQUIT)停止信号
如果接收到了停止信号,那么将会执行相应的shutdownFunc,如果是Run自己exit则不执行shutdownFunc

3.2: 执行用户注册的PostRun函数,可以执行服务停止后等清理工作

3.3: 执行框架注册的PostRun函数


gin cmd demo说明
demo参考gin cmd demo

ctl cmd demo说明
demo参考ctl cmd demo

健康检查实现

健康检查分为三种
1: startup, 该健康检查主要定义何时开始健康检查
2: liveness, 控制pod实例的存活,检查失败,则pod重启
3: readiness, 控制pod实例的流量导入,检查失败,pod流量不在进入
healthcheck健康检查如上所示,框架提供了checker hook和状态开关。
用户可以调用RegXXXCheckers注册相应的检查项,如检查依赖数据库的状态和依赖的上游服务的状态,
来确认服务的健康状态。而状态开关status可以用户手动开关控制。当checker hook和状态开关开启时
健康检查才能通过。

当前三种类型的cmd的会默认加载对应的health cmd, 健康检查统一执行exec命令:

startup: {$binary} startup
liveness: {$binary} liveness
readiness: {$binary} readiness
gin health

如图所示在gin cmd中默认创建了/healthx group路由。
在该/healthx路由组下分别注册了/startup,/liveness,/readiness三个路由。
健康检查会定时访问这些路由,判断服务健康状态。
在gin中还自定义了健康检查开关,比如通过访问/readiness/close路由
HEALTH_STATUS=close {$binary} readiness控制健康检查状态开关。
当服务故障时,可手动实现服务流量隔离。

ctl health

会默认在ctl的启动go协程定时往一个默认文件写时间戳,健康检查会去定期检查这个时间戳是否正常。
因为ctl没有流量的概念,所以它的checker hook只有liveness这种模式。

grpc health

grpc会在grpc server默认注册健康路由,来提供健康检查。通过发生对应的健康检查grpc请求来
确认服务的健康状态。可以通过HEALTH_STATUS=close {$binary} readiness等命令控制健康检查状态开关。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Start deprecated

func Start(project string, cmds ...cmd.Commander)

Deprecated:: Use DioStart

Types

type CobraRun

type CobraRun func(cmd *cobra.Command, args []string) error

type Dio

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

func NewDio

func NewDio() *Dio

func (*Dio) DioStart

func (d *Dio) DioStart(projectName string, cmds ...cmd.Commander) error

DioStart be care cmds should not use PersistentXXXRunX,this is use by Dio root cmd

lifecycle:
			PersistentPreRun
			PreRun
			Run
			PostRun
			PersistentPostRun

func (*Dio) PostRunStepsAppend

func (d *Dio) PostRunStepsAppend(instanceSteps ...step.InstanceStep) error

PostRunStepsAppend append step will exec after step with priority which define by func PostRunRegWithPriority

func (*Dio) PreRunStepsAppend

func (d *Dio) PreRunStepsAppend(instanceSteps ...step.InstanceStep) error

PreRunStepsAppend append step will exec after step with priority which define by func PreRunRegWithPriority

func (*Dio) RegUserEighthPostRunStep

func (d *Dio) RegUserEighthPostRunStep(instanceStep step.InstanceStep) error

func (*Dio) RegUserEighthPreRunStep

func (d *Dio) RegUserEighthPreRunStep(instanceStep step.InstanceStep) error

func (*Dio) RegUserFifthPostRunStep

func (d *Dio) RegUserFifthPostRunStep(instanceStep step.InstanceStep) error

func (*Dio) RegUserFifthPreRunStep

func (d *Dio) RegUserFifthPreRunStep(instanceStep step.InstanceStep) error

func (*Dio) RegUserFirstPostRunStep

func (d *Dio) RegUserFirstPostRunStep(instanceStep step.InstanceStep) error

func (*Dio) RegUserFirstPreRunStep

func (d *Dio) RegUserFirstPreRunStep(instanceStep step.InstanceStep) error

func (*Dio) RegUserFourthPostRunStep

func (d *Dio) RegUserFourthPostRunStep(instanceStep step.InstanceStep) error

func (*Dio) RegUserFourthPreRunStep

func (d *Dio) RegUserFourthPreRunStep(instanceStep step.InstanceStep) error

func (*Dio) RegUserNinethPostRunStep

func (d *Dio) RegUserNinethPostRunStep(instanceStep step.InstanceStep) error

func (*Dio) RegUserNinethPreRunStep

func (d *Dio) RegUserNinethPreRunStep(instanceStep step.InstanceStep) error

func (*Dio) RegUserSecondPostRunStep

func (d *Dio) RegUserSecondPostRunStep(instanceStep step.InstanceStep) error

func (*Dio) RegUserSecondPreRunStep

func (d *Dio) RegUserSecondPreRunStep(instanceStep step.InstanceStep) error

func (*Dio) RegUserSeventhPostRunStep

func (d *Dio) RegUserSeventhPostRunStep(instanceStep step.InstanceStep) error

func (*Dio) RegUserSeventhPreRunStep

func (d *Dio) RegUserSeventhPreRunStep(instanceStep step.InstanceStep) error

func (*Dio) RegUserSixthPostRunStep

func (d *Dio) RegUserSixthPostRunStep(instanceStep step.InstanceStep) error

func (*Dio) RegUserSixthPreRunStep

func (d *Dio) RegUserSixthPreRunStep(instanceStep step.InstanceStep) error

func (*Dio) RegUserTenthPostRunStep

func (d *Dio) RegUserTenthPostRunStep(instanceStep step.InstanceStep) error

func (*Dio) RegUserTenthPreRunStep

func (d *Dio) RegUserTenthPreRunStep(instanceStep step.InstanceStep) error

func (*Dio) RegUserThirdPostRunStep

func (d *Dio) RegUserThirdPostRunStep(instanceStep step.InstanceStep) error

func (*Dio) RegUserThirdPreRunStep

func (d *Dio) RegUserThirdPreRunStep(instanceStep step.InstanceStep) error

Directories

Path Synopsis
Package errors provides a way to return detailed information for an RPC request error.
Package errors provides a way to return detailed information for an RPC request error.
example
ctl
gen
log
registry
Package registry is an interface for service discovery
Package registry is an interface for service discovery
registry/etcdv3
copy from go-plugins/registry/etcdv3 Package etcdv3 provides an etcd version 3 registry
copy from go-plugins/registry/etcdv3 Package etcdv3 provides an etcd version 3 registry
log
writer/rotate/file-rotatelogs
package rotatelogs is a port of File-RotateLogs from Perl (https://metacpan.org/release/File-RotateLogs), and it allows you to automatically rotate output files when you write to them according to the filename pattern that you can specify.
package rotatelogs is a port of File-RotateLogs from Perl (https://metacpan.org/release/File-RotateLogs), and it allows you to automatically rotate output files when you write to them according to the filename pattern that you can specify.

Jump to

Keyboard shortcuts

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