Giter Site home page Giter Site logo

dropsonde's Introduction

Dropsonde

Coverage Status GoDoc

If you have any questions, or want to get attention for a PR or issue please reach out on the #logging-and-metrics channel in the cloudfoundry slack

Go library to collect and emit metric and logging data from CF components. https://godoc.org/github.com/cloudfoundry/dropsonde

Protocol Buffer format

See dropsonde-protocol for the full specification of the dropsonde Protocol Buffer format.

Use this script to generate Go handlers for the various protobuf messages.

Initialization and Configuration

import (
    "github.com/cloudfoundry/dropsonde"
)

func main() {
    dropsonde.Initialize("localhost:3457", "router", "z1", "0")
}

This initializes dropsonde, along with the logs and metrics packages. It also instruments the default HTTP handler for outgoing requests, instrument itself (to count messages sent, etc.), and provides basic runtime stats.

The first argument is the destination for messages (typically metron). The host and port is required. The remaining arguments form the origin. This list is used by downstream portions of the dropsonde system to track the source of metrics.

Alternatively, import github.com/cloudfoundry/dropsonde/metrics to include the ability to send custom metrics, via metrics.SendValue and metrics.IncrementCounter.

Sending application logs and metrics

After calling dropsonde.Initialize (as above), the subpackages logs and metrics are also initialized. (They can be separately initialized, though this requires more setup of emitters, etc.)

Application Logs

Currently, dropsonde only supports sending logs for platform-hosted applications (i.e. not the emitting component itself).

Use logs.SendAppLog and logs.SendAppErrorLog to send single logs, e.g.

logs.SendAppLog("b7ba6142-6e6a-4e0b-81c1-d7025888cce4", "An event happened!", "APP", "0")

To process a stream of app logs (from, say, a socket of an application's STDOUT output), use logs.ScanLogStream and logs.ScanErrorLogStream:

logs.ScanLogStream("b7ba6142-6e6a-4e0b-81c1-d7025888cce4", "APP", "0", appLogSocketConnection)

See the Cloud Foundry DEA Logging Agent (currently deprecated) for an example code that scans log streams using these methods.

Metrics

As mentioned earlier, initializing Dropsonde automatically instruments the default HTTP server and client objects in the net/http package, and will automatically send HttpStart and HttpStop events for every request served or made.

For instrumentation of other metrics, use the metrics package.

  • metrics.SendValue(name, value, unit) sends an event that records the value of a measurement at an instant in time. (These are often called "gauge" metrics by other libraries.) The value is of type float64, and the unit is mandatory. We recommend following this guide for unit names, and highly encourage SI units and prefixes where appropriate.
  • metrics.IncrementCounter(name) and metrics.AddToCounter(name, delta) send events that increment the named counter (by one or the specified non-negative delta, respectively). Note that the cumulative total is not included in the event message, only the increment.

Tags

There are some metric functions/methods which return Chainer types, which can be used to apply tags before sending. In the simplest case, the call will cascade until Send():

err := metrics.Value(name, value, unit).
    SetTag("foo", "bar").
    SetTag("bacon", 12).
    Send()

In more complicated code, the chainer can be passed around, adding tags until the metric is ready to be sent. For example, pre-marshal, you may want to add tags about the type:

chainer := metrics.Value(name, value, unit).
    SetTag("req-mimetype", "json").
    SetTag("name", v.Name)

Later, it could tags about the chosen response type:

chainer = chainer.SetTag("resp-mimetype", respType)

And finally, add tags about the final state:

err := chainer.SetTag("resp-state", "error").
    SetTag("resp-code", http.StatusBadRequest).
    Send()

Note: It is important to note that for counter metrics are summed individually and not in total. If you have historically emitted a counter without tags it is best practice to continue to emit that total metric without tags, and add additional metrics for the individual tagged metrics you'd like to track.

Manual usage

For details on manual usage of dropsonde, please refer to the Godocs. Pay particular attenion to the ByteEmitter, InstrumentedHandler, and InstrumentedRoundTripper types.

Handling dropsonde events

Programs wishing to emit events and metrics should use the package as described above. For programs that wish to process events, we provide the dropsonde/unmarshaller and dropsonde/marshaller packages for decoding/reencoding raw Protocol Buffer messages. Use dropsonde/signature to sign and validate messages.

dropsonde's People

Contributors

ajackson avatar benjamintf1 avatar bradylove avatar chanthing avatar ctlong avatar drich10 avatar duanemay avatar enocom avatar geapi avatar geofffranks avatar jeffresc avatar jmtuley avatar joachimvaldez avatar jtarchie avatar jtuchscherer avatar krishicks avatar lvarvel avatar mrosecrance avatar nelsam avatar roxtar avatar rroberts2222 avatar wfernandes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dropsonde's Issues

New Tag for dropsonde

๐Ÿ‘‹ After this PR was merged, we are unable to get the latest version of this repo, unless we go get github.com/cloudfoundry/dropsonde@master which would be a one-time update to the latest SHA. It'd be great if there would be a new tag other than 1.0.0 (e.g 1.1.0 with the same import-path) so that we could get the latest version of this repo. There are a total of ~40 packages in code.cloudfoundry.org that is still importing this repo.

HttpStartStop event sets an invalid URI when X-Forwarded-For is set

The fix for #14 looks like it is not setting the RemoteAddress field, but instead sets the Host portion of the URI to the value of X-Forwarded-For when the header is present. This is incorrect, as the X-Forwarded-For contains a comma-separated list of IP addresses.

This results in HttpStartStop events from bosh-lite with uris like:

 uri:"http://192.168.50.1, 10.244.0.21/v2/resource_match" remoteAddress:"10.244.0.21:53832"  >

One might expect this:

 uri:"http://api.bosh-lite.com/v2/resource_match" remoteAddress:"192.168.50.1:53832"  >

The question of what to put in the remoteAddress field is an interesting one, since the X-Forwarded-For header cannot really be trusted to be correct and might be modified. That might not be a concern though, and if support for X-Forwarded-For is wanted the last IP address in the list would potentially be the most accurate.

Endianness of UUID and protobuf

Hi there, I just wanted to call out for an issue I'm experiencing, may or may not be a bug.

Trying to parse the returned value from UUID of the protocol in Java, always return a mismatch UUID. So I took a peak into the code and found this line:

return &control.UUID{Low: proto.Uint64(binary.LittleEndian.Uint64(id[:8])), High: proto.Uint64(binary.LittleEndian.Uint64(id[8:]))}

I'm not that familiar with protobuf, but from discussions around the web, it seems that it should take care of endianness of the bytes, and each client convert to its native implementation.

And because this is forcing little endian value, when java clients try to read them, I'm forced to read as BigIntegers, convert to bytes and revert them in order to construct the proper UUID string back.

Is this really the expected behavior? Or should it be a more interoperable way to parse this info?

Regards

Why is emitter set to nil on initialize?

dropsonde/dropsonde.go

Lines 55 to 64 in c9683ed

autowiredEmitter = nil
emitter, err := createDefaultEmitter(strings.Join(origin, originDelimiter), destination)
if err != nil {
return err
}
autowiredEmitter = emitter
initialize()
return nil

Seems unsafe to have a nil pointer reference here. Why not set the emitter to the NullEventEmitter and then, if able to create a proper emitter, setting it to that?

We dereferenced that nil emitter when Diego's inigo integration suite was running with its gorouter's metron address misconfigured. We'll file a separate issue with the gorouter for it not to ignore dropsonde initialization errors, but it seems unsafe for dropsonde to allow itself to get into a bad state.

Thanks,
@Amit-PivotalLabs && Eric

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.