Commit Graph

1436 Commits

Author SHA1 Message Date
Steven Karis 8e8c6345b3
Add config based attributes (#317)
* Add config-based attributes to all spans passing through collector

There is a usecase where all spans going through the collector should be
tagged with some additional attribute information (e.g. env, pipeline).
This solves for that usecase.

Testing Done: unit tests
2019-01-15 17:20:26 -08:00
Dave Raffensperger 8faffe1958
Add CORS option for OC Receiver grpc-gateway (#307)
This adds a new cors_allowed_origins YAML config parameter to the opencensus receiver config block, which, if specified will allow HTTP clients to write to the trace grpc-gateway using CORS with the specified list of origins (wildcards can be used to match all origins or arbitrary origin substrings).

This will help with development of opencensus-web.
2019-01-14 13:44:57 -05:00
Paulo Janotti a08f9827fb
Temporarily disabling gRPC views for OC receiver (#304)
Due to issue https://github.com/census-instrumentation/opencensus-service/issues/287
these are not providing any useful information. Disabling them for now.
2019-01-11 15:12:37 -08:00
Emmanuel T Odeke 1f7c62d885
exporter/metrics: add Prometheus metrics exporter
Added a Prometheus metrics exporter that allows
us to export metrics.
Its configuration is available under YAML field option
```yaml
exporters
    prometheus:
        <key>: <value>
```
where <key> could be any of

* address -- the address on which to run the Prometheus
scrape endpoint /metrics on

* const_labels -- labels that will be applied to each
metric that is exported

* namespace -- optionally if defined records metrics
under a specific namespace, leave it blank to preserve
the names of the proxied metrics (if that's the case)

This change uses the Prometheus metrics exporter
at github.com/orijtech/prometheus-go-metrics-exporter
which will be handed over to the OpenCensus community
whenever a repository is created under the
"census-ecosystem" organization.

Fixes #292
2019-01-11 11:54:55 +03:00
Emmanuel T Odeke e741b37f2c
all: accept MetricsExporters by implementation
ExportersFromYAMLConfig now returns metricsExporters too.
2019-01-10 17:28:14 +03:00
Paulo Janotti 36b8dbc038
Adds Batch Queue of Ids (for tail-sampling) (#282)
* Adds Batch Queue of Ids (for tail-sampling)

Adding one of the types used to implement tail-based sampling.

This type will be used to create the batches that are periodically
processed while running tail-based sampling. The idea is that
receivers will put ids concurrently in a batch while from time
to time a batch will be taken for sampling policy evaluation.

The pipeline of batches behaves in FIFO fashion and the owner of the type
is in charge of closing each batch by calling the proper method (which returns the
first batch in the pipe while also starting a new batch).

* PR Feedback

Trying to avoid confusion with the docs by using pipeline instead of queue.

* Better package name

From id_batch_queue to id_batcher (all related renames: files, folders, etc).
2018-12-31 11:16:47 -08:00
Paulo Janotti 8e51c02a66
Add basic telemetry to collector (#284)
* Add basic telemetry to collector

This change adds a Prometheus endpoint using OC to provide metrics
to the collector. There are settings to control the level and port
in which the metrics are exposed. The main metrics added for now
are in the queued exporters.

* Check for view registration errors

* PR Feedback
2018-12-28 08:17:23 -08:00
Steve Flanders 6b87782dc0 Add dynamic support for VERSION and default to latest (#263)
* Add dynamic support for VERSION

As we complete milestones we plan to cut versions. Today, this requires
editing two separate files and committing them. Instead, default to an
undefined version and allow the version to be passed as part of
build_binaries or make.

* Default to version being latest
2018-12-10 13:41:02 -08:00
Emmanuel T Odeke 5af194d1f9
receiver/jaeger: Jaeger Agent running on UDP ports
* Update receiver/jaeger.New to take in a Configuration
that now allows specifying the Jaeger agent UDP ports
* Separated out startCollector and startAgent helpers
for the Jaeger receiver
* Agent now runs on UDP ports:
+ Thrift Compact: by default 6831
+ Thrift Binary: by default 6832
+ Agent server: by default 5778
* Skipping Jaeger Binary Thrift test
Due to a nest of versions of Thrift-Go, and generated by various
Thrift compilers, we get an error
"Bad version in ReadMessageBegin"
so for now disable the Jaeger Binary Thrift test.
2018-12-05 22:55:15 -08:00
Yang Song be40965ba1
exporter: rename ocagent -> opencensus (#261) 2018-12-06 13:40:50 +08:00
Paulo Janotti b647d6ad11
Enable queue processor (#254)
* Enabling queued processor for jaeger

Uses the processor queue to send data to Jaeger Collectors.
This allows deeper retry queues than what can be done directly with
the Jaeger exporter and also allows better handling of service information
for Jaeger backends.

* Merge fix and minor corrections

* PR Feedback: add queue info about defaults to README.md

* Fix one default that was incorrect.

* Update lint (this was needed since we are using latest lint and it ends updating go.mod and go.sum)
2018-12-05 09:25:11 -08:00
Yang Song 0f326c3bf9 exporter: add ocagent exporter. (#249) 2018-12-04 11:13:13 -08:00
Emmanuel T Odeke b093b60e9a
config: remove CanRunAllOpenCensusReceivers()
Address @pjanotti's suggestions from code review
to remove unnecessary code.
2018-11-30 12:33:11 -08:00
Emmanuel T Odeke 7bfd08ef6c
cmd/ocagent: add OpenCensus Metrics receiver + noopMetricsSink
For now before any OpenCensus Metrics exporter is created, just
hook it up. This will allow applications such as the OpenCensus-PHP
stats backend to send content.

Fixes #216
2018-11-29 22:42:41 -08:00
Emmanuel T Odeke 1c21dc6fe3
cmd/ocagent/config* --> internal/config
Consolidated config related utilities into internal/config

This change introduces the consolidated changes. A followup
will be to also edit cmd/occollector for parity of use with
the now consolidated/extracted functions.

Updates #210
Updates #211
2018-11-29 22:24:04 -08:00
Yang Song f35ec16487 receiver: use TraceData and MetricsData in receivers. (#224)
* receiver: use TraceData and MetricsData in receivers.

* Fix E2E test.
2018-11-20 15:46:40 -08:00
Bogdan Drutu 18467c9e05
Add multi trace/metrics receivers. (#222) 2018-11-20 13:29:29 -08:00
Emmanuel T Odeke 7f5fc67287
receiver/zipkin: consolidate server starting to receiver
Moved the server starting logic to the receiver and updated
New to
  New(address string) (*ZipkinReceiver, error)
instead of
  New(spansink.Sink) (*ZipkinReceiver, error)

This change ensures that after invoking New all the user
has to do is then just invoke:
   zr.StartTraceReception(context.Context, spansink.Sink) error

and then for cleanup
    defer zr.StopTraceReception(context.Context)

Fixes #212
2018-11-19 13:04:53 -07:00
Emmanuel T Odeke 38c9550146
all: revise TraceExporter to take in ...tracepb.Span
Fix TraceExporter's signature from:

    ExportSpanData(ctx context.Context, node *commonpb.Node, spandata ...*trace.SpanData) error

to

    ExportSpans(ctx context.Context, node *commonpb.Node, spans ...*tracepb.Span) error

as the original signature leaked the intention of reusing OpenCensus-Go
exporters, but really that is an implementation detail left to the
exporters.

Fixes #207
2018-11-17 23:43:12 -07:00
Bogdan Drutu 2e6b5247b2
Move span and metrics syncs in the receiver. (#202)
* Move span and metrics syncs in the receiver.

* fix golint

* Fix collector processor.
2018-11-16 16:40:49 -08:00
Paulo Janotti 4f3bb2c88d
Add processor queue (#197)
* Start adding pipeline to collector

This is the basis to do the work for actually implementing OC collector
in the short run. At first enable receivers:

1. OC Receiver
2. Jaeger
3. Zipkin

The queue processor is added but not connected to exporters by default,
although there are options to do so.

As previously indicated before there is some duplication of code
with the agent, this should be reduced as we implement the interfaces and
project coalesce around certain patterns.

The queue is missing its metrics and those will be added soon.
2018-11-16 16:13:24 -08:00
Emmanuel T Odeke 08315f27fa
translator/trace/jaeger: conservative allocations for only existent fields
* Only allocate TraceID and SpanID iff they are non-nil lest we'll
consume 8/16 bytes for every span which becomes quite expensive
* Also retrieve "status.code" and "status.message" as the Jaeger exporter
from OpenCensus sends those
* Avoid creating an attributes map if attributes don't exist and
let go of the `make(map[<K>]<V>, size_hint)` idiom as it prevents
us from being able to detect if values were added to the attributes map
* Added in-code conversion tests to ensure fidelity preservation
* Translate "message" in logs/tags to a description value

Noticed while rolling out the Jaeger receiver/interceptor.

Fixes #187
Fixes #188
Fixes #189
Fixes #190
2018-11-12 02:30:40 -07:00
Emmanuel T Odeke c99676e914
all: rename interceptor to receiver
As per the consensus from #151, rename interceptor to receiver
but also the related interfaces too and their methods.

Fixes #166
2018-11-07 14:41:04 -08:00
Emmanuel T Odeke f8557d732f interceptor/zipkin: logic to parse spans from Protobuf
Can now intercept Zipkin Protobuf spans that are
sent to a Zipkin server.

The ZipkinInterceptor multiplexes on the "Content-Type"
header, checking if the value set is "application/x-protobuf"
otherwise fallback to try parsing as JSON.

* go.mod: use Zipkin-Go which features proto parsing
* Add the "X-B3-Flags" reference from Zipkin resources

Fixes #154
Spawned https://github.com/openzipkin/zipkin-go/issues/87
Waiting on https://github.com/openzipkin/zipkin-go/pull/88
2018-11-07 12:42:19 -08:00
Paulo Janotti 6765422269
Clean up and enable golint (#160)
Makes golint break the build and cleans up the existing issues so no
more are added to the repo.
2018-11-01 14:44:22 -07:00
Paulo Janotti 72aa6578c3
Remove extra functions and improve JSON check in tests (#148)
These changes are a follow up to comments in a previous PR. It changes
the normalization process to compare JSON strings and remove some
extra functions by replacing them with an if/else statement and local
variables.
2018-10-31 11:20:44 -07:00
Emmanuel T Odeke 057ffbc724
interceptor, exporter/zipkin: own Trace exporter with per span attributes
This change introduces our own copy of a modified Zipkin Trace
exporter from OpenCensus-Go. This modification takes into
account the fact that our Zipkin interceptor "intercepts"/proxies
spans while the OpenCensus-Go Zipkin exporter assumes a static
world in which there is only one localEndpoint and no remoteEndpoint.
However, localEndpoint and remoteEndpoint are per-span fields
hence the necessity for us to ensure that users of this project
can have an almost transparent proxying and processing of Zipkin spans.

This change also features an end-to-end test that takes intercepted
Zipkin spans e.g. from a Zipkin Java exporting application, intercepts
them to the AgentCore and then on export we ensure that our output
has all the endpoints "localEndpoint", "remoteEndpoint" as well
as an equivalence of all the other fields.

We also now use the updated Zipkin-Go client after
    https://github.com/openzipkin/zipkin-go/issues/85
was fixed with
    https://github.com/openzipkin/zipkin-go/pull/86

The updated Zipkin-Go no longer serializes empty ipv4
addresses as 0.0.0.0 so remove those from our tests
Fixed as per https://github.com/openzipkin/zipkin-go/pull/86

Fixes #132
Supersedes https://github.com/census-instrumentation/opencensus-go/issues/959
Supersedes https://github.com/census-instrumentation/opencensus-go/issues/960
Spawned https://github.com/openzipkin/zipkin-go/issues/85
2018-10-31 00:05:36 -07:00
Emmanuel T Odeke 9bcf6057bb
interceptor: add zipkin /v2 interceptor (#111)
* interceptor: add zipkin interceptor

* Zipkin interceptor multiplexing + running on 9411

* Can receive spans from diverse sources and successfully
intercept traces from various serviceNames and IPv* combinations.
Verified by examining the data on the Zipkin UI itself by
resending to a server running on a different port.

* End-to-end serialization tests where we intercept JSON
from a wild Zipkin reporter, transform it into trace-proto
then to OpenCensus-Go SpanData and then export it with the
OpenCensus-Go Zipkin exporter, inspect the JSON and compare
it with the final/expected JSON data.

Fixes #24

* interceptor/zipkin: add remoteEndpoint to Node.Attributes

Zipkin's RemoteEndpoint field is necessary when later on
building the dependency graph for Zipkin services.

This change ensures that that field is added as an attribute
to the Node with keys whose prefix is:
  "zipkin.remoteEndpoint." e.g.

- "zipkin.remoteEndpoint.ipv4"
- "zipkin.remoteEndpoint.serviceName"
- "zipkin.remoteEndpoint.port"

* Fail if Zipkin interceptor and exporter run on same address

Fail spectacularly if the Zipkin interceptor and the Zipkin
exporter will all be run on the same address.
This is because this is a self DOS vector as intercepted spans
will be processed by the interceptor, then exported out by
the exporter but instead those exported spans will then be
sent back to the interceptor and this goes on indefinitely
and will just consume memory and resources.

To perform this check:
a) Compare HostPorts of interceptor vs exporter
b) If say "127.0.0.1", "localhost", "" for host and the ports
match
c) Resolve the IPs for the hosts

if any of those steps match return a logical conflict error
which will be thrown later.

The crash will look something like this
```shell
2018/10/23 18:54:41 Configuration logical error: ZipkinInterceptor address ("127.0.0.1:9411") aka (127.0.0.1 on port 9411)
is the same as the interceptor address ("localhost:9411") aka (127.0.0.1 on port 9411)
```

We can now detect any of these clashing configurations:

```yaml
interceptors:
    zipkin:
        address: "127.0.0.1:9411"
exporters:
    zipkin:
        endpoint: "http://localhost:9411/api/v2/spans"
```

```yaml
interceptors:
    zipkin:
        address: ":9411"

exporters:
    zipkin:
        endpoint: "http://localhost:9411/api/v2/spans"
```

```yaml
interceptors:
    zipkin:
        address: "localhost:9411"

exporters:
    zipkin:
        endpoint: "http://localhost:9411/api/v2/spans"
```

```yaml
interceptors:
    zipkin:
        address: "localhost:9411"

exporters:
    zipkin:
        endpoint: "http://:9411/api/v2/spans"
```

```yaml
interceptors:
    zipkin:
        address: "localhost:9411"

exporters:
    zipkin:
        endpoint: "http://127.0.0.1:9411/api/v2/spans"
```

and in a case where IP resolution helped, "10.0.0.147" is my local
address and I sneakishly tried to get the interceptor on "localhost"
which clashes with my local address as per:

```yaml
interceptors:
    zipkin:
        address: "localhost:9411"

exporters:
    zipkin:
        endpoint: "http://10.0.0.147:9411/api/v2/spans"
```

we caught it
```shell
2018/10/23 19:01:01 Configuration logical error: ZipkinInterceptor address ("10.0.0.147:9411") aka (10.0.0.147 on port 9411)
is the same as the interceptor address ("localhost:9411") aka (10.0.0.147 on port 9411)
```

* Go fmt with Go1.10 to match TravisCI

Go1.11's gofmt seems to be more conservating with
aligning literal assignments while Go1.10 seems more
extravagant. This subtle difference was causing TravisCI
failures since TravisCI uses Go1.10.

* interceptor/zipkin: handle compressed HTTP bodies

Some clients such as Zipkin-Java send HTTP bodies
with JSON that's been compressed as "gzip".
This change handles "Content-Encoding" values of:
* "gzip"
* "deflate", "zlib"
and decompresses them accordingly

* interceptor/zipkin: tests use anagram signature

A test that checked for raffled output before used an
"xorChecksum" but that's not really always unique.
The better way is to use an anagram counter, then
create a signature from the serialized map of counted
runes.

* interceptor/zipkin: address review feedback

* Package rename to "zipkinterceptor" --> "zipkininterceptor"
* Fix error names

* Address feedback from review

* move "zipkinRoute" const to the top to make it easily
discoverable and not be buried deep in code
* set status of zipkin interceptor if we encounter an error
while parsing spans. We set the span status to: StatusInvalidArgument
and the error message

* *zipkin: address feedback from review

* Add a comment ot exporter/exporterparse.zipkinExporter
that the mutex "mu" protects all the constituent fields
* Fix and ensure that node uniqueness is clear, with the
proper check from a map lookup but also rename the variable
to store nodes to "uniqueNodes" to make for better code readability

* README.md + default config.yaml: update interceptors docs and information

Added a section in the README.md on the various interceptors
and how to change the Zipkin interceptor address

* sync.Mutex instead of sync.RWMutex for zipkinExporter.mu
2018-10-26 11:41:00 -07:00
Emmanuel T Odeke 9c06662859
exporter/exporterparse: metrics for exported spans
After each exporter has exported spans, record the
number of spans exported with tag:
    "opencensus_exporter": <name>

Updates #64
2018-10-17 20:50:36 -07:00
Emmanuel T Odeke e46c4b63ff all: move helper TimeToTimestamp to internal
Move the common helper TimeToTimestamp to internal
instead of duplicating its functionality allover
the repository. It is needed for implementing other
interceptors.
2018-10-17 00:48:58 -07:00
Emmanuel T Odeke 2962fe95f4 cmd/ocagent: added version command
Added a `version` command to the CLI which
will print out the information leading to when
and how the binary was built. The fields printed
out are:

* Version: The version of ocagent itself
* Goversion: The version of Go that compiled this binary
* OS: The OS it was built for (runtime.GOOS)
* Architecture: The architecture of the system
* GitHash: The hash of the ocagent commit

For example:
```shell
Version      0.0.1
GitHash      7ec3ea8
Goversion    devel +62e5215a2a Thu Oct 4 04:08:08 2018 +0000
OS           darwin
Architecture amd64
```

this will aid in:
* easy bug diagnoses and fixes
* plugin management whereby the exporter plugins MUST
match the version of Go that ocagent was built with inorder
for them to be application binary compatible
* reproducible builds

Also added a Makefile with a couple of directives
that allow for cross-compilation too.

Switched the flag parser from the inflexible "flag"
package in favour of "github.com/spf13/cobra".

Fixes #59
2018-10-16 11:01:48 -07:00
Emmanuel T Odeke 093f0b2169
exporter: add metrics recording helper for Exporters
Updates #64
2018-10-16 04:55:55 -07:00
Emmanuel T Odeke 498e498ca7
interceptor/opencensus: trace instrument batchSpanUploading
Trace instrument the section that performs batch uploading
to the spanreceiver. The created span has a parent link
from the initiating RPC's span. Added tests to ensure that
these conditions always hold.

Updates #63
2018-10-08 16:53:42 -10:00
Emmanuel T Odeke bdb4d3d3dd interceptor/opencensus: record number of received spans
Instrument interceptor/opencensus with stats to record
the number of received spans. This is accomplished by
a helper to process spans that sends over spans even
if the number of spans is 0. Also record with tag_key
"opencensus_interceptor" whose value is the name
of the respective interceptor.

The test to ensure that 0 length spans are also added
is currently disabled because:
* Issue https://github.com/census-instrumentation/opencensus-go/issues/862
is not yet implemented which requests that the OpenCensus-Go
stats worker provide a method Flush to flush all data. Without
it, metrics will contain stale data from previous tests.

Add tests to lock-in this behavior.

Also replace grpc.NewServer with a stats enabled server helper call.
This enables tracing and metrics for each gRPC server by replacing
naked usages of grpc.NewServer with the new helper function:
    internal.GRPCServerWithObservabilityEnabled

Updates #63
2018-10-07 11:49:42 -10:00
JBD 4ed4cc0c38
Make endpoint file JSON (#6)
It allows us to extend what else we are going to store
as metadata in the file.

Fixes #5.
2018-06-28 16:30:02 -07:00
JBD e3604d9820
Initial commit of the exporter daemon and its Go exporter (#1)
This commit contains an initial prototype for the exporter daemon
that can discovered via and endpoint file on the host.

The exporter looks for the endpoint file to see the availability
of the daemon and exports if it is running.

Exporter daemon will allow OpenCensus users to export
without having to link a vendor-specific exporter in their final
binaries. We are expecting the prototype exporter is going to
be implemented in every language and registered by default.

Updates https://github.com/census-instrumentation/opencensus-specs/issues/72.
2018-06-07 15:42:37 -07:00