graphmetrics

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2021 License: Apache-2.0 Imports: 15 Imported by: 1

README

GraphMetrics

Go Reference Go Version Go Report

This is the Go SDK for GraphMetrics.

Usage

We provide middlewares that are easily to plug in your server. If your server is not currently supported, please open an issue so we can fix that.

gqlgen
import (
    "github.com/99designs/gqlgen/graphql/handler"
    "github.com/graphmetrics/graphmetrics-go"
    graphmetricsgqlgen "github.com/graphmetrics/graphmetrics-go/gqlgen"
)
var srv *handler.Server

gm := graphmetricsgqlgen.NewExtension(&graphmetrics.Configuration{ 
	// SEE CONFIGURATION SECTION
})
defer gm.Close() // Keep a reference to the extension and call Close on server shutdown

srv.Use(gm)

Configuration

The SDK needs a few elements to be properly configured using the graphmetrics.Configuration.

  • ApiKey: Your environment api key
  • ServerVersion: (Optional) The version of the server, necessary to catch regressions between releases
  • ClientExtractor: (Optional) Function that retrieves the client details from the context, necessary to differentiate queries coming from different clients
  • Logger: (Optional) A structure logger that respects the interface, otherwise golang "log" is used. Adapters are provided for popular logger, see the logger-go package.
Client extractor

The client extractor fetches the client details from the context. By default, no details are fetched. We provide helper functions for the Apollo client, please let us know if you would like to see other clients supported.

The first step of the extraction is to add the http middleware to your server. The exact way of doing that depends on your server implementation, but generally looks like:

import (
    "github.com/go-chi/chi"
    "github.com/graphmetrics/graphmetrics-go/client"
)

r := chi.NewRouter()

r.Use(client.ApolloMiddleware)

Then you can pass the extractor function in the configuration:

graphmetrics.Configuration{
    ClientExtractor: client.ApolloExtractor,
}
Advanced configuration
  • FieldBufferSize: As we do not want to slow down your queries, we process the field metrics async in a goroutine with a buffered channel in between. Usually this buffer is big enough to handle spikes, but it might not be if you have very large and fast queries. In which case, metrics are dropped and a warning is emitted. Please contact us if that happens and try increasing the buffer in the meantime.
  • OperationBufferSize: Same as FieldBufferSize but for operations.
  • StopTimeout: Change the maximum time the plugin will wait for sending the last metrics when the server is stopping. We suggest leaving it at default (10s) unless you need to kill your process faster.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AdvancedConfiguration

type AdvancedConfiguration struct {
	FieldBufferSize     int // If field metrics are dropped consider increasing it
	OperationBufferSize int // If operation metrics are dropped consider increasing it
	Endpoint            string
	Http                bool
	Debug               bool
	StopTimeout         time.Duration
}

type Aggregator

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

func NewAggregator

func NewAggregator(cfg *Configuration) *Aggregator

func (*Aggregator) PushField

func (a *Aggregator) PushField(msg *FieldMessage)

func (*Aggregator) PushOperation added in v0.3.0

func (a *Aggregator) PushOperation(msg *OperationMessage)

func (*Aggregator) Start

func (a *Aggregator) Start()

func (*Aggregator) Stop

func (a *Aggregator) Stop() error

type Configuration

type Configuration struct {
	ApiKey          string
	ServerVersion   string
	ClientExtractor client.Extractor
	Logger          logger.Logger
	Advanced        *AdvancedConfiguration
}

func (*Configuration) GetClientExtractor added in v0.3.0

func (c *Configuration) GetClientExtractor() client.Extractor

func (*Configuration) GetDebug added in v0.3.0

func (c *Configuration) GetDebug() bool

func (*Configuration) GetEndpoint added in v0.3.0

func (c *Configuration) GetEndpoint() string

func (*Configuration) GetFieldBufferSize added in v0.3.0

func (c *Configuration) GetFieldBufferSize() int

func (*Configuration) GetLogger added in v0.3.0

func (c *Configuration) GetLogger() logger.Logger

func (*Configuration) GetOperationBufferSize added in v0.3.0

func (c *Configuration) GetOperationBufferSize() int

func (*Configuration) GetProtocol added in v0.3.0

func (c *Configuration) GetProtocol() string

func (*Configuration) GetStopTimeout added in v0.3.0

func (c *Configuration) GetStopTimeout() time.Duration

type FieldMessage

type FieldMessage struct {
	TypeName   string
	FieldName  string
	ReturnType string
	Error      error
	Duration   time.Duration
	Client     client.Details
}

type OperationMessage added in v0.3.0

type OperationMessage struct {
	Name      string
	Type      string
	Hash      string
	Signature string
	HasErrors bool
	Duration  time.Duration
	Client    client.Details
}

type Sender

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

func NewSender

func NewSender(cfg *Configuration) *Sender

func (*Sender) SendDefinitions added in v0.3.0

func (s *Sender) SendDefinitions(definitions *models.UsageDefinitions)

func (*Sender) SendMetrics added in v0.3.0

func (s *Sender) SendMetrics(metrics *models.UsageMetrics)

func (*Sender) Stop

func (s *Sender) Stop() error

Directories

Path Synopsis
gqlgen module
internal

Jump to

Keyboard shortcuts

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