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

Use append() for writing telemetry lock to file #585

Merged
merged 1 commit into from
Aug 12, 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
12 changes: 8 additions & 4 deletions ddtelemetry/src/worker/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ddcommon::HttpRequestBuilder;
use http::{Request, Response};
use hyper::Body;
use std::{
fs::File,
fs::OpenOptions,
future::Future,
io::Write,
pin::Pin,
Expand Down Expand Up @@ -46,7 +46,11 @@ pub fn from_config(c: &Config) -> Box<dyn HttpClient + Sync + Send> {
.expect("file urls should always have been encoded in authority");
return Box::new(MockClient {
file: Arc::new(Mutex::new(Box::new(
File::create(file_path).expect("Couldn't open mock client file"),
OpenOptions::new()
.create(true)
.append(true)
.open(file_path.as_path())
.expect("Couldn't open mock client file"),
))),
});
}
Expand Down Expand Up @@ -78,12 +82,12 @@ impl HttpClient for MockClient {
fn request(&self, mut req: Request<hyper::Body>) -> ResponseFuture {
let s = self.clone();
Box::pin(async move {
let body = hyper::body::to_bytes(req.body_mut()).await?;
let mut body = hyper::body::to_bytes(req.body_mut()).await?.to_vec();
body.push(b'\n');

{
let mut writer = s.file.lock().expect("mutex poisoned");
writer.write_all(body.as_ref()).unwrap();
writer.write_all(b"\n").unwrap();
}

Ok(Response::builder()
Expand Down
2 changes: 1 addition & 1 deletion tools/docker/Dockerfile.build
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ENV PATH="/root/.cargo/bin:$PATH"
ARG CARGO_BUILD_INCREMENTAL
ARG CARGO_NET_RETRY
ENV CARGO_NET_RETRY="${CARGO_NET_RETRY}"
RUN cargo install cbindgen && cargo install bindgen-cli --locked && rm -rf /root/.cargo/registry /root/.cargo/git
RUN cargo install cbindgen --version "^0.26" && cargo install bindgen-cli --locked && rm -rf /root/.cargo/registry /root/.cargo/git
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this specify a version for bindgen-cli?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have no idea.


FROM alpine_aws_cli as alpine_builder
COPY --from=alpine_cbindgen /root/.cargo/bin/cbindgen /usr/local/bin/cbindgen
Expand Down