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_BAGGAGE_REMOTERESTRICTIONMANAGER_H
18 #define JAEGERTRACING_BAGGAGE_REMOTERESTRICTIONMANAGER_H
21 #include <condition_variable>
25 #include <unordered_map>
27 #include "jaegertracing/Compilers.h"
29 #include "jaegertracing/Logging.h"
30 #include "jaegertracing/baggage/Restriction.h"
31 #include "jaegertracing/baggage/RestrictionManager.h"
32 #include "jaegertracing/metrics/Metrics.h"
33 #include "jaegertracing/net/IPAddress.h"
34 #include "jaegertracing/net/URI.h"
35 #include "jaegertracing/thrift-gen/BaggageRestrictionManager.h"
37 namespace jaegertracing
{
40 class RemoteRestrictionManager
: public RestrictionManager
{
42 using Clock
= std::chrono::steady_clock
;
43 using KeyRestrictionMap
= std::unordered_map
<std::string
, Restriction
>;
45 static constexpr auto kDefaultDenyBaggageOnInitializationFailure
= false;
46 static constexpr auto kDefaultMaxValueLength
=
47 DefaultRestrictionManager::kDefaultMaxValueLength
;
49 static Clock::duration
defaultRefreshInterval()
51 return std::chrono::minutes(1);
54 RemoteRestrictionManager(const std::string
& serviceName
,
55 const std::string
& hostPort
,
56 bool denyBaggageOnInitializationFailure
,
57 const Clock::duration
& refreshInterval
,
58 logging::Logger
& logger
,
59 metrics::Metrics
& metrics
);
61 ~RemoteRestrictionManager() { close(); }
63 Restriction
getRestriction(const std::string
& /* service */,
64 const std::string
& key
) override
;
66 void close() noexcept override
;
68 const Clock::duration
& refreshInterval() const { return _refreshInterval
; }
73 void updateRestrictions(const net::URI
& remoteURI
) noexcept
;
75 std::string _serviceName
;
76 net::IPAddress _serverAddress
;
77 bool _denyBaggageOnInitializationFailure
;
78 Clock::duration _refreshInterval
;
79 logging::Logger
& _logger
;
80 metrics::Metrics
& _metrics
;
81 KeyRestrictionMap _restrictions
;
85 std::condition_variable _cv
;
89 } // namespace baggage
90 } // namespace jaegertracing
92 #endif // JAEGERTRACING_BAGGAGE_REMOTERESTRICTIONMANAGER_H