Skip to content

Commit 506770d

Browse files
Fix CI
1 parent 9f2f729 commit 506770d

File tree

7 files changed

+133
-136
lines changed

7 files changed

+133
-136
lines changed

Cargo.lock

Lines changed: 26 additions & 26 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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ members = [
3434
"data-pipeline-ffi",
3535
"ddsketch",
3636
"tinybytes",
37+
"agent-info",
3738
]
3839

3940
default-members = [

LICENSE-3rdparty.yml

Lines changed: 62 additions & 86 deletions
Large diffs are not rendered by default.

agent-info/Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@ edition.workspace = true
66
version.workspace = true
77
license.workspace = true
88

9+
[lib]
10+
bench = false
11+
912
[dependencies]
1013
anyhow = "1.0.86"
1114
arc-swap = "1.7.1"
1215
ddcommon = { version = "12.0.0", path = "../ddcommon" }
1316
hyper = { version = "0.14", features = ["client"] }
1417
serde = "1.0.209"
1518
serde_json = "1.0.127"
16-
tokio = "1.40.0"
19+
tokio = "1.37.0"
1720

1821
[dev-dependencies]
1922
httpmock = "0.7.0"
20-
tokio = { version = "1.40.0", features = ["time", "test-util"] }
23+
tokio = { version = "1.37.0", features = ["time", "test-util"] }

agent-info/src/fetcher.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::sync::Arc;
1212
use std::time::Duration;
1313
use tokio::time::sleep;
1414

15+
#[allow(clippy::declare_interior_mutable_const)]
1516
const DATADOG_AGENT_STATE: HeaderName = HeaderName::from_static("datadog-agent-state");
1617

1718
#[derive(Debug)]
@@ -54,8 +55,8 @@ async fn fetch_info_with_state(
5455

5556
/// Fetch the info endpoint once and return the info.
5657
///
57-
/// Can be used for one-time access to the agent's info. If you need to access the info over
58-
/// long period use `AgentInfoFetcher` to keep the info up-to-date.
58+
/// Can be used for one-time access to the agent's info. If you need to access the info several
59+
/// times use `AgentInfoFetcher` to keep the info up-to-date.
5960
///
6061
/// # Example
6162
/// ```no_run
@@ -69,15 +70,15 @@ async fn fetch_info_with_state(
6970
/// println!("Agent version is {}", agent_info.info.version.unwrap());
7071
/// # Ok(())
7172
/// # }
72-
/// ``
73+
/// ```
7374
pub async fn fetch_info(info_endpoint: &Endpoint) -> Result<Box<AgentInfo>> {
7475
match fetch_info_with_state(info_endpoint, None).await? {
7576
FetchInfoStatus::NewState(info) => Ok(info),
7677
FetchInfoStatus::SameState => Err(anyhow!("Invalid state header")),
7778
}
7879
}
7980

80-
/// Fetch the info endpoint and update an ArcSwap based on a given time interval.
81+
/// Fetch the info endpoint and update an ArcSwap keeping it up-to-date.
8182
///
8283
/// Once the fetcher has been created you can get an Arc of the config by calling `get_info`.
8384
/// You can then start the run method, the fetcher will update the AgentInfoArc based on the
@@ -119,17 +120,18 @@ pub struct AgentInfoFetcher {
119120
impl AgentInfoFetcher {
120121
/// Return a new `AgentInfoFetcher` fetching the `info_endpoint` on each `refresh_interval`
121122
/// and updating the stored info.
122-
pub fn new(info_endpoint: Endpoint, fetch_interval: Duration) -> Self {
123+
pub fn new(info_endpoint: Endpoint, refresh_interval: Duration) -> Self {
123124
Self {
124125
info_endpoint,
125126
info: Arc::new(ArcSwapOption::new(None)),
126-
refresh_interval: fetch_interval,
127+
refresh_interval,
127128
}
128129
}
129130

130131
/// Start fetching the info endpoint with the given interval.
131132
///
132-
/// Warning: This method does not return and should be called within a dedicated task.
133+
/// # Warning
134+
/// This method does not return and should be called within a dedicated task.
133135
pub async fn run(&self) {
134136
loop {
135137
let current_info = self.info.load();
@@ -207,6 +209,7 @@ mod tests {
207209

208210
const TEST_INFO_HASH: &str = "8c732aba385d605b010cd5bd12c03fef402eaefce989f0055aa4c7e92fe30077";
209211

212+
#[cfg_attr(miri, ignore)]
210213
#[tokio::test]
211214
async fn test_fetch_info_without_state() {
212215
let server = MockServer::start();
@@ -215,7 +218,7 @@ mod tests {
215218
when.path("/info");
216219
then.status(200)
217220
.header("content-type", "application/json")
218-
.header(DATADOG_AGENT_STATE.to_string(), TEST_INFO_HASH)
221+
.header("datadog-agent-state", TEST_INFO_HASH)
219222
.body(TEST_INFO);
220223
})
221224
.await;
@@ -232,6 +235,7 @@ mod tests {
232235
);
233236
}
234237

238+
#[cfg_attr(miri, ignore)]
235239
#[tokio::test]
236240
async fn test_fetch_info_with_state() {
237241
let server = MockServer::start();
@@ -240,7 +244,7 @@ mod tests {
240244
when.path("/info");
241245
then.status(200)
242246
.header("content-type", "application/json")
243-
.header(DATADOG_AGENT_STATE.to_string(), TEST_INFO_HASH)
247+
.header("datadog-agent-state", TEST_INFO_HASH)
244248
.body(TEST_INFO);
245249
})
246250
.await;
@@ -264,6 +268,7 @@ mod tests {
264268
assert!(matches!(same_state_info_status, FetchInfoStatus::SameState));
265269
}
266270

271+
#[cfg_attr(miri, ignore)]
267272
#[tokio::test]
268273
async fn test_fetch_info() {
269274
let server = MockServer::start();
@@ -272,7 +277,7 @@ mod tests {
272277
when.path("/info");
273278
then.status(200)
274279
.header("content-type", "application/json")
275-
.header(DATADOG_AGENT_STATE.to_string(), TEST_INFO_HASH)
280+
.header("datadog-agent-state", TEST_INFO_HASH)
276281
.body(TEST_INFO);
277282
})
278283
.await;
@@ -289,6 +294,7 @@ mod tests {
289294
);
290295
}
291296

297+
#[cfg_attr(miri, ignore)]
292298
#[tokio::test]
293299
async fn test_agent_info_fetcher_run() {
294300
let server = MockServer::start();
@@ -297,7 +303,7 @@ mod tests {
297303
when.path("/info");
298304
then.status(200)
299305
.header("content-type", "application/json")
300-
.header(DATADOG_AGENT_STATE.to_string(), "1")
306+
.header("datadog-agent-state", "1")
301307
.body(r#"{"version":"1"}"#);
302308
})
303309
.await;
@@ -323,7 +329,7 @@ mod tests {
323329
when.path("/info");
324330
then.status(200)
325331
.header("content-type", "application/json")
326-
.header(DATADOG_AGENT_STATE.to_string(), "2")
332+
.header("datadog-agent-state", "2")
327333
.body(r#"{"version":"2"}"#);
328334
})
329335
.await;

examples/ffi/crashinfo.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ extern "C" {
1515
#include <vector>
1616

1717
static ddog_CharSlice to_slice_c_char(const char *s) { return {.ptr = s, .len = strlen(s)}; }
18-
static ddog_CharSlice to_slice_string(std::string &s) {
18+
static ddog_CharSlice to_slice_c_char(const char *s, std::size_t size) { return {.ptr = s, .len = size}; }
19+
static ddog_CharSlice to_slice_string(std::string const &s) {
1920
return {.ptr = s.data(), .len = s.length()};
2021
}
2122

@@ -39,19 +40,28 @@ void check_result(ddog_crasht_Result result, const char *msg) {
3940
void add_stacktrace(std::unique_ptr<ddog_crasht_CrashInfo, Deleter> &crashinfo) {
4041

4142
// Collect things into vectors so they stay alive till the function exits
42-
std::vector<std::string> filenames;
43-
std::vector<std::string> function_names;
44-
for (uintptr_t i = 0; i < 20; ++i) {
45-
filenames.push_back("/path/to/code/file_" + std::to_string(i));
46-
function_names.push_back("func_" + std::to_string(i));
43+
constexpr std::size_t nb_elements = 20;
44+
std::vector<std::pair<std::string, std::string>> functions_and_filenames{nb_elements};
45+
for (uintptr_t i = 0; i < nb_elements; ++i) {
46+
functions_and_filenames.push_back({"func_" + std::to_string(i), "/path/to/code/file_" + std::to_string(i)});
4747
}
4848

49-
std::vector<ddog_crasht_StackFrameNames> names;
50-
for (uintptr_t i = 0; i < 20; ++i) {
49+
std::vector<ddog_crasht_StackFrameNames> names{nb_elements};
50+
for (auto i = 0; i < nb_elements; i++) {
51+
auto const& [function_name, filename] = functions_and_filenames[i];
52+
53+
auto function_name_slice = to_slice_string(function_name);
54+
auto res = ddog_crasht_demangle(function_name_slice, DDOG_CRASHT_DEMANGLE_OPTIONS_COMPLETE);
55+
if (res.tag == DDOG_CRASHT_STRING_WRAPPER_RESULT_OK)
56+
{
57+
auto string_result = res.ok.message;
58+
function_name_slice = to_slice_c_char((const char*)string_result.ptr, string_result.len);
59+
}
60+
5161
names.push_back({.colno = ddog_Option_U32_some(i),
52-
.filename = to_slice_string(filenames[i]),
62+
.filename = to_slice_string(filename),
5363
.lineno = ddog_Option_U32_some(2 * i + 3),
54-
.name = to_slice_string(function_names[i])});
64+
.name = function_name_slice});
5565
}
5666

5767
std::vector<ddog_crasht_StackFrame> trace;

tools/docker/Dockerfile.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ RUN cargo search nothing --limit 1
6969
# create stubs to cache compilation of dependendencies
7070
COPY [ "Cargo.lock", "Cargo.toml", "./"]
7171
COPY "alloc/Cargo.toml" "alloc/"
72+
COPY "agent-info/Cargo.toml" "agent-info/"
7273
COPY "build-common/Cargo.toml" "build-common/"
7374
COPY "crashtracker/Cargo.toml" "crashtracker/"
7475
COPY "crashtracker-ffi/Cargo.toml" "crashtracker-ffi/"

0 commit comments

Comments
 (0)