| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
// Copyright (c) 2021 The Jaeger Authors. |
| 5 |
// Copyright (c) 2017 Uber Technologies, Inc. |
| 6 |
// |
| 7 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 |
// you may not use this file except in compliance with the License. |
| 9 |
// You may obtain a copy of the License at |
| 10 |
// |
| 11 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 12 |
// |
| 13 |
// Unless required by applicable law or agreed to in writing, software |
| 14 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 15 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 |
// See the License for the specific language governing permissions and |
| 17 |
// limitations under the License. |
| 18 |
|
| 19 |
package testutils |
| 20 |
|
| 21 |
import ( |
| 22 |
"testing" |
| 23 |
|
| 24 |
jaeger_api_v2 "github.com/jaegertracing/jaeger-idl/proto-gen/api_v2" |
| 25 |
"github.com/stretchr/testify/assert" |
| 26 |
"github.com/stretchr/testify/require" |
| 27 |
) |
| 28 |
|
| 29 |
func TestMockAgentSamplingManager(t *testing.T) { |
| 30 |
mockAgent, err := StartMockAgent() |
| 31 |
require.NoError(t, err) |
| 32 |
defer mockAgent.Close() |
| 33 |
|
| 34 |
err = getJSON(t.Context(), "http://"+mockAgent.SamplingServerAddr()+"/", nil) |
| 35 |
require.Error(t, err, "no 'service' parameter") |
| 36 |
err = getJSON(t.Context(), "http://"+mockAgent.SamplingServerAddr()+"/?service=a&service=b", nil) |
| 37 |
require.Error(t, err, "Too many 'service' parameters") |
| 38 |
|
| 39 |
var resp jaeger_api_v2.SamplingStrategyResponse |
| 40 |
err = getJSON(t.Context(), "http://"+mockAgent.SamplingServerAddr()+"/?service=something", &resp) |
| 41 |
require.NoError(t, err) |
| 42 |
assert.Equal(t, jaeger_api_v2.SamplingStrategyType_PROBABILISTIC, resp.StrategyType) |
| 43 |
|
| 44 |
mockAgent.AddSamplingStrategy("service123", &jaeger_api_v2.SamplingStrategyResponse{ |
| 45 |
StrategyType: jaeger_api_v2.SamplingStrategyType_RATE_LIMITING, |
| 46 |
RateLimitingSampling: &jaeger_api_v2.RateLimitingSamplingStrategy{ |
| 47 |
MaxTracesPerSecond: 123, |
| 48 |
}, |
| 49 |
}) |
| 50 |
err = getJSON(t.Context(), "http://"+mockAgent.SamplingServerAddr()+"/?service=service123", &resp) |
| 51 |
require.NoError(t, err) |
| 52 |
assert.Equal(t, jaeger_api_v2.SamplingStrategyType_RATE_LIMITING, resp.StrategyType) |
| 53 |
require.NotNil(t, resp.RateLimitingSampling) |
| 54 |
assert.EqualValues(t, 123, resp.RateLimitingSampling.MaxTracesPerSecond) |
| 55 |
} |