Skip to content

Commit e877f37

Browse files
authored
fix: send satic labels as series labels, not dynamic labels (#43)
1 parent 900baf9 commit e877f37

File tree

7 files changed

+37
-27
lines changed

7 files changed

+37
-27
lines changed

profiler/src/ProfilerEngine/Datadog.Profiler.Native/CorProfilerCallback.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,11 +398,11 @@ bool CorProfilerCallback::InitializeServices()
398398
_pConfiguration->PyroscopeBasicAuthUser(),
399399
_pConfiguration->PyroscopeBasicAuthPassword(),
400400
_pConfiguration->PyroscopeTenantID(),
401-
PyroscopePprofSink::ParseHeadersJSON(std::move(_pConfiguration->PyroscopeHttpHeaders())));
401+
PyroscopePprofSink::ParseHeadersJSON(std::move(_pConfiguration->PyroscopeHttpHeaders())),
402+
_pConfiguration->GetUserTags());
402403
_pExporter = std::make_unique<PprofExporter>(_pApplicationStore,
403404
_pyroscopePprofSink,
404-
sampleTypeDefinitions,
405-
_pConfiguration->GetUserTags());
405+
sampleTypeDefinitions);
406406

407407
_pSamplesCollector = RegisterService<SamplesCollector>(
408408
_pConfiguration.get(),

profiler/src/ProfilerEngine/Datadog.Profiler.Native/PprofBuilder.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
#include "PprofBuilder.h"
66
#include "Log.h"
77

8-
PprofBuilder::PprofBuilder(std::vector<SampleValueType>& sampleTypeDefinitions,
9-
std::vector<std::pair<std::string, std::string>>& staticTags) :
10-
_sampleTypeDefinitions(sampleTypeDefinitions), _staticTags(staticTags)
8+
PprofBuilder::PprofBuilder(std::vector<SampleValueType>& sampleTypeDefinitions) :
9+
_sampleTypeDefinitions(sampleTypeDefinitions)
1110
{
1211
Reset();
1312
}
@@ -38,12 +37,6 @@ void PprofBuilder::AddSample(const Sample& sample)
3837
pLabel->set_str(AddString(*label.second.Get()));
3938
}
4039
}
41-
for (const auto& tag : _staticTags)
42-
{
43-
auto* pLabel = pSample->add_label();
44-
pLabel->set_key(AddString(tag.first));
45-
pLabel->set_str(AddString(tag.second));
46-
}
4740
_samplesCount++;
4841
}
4942

profiler/src/ProfilerEngine/Datadog.Profiler.Native/PprofBuilder.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ class PprofBuilder
1616
{
1717

1818
public:
19-
PprofBuilder(std::vector<SampleValueType>& sampleTypeDefinitions,
20-
std::vector<std::pair<std::string, std::string>>& staticTags);
19+
PprofBuilder(std::vector<SampleValueType>& sampleTypeDefinitions);
2120

2221
void AddSample(const Sample& sample);
2322
int SamplesCount();
@@ -35,5 +34,4 @@ class PprofBuilder
3534
std::map<std::pair<int64_t, int64_t>, int64_t> _locations;
3635
std::vector<SampleValueType>& _sampleTypeDefinitions;
3736

38-
std::vector<std::pair<std::string, std::string>> _staticTags;
3937
};

profiler/src/ProfilerEngine/Datadog.Profiler.Native/PprofExporter.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88

99
PprofExporter::PprofExporter(IApplicationStore* applicationStore,
1010
std::shared_ptr<PProfExportSink> sink,
11-
std::vector<SampleValueType> sampleTypeDefinitions,
12-
const std::vector<std::pair<std::string, std::string>>& staticTags) :
11+
std::vector<SampleValueType> sampleTypeDefinitions
12+
) :
1313
_applicationStore(applicationStore),
1414
_sink(std::move(sink)),
15-
_sampleTypeDefinitions(sampleTypeDefinitions),
16-
_staticTags(staticTags)
15+
_sampleTypeDefinitions(sampleTypeDefinitions)
1716
{
1817
signal(SIGPIPE, SIG_IGN);
1918
}
@@ -60,7 +59,7 @@ PprofBuilder& PprofExporter::GetPprofBuilder(std::string_view runtimeId)
6059
{
6160
return *it->second;
6261
}
63-
auto instance = std::make_unique<PprofBuilder>(_sampleTypeDefinitions, _staticTags);
62+
auto instance = std::make_unique<PprofBuilder>(_sampleTypeDefinitions);
6463
auto res = _perAppBuilder.emplace(runtimeId, std::move(instance));
6564
return *res.first->second;
6665
}

profiler/src/ProfilerEngine/Datadog.Profiler.Native/PprofExporter.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ class PprofExporter : public IExporter
3636
public:
3737
PprofExporter(IApplicationStore* _applicationStore,
3838
std::shared_ptr<PProfExportSink> sin,
39-
std::vector<SampleValueType> sampleTypeDefinitions,
40-
const std::vector<std::pair<std::string, std::string>>& staticTags
39+
std::vector<SampleValueType> sampleTypeDefinitions
4140
);
4241
void Add(std::shared_ptr<Sample> const& sample) override;
4342
void SetEndpoint(const std::string& runtimeId, uint64_t traceId, const std::string& endpoint) override;
@@ -51,6 +50,4 @@ class PprofExporter : public IExporter
5150
std::vector<SampleValueType> _sampleTypeDefinitions;
5251
std::unordered_map<std::string_view, std::unique_ptr<PprofBuilder>> _perAppBuilder;
5352
std::mutex _perAppBuilderLock;
54-
std::vector<std::pair<std::string, std::string>> _staticTags;
55-
5653
};

profiler/src/ProfilerEngine/Datadog.Profiler.Native/PyroscopePprofSink.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ PyroscopePprofSink::PyroscopePprofSink(
1515
std::string basicAuthUser,
1616
std::string basicAuthPassword,
1717
std::string tenantID,
18-
std::map<std::string, std::string> extraHeaders) :
18+
std::map<std::string, std::string> extraHeaders,
19+
const std::vector<std::pair<std::string, std::string>>& staticTags) :
1920
_appName(appName),
21+
_appNameWithLabels(AppNameWithLabels(appName, staticTags)),
2022
_url(server),
2123
_authToken(authToken),
2224
_basicAuthUser(basicAuthUser),
@@ -144,7 +146,7 @@ void PyroscopePprofSink::upload(Pprof pprof, ProfileTime& startTime, ProfileTime
144146

145147
std::string path = Url()
146148
.path(_url.path() + "/ingest")
147-
.add_query("name", _appName)
149+
.add_query("name", _appNameWithLabels)
148150
.add_query("from", std::to_string(startTime.time_since_epoch().count()))
149151
.add_query("until", std::to_string(endTime.time_since_epoch().count()))
150152
.add_query("spyName", "dotnetspy")
@@ -218,6 +220,24 @@ std::string PyroscopePprofSink::SchemeHostPort(Url& url)
218220
return res;
219221
}
220222

223+
std::string PyroscopePprofSink::AppNameWithLabels(const std::string& appName, const std::vector<std::pair<std::string, std::string>>& staticTags)
224+
{
225+
std::stringstream app_name_builder;
226+
app_name_builder << appName << "{";
227+
int i = 0;
228+
for (const auto& item : staticTags)
229+
{
230+
if (i != 0)
231+
{
232+
app_name_builder << ",";
233+
}
234+
app_name_builder << item.first << "=" << item.second;
235+
i++;
236+
}
237+
app_name_builder << "}";
238+
return app_name_builder.str();
239+
}
240+
221241
std::map<std::string, std::string> PyroscopePprofSink::ParseHeadersJSON(std::string headers)
222242
{
223243
std::map<std::string, std::string> result;

profiler/src/ProfilerEngine/Datadog.Profiler.Native/PyroscopePprofSink.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class PyroscopePprofSink : public PProfExportSink
2121
std::string tenantID,
2222
std::string basicAuthUser,
2323
std::string basicAuthPassword,
24-
std::map<std::string, std::string> extraHeaders);
24+
std::map<std::string, std::string> extraHeaders,
25+
const std::vector<std::pair<std::string, std::string>>& staticTags);
2526
~PyroscopePprofSink() override;
2627
void Export(Pprof pprof, ProfileTime& startTime, ProfileTime& endTime) override;
2728
void SetAuthToken(std::string authToken);
@@ -30,6 +31,7 @@ class PyroscopePprofSink : public PProfExportSink
3031

3132
private:
3233
static std::string SchemeHostPort(Url& url);
34+
static std::string AppNameWithLabels(const std::string& appName, const std::vector<std::pair<std::string, std::string>>& staticTags);
3335

3436
struct PyroscopeRequest
3537
{
@@ -43,6 +45,7 @@ class PyroscopePprofSink : public PProfExportSink
4345
httplib::Headers getHeaders();
4446

4547
std::string _appName;
48+
std::string _appNameWithLabels;
4649
Url _url;
4750
httplib::Client _client;
4851
std::atomic<bool> _running;

0 commit comments

Comments
 (0)