Skip to content

Commit

Permalink
Fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
VianneyRuhlmann committed Sep 11, 2024
1 parent 9f2f729 commit 868ebe6
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 125 deletions.
34 changes: 17 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ members = [
"data-pipeline-ffi",
"ddsketch",
"tinybytes",
"agent-info",
]

default-members = [
Expand Down
148 changes: 62 additions & 86 deletions LICENSE-3rdparty.yml

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions agent-info/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ edition.workspace = true
version.workspace = true
license.workspace = true

[lib]
bench = false

[dependencies]
anyhow = "1.0.86"
arc-swap = "1.7.1"
Expand Down
30 changes: 18 additions & 12 deletions agent-info/src/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::sync::Arc;
use std::time::Duration;
use tokio::time::sleep;

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

#[derive(Debug)]
Expand Down Expand Up @@ -54,8 +55,8 @@ async fn fetch_info_with_state(

/// Fetch the info endpoint once and return the info.
///
/// Can be used for one-time access to the agent's info. If you need to access the info over
/// long period use `AgentInfoFetcher` to keep the info up-to-date.
/// Can be used for one-time access to the agent's info. If you need to access the info several
/// times use `AgentInfoFetcher` to keep the info up-to-date.
///
/// # Example
/// ```no_run
Expand All @@ -69,15 +70,15 @@ async fn fetch_info_with_state(
/// println!("Agent version is {}", agent_info.info.version.unwrap());
/// # Ok(())
/// # }
/// ``
/// ```
pub async fn fetch_info(info_endpoint: &Endpoint) -> Result<Box<AgentInfo>> {
match fetch_info_with_state(info_endpoint, None).await? {
FetchInfoStatus::NewState(info) => Ok(info),
FetchInfoStatus::SameState => Err(anyhow!("Invalid state header")),
}
}

/// Fetch the info endpoint and update an ArcSwap based on a given time interval.
/// Fetch the info endpoint and update an ArcSwap keeping it up-to-date.
///
/// Once the fetcher has been created you can get an Arc of the config by calling `get_info`.
/// You can then start the run method, the fetcher will update the AgentInfoArc based on the
Expand Down Expand Up @@ -119,17 +120,18 @@ pub struct AgentInfoFetcher {
impl AgentInfoFetcher {
/// Return a new `AgentInfoFetcher` fetching the `info_endpoint` on each `refresh_interval`
/// and updating the stored info.
pub fn new(info_endpoint: Endpoint, fetch_interval: Duration) -> Self {
pub fn new(info_endpoint: Endpoint, refresh_interval: Duration) -> Self {
Self {
info_endpoint,
info: Arc::new(ArcSwapOption::new(None)),
refresh_interval: fetch_interval,
refresh_interval,
}
}

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

const TEST_INFO_HASH: &str = "8c732aba385d605b010cd5bd12c03fef402eaefce989f0055aa4c7e92fe30077";

#[cfg_attr(miri, ignore)]
#[tokio::test]
async fn test_fetch_info_without_state() {
let server = MockServer::start();
Expand All @@ -215,7 +218,7 @@ mod tests {
when.path("/info");
then.status(200)
.header("content-type", "application/json")
.header(DATADOG_AGENT_STATE.to_string(), TEST_INFO_HASH)
.header("datadog-agent-state", TEST_INFO_HASH)
.body(TEST_INFO);
})
.await;
Expand All @@ -232,6 +235,7 @@ mod tests {
);
}

#[cfg_attr(miri, ignore)]
#[tokio::test]
async fn test_fetch_info_with_state() {
let server = MockServer::start();
Expand All @@ -240,7 +244,7 @@ mod tests {
when.path("/info");
then.status(200)
.header("content-type", "application/json")
.header(DATADOG_AGENT_STATE.to_string(), TEST_INFO_HASH)
.header("datadog-agent-state", TEST_INFO_HASH)
.body(TEST_INFO);
})
.await;
Expand All @@ -264,6 +268,7 @@ mod tests {
assert!(matches!(same_state_info_status, FetchInfoStatus::SameState));
}

#[cfg_attr(miri, ignore)]
#[tokio::test]
async fn test_fetch_info() {
let server = MockServer::start();
Expand All @@ -272,7 +277,7 @@ mod tests {
when.path("/info");
then.status(200)
.header("content-type", "application/json")
.header(DATADOG_AGENT_STATE.to_string(), TEST_INFO_HASH)
.header("datadog-agent-state", TEST_INFO_HASH)
.body(TEST_INFO);
})
.await;
Expand All @@ -289,6 +294,7 @@ mod tests {
);
}

#[cfg_attr(miri, ignore)]
#[tokio::test]
async fn test_agent_info_fetcher_run() {
let server = MockServer::start();
Expand All @@ -297,7 +303,7 @@ mod tests {
when.path("/info");
then.status(200)
.header("content-type", "application/json")
.header(DATADOG_AGENT_STATE.to_string(), "1")
.header("datadog-agent-state", "1")
.body(r#"{"version":"1"}"#);
})
.await;
Expand All @@ -323,7 +329,7 @@ mod tests {
when.path("/info");
then.status(200)
.header("content-type", "application/json")
.header(DATADOG_AGENT_STATE.to_string(), "2")
.header("datadog-agent-state", "2")
.body(r#"{"version":"2"}"#);
})
.await;
Expand Down
30 changes: 20 additions & 10 deletions examples/ffi/crashinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ extern "C" {
#include <vector>

static ddog_CharSlice to_slice_c_char(const char *s) { return {.ptr = s, .len = strlen(s)}; }
static ddog_CharSlice to_slice_string(std::string &s) {
static ddog_CharSlice to_slice_c_char(const char *s, std::size_t size) { return {.ptr = s, .len = size}; }
static ddog_CharSlice to_slice_string(std::string const &s) {
return {.ptr = s.data(), .len = s.length()};
}

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

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

std::vector<ddog_crasht_StackFrameNames> names;
for (uintptr_t i = 0; i < 20; ++i) {
std::vector<ddog_crasht_StackFrameNames> names{nb_elements};
for (auto i = 0; i < nb_elements; i++) {
auto const& [function_name, filename] = functions_and_filenames[i];

auto function_name_slice = to_slice_string(function_name);
auto res = ddog_crasht_demangle(function_name_slice, DDOG_CRASHT_DEMANGLE_OPTIONS_COMPLETE);
if (res.tag == DDOG_CRASHT_STRING_WRAPPER_RESULT_OK)
{
auto string_result = res.ok.message;
function_name_slice = to_slice_c_char((const char*)string_result.ptr, string_result.len);
}

names.push_back({.colno = ddog_Option_U32_some(i),
.filename = to_slice_string(filenames[i]),
.filename = to_slice_string(filename),
.lineno = ddog_Option_U32_some(2 * i + 3),
.name = to_slice_string(function_names[i])});
.name = function_name_slice});
}

std::vector<ddog_crasht_StackFrame> trace;
Expand Down
1 change: 1 addition & 0 deletions tools/docker/Dockerfile.build
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ RUN cargo search nothing --limit 1
# create stubs to cache compilation of dependendencies
COPY [ "Cargo.lock", "Cargo.toml", "./"]
COPY "alloc/Cargo.toml" "alloc/"
COPY "agent-info/Cargo.toml" "agent-info/"
COPY "build-common/Cargo.toml" "build-common/"
COPY "crashtracker/Cargo.toml" "crashtracker/"
COPY "crashtracker-ffi/Cargo.toml" "crashtracker-ffi/"
Expand Down

0 comments on commit 868ebe6

Please sign in to comment.