Skip to content

Commit 25286d4

Browse files
authored
Create separate trace id for BlobStorage requests and link them to original traces (#6444)
1 parent d72f1e4 commit 25286d4

19 files changed

+189
-68
lines changed

ydb/core/base/blobstorage.cpp

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#include "blobstorage.h"
2+
#include <ydb/library/actors/wilson/wilson_span.h>
3+
#include <ydb/library/wilson_ids/wilson.h>
24

35
namespace NKikimr {
46

@@ -44,13 +46,49 @@ bool operator<(const TPDiskCategory x, const TPDiskCategory y) {
4446
return std::make_tuple(x.Type(), x.Kind()) < std::make_tuple(y.Type(), y.Kind());
4547
}
4648

49+
void TEvBlobStorage::TEvPut::ToSpan(NWilson::TSpan& span) const {
50+
span
51+
.Attribute("Id", Id.ToString())
52+
.Attribute("PutHandleClass", NKikimrBlobStorage::EPutHandleClass_Name(HandleClass));
53+
}
54+
4755
std::unique_ptr<TEvBlobStorage::TEvPutResult> TEvBlobStorage::TEvPut::MakeErrorResponse(
4856
NKikimrProto::EReplyStatus status, const TString& errorReason, TGroupId groupId) {
4957
auto res = std::make_unique<TEvPutResult>(status, Id, TStorageStatusFlags(), groupId, 0.0f);
5058
res->ErrorReason = errorReason;
5159
return res;
5260
}
5361

62+
void TEvBlobStorage::TEvGet::ToSpan(NWilson::TSpan& span) const {
63+
i64 totalSize = 0;
64+
for (ui32 i = 0; i < QuerySize; ++i) {
65+
const auto& q = Queries[i];
66+
if (q.Shift < q.Id.BlobSize()) {
67+
totalSize += Min<size_t>(q.Id.BlobSize() - q.Shift, q.Size ? q.Size : Max<size_t>());
68+
}
69+
}
70+
71+
span
72+
.Attribute("TotalSize", totalSize)
73+
.Attribute("GetHandleClass", NKikimrBlobStorage::EGetHandleClass_Name(GetHandleClass))
74+
.Attribute("MustRestoreFirst", MustRestoreFirst)
75+
.Attribute("IsIndexOnly", IsIndexOnly);
76+
77+
if (span.GetTraceId().GetVerbosity() >= TWilson::DsProxyInternals) {
78+
NWilson::TArrayValue queries;
79+
queries.reserve(QuerySize);
80+
for (ui32 i = 0; i < QuerySize; ++i) {
81+
const auto& q = Queries[i];
82+
queries.emplace_back(NWilson::TKeyValueList{{
83+
{"Id", q.Id.ToString()},
84+
{"Shift", q.Shift},
85+
{"Size", q.Size},
86+
}});
87+
}
88+
span.Attribute("Queries", std::move(queries));
89+
}
90+
}
91+
5492
std::unique_ptr<TEvBlobStorage::TEvGetResult> TEvBlobStorage::TEvGet::MakeErrorResponse(
5593
NKikimrProto::EReplyStatus status, const TString& errorReason, TGroupId groupId) {
5694
auto res = std::make_unique<TEvGetResult>(status, QuerySize, groupId);
@@ -67,55 +105,128 @@ std::unique_ptr<TEvBlobStorage::TEvGetResult> TEvBlobStorage::TEvGet::MakeErrorR
67105
return res;
68106
}
69107

108+
void TEvBlobStorage::TEvBlock::ToSpan(NWilson::TSpan& span) const {
109+
span
110+
.Attribute("TabletId", ::ToString(TabletId))
111+
.Attribute("Generation", Generation);
112+
}
113+
70114
std::unique_ptr<TEvBlobStorage::TEvBlockResult> TEvBlobStorage::TEvBlock::MakeErrorResponse(
71115
NKikimrProto::EReplyStatus status, const TString& errorReason, TGroupId /*groupId*/) {
72116
auto res = std::make_unique<TEvBlockResult>(status);
73117
res->ErrorReason = errorReason;
74118
return res;
75119
}
76120

121+
void TEvBlobStorage::TEvPatch::ToSpan(NWilson::TSpan& span) const {
122+
span
123+
.Attribute("OriginalGroupId", OriginalGroupId)
124+
.Attribute("OriginalId", OriginalId.ToString())
125+
.Attribute("PatchedId", PatchedId.ToString());
126+
}
127+
77128
std::unique_ptr<TEvBlobStorage::TEvPatchResult> TEvBlobStorage::TEvPatch::MakeErrorResponse(
78129
NKikimrProto::EReplyStatus status, const TString& errorReason, TGroupId groupId) {
79130
auto res = std::make_unique<TEvPatchResult>(status, PatchedId, TStorageStatusFlags(), groupId, 0.0f);
80131
res->ErrorReason = errorReason;
81132
return res;
82133
}
83134

135+
void TEvBlobStorage::TEvInplacePatch::ToSpan(NWilson::TSpan& /*span*/) const {
136+
}
137+
84138
std::unique_ptr<TEvBlobStorage::TEvInplacePatchResult> TEvBlobStorage::TEvInplacePatch::MakeErrorResponse(
85139
NKikimrProto::EReplyStatus status, const TString& errorReason) {
86140
auto res = std::make_unique<TEvInplacePatchResult>(status, PatchedId, TStorageStatusFlags(), 0.0f);
87141
res->ErrorReason = errorReason;
88142
return res;
89143
}
90144

145+
void TEvBlobStorage::TEvDiscover::ToSpan(NWilson::TSpan& span) const {
146+
span
147+
.Attribute("TabletId", ::ToString(TabletId))
148+
.Attribute("ReadBody", ReadBody);
149+
}
150+
91151
std::unique_ptr<TEvBlobStorage::TEvDiscoverResult> TEvBlobStorage::TEvDiscover::MakeErrorResponse(
92152
NKikimrProto::EReplyStatus status, const TString& errorReason, TGroupId/*groupId*/) {
93153
auto res = std::make_unique<TEvDiscoverResult>(status, MinGeneration, 0);
94154
res->ErrorReason = errorReason;
95155
return res;
96156
}
97157

158+
void TEvBlobStorage::TEvRange::ToSpan(NWilson::TSpan& span) const {
159+
span
160+
.Attribute("TabletId", ::ToString(TabletId))
161+
.Attribute("From", From.ToString())
162+
.Attribute("To", To.ToString())
163+
.Attribute("MustRestoreFirst", MustRestoreFirst)
164+
.Attribute("IsIndexOnly", IsIndexOnly);
165+
}
166+
98167
std::unique_ptr<TEvBlobStorage::TEvRangeResult> TEvBlobStorage::TEvRange::MakeErrorResponse(
99168
NKikimrProto::EReplyStatus status, const TString& errorReason, TGroupId groupId) {
100169
auto res = std::make_unique<TEvRangeResult>(status, From, To, groupId);
101170
res->ErrorReason = errorReason;
102171
return res;
103172
}
104173

174+
void TEvBlobStorage::TEvCollectGarbage::ToSpan(NWilson::TSpan& span) const {
175+
span
176+
.Attribute("TabletId", ::ToString(TabletId))
177+
.Attribute("RecordGeneration", RecordGeneration)
178+
.Attribute("PerGenerationCounter", PerGenerationCounter)
179+
.Attribute("Channel", Channel);
180+
181+
if (Collect) {
182+
span
183+
.Attribute("CollectGeneration", CollectGeneration)
184+
.Attribute("CollectStep", CollectStep);
185+
}
186+
187+
if (span.GetTraceId().GetVerbosity() >= TWilson::DsProxyInternals) {
188+
auto vector = [&](const auto& name, const auto& v) {
189+
if (v) {
190+
NWilson::TArrayValue items;
191+
items.reserve(v->size());
192+
for (const TLogoBlobID& id : *v) {
193+
items.emplace_back(id.ToString());
194+
}
195+
span.Attribute(name, std::move(items));
196+
}
197+
};
198+
vector("Keep", Keep);
199+
vector("DoNotKeep", DoNotKeep);
200+
} else {
201+
if (Keep) {
202+
span.Attribute("NumKeep", static_cast<i64>(Keep->size()));
203+
}
204+
if (DoNotKeep) {
205+
span.Attribute("NumDoNotKeep", static_cast<i64>(DoNotKeep->size()));
206+
}
207+
}
208+
}
209+
105210
std::unique_ptr<TEvBlobStorage::TEvCollectGarbageResult> TEvBlobStorage::TEvCollectGarbage::MakeErrorResponse(
106211
NKikimrProto::EReplyStatus status, const TString& errorReason, TGroupId /*groupId*/) {
107212
auto res = std::make_unique<TEvCollectGarbageResult>(status, TabletId, RecordGeneration, PerGenerationCounter, Channel);
108213
res->ErrorReason = errorReason;
109214
return res;
110215
}
111216

217+
void TEvBlobStorage::TEvStatus::ToSpan(NWilson::TSpan& /*span*/) const
218+
{}
219+
112220
std::unique_ptr<TEvBlobStorage::TEvStatusResult> TEvBlobStorage::TEvStatus::MakeErrorResponse(
113221
NKikimrProto::EReplyStatus status, const TString& errorReason, TGroupId /*groupId*/) {
114222
auto res = std::make_unique<TEvStatusResult>(status, TStorageStatusFlags());
115223
res->ErrorReason = errorReason;
116224
return res;
117225
}
118226

227+
void TEvBlobStorage::TEvAssimilate::ToSpan(NWilson::TSpan& /*span*/) const
228+
{}
229+
119230
std::unique_ptr<TEvBlobStorage::TEvAssimilateResult> TEvBlobStorage::TEvAssimilate::MakeErrorResponse(
120231
NKikimrProto::EReplyStatus status, const TString& errorReason, TGroupId/*groupId*/) {
121232
return std::make_unique<TEvBlobStorage::TEvAssimilateResult>(status, errorReason);

ydb/core/base/blobstorage.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525

2626
#include <optional>
2727

28+
namespace NWilson {
29+
class TSpan;
30+
} // NWilson
31+
2832
namespace NKikimr {
2933

3034
static constexpr ui32 MaxProtobufSize = 67108000;
@@ -993,6 +997,8 @@ struct TEvBlobStorage {
993997
return sizeof(*this) + Buffer.GetSize();
994998
}
995999

1000+
void ToSpan(NWilson::TSpan& span) const;
1001+
9961002
std::unique_ptr<TEvPutResult> MakeErrorResponse(NKikimrProto::EReplyStatus status, const TString& errorReason,
9971003
TGroupId groupId);
9981004
};
@@ -1196,6 +1202,8 @@ struct TEvBlobStorage {
11961202
return sizeof(*this) + QuerySize * sizeof(TQuery);
11971203
}
11981204

1205+
void ToSpan(NWilson::TSpan& span) const;
1206+
11991207
std::unique_ptr<TEvGetResult> MakeErrorResponse(NKikimrProto::EReplyStatus status, const TString& errorReason,
12001208
TGroupId groupId);
12011209

@@ -1349,6 +1357,8 @@ struct TEvBlobStorage {
13491357
return sizeof(*this);
13501358
}
13511359

1360+
void ToSpan(NWilson::TSpan& span) const;
1361+
13521362
std::unique_ptr<TEvBlockResult> MakeErrorResponse(NKikimrProto::EReplyStatus status, const TString& errorReason,
13531363
TGroupId groupId);
13541364
};
@@ -1546,6 +1556,8 @@ struct TEvBlobStorage {
15461556
return sizeof(*this) + sizeof(TDiff) * DiffCount;
15471557
}
15481558

1559+
void ToSpan(NWilson::TSpan& span) const;
1560+
15491561
std::unique_ptr<TEvPatchResult> MakeErrorResponse(NKikimrProto::EReplyStatus status,
15501562
const TString& errorReason, TGroupId groupId);
15511563
};
@@ -1636,6 +1648,8 @@ struct TEvBlobStorage {
16361648
return sizeof(*this) + sizeof(TDiff) * DiffCount;
16371649
}
16381650

1651+
void ToSpan(NWilson::TSpan& span) const;
1652+
16391653
std::unique_ptr<TEvInplacePatchResult> MakeErrorResponse(NKikimrProto::EReplyStatus status,
16401654
const TString& errorReason);
16411655
};
@@ -1723,6 +1737,8 @@ struct TEvBlobStorage {
17231737
return sizeof(*this);
17241738
}
17251739

1740+
void ToSpan(NWilson::TSpan& span) const;
1741+
17261742
std::unique_ptr<TEvDiscoverResult> MakeErrorResponse(NKikimrProto::EReplyStatus status, const TString& errorReason,
17271743
TGroupId groupId);
17281744
};
@@ -1828,6 +1844,8 @@ struct TEvBlobStorage {
18281844
return sizeof(*this);
18291845
}
18301846

1847+
void ToSpan(NWilson::TSpan& span) const;
1848+
18311849
std::unique_ptr<TEvRangeResult> MakeErrorResponse(NKikimrProto::EReplyStatus status, const TString& errorReason,
18321850
TGroupId groupId);
18331851
};
@@ -2023,6 +2041,8 @@ struct TEvBlobStorage {
20232041
return sizeof(*this) + ((Keep ? Keep->size() : 0) + (DoNotKeep ? DoNotKeep->size() : 0)) * sizeof(TLogoBlobID);
20242042
}
20252043

2044+
void ToSpan(NWilson::TSpan& span) const;
2045+
20262046
std::unique_ptr<TEvCollectGarbageResult> MakeErrorResponse(NKikimrProto::EReplyStatus status, const TString& errorReason,
20272047
TGroupId groupId);
20282048
};
@@ -2091,6 +2111,8 @@ struct TEvBlobStorage {
20912111
return sizeof(*this);
20922112
}
20932113

2114+
void ToSpan(NWilson::TSpan& span) const;
2115+
20942116
std::unique_ptr<TEvStatusResult> MakeErrorResponse(NKikimrProto::EReplyStatus status, const TString& errorReason,
20952117
TGroupId groupId);
20962118
};
@@ -2166,6 +2188,8 @@ struct TEvBlobStorage {
21662188
return sizeof(*this);
21672189
}
21682190

2191+
void ToSpan(NWilson::TSpan& span) const;
2192+
21692193
std::unique_ptr<TEvAssimilateResult> MakeErrorResponse(NKikimrProto::EReplyStatus status, const TString& errorReason,
21702194
TGroupId groupId);
21712195
};

ydb/core/blobstorage/dsproxy/dsproxy.h

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,20 @@ class TBlobStorageGroupRequestActor : public TActor<TDerived> {
175175
return NKikimrServices::TActivity::BS_GROUP_REQUEST;
176176
}
177177

178+
template<typename TEv>
178179
TBlobStorageGroupRequestActor(TIntrusivePtr<TBlobStorageGroupInfo> info, TIntrusivePtr<TGroupQueues> groupQueues,
179180
TIntrusivePtr<TBlobStorageGroupProxyMon> mon, const TActorId& source, ui64 cookie,
180181
NKikimrServices::EServiceKikimr logComponent, bool logAccEnabled, TMaybe<TGroupStat::EKind> latencyQueueKind,
181182
TInstant now, TIntrusivePtr<TStoragePoolCounters> &storagePoolCounters, ui32 restartCounter,
182-
NWilson::TSpan&& span, std::shared_ptr<TEvBlobStorage::TExecutionRelay> executionRelay)
183+
NWilson::TTraceId&& traceId, const char *name, const TEv *event,
184+
std::shared_ptr<TEvBlobStorage::TExecutionRelay> executionRelay)
183185
: TActor<TDerived>(&TThis::InitialStateFunc, TDerived::ActorActivityType())
184186
, Info(std::move(info))
185187
, GroupQueues(std::move(groupQueues))
186188
, Mon(std::move(mon))
187189
, PoolCounters(storagePoolCounters)
188190
, LogCtx(logComponent, logAccEnabled)
189-
, Span(std::move(span))
191+
, ParentSpan(TWilson::BlobStorage, std::move(traceId), name)
190192
, RestartCounter(restartCounter)
191193
, CostModel(GroupQueues->CostModel)
192194
, Source(source)
@@ -197,9 +199,16 @@ class TBlobStorageGroupRequestActor : public TActor<TDerived> {
197199
, ExecutionRelay(std::move(executionRelay))
198200
{
199201
TDerived::ActiveCounter(Mon)->Inc();
200-
Span
201-
.Attribute("GroupId", Info->GroupID.GetRawId())
202-
.Attribute("RestartCounter", RestartCounter);
202+
203+
if (ParentSpan) {
204+
const NWilson::TTraceId& parentTraceId = ParentSpan.GetTraceId();
205+
Span = NWilson::TSpan(TWilson::BlobStorage, NWilson::TTraceId::NewTraceId(parentTraceId.GetVerbosity(),
206+
parentTraceId.GetTimeToLive()), ParentSpan.GetName());
207+
ParentSpan.Link(Span.GetTraceId());
208+
Span.Attribute("GroupId", Info->GroupID.GetRawId());
209+
Span.Attribute("RestartCounter", RestartCounter);
210+
event->ToSpan(Span);
211+
}
203212

204213
Y_ABORT_UNLESS(CostModel);
205214
}
@@ -561,8 +570,10 @@ class TBlobStorageGroupRequestActor : public TActor<TDerived> {
561570

562571
if (term) {
563572
if (status == NKikimrProto::OK) {
573+
ParentSpan.EndOk();
564574
Span.EndOk();
565575
} else {
576+
ParentSpan.EndError(errorReason);
566577
Span.EndError(std::move(errorReason));
567578
}
568579
}
@@ -608,6 +619,7 @@ class TBlobStorageGroupRequestActor : public TActor<TDerived> {
608619
TIntrusivePtr<TBlobStorageGroupProxyMon> Mon;
609620
TIntrusivePtr<TStoragePoolCounters> PoolCounters;
610621
TLogContext LogCtx;
622+
NWilson::TSpan ParentSpan;
611623
NWilson::TSpan Span;
612624
TStackVec<std::pair<TDiskResponsivenessTracker::TDiskId, TDuration>, 16> Responsiveness;
613625
TString ErrorReason;

ydb/core/blobstorage/dsproxy/dsproxy_assimilate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class TBlobStorageGroupAssimilateRequest : public TBlobStorageGroupRequestActor<
270270
NWilson::TTraceId traceId, TInstant now, TIntrusivePtr<TStoragePoolCounters>& storagePoolCounters)
271271
: TBlobStorageGroupRequestActor(info, state, mon, source, cookie,
272272
NKikimrServices::BS_PROXY_ASSIMILATE, false, {}, now, storagePoolCounters, ev->RestartCounter,
273-
NWilson::TSpan(TWilson::BlobStorage, std::move(traceId), "DSProxy.Assimilate"), std::move(ev->ExecutionRelay))
273+
std::move(traceId), "DSProxy.Assimilate", ev, std::move(ev->ExecutionRelay))
274274
, SkipBlocksUpTo(ev->SkipBlocksUpTo)
275275
, SkipBarriersUpTo(ev->SkipBarriersUpTo)
276276
, SkipBlobsUpTo(ev->SkipBlobsUpTo)

ydb/core/blobstorage/dsproxy/dsproxy_block.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ class TBlobStorageGroupBlockRequest : public TBlobStorageGroupRequestActor<TBlob
135135
TBlobStorageGroupBlockRequest(const TIntrusivePtr<TBlobStorageGroupInfo> &info,
136136
const TIntrusivePtr<TGroupQueues> &state, const TActorId &source,
137137
const TIntrusivePtr<TBlobStorageGroupProxyMon> &mon, TEvBlobStorage::TEvBlock *ev,
138-
ui64 cookie, NWilson::TSpan&& span, TInstant now,
138+
ui64 cookie, NWilson::TTraceId&& traceId, TInstant now,
139139
TIntrusivePtr<TStoragePoolCounters> &storagePoolCounters)
140140
: TBlobStorageGroupRequestActor(info, state, mon, source, cookie,
141141
NKikimrServices::BS_PROXY_BLOCK, false, {}, now, storagePoolCounters, ev->RestartCounter,
142-
std::move(span), std::move(ev->ExecutionRelay))
142+
std::move(traceId), "DSProxy.Block", ev, std::move(ev->ExecutionRelay))
143143
, TabletId(ev->TabletId)
144144
, Generation(ev->Generation)
145145
, Deadline(ev->Deadline)
@@ -179,12 +179,7 @@ IActor* CreateBlobStorageGroupBlockRequest(const TIntrusivePtr<TBlobStorageGroup
179179
const TIntrusivePtr<TGroupQueues> &state, const TActorId &source,
180180
const TIntrusivePtr<TBlobStorageGroupProxyMon> &mon, TEvBlobStorage::TEvBlock *ev,
181181
ui64 cookie, NWilson::TTraceId traceId, TInstant now, TIntrusivePtr<TStoragePoolCounters> &storagePoolCounters) {
182-
NWilson::TSpan span(TWilson::BlobStorage, std::move(traceId), "DSProxy.Block");
183-
if (span) {
184-
span.Attribute("event", ev->ToString());
185-
}
186-
187-
return new TBlobStorageGroupBlockRequest(info, state, source, mon, ev, cookie, std::move(span), now, storagePoolCounters);
182+
return new TBlobStorageGroupBlockRequest(info, state, source, mon, ev, cookie, std::move(traceId), now, storagePoolCounters);
188183
}
189184

190185
} // NKikimr

ydb/core/blobstorage/dsproxy/dsproxy_collect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class TBlobStorageGroupCollectGarbageRequest : public TBlobStorageGroupRequestAc
147147
NWilson::TTraceId traceId, TInstant now, TIntrusivePtr<TStoragePoolCounters> &storagePoolCounters)
148148
: TBlobStorageGroupRequestActor(info, state, mon, source, cookie,
149149
NKikimrServices::BS_PROXY_COLLECT, false, {}, now, storagePoolCounters, ev->RestartCounter,
150-
NWilson::TSpan(TWilson::BlobStorage, std::move(traceId), "DSProxy.CollectGarbage"), std::move(ev->ExecutionRelay))
150+
std::move(traceId), "DSProxy.CollectGarbage", ev, std::move(ev->ExecutionRelay))
151151
, TabletId(ev->TabletId)
152152
, RecordGeneration(ev->RecordGeneration)
153153
, PerGenerationCounter(ev->PerGenerationCounter)

0 commit comments

Comments
 (0)