Skip to content

Commit

Permalink
0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jerbly committed Aug 10, 2024
1 parent 7baecdb commit ccee820
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 6 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# 0.3.0

- `service.name` must be sent vs `service_name` now for consistency
- a `PATCH` to update the `ttl` will extend from the current span duration. e.g. patching 10000 to a span that has been running for 34125ms will set the ttl to 44125
- added `test.sh` to run through the operations and expiration behaviour

# 0.2.1

- API changed to use HTTP verbs for crud

# 0.1.0

- First release
2 changes: 1 addition & 1 deletion 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
@@ -1,6 +1,6 @@
[package]
name = "testevents"
version = "0.2.1"
version = "0.3.0"
edition = "2021"
authors = ["Jeremy Blythe <[email protected]>"]
repository = "https://github.com/jerbly/testevents"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ A service to make it easier to create Honeycomb spans in some restricted environ

Spans are "closed" with a `DELETE` to `/{trace_id}/{span_id}/` - this creates the Honeycomb event with a calculated `duration_ms` from the "open" call.

`PATCH` to `/{trace_id}/{span_id}/` can be used to merge a set of key-values into the "open" span. Existing keys will have their values overwritten. You can change the `ttl` to extend or shorten the time to expiry.
`PATCH` to `/{trace_id}/{span_id}/` can be used to merge a set of key-values into the "open" span. Existing keys will have their values overwritten. You can change the `ttl` to extend or shorten the time to expiry. e.g. patching 10000 to a span that has been running for 34125ms will set the ttl to 44125.

## Installing

Expand Down Expand Up @@ -41,7 +41,7 @@ Make a root span:
curl -i -X POST \
'http://127.0.0.1:3003/' \
-H 'Content-Type: application/json' \
-d '{"service_name":"jerbly-test",
-d '{"service.name":"jerbly-test",
"name":"test",
"hello":"world",
"ttl":600000}'
Expand All @@ -60,7 +60,7 @@ Make a child span:
curl -i -X POST \
'http://127.0.0.1:3003/4c278c122e123f87036b44772861b9f4/5370f70191c4b03c/' \
-H 'Content-Type: application/json' \
-d '{"service_name":"jerbly-test",
-d '{"service.name":"jerbly-test",
"name":"test_child",
"hello":"child span",
"ttl":600000}'
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ async fn main() -> anyhow::Result<()> {
// run it
let bind_port = std::env::var("TESTEVENTS_PORT").unwrap_or("3003".to_string());
let listener = tokio::net::TcpListener::bind(format!("0.0.0.0:{bind_port}")).await?;
println!("testevents version: {}", env!("CARGO_PKG_VERSION"));
println!("listening on {}", listener.local_addr()?);
axum::serve(listener, app).await?;

Expand Down
10 changes: 9 additions & 1 deletion src/span_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,20 @@ impl SpanAttributes {
.unwrap_or_default()
.clone_into(&mut self.service_name),
"status_code" => self.status_code = value.as_i64().unwrap_or_default(),
"ttl" => self.ttl = value.as_i64().unwrap_or_default(),
"ttl" => self.set_ttl(value.as_i64().unwrap_or_default()),
_ => {
self.extra.insert(key, value);
}
}
}
}

fn set_ttl(&mut self, ttl: i64) {
// set a new ttl which is millis from timestamp + incoming ttl
let now = Utc::now().timestamp_millis();
let current_used_millis = now - self.timestamp.timestamp_millis();
self.ttl = current_used_millis + ttl;
}
}

#[derive(Debug, Serialize, Clone)]
Expand Down Expand Up @@ -159,6 +166,7 @@ impl SpanAttributes {

#[derive(Deserialize, Debug)]
pub struct QueryAttributes {
#[serde(rename = "service.name")]
service_name: String,
name: String,
ttl: Option<i64>,
Expand Down
25 changes: 25 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
url="http://localhost:3003"

echo "Make a root span"
response=$(curl -s -X POST $url/ -H 'Content-Type: application/json' -d '{"service.name":"jerbly-test","name":"test","hello":"world","ttl":3600000}')
root_span_id=$(echo $response | jq -r '.span_id')
root_trace_id=$(echo $response | jq -r '.trace_id')
sleep 1

echo "Make a child span"
response=$(curl -s -X POST $url/$root_trace_id/$root_span_id/ -H 'Content-Type: application/json' -d '{"service.name":"jerbly-test","name":"child","ttl":3600000}')
span_id=$(echo $response | jq -r '.span_id')
sleep 1

echo "Patch the child span with a new value and a shorter ttl - and let it timeout"
curl -s -X PATCH $url/$root_trace_id/$span_id/ -H 'Content-Type: application/json' -d '{"new":true,"ttl":1000}'
sleep 2

echo ""
echo "Check for a 404 on an attempt to DELETE the expired child span"
response=$(curl -s -o /dev/null -w "%{http_code}" -X DELETE $url/$root_trace_id/$span_id/)
echo "Status code: $response"

echo "Close the root span"
curl -s -X DELETE $url/$root_trace_id/$root_span_id/

0 comments on commit ccee820

Please sign in to comment.