go-loggregator: code.cloudfoundry.org/go-loggregator Index | Files | Directories

package loggregator

import "code.cloudfoundry.org/go-loggregator"

Package loggregator provides clients to send data to the Loggregator v1 and v2 API.

The v2 API distinguishes itself from the v1 API on three counts:

1) it uses gRPC, 2) it uses a streaming connection, and 3) it supports batching to improve performance.

The code here provides a generic interface into the two APIs. Clients who prefer more fine grained control may generate their own code using the protobuf and gRPC service definitions found at: github.com/cloudfoundry/loggregator-api.

Note that on account of the client using batching wherein multiple messages may be sent at once, there is no meaningful error return value available. Each of the methods below make a best-effort at message delivery. Even in the event of a failed send, the client will not block callers.

In general, use IngressClient for communicating with Loggregator's v2 API. For Loggregator's v1 API, see v1/client.go.

Index

Package Files

doc.go envelope_stream_connector.go ingress_client.go one_to_one_envelope_batch_diode.go rlp_gateway_client.go tls.go

func NewEgressTLSConfig Uses

func NewEgressTLSConfig(caPath, certPath, keyPath string) (*tls.Config, error)

NewEgressTLSConfig provides a convenient means for creating a *tls.Config which uses the CA, cert, and key for the egress endpoint.

func NewIngressTLSConfig Uses

func NewIngressTLSConfig(caPath, certPath, keyPath string) (*tls.Config, error)

NewIngressTLSConfig provides a convenient means for creating a *tls.Config which uses the CA, cert, and key for the ingress endpoint.

func WithEnvelopeTag Uses

func WithEnvelopeTag(name, value string) func(proto.Message)

WithEnvelopeTag adds a tag to the envelope.

func WithEnvelopeTags Uses

func WithEnvelopeTags(tags map[string]string) func(proto.Message)

WithEnvelopeTags adds tag information that can be text, integer, or decimal to the envelope. WithEnvelopeTags expects a single call with a complete map and will overwrite if called a second time.

type Doer Uses

type Doer interface {
    // Do is a implementation of the http.Client's Do method.
    Do(*http.Request) (*http.Response, error)
}

Doer is used to make HTTP requests to the RLP Gateway.

type EmitCounterOption Uses

type EmitCounterOption func(proto.Message)

EmitCounterOption is the option type passed into EmitCounter.

func WithCounterAppInfo Uses

func WithCounterAppInfo(appID string, index int) EmitCounterOption

WithCounterAppInfo configures an envelope with both the app ID and index. Exists for backward compatability. If possible, use WithCounterSourceInfo instead.

func WithCounterSourceInfo Uses

func WithCounterSourceInfo(sourceID, instanceID string) EmitCounterOption

WithCounterSourceInfo configures an envelope with both the app ID and source ID.

func WithDelta Uses

func WithDelta(d uint64) EmitCounterOption

WithDelta is an option that sets the delta for a counter.

func WithTotal Uses

func WithTotal(t uint64) EmitCounterOption

WithTotal is an option that sets the total for a counter.

type EmitEventOption Uses

type EmitEventOption func(proto.Message)

EmitEventOption is the option type passed into EmitEvent.

func WithEventSourceInfo Uses

func WithEventSourceInfo(sourceID, instanceID string) EmitEventOption

WithEventSourceInfo configures an envelope with both the source and instance IDs.

type EmitGaugeOption Uses

type EmitGaugeOption func(proto.Message)

EmitGaugeOption is the option type passed into EmitGauge.

func WithGaugeAppInfo Uses

func WithGaugeAppInfo(appID string, index int) EmitGaugeOption

WithGaugeAppInfo configures an envelope with both the app ID and index. Exists for backward compatability. If possible, use WithGaugeSourceInfo instead.

func WithGaugeSourceInfo Uses

func WithGaugeSourceInfo(sourceID, instanceID string) EmitGaugeOption

WithGaugeSourceInfo configures an envelope with both the source ID and instance ID.

func WithGaugeValue Uses

func WithGaugeValue(name string, value float64, unit string) EmitGaugeOption

WithGaugeValue adds a gauge information. For example, to send information about current CPU usage, one might use:

WithGaugeValue("cpu", 3.0, "percent")

An number of calls to WithGaugeValue may be passed into EmitGauge. If there are duplicate names in any of the options, i.e., "cpu" and "cpu", then the last EmitGaugeOption will take precedence.

type EmitLogOption Uses

type EmitLogOption func(proto.Message)

EmitLogOption is the option type passed into EmitLog

func WithAppInfo Uses

func WithAppInfo(appID, sourceType, sourceInstance string) EmitLogOption

WithAppInfo configures the meta data associated with emitted data. Exists for backward compatability. If possible, use WithSourceInfo instead.

func WithSourceInfo Uses

func WithSourceInfo(sourceID, sourceType, sourceInstance string) EmitLogOption

WithSourceInfo configures the meta data associated with emitted data

func WithStdout Uses

func WithStdout() EmitLogOption

WithStdout sets the output type to stdout. Without using this option, all data is assumed to be stderr output.

type EmitTimerOption Uses

type EmitTimerOption func(proto.Message)

EmitTimerOption is the option type passed into EmitTimer.

func WithTimerSourceInfo Uses

func WithTimerSourceInfo(sourceID, instanceID string) EmitTimerOption

WithTimerSourceInfo configures an envelope with both the source and instance IDs.

type EnvelopeStream Uses

type EnvelopeStream func() []*loggregator_v2.Envelope

EnvelopeStream returns batches of envelopes. It blocks until its context is done or a batch of envelopes is available.

type EnvelopeStreamConnector Uses

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

EnvelopeStreamConnector provides a way to connect to loggregator and consume a stream of envelopes. It handles reconnecting and provides a stream for the lifecycle of the given context. It should be created with the NewEnvelopeStreamConnector constructor.

func NewEnvelopeStreamConnector Uses

func NewEnvelopeStreamConnector(
    addr string,
    t *tls.Config,
    opts ...EnvelopeStreamOption,
) *EnvelopeStreamConnector

NewEnvelopeStreamConnector creates a new EnvelopeStreamConnector. Its TLS configuration must share a CA with the loggregator server.

func (*EnvelopeStreamConnector) Stream Uses

func (c *EnvelopeStreamConnector) Stream(ctx context.Context, req *loggregator_v2.EgressBatchRequest) EnvelopeStream

Stream returns a new EnvelopeStream for the given context and request. The lifecycle of the EnvelopeStream is managed by the given context. If the underlying gRPC stream dies, it attempts to reconnect until the context is done.

type EnvelopeStreamOption Uses

type EnvelopeStreamOption func(*EnvelopeStreamConnector)

EnvelopeStreamOption configures a EnvelopeStreamConnector.

func WithEnvelopeStreamBuffer Uses

func WithEnvelopeStreamBuffer(size int, alerter func(missed int)) EnvelopeStreamOption

WithEnvelopeStreamBuffer enables the EnvelopeStream to read more quickly from the stream. It puts each envelope in a buffer that overwrites data if it is not being drained quick enough. If the buffer drops data, the 'alerter' function will be invoked with the number of envelopes dropped.

func WithEnvelopeStreamConnectorDialOptions Uses

func WithEnvelopeStreamConnectorDialOptions(opts ...grpc.DialOption) EnvelopeStreamOption

WithEnvelopeStreamConnectorDialOptions allows for configuration of grpc dial options.

func WithEnvelopeStreamLogger Uses

func WithEnvelopeStreamLogger(l Logger) EnvelopeStreamOption

WithEnvelopeStreamLogger allows for the configuration of a logger. By default, the logger is disabled.

type IngressClient Uses

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

IngressClient represents an emitter into loggregator. It should be created with the NewIngressClient constructor.

func NewIngressClient Uses

func NewIngressClient(tlsConfig *tls.Config, opts ...IngressOption) (*IngressClient, error)

NewIngressClient creates a v2 loggregator client. Its TLS configuration must share a CA with the loggregator server.

func (*IngressClient) CloseSend Uses

func (c *IngressClient) CloseSend() error

CloseSend will flush the envelope buffers and close the stream to the ingress server. This method will block until the buffers are flushed.

func (*IngressClient) Emit Uses

func (c *IngressClient) Emit(e *loggregator_v2.Envelope)

Emit sends an envelope. It will sent within a batch.

func (*IngressClient) EmitCounter Uses

func (c *IngressClient) EmitCounter(name string, opts ...EmitCounterOption)

EmitCounter sends a counter envelope with a delta of 1.

func (*IngressClient) EmitEvent Uses

func (c *IngressClient) EmitEvent(ctx context.Context, title, body string, opts ...EmitEventOption) error

EmitEvent sends an Event envelope.

func (*IngressClient) EmitGauge Uses

func (c *IngressClient) EmitGauge(opts ...EmitGaugeOption)

EmitGauge sends the configured gauge values to loggregator. If no EmitGaugeOption values are present, the client will emit an empty gauge.

func (*IngressClient) EmitLog Uses

func (c *IngressClient) EmitLog(message string, opts ...EmitLogOption)

EmitLog sends a message to loggregator.

func (*IngressClient) EmitTimer Uses

func (c *IngressClient) EmitTimer(name string, start, stop time.Time, opts ...EmitTimerOption)

EmitTimer sends a timer envelope with the given name, start time and stop time.

type IngressOption Uses

type IngressOption func(*IngressClient)

IngressOption is the type of a configurable client option.

func WithAddr Uses

func WithAddr(addr string) IngressOption

WithAddr allows for the configuration of the loggregator v2 address. The value to defaults to localhost:3458, which happens to be the default address in the loggregator server.

func WithBatchFlushInterval Uses

func WithBatchFlushInterval(d time.Duration) IngressOption

WithBatchFlushInterval allows for the configuration of the maximum time to wait before sending a batch of messages. Note that the batch interval may be triggered prior to the batch reaching the configured maximum size.

func WithBatchMaxSize Uses

func WithBatchMaxSize(maxSize uint) IngressOption

WithBatchMaxSize allows for the configuration of the number of messages to collect before emitting them into loggregator. By default, its value is 100 messages.

Note that aside from batch size, messages will be flushed from the client into loggregator at a fixed interval to ensure messages are not held for an undue amount of time before being sent. In other words, even if the client has not yet achieved the maximum batch size, the batch interval may trigger the messages to be sent.

func WithContext Uses

func WithContext(ctx context.Context) IngressOption

WithContext configures the context that manages the lifecycle for the gRPC connection. It defaults to a context.Background().

func WithDialOptions Uses

func WithDialOptions(opts ...grpc.DialOption) IngressOption

func WithLogger Uses

func WithLogger(l Logger) IngressOption

WithLogger allows for the configuration of a logger. By default, the logger is disabled.

func WithTag Uses

func WithTag(name, value string) IngressOption

WithTag allows for the configuration of arbitrary string value metadata which will be included in all data sent to Loggregator

type Logger Uses

type Logger interface {
    Printf(string, ...interface{})
    Panicf(string, ...interface{})
}

Logger declares the minimal logging interface used within the v2 client

type OneToOneEnvelopeBatch Uses

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

OneToOneEnvelopeBatch diode is optimized for a single writer and a single reader

func NewOneToOneEnvelopeBatch Uses

func NewOneToOneEnvelopeBatch(size int, alerter gendiodes.Alerter, opts ...gendiodes.PollerConfigOption) *OneToOneEnvelopeBatch

NewOneToOneEnvelopeBatch initializes a new one to one diode for envelope batches of a given size and alerter. The alerter is called whenever data is dropped with an integer representing the number of envelope batches that were dropped.

func (*OneToOneEnvelopeBatch) Next Uses

func (d *OneToOneEnvelopeBatch) Next() []*loggregator_v2.Envelope

Next will return the next envelope batch to be read from the diode. If the diode is empty this method will block until anenvelope is available to be read.

func (*OneToOneEnvelopeBatch) Set Uses

func (d *OneToOneEnvelopeBatch) Set(data []*loggregator_v2.Envelope)

Set inserts the given V2 envelope into the diode.

func (*OneToOneEnvelopeBatch) TryNext Uses

func (d *OneToOneEnvelopeBatch) TryNext() ([]*loggregator_v2.Envelope, bool)

TryNext returns the next envelope batch to be read from the diode. If the diode is empty it will return a nil envelope and false for the bool.

type RLPGatewayClient Uses

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

func NewRLPGatewayClient Uses

func NewRLPGatewayClient(addr string, opts ...RLPGatewayClientOption) *RLPGatewayClient

func (*RLPGatewayClient) Stream Uses

func (c *RLPGatewayClient) Stream(ctx context.Context, req *loggregator_v2.EgressBatchRequest) EnvelopeStream

Stream returns a new EnvelopeStream for the given context and request. The lifecycle of the EnvelopeStream is managed by the given context. If the underlying SSE stream dies, it attempts to reconnect until the context is done. Any errors are logged via the client's logger.

type RLPGatewayClientOption Uses

type RLPGatewayClientOption func(*RLPGatewayClient)

RLPGatewayClientOption is the type of a configurable client option.

func WithRLPGatewayClientLogger Uses

func WithRLPGatewayClientLogger(log *log.Logger) RLPGatewayClientOption

WithRLPGatewayClientLogger returns a RLPGatewayClientOption to configure the logger of the RLPGatewayClient. It defaults to a silent logger.

func WithRLPGatewayHTTPClient Uses

func WithRLPGatewayHTTPClient(d Doer) RLPGatewayClientOption

WithRLPGatewayClientLogger returns a RLPGatewayClientOption to configure the HTTP client. It defaults to the http.DefaultClient.

Directories

PathSynopsis
conversion
pulseemitter
rpc/loggregator_v2
runtimeemitter
v1Package v1 provides a client to connect with the loggregtor v1 API

Package loggregator imports 21 packages (graph) and is imported by 39 packages. Updated 2019-10-07. Refresh now. Tools for package owners.