nozzle

package module
v0.0.0-...-f4952a4 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2017 License: MIT Imports: 9 Imported by: 4

README

go-nozzle Build Status Go Documentation

go-nozzle is a pacakge for Go (golang) for building CloudFoundry(CF) nozzle. Nozzle is a program which consume data from the Loggregator Firehose and then select, buffer, and transform data, and forward it to other applications like Apache Kafka or external services like Data Dog.

With this package, you can create a nozzle client which gets the access token for firehose from UAA (when token is not provided), connects firehose endpoint and consumes logs (by default, it uses cloudfoundry/noaa client) and detects slow consumer alert. All you need to do is writing output part of nozzle (e.g., kafka producing).

Documentation is available on GoDoc.

Install

To install, use go get:

$ go get github.com/rakutentech/go-nozzle

Usage

The following is the simple example,

// Setup consumer configuration
config := &nozzle.Config{
	DopplerAddr:    "wss://doppler.cloudfoundry.net",
    UaaAddr:        "https://uaa.cloudfoundry.net",
    Username:       "tcnksm",
    Password:       "xyz",
    SubscriptionID: "go-nozzle-example-A",
}
   
// Create default consumer
consumer, _  := nozzle.NewConsumer(config)

// Start consumer
consumer.Start()

// Consume events
event := <-consumer.Events()
... 

Also you can check the example usage of go-nozzle on example directory.

Author

Taichi Nakashima

Documentation

Overview

nozzle is a package for building your CloudFoundry(CF) nozzle. nozzle is a program which consume data from the Loggregator firehose (https://github.com/cloudfoundry/loggregator) and then select, buffer, and transform data and forward it to other applications, components or services.

This pacakge provides the consumer which (1) gets the access token for firehose, (2) connects firehose and consume logs, (3) detects slow consumer alert. To get starts, see Config and Consumer.

If you want to change the behavior of default consumer, then implement the interface of it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// DopplerAddr is a doppler firehose endpoint address to connect.
	// The address should start with 'wss://' (websocket endopint).
	DopplerAddr string

	// Token is an access token to connect to firehose. It's neccesary
	// to consume logs from doppler.
	//
	// If it's empty, the token is feched from UAA server.
	// To fetch token from UAA server, UaaAddr and Username/Password
	// for CF admin need to be set.
	Token string

	// SubscriptionID is unique id for a pool of clients of firehose.
	// For each SubscriptionID, all data will be distributed evenly
	// among that subscriber's client pool.
	SubscriptionID string

	// UaaAddr is UAA endpoint address. This is used for fetching access
	// token if Token is empty. To get token you also need to set
	// Username/Password for CloudFoundry admin.
	UaaAddr string

	// UaaTimeout is timeout to wait after sending request to uaa server.
	// The default value is 30 seconds.
	UaaTimeout time.Duration

	// Username is admin username of CloudFoundry. This is used for fetching
	// access token if Token is empty.
	Username string

	// Password is admin password of CloudFoundry. This is used for fetching
	// access token if Token is empty.
	Password string

	// Insecure is used for skipping verifying insecure connection with doppler
	// and UAA. Default value is false, not skipping.
	//
	// If it true, by default, connection to doppler & UAA will be insecure.
	// We strongly recommend not to set true instead of testing purpose.
	Insecure bool

	// DebugPrinter is noaa.DebugPrinter. It's used for debugging
	// Noaa. Noaa is a client library to consume metric and log
	// messages from Doppler.
	DebugPrinter noaaConsumer.DebugPrinter

	// Logger is logger for go-nozzle. By default, output will be
	// discarded and not be displayed.
	Logger *log.Logger

	// IdleTimeout is how much time to wait for a message to arrive. If no
	// message arrives with this period, the ws connection is considered dead.
	// If 0 (default) the timeout is disabled.
	IdleTimeout time.Duration

	// RetryCount defines how many times consumer will retry to connect to doppler
	RetryCount int
	// contains filtered or unexported fields
}

Config is a configuration struct for go-nozzle. It contains all required values for using this pacakge. This is used for argument when constructing nozzle client.

type Consumer

type Consumer interface {
	// Events returns the read channel for the events that consumed by
	// rawConsumer(by default Noaa).
	Events() <-chan *events.Envelope

	// Detects returns the read channel that is notified slowConsumerAlerts
	// handled by SlowDetector.
	Detects() <-chan error

	// Error returns the read channel of erros that occured during consuming.
	Errors() <-chan error

	// Start starts consuming upstream events by RawConsumer and stop SlowDetector.
	// If any, returns error.
	Start() error

	// Close stop consuming upstream events by RawConsumer and stop SlowDetector.
	// If any, returns error.
	Close() error
}

Consumer defines the interface of consumer it receives upstream firehose events and slowConsumerAlerts events and errors.

func NewConsumer

func NewConsumer(config *Config) (Consumer, error)

NewConsumer constructs a new consumer client for nozzle.

You need access token for consuming firehose log. There is 2 ways to construct. The one is to get token beforehand by yourself and use it. The other is to provide UAA endopoint with username/password for CloudFoundry admin to fetch the token.

It returns error if the token is empty or can not fetch token from UAA If token is not empty or successfully getting from UAA, then it returns nozzle.Consumer. (In initial version, it starts consuming here but now Start() should be called).

func NewDefaultConsumer deprecated

func NewDefaultConsumer(config *Config) (Consumer, error)

Deprecated: NewDefaultConsumer is deprecated, use NewConsumer instead

Directories

Path Synopsis
This directory contains a example usage of go-nozzle.
This directory contains a example usage of go-nozzle.

Jump to

Keyboard shortcuts

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