Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a DogStatsD API in the sidecar #399

Merged
merged 22 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock

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

81 changes: 81 additions & 0 deletions LICENSE-3rdparty.yml

Large diffs are not rendered by default.

123 changes: 121 additions & 2 deletions sidecar-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ use datadog_sidecar::agent_remote_config::{
};
use datadog_sidecar::config;
use datadog_sidecar::config::LogMethod;
use datadog_sidecar::dogstatsd::DogStatsDAction;
use datadog_sidecar::one_way_shared_memory::{OneWayShmReader, ReaderOpener};
use datadog_sidecar::service::{
blocking::{self, SidecarTransport},
InstanceId, QueueId, RuntimeMetadata, SerializedTracerHeaderTags, SessionConfig, SidecarAction,
};
use ddcommon::tag::Tag;
use ddcommon::Endpoint;
use ddcommon_ffi as ffi;
use ddcommon_ffi::MaybeError;
Expand Down Expand Up @@ -389,7 +391,8 @@ pub extern "C" fn ddog_sidecar_is_closed(transport: &mut Box<SidecarTransport>)
pub unsafe extern "C" fn ddog_sidecar_session_set_config(
transport: &mut Box<SidecarTransport>,
session_id: ffi::CharSlice,
endpoint: &Endpoint,
agent_endpoint: &Endpoint,
dogstatsd_endpoint: &Endpoint,
flush_interval_milliseconds: u64,
force_flush_size: usize,
force_drop_size: usize,
Expand All @@ -400,7 +403,8 @@ pub unsafe extern "C" fn ddog_sidecar_session_set_config(
transport,
session_id.to_utf8_lossy().into(),
&SessionConfig {
endpoint: endpoint.clone(),
endpoint: agent_endpoint.clone(),
dogstatsd_endpoint: dogstatsd_endpoint.clone(),
flush_interval: Duration::from_millis(flush_interval_milliseconds),
force_flush_size,
force_drop_size,
Expand Down Expand Up @@ -523,3 +527,118 @@ pub unsafe extern "C" fn ddog_sidecar_stats(
buf.copy_from_slice(str.as_bytes());
ffi::CharSlice::from_raw_parts(malloced as *mut c_char, size)
}

#[no_mangle]
#[allow(clippy::missing_safety_doc)]
pub unsafe extern "C" fn ddog_sidecar_dogstatsd_count(
transport: &mut Box<SidecarTransport>,
instance_id: &InstanceId,
metric: ffi::CharSlice,
value: i64,
tags: Option<&ddcommon_ffi::Vec<Tag>>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we passa all the tags all the time? Some of them (e.g lang, lang_interpreter, lang_version, tracer_version, runtimeId won't change from one session to another.
Also, not saying we should do it, but we do process at least some tags in .NET (cf this), do you do it on php side?

Copy link
Contributor

@bwoebi bwoebi May 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we do that on the PHP side. The language/version/runtime id tags could be probably directly provided within the sidecar. PR #398 anyway transfers that language/version info as part of session info. We could just use that part and merge it here. Should be more efficient too :-)
Would make sense to me, great point, Pierre!

Copy link
Contributor

@pierotibou pierotibou May 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If processing happens on the client side we should document it Somewhere in the API that we expect input data to be already processed.

) -> MaybeError {
try_c!(blocking::send_dogstatsd_actions(
transport,
instance_id,
vec![DogStatsDAction::Count(
metric.to_utf8_lossy().into_owned(),
value,
tags.map(|tags| tags.iter().cloned().collect())
.unwrap_or_default()
),],
));

MaybeError::None
}

#[no_mangle]
#[allow(clippy::missing_safety_doc)]
pub unsafe extern "C" fn ddog_sidecar_dogstatsd_distribution(
transport: &mut Box<SidecarTransport>,
instance_id: &InstanceId,
metric: ffi::CharSlice,
value: f64,
tags: Option<&ddcommon_ffi::Vec<Tag>>,
) -> MaybeError {
try_c!(blocking::send_dogstatsd_actions(
transport,
instance_id,
vec![DogStatsDAction::Distribution(
metric.to_utf8_lossy().into_owned(),
value,
tags.map(|tags| tags.iter().cloned().collect())
.unwrap_or_default()
),],
));

MaybeError::None
}

#[no_mangle]
#[allow(clippy::missing_safety_doc)]
pub unsafe extern "C" fn ddog_sidecar_dogstatsd_gauge(
transport: &mut Box<SidecarTransport>,
instance_id: &InstanceId,
metric: ffi::CharSlice,
value: f64,
tags: Option<&ddcommon_ffi::Vec<Tag>>,
) -> MaybeError {
try_c!(blocking::send_dogstatsd_actions(
transport,
instance_id,
vec![DogStatsDAction::Gauge(
metric.to_utf8_lossy().into_owned(),
value,
tags.map(|tags| tags.iter().cloned().collect())
.unwrap_or_default()
),],
));

MaybeError::None
}

#[no_mangle]
#[allow(clippy::missing_safety_doc)]
pub unsafe extern "C" fn ddog_sidecar_dogstatsd_histogram(
transport: &mut Box<SidecarTransport>,
instance_id: &InstanceId,
metric: ffi::CharSlice,
value: f64,
tags: Option<&ddcommon_ffi::Vec<Tag>>,
) -> MaybeError {
try_c!(blocking::send_dogstatsd_actions(
transport,
instance_id,
vec![DogStatsDAction::Histogram(
metric.to_utf8_lossy().into_owned(),
value,
tags.map(|tags| tags.iter().cloned().collect())
.unwrap_or_default()
),],
));

MaybeError::None
}

#[no_mangle]
#[allow(clippy::missing_safety_doc)]
pub unsafe extern "C" fn ddog_sidecar_dogstatsd_set(
transport: &mut Box<SidecarTransport>,
instance_id: &InstanceId,
metric: ffi::CharSlice,
value: i64,
tags: Option<&ddcommon_ffi::Vec<Tag>>,
) -> MaybeError {
try_c!(blocking::send_dogstatsd_actions(
transport,
instance_id,
vec![DogStatsDAction::Set(
metric.to_utf8_lossy().into_owned(),
value,
tags.map(|tags| tags.iter().cloned().collect())
.unwrap_or_default()
),],
));

MaybeError::None
}
2 changes: 2 additions & 0 deletions sidecar-ffi/tests/sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ fn test_ddog_sidecar_register_app() {
api_key: None,
url: hyper::Uri::from_static("http://localhost:8082/"),
},
&Endpoint::default(),
1000,
1000000,
10000000,
Expand Down Expand Up @@ -131,6 +132,7 @@ fn test_ddog_sidecar_register_app() {
api_key: None,
url: hyper::Uri::from_static("http://localhost:8083/"),
},
&Endpoint::default(),
1000,
1000000,
10000000,
Expand Down
1 change: 1 addition & 0 deletions sidecar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ libc = { version = "0.2" }

# watchdog and self telemetry
memory-stats = { version = "1.0.0" }
cadence = "1.3.0"

[dependencies.windows]
features = [
Expand Down
Loading
Loading