dmetering

package module
v0.0.0-...-50d9add Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

README

dfuse Metering Library

reference License

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

Usage

See example usage in dgraphql.

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

  • null://

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 dfuse 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 EmitWithContext

func EmitWithContext(ev Event, ctx context.Context)

func EmitWithCredentials

func EmitWithCredentials(ev Event, creds authenticator.Credentials)

func GetStatusCounters

func GetStatusCounters() (total, errors uint64)

func NewMeteringMiddleware

func NewMeteringMiddleware(next http.Handler, metering Metering, source, kind string, trackRequestsAndResponses, trackIngressAndEgressBytes bool) http.Handler

func NewMeteringMiddlewareFunc

func NewMeteringMiddlewareFunc(metering Metering, source, kind string) func(http.Handler) http.Handler

func NewMeteringMiddlewareFuncWithOptions

func NewMeteringMiddlewareFuncWithOptions(metering Metering, source, kind string, trackRequestsAndResponses, trackIngressAndEgressBytes bool) func(http.Handler) http.Handler

func Register

func Register(name string, factory FactoryFunc)

func SetDefaultMeter

func SetDefaultMeter(m Metering)

func WaitToFlush

func WaitToFlush()

Types

type Event

type Event struct {
	Source            string `json:"source"`
	Kind              string `json:"kind"`
	Method            string `json:"method"`
	RequestsCount     int64  `json:"requests_count,omitempty"`
	ResponsesCount    int64  `json:"responses_count,omitempty"`
	IngressBytes      int64  `json:"ingress_bytes,omitempty"`
	EgressBytes       int64  `json:"egress_bytes,omitempty"`
	IdleTime          int64  `json:"idle_time,omitempty"`
	RateLimitHitCount int64  `json:"rate_limit_hit_count,omitempty"`
}

Event represents a metering event that needs to be recorded

type FactoryFunc

type FactoryFunc func(config string) (Metering, error)

type Metering

type Metering interface {
	EmitWithContext(ev Event, ctx context.Context)
	EmitWithCredentials(ev Event, creds authenticator.Credentials)
	GetStatusCounters() (total, errors uint64)
	WaitToFlush()
}

func New

func New(config string) (Metering, error)

type MeteringMiddleware

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

func (*MeteringMiddleware) ServeHTTP

func (m *MeteringMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request)

type MeteringResponseWriter

type MeteringResponseWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

func (*MeteringResponseWriter) Write

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

Jump to

Keyboard shortcuts

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