Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Jaeger remote sampler #936

Merged
merged 43 commits into from Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
6c157f6
Add Jaeger remote sampler
kvrhdn Aug 4, 2021
b3a0fd4
add jaeger_remote/example
kvrhdn Aug 12, 2021
8f55d8d
Extract samplingStrategyParser
kvrhdn Aug 13, 2021
cf5fac2
Generate code from jaeger-idl
kvrhdn Aug 17, 2021
5500e91
Add per operation sampler, fix CI
kvrhdn Aug 17, 2021
14342ba
Fix Description()
kvrhdn Aug 18, 2021
e499f84
Merge branch 'main' into jaeger_remote
kvrhdn Nov 1, 2021
6eb570e
Delete jaeger-idl submodule, directly check in sampling.proto
kvrhdn Nov 1, 2021
0d0bf03
Update OTel dependencies
kvrhdn Nov 1, 2021
68e05c5
Update README.md
kvrhdn Nov 1, 2021
e7ee478
Improve test coverage
kvrhdn Nov 2, 2021
34cbbfb
Merge remote-tracking branch 'base/main' into jaeger_remote
kvrhdn Nov 8, 2021
8b492bf
(Sampler).Description() must not change over time
kvrhdn Nov 8, 2021
8bb5399
Replace internals with jaeger-client-go
kvrhdn Nov 16, 2021
f4f3592
Address linting issues
kvrhdn Nov 29, 2021
8f379c1
Fix race condition in test
kvrhdn Nov 29, 2021
04c1b48
Merge branch 'main' into jaeger_remote
kvrhdn Nov 29, 2021
c9acff6
Merge branch 'main' into jaeger_remote
kvrhdn Dec 7, 2021
a373c13
Merge branch 'main' into jaeger_remote
Aneurysm9 Dec 12, 2021
eb75278
Merge branch 'main' into jaeger_remote
Aneurysm9 Jan 28, 2022
4e0ce71
Update samplers/jaegerremote/README.md
hanyuancheung Mar 3, 2022
bf662c3
Merge branch 'main' into jaeger_remote
hanyuancheung Mar 4, 2022
e49435d
Update samplers/jaegerremote/internal/testutils/mock_agent.go
hanyuancheung Mar 7, 2022
fbe7e30
Merge branch 'main' into jaeger_remote
hanyuancheung Mar 7, 2022
f0ea53d
revmoe go.mod debug info
dino-ma Mar 4, 2022
7906f56
fix Copyright and
dino-ma Mar 7, 2022
97bebca
add from
dino-ma Mar 7, 2022
d4ebea2
Update dependency
dino-ma Mar 7, 2022
3fa7800
Modified according to pr
dino-ma Mar 7, 2022
d311912
change config from https://github.com/open-telemetry/opentelemetry-go…
dino-ma Mar 7, 2022
823989b
(fix:sampler_remote_options.go):change config
dino-ma Mar 8, 2022
d337bb8
(fix:constants.go):remove Copyright
dino-ma Mar 8, 2022
aa1dc44
(fix:samoler_remote.go):fix config and add default
dino-ma Mar 8, 2022
82ea29d
Update samplers/jaegerremote/sampler_remote_options.go
dino-ma Mar 8, 2022
d4a19ac
Merge branch 'jaeger_remote' of github.com:kvrhdn/opentelemetry-go-co…
dino-ma Mar 8, 2022
9ee4701
add local path
dino-ma Mar 9, 2022
bbb1c21
Merge branch 'main' into jaeger_remote
Aneurysm9 Mar 9, 2022
3fc124f
fix lint
dino-ma Mar 9, 2022
ecc557d
make precommit fix
dino-ma Mar 9, 2022
139c1c8
(fix:sampler_remote_option.go):The default port of jaeger agent is 57…
dino-ma Mar 9, 2022
4474a8f
change for Style guide
dino-ma Mar 10, 2022
76fcb9a
change for Update samplers/jaegerremote/sampler_remote_options.go
dino-ma Mar 11, 2022
40f8379
Merge branch 'main' into jaeger_remote
Aneurysm9 Mar 11, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions samplers/jaeger_remote/README.md
@@ -0,0 +1,5 @@
# Jaeger Remote Sampler

This package implements a `"go.opentelemetry.io/otel/sdk".Sampler` that fetches its configuration from a Jaeger agent.

The sampling strategy definition: [sampling.proto](https://github.com/jaegertracing/jaeger-idl/blob/master/proto/api_v2/sampling.proto).
69 changes: 69 additions & 0 deletions samplers/jaeger_remote/config.go
@@ -0,0 +1,69 @@
// Copyright The OpenTelemetry Authors
//
// 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 jaeger_remote // import "go.opentelemetry.io/contrib/samplers/jaeger_remote"

import "time"

type config struct {
service string
endpoint string
pollingInterval time.Duration
initialSamplingRate float64
}

func defaultConfig() *config {
return &config{
service: "",
endpoint: "localhost:5778",
pollingInterval: defaultPollingInterval,
initialSamplingRate: defaultSamplingRate,
}
}

type Option interface {
apply(config *config)
}

type optionFunc func(config *config)

var _ Option = optionFunc(nil)

func (fn optionFunc) apply(config *config) {
fn(config)
}

func WithService(service string) Option {
return optionFunc(func(config *config) {
config.service = service
})
}

func WithEndpoint(endpoint string) Option {
return optionFunc(func(config *config) {
config.endpoint = endpoint
})
}

func WithPollingInterval(pollingInterval time.Duration) Option {
return optionFunc(func(config *config) {
config.pollingInterval = pollingInterval
})
}

func WithInitialSamplingRate(initialSamplingRate float64) Option {
return optionFunc(func(config *config) {
config.initialSamplingRate = initialSamplingRate
})
}
16 changes: 16 additions & 0 deletions samplers/jaeger_remote/doc.go
@@ -0,0 +1,16 @@
// Copyright The OpenTelemetry Authors
//
// 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 jaeger_remote implements the Jaeger Remote protocol.
package jaeger_remote // import "go.opentelemetry.io/contrib/samplers/jaeger_remote"
59 changes: 59 additions & 0 deletions samplers/jaeger_remote/fetcher.go
@@ -0,0 +1,59 @@
// Copyright The OpenTelemetry Authors
//
// 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 jaeger_remote // import "go.opentelemetry.io/contrib/samplers/jaeger_remote"

import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/url"

jaeger_api_v2 "github.com/jaegertracing/jaeger/proto-gen/api_v2"
)

type samplingStrategyFetcher interface {
Fetch() (jaeger_api_v2.SamplingStrategyResponse, error)
}

type samplingStrategyFetcherImpl struct {
serviceName string
endpoint string
httpClient *http.Client
}

var _ samplingStrategyFetcher = samplingStrategyFetcherImpl{}

func (f samplingStrategyFetcherImpl) Fetch() (s jaeger_api_v2.SamplingStrategyResponse, err error) {
uri := f.endpoint + "?service=" + url.QueryEscape(f.serviceName)

resp, err := f.httpClient.Get(uri)
if err != nil {
return
}
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return
}

if resp.StatusCode != http.StatusOK {
return s, fmt.Errorf("request failed (%d): %s", resp.StatusCode, body)
}

err = json.Unmarshal(body, &s)
return
}
75 changes: 75 additions & 0 deletions samplers/jaeger_remote/fetcher_test.go
@@ -0,0 +1,75 @@
package jaeger_remote

import (
"net/http"
"net/http/httptest"
"testing"

jaeger_api_v2 "github.com/jaegertracing/jaeger/proto-gen/api_v2"
"github.com/stretchr/testify/assert"
)

func Test_samplingStrategyFetcher_Fetch(t *testing.T) {
tests := []struct {
name string
responseStatusCode int
responseBody string
expectedErr string
expectedStrategy jaeger_api_v2.SamplingStrategyResponse
}{
{
name: "RequestOK",
responseStatusCode: http.StatusOK,
responseBody: `{
"strategyType": 0,
"probabilisticSampling": {
"samplingRate": 0.5
}
}`,
expectedStrategy: jaeger_api_v2.SamplingStrategyResponse{
StrategyType: jaeger_api_v2.SamplingStrategyType_PROBABILISTIC,
ProbabilisticSampling: &jaeger_api_v2.ProbabilisticSamplingStrategy{
SamplingRate: 0.5,
},
},
},
{
name: "RequestError",
responseStatusCode: http.StatusTooManyRequests,
responseBody: "you are sending too many requests",
expectedErr: "request failed (429): you are sending too many requests",
},
{
name: "InvalidResponseData",
responseStatusCode: http.StatusOK,
responseBody: `{"strategy`,
expectedErr: "unexpected end of JSON input",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "/?service=foo", r.URL.RequestURI())

w.WriteHeader(tt.responseStatusCode)
_, err := w.Write([]byte(tt.responseBody))
assert.NoError(t, err)
}))
defer server.Close()

fetcher := samplingStrategyFetcherImpl{
serviceName: "foo",
endpoint: server.URL,
httpClient: http.DefaultClient,
}

strategyResponse, err := fetcher.Fetch()
if tt.expectedErr != "" {
assert.EqualError(t, err, tt.expectedErr)
} else {
assert.NoError(t, err)
assert.Equal(t, tt.expectedStrategy, strategyResponse)
}
})
}
}
10 changes: 10 additions & 0 deletions samplers/jaeger_remote/go.mod
@@ -0,0 +1,10 @@
module go.opentelemetry.io/contrib/samplers/jaeger_remote

go 1.16

require (
github.com/jaegertracing/jaeger v1.24.0
github.com/stretchr/testify v1.7.0
go.opentelemetry.io/otel v1.0.0-RC2
go.opentelemetry.io/otel/sdk v1.0.0-RC2
)