goapm

package module
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: MIT Imports: 22 Imported by: 3

README

goapm

Go Report Card codecov CI GitHub release (latest SemVer) Go Reference

goapm is a toolkit for monitoring and observability of golang applications. It provides a set of libraries that are wrapped around opentelemetry.

Example

Features

  • Components support opentelemetry
    • sql.DB
    • gorm.DB
    • RedisV6
    • RedisV9
    • HTTP
    • Gin
    • GRPC Server
    • GRPC Client
  • Metrics
  • AutoPProf
  • APM
  • RotateLog

Architecture

architecture

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Infra

type Infra struct {
	// Name is the business name of the infra.
	Name string
	// Tracer is the tracer for the infra,
	Tracer trace.Tracer
	// contains filtered or unexported fields
}

Infra is an infrastructure manager for goapm. It is recommended to create a single instance of Infra and share it across the application. TODO: add a print function to print the infra's components and closers.

func NewInfra

func NewInfra(name string, opts ...InfraOption) *Infra

NewInfra creates a new infra with the given options.

func (*Infra) Defer added in v0.0.20

func (infra *Infra) Defer(fn func())

Defer appends a defer function to the infra.

func (*Infra) FullName added in v0.0.14

func (infra *Infra) FullName() string

FullName returns the full name of the infra, it is the combination of the infra name and the hostname.

func (*Infra) Gorm

func (infra *Infra) Gorm(name string) *gorm.DB

Gorm returns the gorm db client with the given name.

func (*Infra) Hostname added in v0.0.17

func (infra *Infra) Hostname() string

Hostname returns the hostname of the machine running the application.

func (*Infra) MySQL

func (infra *Infra) MySQL(name string) *sql.DB

MySQL returns the mysql db client with the given name.

func (*Infra) NewGRPCServer added in v0.0.7

func (infra *Infra) NewGRPCServer(addr string) *apm.GrpcServer

NewGRPCServer creates a new grpc server with the given address. If the tableflip is created, the server will listen on the address with the tableflip.

func (*Infra) NewGin added in v0.0.7

func (infra *Infra) NewGin(metricsAuth gin.HandlerFunc, opts ...gin.OptionFunc) *gin.Engine

NewGin creates a new gin engine with otel tracing and metrics. It will automatically add the otel tracing and metrics middleware to the engine. If metricsAuth is not nil, it will add a metrics handler with the given auth middleware.

func (*Infra) NewHTTPServer added in v0.0.7

func (infra *Infra) NewHTTPServer(addr string) *apm.HTTPServer

NewHTTPServer creates a new http server with the given address. If the tableflip is created, the server will listen on the address with the tableflip. Otherwise, it will listen on the address directly.

func (*Infra) PrependDefer added in v0.0.20

func (infra *Infra) PrependDefer(fn func())

PrependDefer prepends a defer function to the infra.

func (*Infra) RangeGormDB added in v0.0.15

func (infra *Infra) RangeGormDB(fn func(name string, db *gorm.DB))

RangeGormDB ranges the gorm.DB of the infra.

func (*Infra) RangeRedisV6 added in v0.0.15

func (infra *Infra) RangeRedisV6(fn func(name string, client *apm.RedisV6))

RangeRedisV6 ranges the redis v6 client of the infra.

func (*Infra) RangeRedisV9 added in v0.0.15

func (infra *Infra) RangeRedisV9(fn func(name string, client *redis.Client))

RangeRedisV9 ranges the redis v9 client of the infra.

func (*Infra) RangeSqlDB added in v0.0.15

func (infra *Infra) RangeSqlDB(fn func(name string, db *sql.DB))

RangeSqlDB ranges the sql.DB of the infra.

func (*Infra) RedisV6

func (infra *Infra) RedisV6(name string) *apm.RedisV6

RedisV6 returns the redis v6 client with the given name.

func (*Infra) RedisV9

func (infra *Infra) RedisV9(name string) *redis.Client

RedisV9 returns the redis v9 client with the given name.

func (*Infra) Stop

func (infra *Infra) Stop()

Stop stops the infra.

func (*Infra) Tableflip added in v0.0.7

func (infra *Infra) Tableflip() *tableflip.Upgrader

Tableflip returns the tableflip of the infra.

func (*Infra) WaitToStop added in v0.0.11

func (infra *Infra) WaitToStop()

WaitToStop waits for the infra to stop. It should be called in front of the infra.Stop().

type InfraOption

type InfraOption func(*Infra)

InfraOption is the option for Infra.

func WithAPM

func WithAPM(otelEndpoint string, opts ...apm.ApmOption) InfraOption

WithAPM creates a new apm and adds it to the infra.

func WithAutoPProf

func WithAutoPProf(autoPProfOpts *apm.AutoPProfOpt, opts ...holmes.Option) InfraOption

WithAutoPProf starts a holmes dumper to automatically record the running state of the program.

func WithCloser added in v0.0.7

func WithCloser(fn func()) InfraOption

WithCloser adds a closer to the infra.

func WithGorm

func WithGorm(name, addr string) InfraOption

WithGorm creates a new gorm db and adds it to the infra. name is the business name of the db, and addr is the address of the db.

func WithMetrics

func WithMetrics(collectors ...prometheus.Collector) InfraOption

WithMetrics registers the given collectors to the goapm metrics registry. It default provides some collectors defined in goapm/metric.go.

func WithMySQL

func WithMySQL(name, addr string) InfraOption

WithMySQL creates a new mysql db and adds it to the infra. name is the business name of the db, and addr is the address of the db.

func WithRedisV6

func WithRedisV6(name string, opts *redisv6.Options) InfraOption

WithRedisV6 creates a new redis v6 client and adds it to the infra. name is the business name of the redis, and opts is the options of the redis. nolint:dupl

func WithRedisV9

func WithRedisV9(name string, opts *redis.Options) InfraOption

WithRedisV9 creates a new redis v9 client and adds it to the infra. name is the business name of the redis, and opts is the options of the redis. nolint:dupl

func WithRotateLog

func WithRotateLog(path string, opts ...rotatelogs.Option) InfraOption

WithRotateLog creates a new rotate log and sets it to the logrus. It default rotates every 7 days and keeps 7 days' logs.

func WithTableflip added in v0.0.7

func WithTableflip(opts tableflip.Options, sigs ...os.Signal) InfraOption

WithTableflip creates a new tableflip and adds it to the infra. The tableflip is used to support graceful restart. If the tableflip is created, the infra will listen the ports with it for http and rpc servers. NOTE: we recommend that this should be the first option to be called.

Directories

Path Synopsis
examples
protos Module

Jump to

Keyboard shortcuts

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