Skip to content

Commit

Permalink
Merge branch 'main' into david.lee/workflow-to-build-serverless-agent…
Browse files Browse the repository at this point in the history
…-testing
  • Loading branch information
morrisonlevi authored Oct 5, 2023
2 parents 5d74289 + ad8ff1f commit 6f8c206
Show file tree
Hide file tree
Showing 39 changed files with 390 additions and 416 deletions.
24 changes: 12 additions & 12 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ resolver = "2"
[workspace.package]
rust-version = "1.69"
edition = "2021"
version = "4.0.0"
version = "5.0.0"
license = "Apache-2.0"

[profile.dev]
Expand Down
1 change: 1 addition & 0 deletions ddtelemetry/src/data/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub struct Serie {
pub common: bool,
#[serde(rename = "type")]
pub _type: MetricType,
pub interval: u64,
}

#[derive(Serialize, Debug, Clone, Copy)]
Expand Down
2 changes: 2 additions & 0 deletions ddtelemetry/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ pub struct MetricBuckets {
}

impl MetricBuckets {
pub const METRICS_FLUSH_INTERVAL: time::Duration = time::Duration::from_secs(10);

pub fn flush_agregates(&mut self) {
let timestamp = unix_timestamp_now();
for (key, bucket) in self.buckets.drain() {
Expand Down
3 changes: 2 additions & 1 deletion ddtelemetry/src/worker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ impl TelemetryWorker {
points,
common: context.common,
_type: context.metric_type,
interval: MetricBuckets::METRICS_FLUSH_INTERVAL.as_secs(),
});
}

Expand Down Expand Up @@ -790,7 +791,7 @@ impl TelemetryWorkerBuilder {
client,
deadlines: scheduler::Scheduler::new(vec![
(
time::Duration::from_secs(10),
MetricBuckets::METRICS_FLUSH_INTERVAL,
LifecycleAction::FlushMetricAggr,
),
(telemetry_hearbeat_interval, LifecycleAction::FlushData),
Expand Down
4 changes: 2 additions & 2 deletions profiling-ffi/src/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use crate::Timespec;
use datadog_profiling::exporter;
use datadog_profiling::exporter::{ProfileExporter, Request};
use datadog_profiling::profile::profiled_endpoints;
use datadog_profiling::internal::ProfiledEndpointsStats;
use ddcommon::tag::Tag;
use ddcommon_ffi::slice::{AsBytes, ByteSlice, CharSlice, Slice};
use ddcommon_ffi::Error;
Expand Down Expand Up @@ -227,7 +227,7 @@ pub unsafe extern "C" fn ddog_prof_Exporter_Request_build(
files_to_compress_and_export: Slice<File>,
files_to_export_unmodified: Slice<File>,
optional_additional_tags: Option<&ddcommon_ffi::Vec<Tag>>,
optional_endpoints_stats: Option<&profiled_endpoints::ProfiledEndpointsStats>,
optional_endpoints_stats: Option<&ProfiledEndpointsStats>,
optional_internal_metadata_json: Option<&CharSlice>,
timeout_ms: u64,
) -> RequestBuildResult {
Expand Down
33 changes: 17 additions & 16 deletions profiling-ffi/src/profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021-Present Datadog, Inc.

use crate::Timespec;
use datadog_profiling::profile::{self, api, profiled_endpoints};
use datadog_profiling::api;
use datadog_profiling::internal;
use datadog_profiling::internal::ProfiledEndpointsStats;
use ddcommon_ffi::slice::{AsBytes, CharSlice, Slice};
use ddcommon_ffi::Error;
use std::convert::{TryFrom, TryInto};
Expand All @@ -16,17 +18,17 @@ use std::time::{Duration, SystemTime};
pub struct Profile {
// This may possibly be null, but will be a valid pointer to an owned
// Profile otherwise.
inner: *mut profile::Profile,
inner: *mut internal::Profile,
}

impl Profile {
fn new(profile: profile::Profile) -> Self {
fn new(profile: internal::Profile) -> Self {
Profile {
inner: Box::into_raw(Box::new(profile)),
}
}

fn take(&mut self) -> Option<Box<profile::Profile>> {
fn take(&mut self) -> Option<Box<internal::Profile>> {
// Leaving a null will help with double-free issues that can
// arise in C. Of course, it's best to never get there in the
// first place!
Expand Down Expand Up @@ -349,13 +351,12 @@ pub unsafe extern "C" fn ddog_prof_Profile_new(
start_time: Option<&Timespec>,
) -> ProfileNewResult {
let types: Vec<api::ValueType> = sample_types.into_slice().iter().map(Into::into).collect();
let start_time = start_time.map_or_else(SystemTime::now, SystemTime::from);
let period = period.map(Into::into);

let builder = profile::Profile::builder()
.period(period.map(Into::into))
.sample_types(types)
.start_time(start_time.map(SystemTime::from));

ProfileNewResult::Ok(Profile::new(builder.build()))
let internal_profile = internal::Profile::new(start_time, &types, period);
let ffi_profile = Profile::new(internal_profile);
ProfileNewResult::Ok(ffi_profile)
}

/// # Safety
Expand Down Expand Up @@ -422,7 +423,7 @@ unsafe fn ddog_prof_profile_add_impl(
) -> anyhow::Result<()> {
let profile = profile_ptr_to_inner(profile_ptr)?;

match sample.try_into().map(|s| profile.add(s, timestamp)) {
match sample.try_into().map(|s| profile.add_sample(s, timestamp)) {
Ok(r) => match r {
Ok(_) => Ok(()),
Err(err) => Err(err),
Expand All @@ -433,7 +434,7 @@ unsafe fn ddog_prof_profile_add_impl(

unsafe fn profile_ptr_to_inner<'a>(
profile_ptr: *mut Profile,
) -> anyhow::Result<&'a mut profile::Profile> {
) -> anyhow::Result<&'a mut internal::Profile> {
match profile_ptr.as_mut() {
None => anyhow::bail!("profile pointer was null"),
Some(inner_ptr) => match inner_ptr.inner.as_mut() {
Expand Down Expand Up @@ -618,7 +619,7 @@ pub unsafe extern "C" fn ddog_prof_Profile_add_upscaling_rule_proportional(
}

unsafe fn add_upscaling_rule(
profile: &mut profile::Profile,
profile: &mut internal::Profile,
offset_values: Slice<usize>,
label_name: CharSlice,
label_value: CharSlice,
Expand All @@ -642,7 +643,7 @@ pub struct EncodedProfile {
start: Timespec,
end: Timespec,
buffer: ddcommon_ffi::Vec<u8>,
endpoints_stats: Box<profiled_endpoints::ProfiledEndpointsStats>,
endpoints_stats: Box<ProfiledEndpointsStats>,
}

/// # Safety
Expand All @@ -659,8 +660,8 @@ pub unsafe extern "C" fn ddog_prof_EncodedProfile_drop(profile: Option<&mut Enco
}
}

impl From<profile::EncodedProfile> for EncodedProfile {
fn from(value: profile::EncodedProfile) -> Self {
impl From<internal::EncodedProfile> for EncodedProfile {
fn from(value: internal::EncodedProfile) -> Self {
let start = value.start.into();
let end = value.end.into();
let buffer = value.buffer.into();
Expand Down
15 changes: 7 additions & 8 deletions profiling-replayer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ mod profile_index;
mod replayer;

use clap::{command, Arg, ArgAction};
use datadog_profiling::profile;
use prost::Message;
use std::borrow::Cow;
use std::io::Cursor;
Expand Down Expand Up @@ -144,15 +143,15 @@ fn main() -> anyhow::Result<()> {
std::fs::read(input)?
};

let pprof = profile::pprof::Profile::decode(&mut Cursor::new(source))?;
let pprof = datadog_profiling::pprof::Profile::decode(&mut Cursor::new(source))?;

let mut replayer = Replayer::try_from(&pprof)?;

let mut outprof = profile::Profile::builder()
.start_time(Some(replayer.start_time))
.sample_types(replayer.sample_types.clone())
.period(replayer.period)
.build();
let mut outprof = datadog_profiling::internal::Profile::new(
replayer.start_time,
&replayer.sample_types,
replayer.period,
);

// Before benchmarking, let's calculate some statistics.
// No point doing that if there aren't at least 4 samples though.
Expand Down Expand Up @@ -184,7 +183,7 @@ fn main() -> anyhow::Result<()> {

let before = Instant::now();
for (timestamp, sample) in samples {
outprof.add(sample, timestamp)?;
outprof.add_sample(sample, timestamp)?;
}
let duration = before.elapsed();

Expand Down
2 changes: 1 addition & 1 deletion profiling-replayer/src/profile_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2023-Present Datadog, Inc.

use anyhow::Result;
use datadog_profiling::profile::pprof::{Function, Location, Mapping, Profile};
use datadog_profiling::pprof::{Function, Location, Mapping, Profile};
use std::collections::HashMap;

pub struct ProfileIndex<'pprof> {
Expand Down
4 changes: 3 additions & 1 deletion profiling-replayer/src/replayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2023-Present Datadog, Inc.

use crate::profile_index::ProfileIndex;
use datadog_profiling::profile::{api, pprof, Timestamp};
use datadog_profiling::api;
use datadog_profiling::internal::Timestamp;
use datadog_profiling::pprof;
use std::ops::{Add, Sub};
use std::time::{Duration, SystemTime, UNIX_EPOCH};

Expand Down
13 changes: 6 additions & 7 deletions profiling/examples/profiles.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021-Present Datadog, Inc.

use datadog_profiling::profile::{api, Profile};
use datadog_profiling::api;
use datadog_profiling::internal::Profile;
use std::io::Write;
use std::process::exit;
use std::time::SystemTime;

// Keep this in-sync with profiles.c
fn main() {
Expand Down Expand Up @@ -54,13 +56,10 @@ fn main() {
labels: vec![],
};

// Not setting .start_time intentionally to use the current time.
let mut profile: Profile = Profile::builder()
.sample_types(sample_types)
.period(Some(period))
.build();
// Intentionally use the current time.
let mut profile = Profile::new(SystemTime::now(), &sample_types, Some(period));

match profile.add(sample, None) {
match profile.add_sample(sample, None) {
Ok(_) => {}
Err(_) => exit(1),
}
Expand Down
2 changes: 1 addition & 1 deletion profiling/src/profile/api.rs → profiling/src/api.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021-Present Datadog, Inc.

use crate::profile::pprof;
use crate::pprof;
use std::ops::{Add, Sub};
use std::time::{Duration, SystemTime, UNIX_EPOCH};

Expand Down
2 changes: 1 addition & 1 deletion profiling/src/exporter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub use connector::uds::{socket_path_from_uri, socket_path_to_uri};
#[cfg(windows)]
pub use connector::named_pipe::{named_pipe_path_from_uri, named_pipe_path_to_uri};

use crate::profile::profiled_endpoints::ProfiledEndpointsStats;
use crate::internal::ProfiledEndpointsStats;

const DURATION_ZERO: std::time::Duration = std::time::Duration::from_millis(0);

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2023-Present Datadog, Inc.
use super::*;
use crate::profile::profiled_endpoints::ProfiledEndpointsStats;

pub struct Endpoints {
pub endpoint_label: StringId,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 6f8c206

Please sign in to comment.