Skip to content

Commit 8e585fe

Browse files
authored
Merge branch 'main' into dsn/reqwest
2 parents 2ed49d7 + 5974f2e commit 8e585fe

File tree

30 files changed

+2672
-34
lines changed

30 files changed

+2672
-34
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
.gitignore @Datadog/libdatadog
1212
.gitlab-ci.yml @Datadog/apm-common-components-core
1313
.gitlab/benchmarks.yml @Datadog/apm-common-components-core
14+
.gitlab/fuzz.yml @Datadog/chaos-platform
1415
benchmark/ @Datadog/apm-common-components-core
1516
bin_tests/ @Datadog/libdatadog-profiling
1617
build-common/ @Datadog/apm-common-components-core
@@ -64,6 +65,7 @@ tests/spawn_from_lib/ @Datadog/libdatadog-php @Datadog/libdatadog
6465
tests/windows_package/ @Datadog/apm-common-components-core
6566
tools/ @Datadog/apm-common-components-core
6667
windows/ @Datadog/libdatadog-core
68+
fuzz/ @Datadog/chaos-platform
6769

6870
# Specific overrides (must come after their general patterns above)
6971
bin_tests/tests/test_the_tests.rs @Datadog/libdatadog-core

.gitlab-ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ variables:
77

88
include:
99
- local: .gitlab/benchmarks.yml
10+
- local: .gitlab/fuzz.yml
1011

1112
trigger_internal_build:
1213
variables:

.gitlab/fuzz.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Fuzzing job configuration
2+
# This job discovers, builds, and uploads all cargo-fuzz targets to the internal fuzzing infrastructure
3+
# See ci/README_FUZZING.md for more information
4+
5+
variables:
6+
BASE_CI_IMAGE: registry.ddbuild.io/ci/benchmarking-platform:libdatadog-benchmarks
7+
8+
fuzz:
9+
tags: ["arch:amd64"]
10+
needs: []
11+
image:
12+
name: $BASE_CI_IMAGE
13+
rules:
14+
# runs on gitlab schedule and on merge to main.
15+
# Also allow manual run in branches for ease of debug / testing
16+
- if: '$CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE == "schedule"'
17+
allow_failure: true
18+
- if: $CI_COMMIT_BRANCH == "main"
19+
allow_failure: true
20+
- when: manual
21+
allow_failure: true
22+
timeout: 1h
23+
script:
24+
- VAULT_VERSION=1.15.4 && curl -fsSL "https://releases.hashicorp.com/vault/${VAULT_VERSION}/vault_${VAULT_VERSION}_linux_amd64.zip" -o vault.zip && unzip vault.zip && mv vault /usr/local/bin/vault && rm vault.zip && chmod +x /usr/local/bin/vault
25+
- rustup default nightly
26+
- cargo install cargo-fuzz
27+
- pip3 install requests toml
28+
- python3 fuzz/fuzz_infra.py
29+
allow_failure: true
30+
variables:
31+
KUBERNETES_SERVICE_ACCOUNT_OVERWRITE: libdatadog

Cargo.lock

Lines changed: 15 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ resolver = "2"
6565
[workspace.package]
6666
rust-version = "1.84.1"
6767
edition = "2021"
68-
version = "24.0.1"
68+
version = "25.0.0"
6969
license = "Apache-2.0"
7070
authors = ["Datadog Inc. <[email protected]>"]
7171

examples/ffi/profiles.c

Lines changed: 104 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#include <stdio.h>
77
#include <stdlib.h>
88

9+
// Number of samples to add with each API
10+
#define NUM_SAMPLES 5000000
11+
912
int main(void) {
1013
const ddog_prof_ValueType wall_time = {
1114
.type_ = DDOG_CHARSLICE_C("wall-time"),
@@ -14,16 +17,27 @@ int main(void) {
1417
const ddog_prof_Slice_ValueType sample_types = {&wall_time, 1};
1518
const ddog_prof_Period period = {wall_time, 60};
1619

17-
ddog_prof_Profile_NewResult new_result = ddog_prof_Profile_new(sample_types, &period);
18-
if (new_result.tag != DDOG_PROF_PROFILE_NEW_RESULT_OK) {
19-
ddog_CharSlice message = ddog_Error_message(&new_result.err);
20-
fprintf(stderr, "%.*s", (int)message.len, message.ptr);
21-
ddog_Error_drop(&new_result.err);
20+
// Create a ProfilesDictionary for the new API
21+
ddog_prof_ProfilesDictionaryHandle dict = {0};
22+
ddog_prof_Status dict_status = ddog_prof_ProfilesDictionary_new(&dict);
23+
if (dict_status.err != NULL) {
24+
fprintf(stderr, "Failed to create dictionary: %s\n", dict_status.err);
25+
ddog_prof_Status_drop(&dict_status);
2226
exit(EXIT_FAILURE);
2327
}
2428

25-
ddog_prof_Profile *profile = &new_result.ok;
29+
// Create profile using the dictionary
30+
ddog_prof_Profile profile = {0};
31+
ddog_prof_Status profile_status =
32+
ddog_prof_Profile_with_dictionary(&profile, &dict, sample_types, &period);
33+
if (profile_status.err != NULL) {
34+
fprintf(stderr, "Failed to create profile: %s\n", profile_status.err);
35+
ddog_prof_Status_drop(&profile_status);
36+
ddog_prof_ProfilesDictionary_drop(&dict);
37+
exit(EXIT_FAILURE);
38+
}
2639

40+
// Original API sample
2741
ddog_prof_Location root_location = {
2842
// yes, a zero-initialized mapping is valid
2943
.mapping = (ddog_prof_Mapping){0},
@@ -44,28 +58,107 @@ int main(void) {
4458
.labels = {&label, 1},
4559
};
4660

47-
for (int i = 0; i < 10000000; i++) {
61+
for (int i = 0; i < NUM_SAMPLES; i++) {
4862
label.num = i;
4963

50-
ddog_prof_Profile_Result add_result = ddog_prof_Profile_add(profile, sample, 0);
64+
ddog_prof_Profile_Result add_result = ddog_prof_Profile_add(&profile, sample, 0);
5165
if (add_result.tag != DDOG_PROF_PROFILE_RESULT_OK) {
5266
ddog_CharSlice message = ddog_Error_message(&add_result.err);
5367
fprintf(stderr, "%.*s", (int)message.len, message.ptr);
5468
ddog_Error_drop(&add_result.err);
5569
}
5670
}
5771

72+
// New API sample using the dictionary
73+
// Insert strings into the dictionary
74+
ddog_prof_StringId2 function_name_id, filename_id, label_key_id;
75+
76+
dict_status = ddog_prof_ProfilesDictionary_insert_str(
77+
&function_name_id, dict, DDOG_CHARSLICE_C("{main}"), DDOG_PROF_UTF8_OPTION_ASSUME);
78+
if (dict_status.err != NULL) {
79+
fprintf(stderr, "Failed to insert function name: %s\n", dict_status.err);
80+
ddog_prof_Status_drop(&dict_status);
81+
goto cleanup;
82+
}
83+
84+
dict_status = ddog_prof_ProfilesDictionary_insert_str(&filename_id, dict,
85+
DDOG_CHARSLICE_C("/srv/example/index.php"),
86+
DDOG_PROF_UTF8_OPTION_ASSUME);
87+
if (dict_status.err != NULL) {
88+
fprintf(stderr, "Failed to insert filename: %s\n", dict_status.err);
89+
ddog_prof_Status_drop(&dict_status);
90+
goto cleanup;
91+
}
92+
93+
dict_status = ddog_prof_ProfilesDictionary_insert_str(
94+
&label_key_id, dict, DDOG_CHARSLICE_C("unique_counter"), DDOG_PROF_UTF8_OPTION_ASSUME);
95+
if (dict_status.err != NULL) {
96+
fprintf(stderr, "Failed to insert label key: %s\n", dict_status.err);
97+
ddog_prof_Status_drop(&dict_status);
98+
goto cleanup;
99+
}
100+
101+
// Create a function using the dictionary IDs
102+
ddog_prof_FunctionId2 function_id;
103+
ddog_prof_Function2 function2 = {
104+
.name = function_name_id,
105+
.system_name = DDOG_PROF_STRINGID2_EMPTY,
106+
.file_name = filename_id,
107+
};
108+
109+
dict_status = ddog_prof_ProfilesDictionary_insert_function(&function_id, dict, &function2);
110+
if (dict_status.err != NULL) {
111+
fprintf(stderr, "Failed to insert function: %s\n", dict_status.err);
112+
ddog_prof_Status_drop(&dict_status);
113+
goto cleanup;
114+
}
115+
116+
// Create a location using the dictionary IDs
117+
ddog_prof_Location2 location2 = {
118+
.mapping = (ddog_prof_MappingId2){0}, // null mapping is valid
119+
.function = function_id,
120+
.address = 0,
121+
.line = 0,
122+
};
123+
124+
// New API sample using dictionary IDs
125+
ddog_prof_Label2 label2 = {
126+
.key = label_key_id,
127+
.str = DDOG_CHARSLICE_C(""),
128+
.num = 0,
129+
.num_unit = DDOG_CHARSLICE_C(""),
130+
};
131+
const ddog_prof_Sample2 sample2 = {
132+
.locations = {&location2, 1},
133+
.values = {&value, 1},
134+
.labels = {&label2, 1},
135+
};
136+
137+
for (int i = 0; i < NUM_SAMPLES; i++) {
138+
label2.num = i;
139+
140+
ddog_prof_Status add2_status = ddog_prof_Profile_add2(&profile, sample2, 0);
141+
if (add2_status.err != NULL) {
142+
fprintf(stderr, "add2 error: %s\n", add2_status.err);
143+
ddog_prof_Status_drop(&add2_status);
144+
}
145+
}
146+
58147
// printf("Press any key to reset and drop...");
59148
// getchar();
60149

61-
ddog_prof_Profile_Result reset_result = ddog_prof_Profile_reset(profile);
150+
cleanup:
151+
; // Can't have a declaration after a label pre-C23, so use an empty statement.
152+
ddog_prof_Profile_Result reset_result = ddog_prof_Profile_reset(&profile);
62153
if (reset_result.tag != DDOG_PROF_PROFILE_RESULT_OK) {
63154
ddog_CharSlice message = ddog_Error_message(&reset_result.err);
64155
fprintf(stderr, "%.*s", (int)message.len, message.ptr);
65156
ddog_Error_drop(&reset_result.err);
66157
}
67-
ddog_prof_Profile_drop(profile);
158+
ddog_prof_Profile_drop(&profile);
68159

160+
// Drop the dictionary
161+
ddog_prof_ProfilesDictionary_drop(&dict);
69162

70163
return 0;
71-
}
164+
}

0 commit comments

Comments
 (0)