ocaero

package module
v0.0.0-...-29a80f1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2020 License: ISC Imports: 6 Imported by: 0

README

ocaero

OpenCensus Aerospike client wrapper for Go

Contexts

The contexts supplied to ocaero client calls are used to supply tags to Open Census measurements. Canceling a context will not cause the underlying aerospike calls to be cancelled.

Migration

To interact with this wrapper instead of the regular aerospike client, call ocaero.Wrap() and supply a context to client method calls.

var (
    ctx = context.Background()
    ocaeroClient = ocaero.Wrap(aeroClient, "my-aero")
    policy = as.NewQueryPolicy()
    statement = as.NewStatement("my-namespace", "my-set")
)

ocaeroClient.Query(ctx, policy, statement)

TODO

  • Add remaining Aerospike client functions
  • Add Open Census tracing

Documentation

Overview

Package ocaero supplies a wrapper for the aerospile go client to report metrics with OpenCensus

Example

This example shows how to use ocaero.Wrapper and register views with OpenCensus

var (
	aeroClient    *aerospike.Client // TODO actually make the client connection
	ocAeroWrapper = ocaero.Wrap(aeroClient, "my-aero")
)

ocaero.RegisterAllViews()

data, err := getData(context.Background(), ocAeroWrapper)

if err != nil {
	log.Printf("Unable to query: %s", err.Error())
	return
}

log.Println("Got data:", data)

data = data + " updated"

err = setData(context.Background(), ocAeroWrapper)

if err != nil {
	log.Printf("Unable to update data: %s", err.Error())
	return
}

log.Println("Updated data")
Output:

Example (CustomTags)

This example shows how to add custom tags to existing ocaero views

var (
	aeroClient    *aerospike.Client // TODO actually make the client connection
	ocAeroWrapper = ocaero.Wrap(aeroClient, "my-aero")
)

// appVersionTag is a tag represening the current version of the application
appVersionTag, _ := tag.NewKey("app_version")

// add the tag to the views
ocaero.GoAerospikeLatencyView.TagKeys = append(
	ocaero.GoAerospikeLatencyView.TagKeys,
	appVersionTag,
)

ocaero.GoAerospikeCallsView.TagKeys = append(
	ocaero.GoAerospikeCallsView.TagKeys,
	appVersionTag,
)

// adding the tag to the application context will make the tag/value
// available to any view its been added to
ctx, _ := tag.New(context.Background(), tag.Insert(
	appVersionTag,
	"v1.0.0",
))

ocaero.RegisterAllViews()

data, err := getData(ctx, ocAeroWrapper)

if err != nil {
	log.Printf("Unable to query: %s", err.Error())
	return
}

log.Println("Got data:", data)

data = data + " updated"

err = setData(context.Background(), ocAeroWrapper)

if err != nil {
	log.Printf("Unable to update data: %s", err.Error())
	return
}

log.Println("Updated data")
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// GoAeroInstanceName is the name of the aerospike instance.
	GoAeroInstanceName, _ = tag.NewKey("go_aerospike_instance_name")

	// GoAeroMethod is the client method called.
	GoAeroMethod = tag.MustNewKey("go_aerospike_method")

	// GoAeroStatus identifies the command status
	GoAeroStatus = tag.MustNewKey("go_aerospike_status")

	DefaultTags = []tag.Key{
		GoAeroMethod,
		GoAeroStatus,
	}
)

The following tags are applied to stats recorded by this package

View Source
var (
	GoAerospikeLatencyView = &view.View{
		Name:        "go.aerospike/client/latency",
		Description: "The distribution of latency of various calls in milliseconds",
		Measure:     MeasureLatencyMs,
		Aggregation: DefaultMillisecondsDistribution,
		TagKeys:     DefaultTags,
	}

	GoAerospikeCallsView = &view.View{
		Name:        "go.aerospike/client/calls",
		Description: "The number of various calls of methods",
		Measure:     MeasureLatencyMs,
		Aggregation: view.Count(),
		TagKeys:     DefaultTags,
	}

	DefaultViews = []*view.View{GoAerospikeLatencyView, GoAerospikeCallsView}
)

Package ocaero provides some convenience views. You still need to register these views for data to actually be collected. You can use the RegisterAllViews function for this.

View Source
var (
	DefaultMillisecondsDistribution = view.Distribution(
		0.0,
		0.001,
		0.005,
		0.01,
		0.05,
		0.1,
		0.5,
		1.0,
		1.5,
		2.0,
		2.5,
		5.0,
		10.0,
		25.0,
		50.0,
		100.0,
		200.0,
		400.0,
		600.0,
		800.0,
		1000.0,
		1500.0,
		2000.0,
		2500.0,
		5000.0,
		10000.0,
		20000.0,
		40000.0,
		100000.0,
		200000.0,
		500000.0,
	)
)

Default distributions used by views in this package

View Source
var (
	MeasureLatencyMs = stats.Int64("go.aerospike/latency", "The latency of calls in milliseconds", stats.UnitMilliseconds)
)

The following measures are supported for use in custom views.

Functions

func RegisterAllViews

func RegisterAllViews() error

RegisterAllViews registers all the views to enable collection of stats

Types

type Client

type Client interface {
	Querier
	PutBinser
}

Client defines all the available Aerospike interactions

type PutBinser

type PutBinser interface {
	PutBins(ctx context.Context, policy *as.WritePolicy, key *as.Key, bins ...*as.Bin) error
}

PutBinser allows a caller to set bins in Aerospike

type Querier

type Querier interface {
	Query(ctx context.Context, policy *as.QueryPolicy, stmt *as.Statement) (*as.Recordset, error)
}

Querier allows a caller to perform an Aerospike query

type Wrapper

type Wrapper struct {
	*as.Client
	// contains filtered or unexported fields
}

Wrapper reports method call latency with OpenCensus

Contexts

Contexts are supplied Wrapper methods but aren't supported by the underlying Aerospike client. Instead they are supplied to the OpenCensus metrics.

func Wrap

func Wrap(aeroClient *as.Client, instanceName string) *Wrapper

Wrap uses an Aerospike Client to make a Wrapper

func (*Wrapper) PutBins

func (wrapper *Wrapper) PutBins(ctx context.Context, policy *as.WritePolicy, key *as.Key, bins ...*as.Bin) (err error)

PutBins routes requests to the aerospike client and reports latency to OpenCensus metrics

func (*Wrapper) Query

func (wrapper *Wrapper) Query(ctx context.Context, policy *as.QueryPolicy, stmt *as.Statement) (recordSet *as.Recordset, err error)

Query routes requests to the aerospike client and reports latency to OpenCensus metrics

Jump to

Keyboard shortcuts

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