]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/jaeger-client-cpp/src/jaegertracing/samplers/RateLimitingSampler.h
2 * Copyright (c) 2017 Uber Technologies, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef JAEGERTRACING_SAMPLERS_RATELIMITINGSAMPLER_H
18 #define JAEGERTRACING_SAMPLERS_RATELIMITINGSAMPLER_H
20 #include "jaegertracing/Compilers.h"
22 #include "jaegertracing/Constants.h"
23 #include "jaegertracing/Tag.h"
24 #include "jaegertracing/samplers/Sampler.h"
25 #include "jaegertracing/samplers/SamplingStatus.h"
26 #include "jaegertracing/utils/RateLimiter.h"
31 namespace jaegertracing
{
33 } // namespace jaegertracing
35 namespace jaegertracing
{
38 class RateLimitingSampler
: public Sampler
{
40 explicit RateLimitingSampler(double maxTracesPerSecond
)
41 : _maxTracesPerSecond(maxTracesPerSecond
)
42 , _rateLimiter(_maxTracesPerSecond
, std::max(_maxTracesPerSecond
, 1.0))
43 , _tags({ { kSamplerTypeTagKey
, kSamplerTypeRateLimiting
},
44 { kSamplerParamTagKey
, maxTracesPerSecond
} })
48 SamplingStatus
isSampled(const TraceID
& id
,
49 const std::string
& operation
) override
51 return SamplingStatus(_rateLimiter
.checkCredit(1), _tags
);
54 void close() override
{}
56 Type
type() const override
{ return Type::kRateLimitingSampler
; }
59 double _maxTracesPerSecond
;
60 utils::RateLimiter
<> _rateLimiter
;
61 std::vector
<Tag
> _tags
;
64 } // namespace samplers
65 } // namespace jaegertracing
67 #endif // JAEGERTRACING_SAMPLERS_RATELIMITINGSAMPLER_H