Skip to content

Commit

Permalink
Add Jaeger remote sampler (#936)
Browse files Browse the repository at this point in the history
* Add Jaeger remote sampler

* add jaeger_remote/example

* Extract samplingStrategyParser

* Generate code from jaeger-idl

* Add per operation sampler, fix CI

* Fix Description()

* Delete jaeger-idl submodule, directly check in sampling.proto

* Update OTel dependencies

* Update README.md

* Improve test coverage

* (Sampler).Description() must not change over time

PR to update spec: open-telemetry/opentelemetry-specification#2095
If this is approved we can revert this commit.

* Replace internals with jaeger-client-go

* Address linting issues

* Fix race condition in test

* Update samplers/jaegerremote/README.md

Co-authored-by: Yuri Shkuro <yurishkuro@users.noreply.github.com>

* Update samplers/jaegerremote/internal/testutils/mock_agent.go

Co-authored-by: Yuri Shkuro <yurishkuro@users.noreply.github.com>

* revmoe go.mod debug info

* fix Copyright and

* add from

* Update dependency

* Modified according to pr

* change config from https://github.com/open-telemetry/opentelemetry-go/blob/main/CONTRIBUTING.md#configuration

* (fix:sampler_remote_options.go):change config

* (fix:constants.go):remove Copyright

* (fix:samoler_remote.go):fix config and add default

* Update samplers/jaegerremote/sampler_remote_options.go

yet

Co-authored-by: Anthony Mirabella <a9@aneurysm9.com>

* add local path

* fix lint

* make precommit fix

* (fix:sampler_remote_option.go):The default port of jaeger agent is 5778, but there are other ports specified by the user, so the sampling address and fetch address are strongly bound

* change for Style guide

* change for Update samplers/jaegerremote/sampler_remote_options.go

Co-authored-by: Anthony Mirabella <a9@aneurysm9.com>
Co-authored-by: Chester Cheung <cheung.zhy.csu@gmail.com>
Co-authored-by: Yuri Shkuro <yurishkuro@users.noreply.github.com>
Co-authored-by: dino.ma <dino_ma@163.com>
  • Loading branch information
5 people committed Mar 11, 2022
1 parent 888a8d8 commit a700e18
Show file tree
Hide file tree
Showing 27 changed files with 4,243 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .github/dependabot.yml
Expand Up @@ -674,6 +674,24 @@ updates:
schedule:
interval: "weekly"
day: "sunday"
- package-ecosystem: "gomod"
directory: "/samplers/jaegerremote"
labels:
- dependencies
- go
- "Skip Changelog"
schedule:
interval: "weekly"
day: "sunday"
- package-ecosystem: "gomod"
directory: "/samplers/jaegerremote/example"
labels:
- dependencies
- go
- "Skip Changelog"
schedule:
interval: "weekly"
day: "sunday"
- package-ecosystem: "gomod"
directory: "/tools"
labels:
Expand Down
11 changes: 11 additions & 0 deletions samplers/jaegerremote/Makefile
@@ -0,0 +1,11 @@
PROTOC=docker run --rm -v${PWD}:${PWD} -w${PWD} otel/build-protobuf:latest --proto_path=${PWD}

PROTO_INCLUDES=-I/usr/include/github.com/gogo/protobuf

.PHONY: proto-gen
proto-gen:
mkdir -p internal/proto-gen

$(PROTOC) $(PROTO_INCLUDES) \
--gogo_out=$(PWD)/internal/proto-gen \
${PWD}/jaeger-idl/proto/api_v2/sampling.proto
38 changes: 38 additions & 0 deletions samplers/jaegerremote/README.md
@@ -0,0 +1,38 @@
# Jaeger Remote Sampler

This package implements [Jaeger remote sampler](https://www.jaegertracing.io/docs/latest/sampling/#collector-sampling-configuration).

## Example

[example/](./example) shows how to host remote sampling strategies using the OpenTelemetry Collector.
The Collector uses the Jaeger receiver to host the strategy file. Note you do not need to run Jaeger to make use of the Jaeger remote sampling protocol. However, you do need Jaeger backend if you want to utilize its adaptive sampling engine that auto-calculates remote sampling strategies.

Run the OpenTelemetry Collector using docker-compose:

```shell
$ docker-compose up -d
```

You can fetch the strategy file using curl:

```shell
$ curl 'localhost:5778/sampling?service=foo'
$ curl 'localhost:5778/sampling?service=myService'
```

Run the Go program.
This program will start with an initial sampling percentage of 50% and tries to fetch the sampling strategies from the OpenTelemetry Collector.
It will print the entire Jaeger remote sampler structure every 10 seconds, this allows you to observe the internal sampler.

```shell
$ go run .
```

## Update generated Jaeger code

Code is generated using the .proto files from [jaeger-idl](https://github.com/jaegertracing/jaeger-idl).
In case [sampling.proto](./jaeger-idl/proto/api_v2/sampling.proto) is modified these have to be regenerated.

```shell
$ make proto-gen
```
31 changes: 31 additions & 0 deletions samplers/jaegerremote/constants.go
@@ -0,0 +1,31 @@
// Copyright The OpenTelemetry Authors
// Copyright (c) 2021 The Jaeger Authors.
// Copyright (c) 2017 Uber Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package jaegerremote

import (
"fmt"
)

const (
// defaultSamplingServerPort is the default port to fetch sampling config from, via http
defaultSamplingServerPort = 5778
)

var (
// defaultSamplingServerURL is the default url to fetch sampling config from, via http
defaultSamplingServerURL = fmt.Sprintf("http://127.0.0.1:%d/sampling", defaultSamplingServerPort)
)
18 changes: 18 additions & 0 deletions samplers/jaegerremote/doc.go
@@ -0,0 +1,18 @@
// Copyright The OpenTelemetry Authors
// Copyright (c) 2021 The Jaeger Authors.
// Copyright (c) 2017 Uber Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package jaegerremote implements the Jaeger Remote protocol.
package jaegerremote // import "go.opentelemetry.io/contrib/samplers/jaegerremote"
11 changes: 11 additions & 0 deletions samplers/jaegerremote/example/docker-compose.yaml
@@ -0,0 +1,11 @@
version: "3"
services:

otel-collector:
image: otel/opentelemetry-collector:latest
command: [ "--config=/etc/otel-collector.yaml" ]
volumes:
- ./otel-collector.yaml:/etc/otel-collector.yaml
- ./strategies.json:/etc/strategies.json
ports:
- "5778:5778" # default jaeger remote sampling port
13 changes: 13 additions & 0 deletions samplers/jaegerremote/example/go.mod
@@ -0,0 +1,13 @@
module go.opentelemetry.io/contrib/samplers/jaegerremote/example

go 1.16

require (
github.com/davecgh/go-spew v1.1.1
go.opentelemetry.io/contrib/samplers/jaegerremote v0.22.0
go.opentelemetry.io/otel v1.4.1
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.1.0
go.opentelemetry.io/otel/sdk v1.4.1
)

replace go.opentelemetry.io/contrib/samplers/jaegerremote => ../

0 comments on commit a700e18

Please sign in to comment.