Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Commit

Permalink
Fix strategyType (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
black-adder committed Apr 18, 2017
1 parent caac859 commit b830e0f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/_flow/sampler-thrift.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ declare type PerOperationSamplingStrategies = {
}

declare type SamplingStrategyResponse = {
strategyType: number,
strategyType: string,
probabilisticSampling?: ProbabilisticSamplingStrategy,
rateLimitingSampling?: RateLimitingSamplingStrategy,
operationSampling?: PerOperationSamplingStrategies
Expand Down
16 changes: 5 additions & 11 deletions src/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import SpanContext from './span_context';
import Span from './span';
import ConstSampler from './samplers/const_sampler';
import InMemoryReporter from './reporters/in_memory_reporter';
import ProbabilisticSampler from './samplers/probabilistic_sampler';
import RateLimitingSampler from './samplers/ratelimiting_sampler';
import RemoteReporter from './reporters/remote_reporter';
Expand Down Expand Up @@ -155,16 +152,18 @@ export default class Configuration {
* as process-level tags on the Tracer itself.
*/
static initTracer(config, options = {}) {
let reporters = [];
let reporter;
let sampler;
if (options.metrics) {
options.metrics = new Metrics(options.metrics);
}
if (config.disable) {
return new opentracing.Tracer();
} else {
if (config.sampler) {
sampler = Configuration._getSampler(config);
} else {
sampler = new RemoteSampler(config.serviceName);
sampler = new RemoteSampler(config.serviceName, options);
}

if (!options.reporter) {
Expand All @@ -180,17 +179,12 @@ export default class Configuration {
);
}

var metrics = null;
if (options.metrics) {
metrics = new Metrics(options.metrics);
}

return new Tracer(
config.serviceName,
reporter,
sampler,
{
metrics: metrics,
metrics: options.metrics,
logger: options.logger,
tags: options.tags
}
Expand Down
4 changes: 2 additions & 2 deletions src/samplers/remote_sampler.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ const DEFAULT_REFRESH_INTERVAL = 60000;
const DEFAULT_MAX_OPERATIONS = 2000;
const DEFAULT_SAMPLING_HOST = '0.0.0.0';
const DEFAULT_SAMPLING_PORT = 5778;
const PROBABILISTIC_STRATEGY_TYPE = 0;
const RATELIMITING_STRATEGY_TYPE = 1;
const PROBABILISTIC_STRATEGY_TYPE = 'PROBABILISTIC';
const RATELIMITING_STRATEGY_TYPE = 'RATE_LIMITING';

export default class RemoteControlledSampler {

Expand Down
8 changes: 4 additions & 4 deletions test/samplers/remote_sampler.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe('RemoteSampler', () => {
remoteSampler._refreshSamplingStrategy();
};
server.addStrategy('service1', {
strategyType: 0,
strategyType: 'PROBABILISTIC',
probabilisticSampling: {
samplingRate: 1.0
}
Expand All @@ -129,7 +129,7 @@ describe('RemoteSampler', () => {
done();
};
server.addStrategy('service1', {
strategyType: 1,
strategyType: 'RATE_LIMITING',
rateLimitingSampling: {
maxTracesPerSecond: maxTracesPerSecond
}
Expand All @@ -139,7 +139,7 @@ describe('RemoteSampler', () => {

it('should set per-operation sampler', (done) => {
server.addStrategy('service1', {
strategyType: 0,
strategyType: 'PROBABILISTIC',
probabilisticSampling: {
samplingRate: 1.0
},
Expand Down Expand Up @@ -168,7 +168,7 @@ describe('RemoteSampler', () => {

it('should refresh periodically', (done) => {
server.addStrategy('service1', {
strategyType: 0,
strategyType: 'PROBABILISTIC',
probabilisticSampling: {
samplingRate: 0.777
}
Expand Down

0 comments on commit b830e0f

Please sign in to comment.