-
Notifications
You must be signed in to change notification settings - Fork 589
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor tracing configurator to be available from actor system threa…
…ds (#12067)
- Loading branch information
1 parent
b2da93a
commit 4f81e50
Showing
16 changed files
with
147 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include "wilson_tracing_control.h" | ||
|
||
#include <ydb/core/base/appdata_fwd.h> | ||
#include <ydb/core/jaeger_tracing/sampling_throttling_configurator.h> | ||
#include <ydb/core/jaeger_tracing/sampling_throttling_control.h> | ||
|
||
#include <util/thread/singleton.h> | ||
#include <util/system/compiler.h> | ||
#include <util/system/tls.h> | ||
#include <util/system/yassert.h> | ||
|
||
namespace NKikimr::NJaegerTracing { | ||
|
||
namespace { | ||
|
||
Y_POD_STATIC_THREAD(TSamplingThrottlingControl*) TracingControlRawPtr; | ||
|
||
class TSamplingThrottlingControlTlsHolder { | ||
public: | ||
TSamplingThrottlingControlTlsHolder() | ||
: Control(CreateNewTracingControl()) | ||
{} | ||
|
||
TSamplingThrottlingControl* GetTracingControlPtr() { | ||
if (Y_UNLIKELY(!Control)) { | ||
Control = CreateNewTracingControl(); | ||
} | ||
return Control.Get(); | ||
} | ||
|
||
void ResetTracingControl() { | ||
Control = nullptr; | ||
} | ||
|
||
private: | ||
static TIntrusivePtr<TSamplingThrottlingControl> CreateNewTracingControl() { | ||
Y_ASSERT(HasAppData()); // In general we must call this from actor thread | ||
if (Y_UNLIKELY(!HasAppData())) { | ||
return nullptr; | ||
} | ||
|
||
return AppData()->TracingConfigurator->GetControl(); | ||
} | ||
|
||
private: | ||
TIntrusivePtr<TSamplingThrottlingControl> Control; | ||
}; | ||
|
||
TSamplingThrottlingControl* GetTracingControlTls() { | ||
if (Y_UNLIKELY(!TracingControlRawPtr)) { | ||
TracingControlRawPtr = FastTlsSingleton<TSamplingThrottlingControlTlsHolder>()->GetTracingControlPtr(); | ||
} | ||
return TracingControlRawPtr; | ||
} | ||
|
||
} // namespace | ||
|
||
void HandleTracing(NWilson::TTraceId& traceId, const TRequestDiscriminator& discriminator) { | ||
TSamplingThrottlingControl* control = GetTracingControlTls(); | ||
if (Y_LIKELY(control)) { | ||
control->HandleTracing(traceId, discriminator); | ||
} | ||
} | ||
|
||
void ClearTracingControl() { | ||
if (TracingControlRawPtr) { | ||
TracingControlRawPtr = nullptr; | ||
FastTlsSingleton<TSamplingThrottlingControlTlsHolder>()->ResetTracingControl(); | ||
} | ||
} | ||
|
||
} // namespace NKikimr::NJaegerTracing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
#include <ydb/core/jaeger_tracing/request_discriminator.h> | ||
#include <ydb/library/actors/wilson/wilson_trace.h> | ||
|
||
namespace NKikimr::NJaegerTracing { | ||
|
||
// Generate a new trace id (or throttle existing one) | ||
// with probability according to current configuration and request type. | ||
// Can be called from actor system threads. | ||
void HandleTracing(NWilson::TTraceId& traceId, const TRequestDiscriminator& discriminator); | ||
|
||
// For test purposes | ||
// Clears tracing control TLS variables that depend on AppData | ||
void ClearTracingControl(); | ||
|
||
} // namespace NKikimr::NJaegerTracing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.