Add go doc to metricemitter client
@@ -8,6 +8,7 @@ import (
"google.golang.org/grpc"
)
+// Client is used to initialize and emit metrics on a given pulse interval.
type Client struct {
ingressClient v2.IngressClient
pulseInterval time.Duration
@@ -20,32 +21,44 @@ type sendable interface {
WithEnvelope(func(*v2.Envelope) error) error
}
+// ClientOption is a function that can be passed into the NewClient for
+// optional configuration on the client.
type ClientOption func(*Client)
+// WithGRPCDialOptions is a ClientOption that will set the gRPC dial options on
+// the Clients IngressClient.
func WithGRPCDialOptions(opts ...grpc.DialOption) ClientOption {
return func(c *Client) {
c.dialOpts = opts
}
}
+// WithPulseInterval is a ClientOption will set the rate at which each metric
+// will be sent to the IngressClient.
func WithPulseInterval(d time.Duration) ClientOption {
return func(c *Client) {
c.pulseInterval = d
}
}
+// WithSourceID is a ClientOption that will set the SourceID to be set on
+// every envelope sent to the IngressClient.
func WithSourceID(s string) ClientOption {
return func(c *Client) {
c.sourceID = s
}
}
+// WithOrigin is a ClientOption that will set an origin tag to be added
+// to every envelope sent to the IngressClient.
func WithOrigin(name string) ClientOption {
return func(c *Client) {
c.tags["origin"] = name
}
}
+// WithDeployment is a ClientOption that will set a deployment, job and index
+// tab on every envelope sent to the IngressClient.
func WithDeployment(deployment, job, index string) ClientOption {
return func(c *Client) {
c.tags["deployment"] = deployment
@@ -54,6 +67,8 @@ func WithDeployment(deployment, job, index string) ClientOption {
}
}
+// NewClient initializes a new Client and opens a gRPC connection to the given
+// address.
func NewClient(addr string, opts ...ClientOption) (*Client, error) {
client := &Client{
tags: make(map[string]string),
@@ -74,6 +89,10 @@ func NewClient(addr string, opts ...ClientOption) (*Client, error) {
return client, nil
}
+// NewCounter will return a new Counter metric that can be incremented. The
+// value of the counter will be sent to the Clients IngressClient at the
+// interval configured on the Client. When the counters value is sent to the
+// IngressClient the value is reset to 0.
func (c *Client) NewCounter(name string, opts ...MetricOption) *Counter {
opts = append(opts, WithTags(c.tags))
m := NewCounter(name, c.sourceID, opts...)
@@ -82,6 +101,9 @@ func (c *Client) NewCounter(name string, opts ...MetricOption) *Counter {
return m
}
+// NewGauge will return a new Gauge metric that has a value that can be set.
+// The value of the gauge will be sent to the Clients IngressClient at the
+// interval configured on the Client.
func (c *Client) NewGauge(name, unit string, opts ...MetricOption) *Gauge {
opts = append(opts, WithTags(c.tags))
m := NewGauge(name, unit, c.sourceID, opts...)
