consul

package
v1.26.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2020 License: Apache-2.0, BSD-3-Clause, Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Example

Here's an example illustrating a simple use case for interacting with consul with tracing enabled.

// Get a new Consul client
client, err := NewClient(consul.DefaultConfig(), WithServiceName("consul.example"))
if err != nil {
	log.Fatal(err)
}

// Optionally, create a new root span
root, ctx := tracer.StartSpanFromContext(context.Background(), "root_span",
	tracer.SpanType(ext.SpanTypeConsul),
	tracer.ServiceName("example"),
)
defer root.Finish()
client = client.WithContext(ctx)

// Get a handle to the KV API
kv := client.KV()

// PUT a new KV pair
p := &consul.KVPair{Key: "test", Value: []byte("1000")}
_, err = kv.Put(p, nil)
if err != nil {
	log.Fatal(err)
}

// Lookup the pair
pair, _, err := kv.Get("test", nil)
if err != nil {
	log.Fatal(err)
}
fmt.Printf("%v: %s\n", pair.Key, pair.Value)
Output:

test: 1000

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client wraps the regular *consul.Client and augments it with tracing. Use NewClient to initialize it.

func NewClient

func NewClient(config *consul.Config, opts ...ClientOption) (*Client, error)

NewClient returns a traced Consul client.

func WrapClient

func WrapClient(c *consul.Client, opts ...ClientOption) *Client

WrapClient wraps a given consul.Client with a tracer under the given service name.

func (*Client) KV

func (c *Client) KV() *KV

KV returns the KV for the Client.

func (*Client) WithContext

func (c *Client) WithContext(ctx context.Context) *Client

WithContext sets a context on a Client. Use it to ensure that emitted spans have the correct parent.

type ClientOption

type ClientOption func(*clientConfig)

ClientOption represents an option that can be used to create or wrap a client.

func WithAnalytics

func WithAnalytics(on bool) ClientOption

WithAnalytics enables Trace Analytics for all started spans.

func WithAnalyticsRate

func WithAnalyticsRate(rate float64) ClientOption

WithAnalyticsRate sets the sampling rate for Trace Analytics events correlated to started spans.

func WithServiceName

func WithServiceName(name string) ClientOption

WithServiceName sets the given service name for the client.

type KV

type KV struct {
	*consul.KV
	// contains filtered or unexported fields
}

A KV is used to trace requests to Consul's KV.

func (*KV) Acquire

func (k *KV) Acquire(p *consul.KVPair, q *consul.WriteOptions) (bool, *consul.WriteMeta, error)

Acquire is used for a lock acquisition operation. The Key, Flags, Value and Session are respected. Returns true on success or false on failures.

func (*KV) CAS

CAS is used for a Check-And-Set operation. The Key, ModifyIndex, Flags and Value are respected. Returns true on success or false on failures.

func (*KV) Delete

func (k *KV) Delete(key string, w *consul.WriteOptions) (*consul.WriteMeta, error)

Delete is used to delete a single key.

func (*KV) DeleteCAS

func (k *KV) DeleteCAS(p *consul.KVPair, q *consul.WriteOptions) (bool, *consul.WriteMeta, error)

DeleteCAS is used for a Delete Check-And-Set operation. The Key and ModifyIndex are respected. Returns true on success or false on failures.

func (*KV) DeleteTree

func (k *KV) DeleteTree(prefix string, w *consul.WriteOptions) (*consul.WriteMeta, error)

DeleteTree is used to delete all keys under a prefix.

func (*KV) Get

func (k *KV) Get(key string, q *consul.QueryOptions) (*consul.KVPair, *consul.QueryMeta, error)

Get is used to lookup a single key. The returned pointer to the KVPair will be nil if the key does not exist.

func (*KV) Keys

func (k *KV) Keys(prefix, separator string, q *consul.QueryOptions) ([]string, *consul.QueryMeta, error)

Keys is used to list all the keys under a prefix. Optionally, a separator can be used to limit the responses.

func (*KV) List

func (k *KV) List(prefix string, q *consul.QueryOptions) ([]*consul.KVPair, *consul.QueryMeta, error)

List is used to lookup all keys under a prefix.

func (*KV) Put

func (k *KV) Put(p *consul.KVPair, q *consul.WriteOptions) (*consul.WriteMeta, error)

Put is used to write a new value. Only the Key, Flags and Value is respected.

func (*KV) Release

func (k *KV) Release(p *consul.KVPair, q *consul.WriteOptions) (bool, *consul.WriteMeta, error)

Release is used for a lock release operation. The Key, Flags, Value and Session are respected. Returns true on success or false on failures.

Jump to

Keyboard shortcuts

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