dmetering

package module
v0.0.0-...-f4cae47 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: Apache-2.0 Imports: 11 Imported by: 31

README

StreamingFast Metering Library

reference License

This is the usage metering library used as part of StreamingFast.

Usage

See example usage in dgraphql.

The following plugins are provided by this package: (feel free to implement your own)

  • null://
  • logger://
  • grpc://

Contributing

Issues and PR in this repo related strictly to the dmetering library.

Report any protocol-specific issues in their respective repositories

Please first refer to the general StreamingFast contribution guide, if you wish to contribute to this code base.

License

Apache 2.0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Emit

func Emit(ctx context.Context, event Event)

func Register

func Register(name string, factory FactoryFunc)

func RegisterNull

func RegisterNull()

func SetDefaultEmitter

func SetDefaultEmitter(m EventEmitter)

func WithBytesMeter

func WithBytesMeter(ctx context.Context) context.Context

func WithCounter

func WithCounter(ctx context.Context, name string) context.Context

func WithExistingBytesMeter

func WithExistingBytesMeter(ctx context.Context, bm Meter) context.Context

Types

type Event

type Event struct {
	Endpoint string             `json:"endpoint"`
	Metrics  map[string]float64 `json:"metrics,omitempty"`

	UserID    string `json:"user_id"`
	ApiKeyID  string `json:"api_key_id"`
	IpAddress string `json:"ip_address"`

	Meta string `json:"meta"`

	Timestamp time.Time `json:"timestamp"`
}

func (Event) MarshalLogObject

func (ev Event) MarshalLogObject(enc zapcore.ObjectEncoder) error

func (Event) ToProto

func (ev Event) ToProto(network string) *pbmetering.Event

type EventEmitter

type EventEmitter interface {
	Shutdown(error)
	Emit(ctx context.Context, ev Event)
}

func GetDefaultEmitter

func GetDefaultEmitter() EventEmitter

func New

func New(config string, logger *zap.Logger) (EventEmitter, error)

type FactoryFunc

type FactoryFunc func(config string, logger *zap.Logger) (EventEmitter, error)

type Meter

type Meter interface {
	AddBytesWritten(n int)
	AddBytesRead(n int)

	AddBytesWrittenCtx(ctx context.Context, n int)
	AddBytesReadCtx(ctx context.Context, n int)

	BytesWritten() uint64
	BytesRead() uint64

	BytesWrittenDelta() uint64
	BytesReadDelta() uint64

	AddCounter(name string)
	CountInc(name string, n int)
	CountDec(name string, n int)
	GetCount(name string) int
	ResetCount(name string)
}
var NoopBytesMeter Meter = &noopMeter{}

func GetBytesMeter

func GetBytesMeter(ctx context.Context) Meter

func NewBytesMeter

func NewBytesMeter() Meter

type MeterLogData

type MeterLogData struct {
	Filename *string
	Store    *string
	TraceId  *string
	Mode     mode
	NBytes   int
}

func (*MeterLogData) MarshalLogObject

func (mld *MeterLogData) MarshalLogObject(enc zapcore.ObjectEncoder) error

Directories

Path Synopsis
pb

Jump to

Keyboard shortcuts

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